comparison examples/04-Audio/FFT-phase-vocoder/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
119 // in from the call to initAudio(). 119 // in from the call to initAudio().
120 // 120 //
121 // Return true on success; returning false halts the program. 121 // Return true on success; returning false halts the program.
122 bool setup(BelaContext* context, void* userData) 122 bool setup(BelaContext* context, void* userData)
123 { 123 {
124 // Check that we have the same number of inputs and outputs.
125 if(context->audioInChannels != context->audioOutChannels ||
126 context->analogInChannels != context-> analogOutChannels){
127 printf("Error: for this project, you need the same number of input and output channels.\n");
128 return false;
129 }
130
124 midi.readFrom(0); 131 midi.readFrom(0);
125 midi.setParserCallback(midiCallback); 132 midi.setParserCallback(midiCallback);
126 // Retrieve a parameter passed in from the initAudio() call 133 // Retrieve a parameter passed in from the initAudio() call
127 gSampleData = *(SampleData *)userData; 134 gSampleData = *(SampleData *)userData;
128 135
136 143
137 memset(timeDomainOut, 0, gFFTSize * sizeof (ne10_fft_cpx_float32_t)); 144 memset(timeDomainOut, 0, gFFTSize * sizeof (ne10_fft_cpx_float32_t));
138 memset(gOutputBuffer, 0, BUFFER_SIZE * sizeof(float)); 145 memset(gOutputBuffer, 0, BUFFER_SIZE * sizeof(float));
139 146
140 // Allocate buffer to mirror and modify the input 147 // Allocate buffer to mirror and modify the input
141 gInputAudio = (float *)malloc(context->audioFrames * context->audioChannels * sizeof(float)); 148 gInputAudio = (float *)malloc(context->audioFrames * context->audioOutChannels * sizeof(float));
142 if(gInputAudio == 0) 149 if(gInputAudio == 0)
143 return false; 150 return false;
144 151
145 // Allocate the window buffer based on the FFT size 152 // Allocate the window buffer based on the FFT size
146 gWindowBuffer = (float *)malloc(gFFTSize * sizeof(float)); 153 gWindowBuffer = (float *)malloc(gFFTSize * sizeof(float));
230 // will be 0. 237 // will be 0.
231 void render(BelaContext* context, void* userData) 238 void render(BelaContext* context, void* userData)
232 { 239 {
233 float* audioOut = context->audioOut; 240 float* audioOut = context->audioOut;
234 int numAudioFrames = context->audioFrames; 241 int numAudioFrames = context->audioFrames;
235 int numAudioChannels = context->audioChannels; 242 int numAudioChannels = context->audioOutChannels;
236 // ------ this code internal to the demo; leave as is ---------------- 243 // ------ this code internal to the demo; leave as is ----------------
237 244
238 // Prep the "input" to be the sound file played in a loop 245 // Prep the "input" to be the sound file played in a loop
239 for(int n = 0; n < numAudioFrames; n++) { 246 for(int n = 0; n < numAudioFrames; n++) {
240 if(gReadPtr < gSampleData.sampleLen) 247 if(gReadPtr < gSampleData.sampleLen)