comparison examples/10-Instruments/d-box/render.cpp @ 543:8f8809c77dda prerelease

updated basics, digital, instruments, extras examples
author chnrx <chris.heinrichs@gmail.com>
date Fri, 24 Jun 2016 13:19:52 +0100
parents 8fcfbfb32aa0
children
comparison
equal deleted inserted replaced
542:3016638b4da2 543:8f8809c77dda
157 #endif 157 #endif
158 158
159 bool setup(BelaContext *context, void *userData) { 159 bool setup(BelaContext *context, void *userData) {
160 int oscBankHopSize = *(int *)userData; 160 int oscBankHopSize = *(int *)userData;
161 161
162 if(context->analogChannels != 8) { 162 if(context->analogOutChannels <= 8 || context->analogInChannels <= 8) {
163 printf("Error: D-Box needs matrix enabled with 8 channels.\n"); 163 printf("Error: D-Box needs at least 8 analog IO channels.\n");
164 return false;
165 }
166
167 if(context->audioInChannels != context->audioOutChannels ||
168 context->analogInChannels != context-> analogOutChannels){
169 printf("Error: for this project, you need the same number of input and output channels.\n");
164 return false; 170 return false;
165 } 171 }
166 172
167 // Allocate two buffers for rendering oscillator bank samples 173 // Allocate two buffers for rendering oscillator bank samples
168 // One will be used for writing in the background while the other is used for reading 174 // One will be used for writing in the background while the other is used for reading
169 // on the audio thread. 8-byte alignment needed for the NEON code. 175 // on the audio thread. 8-byte alignment needed for the NEON code.
170 if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * context->audioChannels * sizeof(float))) { 176 if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * context->audioOutChannels * sizeof(float))) {
171 printf("Error allocating render buffers\n"); 177 printf("Error allocating render buffers\n");
172 return false; 178 return false;
173 } 179 }
174 if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * context->audioChannels * sizeof(float))) { 180 if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * context->audioOutChannels * sizeof(float))) {
175 printf("Error allocating render buffers\n"); 181 printf("Error allocating render buffers\n");
176 return false; 182 return false;
177 } 183 }
178 gOscillatorBufferWrite = gOscillatorBuffer1; 184 gOscillatorBufferWrite = gOscillatorBuffer1;
179 gOscillatorBufferRead = gOscillatorBuffer2; 185 gOscillatorBufferRead = gOscillatorBuffer2;
180 186
181 memset(gOscillatorBuffer1, 0, oscBankHopSize * context->audioChannels * sizeof(float)); 187 memset(gOscillatorBuffer1, 0, oscBankHopSize * context->audioOutChannels * sizeof(float));
182 memset(gOscillatorBuffer2, 0, oscBankHopSize * context->audioChannels * sizeof(float)); 188 memset(gOscillatorBuffer2, 0, oscBankHopSize * context->audioOutChannels * sizeof(float));
183 189
184 // Initialise the dynamic wavetable used by the oscillator bank 190 // Initialise the dynamic wavetable used by the oscillator bank
185 // It should match the size of the static one already allocated in the OscillatorBank object 191 // It should match the size of the static one already allocated in the OscillatorBank object
186 // Don't forget a guard point at the end of the table 192 // Don't forget a guard point at the end of the table
187 gDynamicWavetableLength = gOscBanks[gCurrentOscBank]->lookupTableSize; 193 gDynamicWavetableLength = gOscBanks[gCurrentOscBank]->lookupTableSize;
248 if(gOscBanks[gCurrentOscBank]->state==bank_toreset) 254 if(gOscBanks[gCurrentOscBank]->state==bank_toreset)
249 gOscBanks[gCurrentOscBank]->resetOscillators(); 255 gOscBanks[gCurrentOscBank]->resetOscillators();
250 256
251 if(gOscBanks[gCurrentOscBank]->state==bank_playing) 257 if(gOscBanks[gCurrentOscBank]->state==bank_playing)
252 { 258 {
253 assert(context->audioChannels == 2); 259 assert(context->audioOutChannels == 2);
254 260
255 #ifdef OLD_OSCBANK 261 #ifdef OLD_OSCBANK
256 memset(audioOut, 0, numAudioFrames * * sizeof(float)); 262 memset(audioOut, 0, numAudioFrames * * sizeof(float));
257 263
258 /* Render the oscillator bank. The oscillator bank function is written in NEON assembly 264 /* Render the oscillator bank. The oscillator bank function is written in NEON assembly