# HG changeset patch # User Giulio Moro # Date 1465334903 -3600 # Node ID db1e024858b040403434162b095a05139e6ddbe5 # Parent d2ce15eed8c1b58616402bd6005977b18f55f521 libpd: added digital ins through [adc~] diff -r d2ce15eed8c1 -r db1e024858b0 examples/basic_libpd/render.cpp --- a/examples/basic_libpd/render.cpp Tue Jun 07 17:29:54 2016 +0100 +++ b/examples/basic_libpd/render.cpp Tue Jun 07 22:28:23 2016 +0100 @@ -76,7 +76,7 @@ for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){ dtm[ch] = new DigitalToMessage; dtm[ch]->setCallback(sendDigitalMessage, receiverNames[ch]); - pinMode(context, 0, ch, OUTPUT); + pinMode(context, 0, ch, INPUT); } } midi.readFrom(0); @@ -254,17 +254,31 @@ } //then digital - //TODO: in multiple places we assume that the number of digitals is same as number of audio + //TODO: in multiple places below we assume that the number of digitals is same as number of audio + // digital in at message-rate for(unsigned int n = 0; n < context->digitalChannels; ++n){ - // TODO: note that we consider only the first sample of the block + // note that we consider only the first sample of the block // considering all of them is notably more expensive // TODO: only process the channels marked as such dtm[n]->process(n + 16, &context->digital[audioFrameBase], 1); } + // digital in at signal-rate + for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { + for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8); + k < 16; ++k, p1 += gLibpdBlockSize) { + // note that we only write the last sample of the block + // writing all of them is notably more expensive. + + // TODO: only process the channels marked as such + unsigned int digitalFrame = audioFrameBase + j; + *p1 = digitalRead(context, digitalFrame, k); + } + } libpd_process_sys(); // process the block - //digital + //digital out + // digital at message-rate for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { unsigned int digitalFrame = (audioFrameBase + j); for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8); @@ -273,6 +287,7 @@ digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5); } } + //audio for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {