comparison examples/01-Basics/passthrough/render.cpp @ 539:b486344aa796 prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 01:43:53 +0100
parents bfcbeb437869
children 8f8809c77dda
comparison
equal deleted inserted replaced
538:58652b93ef7e 539:b486344aa796
20 The Bela software is distributed under the GNU Lesser General Public License 20 The Bela software is distributed under the GNU Lesser General Public License
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt 21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
22 */ 22 */
23 23
24 #include <Bela.h> 24 #include <Bela.h>
25 #include <rtdk.h>
26 25
27 bool setup(BelaContext *context, void *userData) 26 bool setup(BelaContext *context, void *userData)
28 { 27 {
29 // Nothing to do here... 28 // Nothing to do here...
29 if(context->audioInChannels != context->audioOutChannels ||
30 context->analogInChannels != context-> analogOutChannels){
31 printf("Error: for this project, you need the same number of input and output channels.\n");
32 return false;
33 }
30 return true; 34 return true;
31 } 35 }
32 36
33 void render(BelaContext *context, void *userData) 37 void render(BelaContext *context, void *userData)
34 { 38 {
39
35 // Simplest possible case: pass inputs through to outputs 40 // Simplest possible case: pass inputs through to outputs
36 for(unsigned int n = 0; n < context->audioFrames; n++) { 41 for(unsigned int n = 0; n < context->audioFrames; n++) {
37 for(unsigned int ch = 0; ch < context->audioChannels; ch++){ 42 for(unsigned int ch = 0; ch < context->audioInChannels; ch++){
38 // Two equivalent ways to write this code 43 // Two equivalent ways to write this code
39 44
40 // The long way, using the buffers directly: 45 // The long way, using the buffers directly:
41 // context->audioOut[n * context->audioChannels + ch] = 46 // context->audioOut[n * context->audioOutChannels + ch] =
42 // context->audioIn[n * context->audioChannels + ch]; 47 // context->audioIn[n * context->audioInChannels + ch];
43 48
44 // Or using the macros: 49 // Or using the macros:
45 audioWrite(context, n, ch, audioRead(context, n, ch)); 50 audioWrite(context, n, ch, audioRead(context, n, ch));
46 } 51 }
47 } 52 }
48 53
49 // Same with analog channelss 54 // Same with analog channels
50 for(unsigned int n = 0; n < context->analogFrames; n++) { 55 for(unsigned int n = 0; n < context->analogFrames; n++) {
51 for(unsigned int ch = 0; ch < context->analogChannels; ch++) { 56 for(unsigned int ch = 0; ch < context->analogInChannels; ch++) {
52 // Two equivalent ways to write this code 57 // Two equivalent ways to write this code
53 58
54 // The long way, using the buffers directly: 59 // The long way, using the buffers directly:
55 // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; 60 // context->analogOut[n * context->analogOutChannels + ch] =
61 // context->analogIn[n * context->analogInChannels + ch];
56 62
57 // Or using the macros: 63 // Or using the macros:
58 analogWrite(context, n, ch, analogRead(context, n, ch)); 64 analogWrite(context, n, ch, analogRead(context, n, ch));
59 } 65 }
60 } 66 }