comparison examples/04-Audio/FFT-audio-in/render.cpp @ 544:cdabbaf3a252 prerelease

Updated Audio examples for audioOutChannels etc.
author Robert Jack <robert.h.jack@gmail.com>
date Fri, 24 Jun 2016 13:32:07 +0100
parents 1cec96845a23
children
comparison
equal deleted inserted replaced
543:8f8809c77dda 544:cdabbaf3a252
38 static ne10_fft_cpx_float32_t* frequencyDomain; 38 static ne10_fft_cpx_float32_t* frequencyDomain;
39 static ne10_fft_cfg_float32_t cfg; 39 static ne10_fft_cfg_float32_t cfg;
40 40
41 bool setup(BelaContext *context, void *userData) 41 bool setup(BelaContext *context, void *userData)
42 { 42 {
43
44 // Check that we have the same number of inputs and outputs.
45 if(context->audioInChannels != context->audioOutChannels ||
46 context->analogInChannels != context-> analogOutChannels){
47 printf("Error: for this project, you need the same number of input and output channels.\n");
48 return false;
49 }
50
43 // Retrieve a parameter passed in from the initAudio() call 51 // Retrieve a parameter passed in from the initAudio() call
44 gFFTSize = *(int *)userData; 52 gFFTSize = *(int *)userData;
45 53
46 timeDomainIn = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); 54 timeDomainIn = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t));
47 timeDomainOut = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); 55 timeDomainOut = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t));
54 } 62 }
55 63
56 void render(BelaContext *context, void *userData) 64 void render(BelaContext *context, void *userData)
57 { 65 {
58 for(unsigned int n = 0; n < context->audioFrames; n++) { 66 for(unsigned int n = 0; n < context->audioFrames; n++) {
59 timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioChannels] + 67 timeDomainIn[gReadPointer].r = (ne10_float32_t) ((context->audioIn[n*context->audioInChannels] +
60 context->audioIn[n*context->audioChannels+1]) * 0.5); 68 context->audioIn[n*context->audioOutChannels+1]) * 0.5);
61 timeDomainIn[gReadPointer].i = 0; 69 timeDomainIn[gReadPointer].i = 0;
62 70
63 if(++gReadPointer >= gFFTSize) 71 if(++gReadPointer >= gFFTSize)
64 { 72 {
65 //FFT 73 //FFT
72 80
73 gReadPointer = 0; 81 gReadPointer = 0;
74 gWritePointer = 0; 82 gWritePointer = 0;
75 } 83 }
76 84
77 for(unsigned int channel = 0; channel < context->audioChannels; channel++) 85 for(unsigned int channel = 0; channel < context->audioOutChannels; channel++)
78 context->audioOut[n * context->audioChannels + channel] = (float) timeDomainOut[gWritePointer].r; 86 context->audioOut[n * context->audioOutChannels + channel] = (float) timeDomainOut[gWritePointer].r;
79 gWritePointer++; 87 gWritePointer++;
80 } 88 }
81 } 89 }
82 90
83 void cleanup(BelaContext *context, void *userData) 91 void cleanup(BelaContext *context, void *userData)