Mercurial > hg > beaglert
comparison examples/basic_libpd/render.cpp @ 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 | 0e1e0dfe24c5 |
children | 6e454ebd9cc4 |
comparison
equal
deleted
inserted
replaced
347:d2ce15eed8c1 | 348:db1e024858b0 |
---|---|
74 dtm = new DigitalToMessage* [context->digitalChannels]; | 74 dtm = new DigitalToMessage* [context->digitalChannels]; |
75 if(context->digitalChannels > 0){ | 75 if(context->digitalChannels > 0){ |
76 for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){ | 76 for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){ |
77 dtm[ch] = new DigitalToMessage; | 77 dtm[ch] = new DigitalToMessage; |
78 dtm[ch]->setCallback(sendDigitalMessage, receiverNames[ch]); | 78 dtm[ch]->setCallback(sendDigitalMessage, receiverNames[ch]); |
79 pinMode(context, 0, ch, OUTPUT); | 79 pinMode(context, 0, ch, INPUT); |
80 } | 80 } |
81 } | 81 } |
82 midi.readFrom(0); | 82 midi.readFrom(0); |
83 midi.writeTo(0); | 83 midi.writeTo(0); |
84 #ifdef PARSE_MIDI | 84 #ifdef PARSE_MIDI |
252 } | 252 } |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 //then digital | 256 //then digital |
257 //TODO: in multiple places we assume that the number of digitals is same as number of audio | 257 //TODO: in multiple places below we assume that the number of digitals is same as number of audio |
258 // digital in at message-rate | |
258 for(unsigned int n = 0; n < context->digitalChannels; ++n){ | 259 for(unsigned int n = 0; n < context->digitalChannels; ++n){ |
259 // TODO: note that we consider only the first sample of the block | 260 // note that we consider only the first sample of the block |
260 // considering all of them is notably more expensive | 261 // considering all of them is notably more expensive |
261 // TODO: only process the channels marked as such | 262 // TODO: only process the channels marked as such |
262 dtm[n]->process(n + 16, &context->digital[audioFrameBase], 1); | 263 dtm[n]->process(n + 16, &context->digital[audioFrameBase], 1); |
263 } | 264 } |
265 // digital in at signal-rate | |
266 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { | |
267 for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8); | |
268 k < 16; ++k, p1 += gLibpdBlockSize) { | |
269 // note that we only write the last sample of the block | |
270 // writing all of them is notably more expensive. | |
271 | |
272 // TODO: only process the channels marked as such | |
273 unsigned int digitalFrame = audioFrameBase + j; | |
274 *p1 = digitalRead(context, digitalFrame, k); | |
275 } | |
276 } | |
264 | 277 |
265 libpd_process_sys(); // process the block | 278 libpd_process_sys(); // process the block |
266 | 279 |
267 //digital | 280 //digital out |
281 // digital at message-rate | |
268 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { | 282 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { |
269 unsigned int digitalFrame = (audioFrameBase + j); | 283 unsigned int digitalFrame = (audioFrameBase + j); |
270 for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8); | 284 for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8); |
271 k < context->digitalChannels; k++, p1 += gLibpdBlockSize) { | 285 k < context->digitalChannels; k++, p1 += gLibpdBlockSize) { |
272 // TODO: only process the channels marked as such | 286 // TODO: only process the channels marked as such |
273 digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5); | 287 digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5); |
274 } | 288 } |
275 } | 289 } |
290 | |
276 //audio | 291 //audio |
277 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { | 292 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { |
278 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) { | 293 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) { |
279 audioWrite(context, audioFrameBase + j, k, *p1); | 294 audioWrite(context, audioFrameBase + j, k, *p1); |
280 } | 295 } |