Mercurial > hg > beaglert
comparison core/default_libpd_render.cpp @ 537:bfcbeb437869 API-update
Updated RTAudioSettings with in/out, ported some examples and libpd
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 24 Jun 2016 01:36:07 +0100 |
parents | 485913c58a61 |
children |
comparison
equal
deleted
inserted
replaced
528:5c8f46fcd4d0 | 537:bfcbeb437869 |
---|---|
134 snprintf(str, strSize, "%s%s", folder, file); | 134 snprintf(str, strSize, "%s%s", folder, file); |
135 if(access(str, F_OK) == -1 ) { | 135 if(access(str, F_OK) == -1 ) { |
136 printf("Error file %s/%s not found. The %s file should be your main patch.\n", folder, file, file); | 136 printf("Error file %s/%s not found. The %s file should be your main patch.\n", folder, file, file); |
137 return false; | 137 return false; |
138 } | 138 } |
139 | 139 if(context->analogInChannels != context->analogOutChannels || |
140 context->audioInChannels != context->audioOutChannels){ | |
141 printf("This project requires the number of inputs and the number of outputs to be the same\n"); | |
142 return false; | |
143 } | |
140 // analog setup | 144 // analog setup |
141 gAnalogChannelsInUse = context->analogChannels; | 145 gAnalogChannelsInUse = context->analogInChannels; |
142 | 146 |
143 // digital setup | 147 // digital setup |
144 dcm.setCallback(sendDigitalMessage); | 148 dcm.setCallback(sendDigitalMessage); |
145 if(context->digitalChannels > 0){ | 149 if(context->digitalChannels > 0){ |
146 for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){ | 150 for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){ |
303 unsigned int j; | 307 unsigned int j; |
304 unsigned int k; | 308 unsigned int k; |
305 float* p0; | 309 float* p0; |
306 float* p1; | 310 float* p1; |
307 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { | 311 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { |
308 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) { | 312 for (k = 0, p1 = p0; k < context->audioInChannels; k++, p1 += gLibpdBlockSize) { |
309 *p1 = audioRead(context, audioFrameBase + j, k); | 313 *p1 = audioRead(context, audioFrameBase + j, k); |
310 } | 314 } |
311 } | 315 } |
312 // then analogs | 316 // then analogs |
313 // this loop resamples by ZOH, as needed, using m | 317 // this loop resamples by ZOH, as needed, using m |
314 if(context->analogChannels == 8 ){ //hold the value for two frames | 318 if(context->analogInChannels == 8 ){ //hold the value for two frames |
315 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { | 319 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { |
316 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { | 320 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { |
317 unsigned int analogFrame = (audioFrameBase + j) / 2; | 321 unsigned int analogFrame = (audioFrameBase + j) / 2; |
318 *p1 = analogRead(context, analogFrame, k); | 322 *p1 = analogRead(context, analogFrame, k); |
319 } | 323 } |
320 } | 324 } |
321 } else if(context->analogChannels == 4){ //write every frame | 325 } else if(context->analogInChannels == 4){ //write every frame |
322 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { | 326 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { |
323 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { | 327 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { |
324 unsigned int analogFrame = audioFrameBase + j; | 328 unsigned int analogFrame = audioFrameBase + j; |
325 *p1 = analogRead(context, analogFrame, k); | 329 *p1 = analogRead(context, analogFrame, k); |
326 } | 330 } |
327 } | 331 } |
328 } else if(context->analogChannels == 2){ //drop every other frame | 332 } else if(context->analogInChannels == 2){ //drop every other frame |
329 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { | 333 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) { |
330 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { | 334 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; ++k, p1 += gLibpdBlockSize) { |
331 unsigned int analogFrame = (audioFrameBase + j) * 2; | 335 unsigned int analogFrame = (audioFrameBase + j) * 2; |
332 *p1 = analogRead(context, analogFrame, k); | 336 *p1 = analogRead(context, analogFrame, k); |
333 } | 337 } |
367 // digital out at message-rate | 371 // digital out at message-rate |
368 dcm.processOutput(&context->digital[audioFrameBase], gLibpdBlockSize); | 372 dcm.processOutput(&context->digital[audioFrameBase], gLibpdBlockSize); |
369 | 373 |
370 //audio | 374 //audio |
371 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { | 375 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { |
372 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) { | 376 for (k = 0, p1 = p0; k < context->audioOutChannels; k++, p1 += gLibpdBlockSize) { |
373 audioWrite(context, audioFrameBase + j, k, *p1); | 377 audioWrite(context, audioFrameBase + j, k, *p1); |
374 } | 378 } |
375 } | 379 } |
376 //scope | 380 //scope |
377 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { | 381 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { |
381 scope.log(gScopeOut[0], gScopeOut[1], gScopeOut[2], gScopeOut[3]); | 385 scope.log(gScopeOut[0], gScopeOut[1], gScopeOut[2], gScopeOut[3]); |
382 } | 386 } |
383 | 387 |
384 | 388 |
385 //analog | 389 //analog |
386 if(context->analogChannels == 8){ | 390 if(context->analogOutChannels == 8){ |
387 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames | 391 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames |
388 unsigned int analogFrame = (audioFrameBase + j) / 2; | 392 unsigned int analogFrame = (audioFrameBase + j) / 2; |
389 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { | 393 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { |
390 analogWriteOnce(context, analogFrame, k, *p1); | 394 analogWriteOnce(context, analogFrame, k, *p1); |
391 } | 395 } |
392 } | 396 } |
393 } else if(context->analogChannels == 4){ //write every frame | 397 } else if(context->analogOutChannels == 4){ //write every frame |
394 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { | 398 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) { |
395 unsigned int analogFrame = (audioFrameBase + j); | 399 unsigned int analogFrame = (audioFrameBase + j); |
396 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { | 400 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { |
397 analogWriteOnce(context, analogFrame, k, *p1); | 401 analogWriteOnce(context, analogFrame, k, *p1); |
398 } | 402 } |
399 } | 403 } |
400 } else if(context->analogChannels == 2){ //write every frame twice | 404 } else if(context->analogOutChannels == 2){ //write every frame twice |
401 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { | 405 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) { |
402 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { | 406 for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstAnalogChannel; k < gAnalogChannelsInUse; k++, p1 += gLibpdBlockSize) { |
403 int analogFrame = audioFrameBase * 2 + j * 2; | 407 int analogFrame = audioFrameBase * 2 + j * 2; |
404 analogWriteOnce(context, analogFrame, k, *p1); | 408 analogWriteOnce(context, analogFrame, k, *p1); |
405 analogWriteOnce(context, analogFrame + 1, k, *p1); | 409 analogWriteOnce(context, analogFrame + 1, k, *p1); |
406 } | 410 } |
407 } | 411 } |