changeset 348:db1e024858b0 prerelease

libpd: added digital ins through [adc~]
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 07 Jun 2016 22:28:23 +0100
parents d2ce15eed8c1
children 6e454ebd9cc4
files examples/basic_libpd/render.cpp
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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) {