# HG changeset patch # User andrewm # Date 1422027310 0 # Node ID 06f93bef7dd20abaa955c9f44659cf23f73ff799 # Parent 6adb088196a71741b7454bdb44832ea4e8bda83d Updated remaining examples to new API diff -r 6adb088196a7 -r 06f93bef7dd2 projects/audio_in_FFT/render.cpp --- a/projects/audio_in_FFT/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/audio_in_FFT/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -13,7 +13,6 @@ int gFFTSize; float gFFTScaleFactor = 0; -int gNumChannels; int gReadPointer = 0; int gWritePointer = 0; @@ -33,14 +32,15 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { // Retrieve a parameter passed in from the initAudio() call gFFTSize = *(int *)userData; gFFTScaleFactor = 1.0f / (float)gFFTSize; - gNumChannels = numChannels; timeDomainIn = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); timeDomainOut = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); @@ -61,7 +61,7 @@ uint16_t *matrixIn, uint16_t *matrixOut) { for(int n = 0; n < numAudioFrames; n++) { - timeDomainIn[gReadPointer].r = (ne10_float32_t) ((audioIn[n*gNumChannels] + audioIn[n*gNumChannels+1]) * 0.5); + timeDomainIn[gReadPointer].r = (ne10_float32_t) ((audioIn[n*gNumAudioChannels] + audioIn[n*gNumAudioChannels+1]) * 0.5); timeDomainIn[gReadPointer].i = 0; if(++gReadPointer >= gFFTSize) @@ -78,8 +78,8 @@ gWritePointer = 0; } - for(int channel = 0; channel < gNumChannels; channel++) - audioOut[n * gNumChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; + for(int channel = 0; channel < gNumAudioChannels; channel++) + audioOut[n * gNumAudioChannels + channel] = (float) timeDomainOut[gWritePointer].r * gFFTScaleFactor; gWritePointer++; } } diff -r 6adb088196a7 -r 06f93bef7dd2 projects/d-box/render.cpp --- a/projects/d-box/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/d-box/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -29,7 +29,6 @@ extern bool gIsLoading; extern bool gAudioIn; extern int gPeriodSize; -int gChannels = 2; float *gOscillatorBuffer1, *gOscillatorBuffer2; float *gOscillatorBufferRead, *gOscillatorBufferWrite; @@ -131,26 +130,34 @@ uint16_t *matrixIn, uint16_t *matrixOut); #endif -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, int numAudioFramesPerPeriod, float matrixSampleRate, float audioSampleRate, void *userData) { - gChannels = numChannels; +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { int oscBankHopSize = *(int *)userData; + if(numMatrixChannels != 8) { + printf("Error: D-Box needs matrix enabled with 8 channels.\n"); + return false; + } + // Allocate two buffers for rendering oscillator bank samples // One will be used for writing in the background while the other is used for reading // on the audio thread. 8-byte alignment needed for the NEON code. - if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gChannels * sizeof(float))) { + if(posix_memalign((void **)&gOscillatorBuffer1, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) { printf("Error allocating render buffers\n"); return false; } - if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gChannels * sizeof(float))) { + if(posix_memalign((void **)&gOscillatorBuffer2, 8, oscBankHopSize * gNumAudioChannels * sizeof(float))) { printf("Error allocating render buffers\n"); return false; } gOscillatorBufferWrite = gOscillatorBuffer1; gOscillatorBufferRead = gOscillatorBuffer2; - memset(gOscillatorBuffer1, 0, oscBankHopSize * gChannels * sizeof(float)); - memset(gOscillatorBuffer2, 0, oscBankHopSize * gChannels * sizeof(float)); + memset(gOscillatorBuffer1, 0, oscBankHopSize * gNumAudioChannels * sizeof(float)); + memset(gOscillatorBuffer2, 0, oscBankHopSize * gNumAudioChannels * sizeof(float)); // Initialise the dynamic wavetable used by the oscillator bank // It should match the size of the static one already allocated in the OscillatorBank object @@ -222,10 +229,10 @@ if(gOscBanks[gCurrentOscBank]->state==bank_playing) { - assert(gChannels == 2); + assert(gNumAudioChannels == 2); #ifdef OLD_OSCBANK - memset(audioOut, 0, numAudioFrames * gChannels * sizeof(float)); + memset(audioOut, 0, numAudioFrames * gNumAudioChannels * sizeof(float)); /* Render the oscillator bank. The oscillator bank function is written in NEON assembly * and it strips out all extra checks, so find out in advance whether we can render a whole @@ -262,7 +269,7 @@ gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, gDynamicWavetable/*gOscBanks[gCurrentOscBank]->lookupTable*/); framesRemaining -= gOscBanks[gCurrentOscBank]->hopCounter; - audioOutWithOffset += gChannels * gOscBanks[gCurrentOscBank]->hopCounter; + audioOutWithOffset += gNumAudioChannels * gOscBanks[gCurrentOscBank]->hopCounter; gOscBanks[gCurrentOscBank]->sampleCount += gOscBanks[gCurrentOscBank]->hopCounter; gOscBanks[gCurrentOscBank]->nextHop(); } @@ -562,7 +569,7 @@ gOscillatorNeedsRender = false; /* Render one frame into the write buffer */ - memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gChannels * sizeof(float)); + memset(gOscillatorBufferWrite, 0, gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels * sizeof(float)); oscillator_bank_neon(gOscBanks[gCurrentOscBank]->hopCounter, gOscillatorBufferWrite, gOscBanks[gCurrentOscBank]->actPartNum, gOscBanks[gCurrentOscBank]->lookupTableSize, @@ -572,7 +579,7 @@ gOscBanks[gCurrentOscBank]->oscillatorAmplitudeDerivatives, /*gOscBanks[gCurrentOscBank]->lookupTable*/gDynamicWavetable); - gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gChannels; + gOscillatorBufferWriteCurrentSize = gOscBanks[gCurrentOscBank]->hopCounter * gNumAudioChannels; /* Update the pitch right before the hop * Total CV range +/- N_OCT octaves diff -r 6adb088196a7 -r 06f93bef7dd2 projects/filter_FIR/render.cpp --- a/projects/filter_FIR/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/filter_FIR/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -17,8 +17,6 @@ SampleData gSampleData; // User defined structure to get complex data from main int gReadPtr; // Position of last read sample from file -int gNumChannels; - // filter vars ne10_fir_instance_f32_t gFIRfilter; @@ -48,16 +46,17 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { // Retrieve a parameter passed in from the initAudio() call gSampleData = *(SampleData *)userData; gReadPtr = -1; - gNumChannels = numChannels; gPeriodSize = numMatrixFramesPerPeriod; initialise_filter(); @@ -93,8 +92,8 @@ ne10_fir_float_neon(&gFIRfilter, gFIRfilterIn, gFIRfilterOut, blockSize); for(int n = 0; n < numAudioFrames; n++) { - for(int channel = 0; channel < gNumChannels; channel++) - audioOut[n * gNumChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel + for(int channel = 0; channel < gNumAudioChannels; channel++) + audioOut[n * gNumAudioChannels + channel] = gFIRfilterOut[n]; // ...and put it in both left and right channel } diff -r 6adb088196a7 -r 06f93bef7dd2 projects/filter_IIR/render.cpp --- a/projects/filter_IIR/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/filter_IIR/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -15,7 +15,6 @@ SampleData gSampleData; // User defined structure to get complex data from main int gReadPtr; // Position of last read sample from file -int gNumChannels; // filter vars float gLastX[2]; @@ -55,16 +54,17 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { // Retrieve a parameter passed in from the initAudio() call gSampleData = *(SampleData *)userData; gReadPtr = -1; - gNumChannels = numChannels; initialise_filter(200); @@ -101,8 +101,8 @@ gLastY[1] = gLastY[0]; gLastY[0] = out; - for(int channel = 0; channel < gNumChannels; channel++) - audioOut[n * gNumChannels + channel] = out; // ...and put it in both left and right channel + for(int channel = 0; channel < gNumAudioChannels; channel++) + audioOut[n * gNumAudioChannels + channel] = out; // ...and put it in both left and right channel } diff -r 6adb088196a7 -r 06f93bef7dd2 projects/oscillator_bank/render.cpp --- a/projects/oscillator_bank/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/oscillator_bank/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -58,13 +58,19 @@ // in from the call to initAudio(). // // Return true on success; returning false halts the program. - -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { srandom(time(NULL)); + if(numAudioChannels != 2) { + rt_printf("Error: this example needs stereo audio enabled\n"); + return false; + } + // Initialise the sine wavetable if(posix_memalign((void **)&gWavetable, 8, (gWavetableLength + 1) * sizeof(float))) { rt_printf("Error allocating wavetable\n"); diff -r 6adb088196a7 -r 06f93bef7dd2 projects/samples/render.cpp --- a/projects/samples/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/samples/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -15,7 +15,6 @@ SampleData gSampleData; // User defined structure to get complex data from main int gReadPtr; // Position of last read sample from file -int gNumChannels; // Task for handling the update of the frequencies using the matrix AuxiliaryTask gTriggerSamplesTask; @@ -32,16 +31,17 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { // Retrieve a parameter passed in from the initAudio() call gSampleData = *(SampleData *)userData; gReadPtr = -1; - gNumChannels = numChannels; // Initialise auxiliary tasks if(!initialise_trigger()) @@ -68,8 +68,8 @@ if(gReadPtr >= gSampleData.sampleLen) gReadPtr = -1; - for(int channel = 0; channel < gNumChannels; channel++) - audioOut[n * gNumChannels + channel] = out; // ...and put it in both left and right channel + for(int channel = 0; channel < gNumAudioChannels; channel++) + audioOut[n * gNumAudioChannels + channel] = out; // ...and put it in both left and right channel } // Request that the lower-priority task run at next opportunity diff -r 6adb088196a7 -r 06f93bef7dd2 projects/tank_wars/render.cpp --- a/projects/tank_wars/render.cpp Fri Jan 23 15:17:09 2015 +0000 +++ b/projects/tank_wars/render.cpp Fri Jan 23 15:35:10 2015 +0000 @@ -14,11 +14,6 @@ #include #include -float gFrequency; -float gPhase; -float gInverseSampleRate; -int gNumChannels; - int gInputTank1Angle = 0; // Inputs for the cannon angles int gInputTank2Angle = 1; int gInputLauncher = 2; // Input for launcher FSR @@ -77,15 +72,17 @@ // // Return true on success; returning false halts the program. -bool initialise_render(int numChannels, int numMatrixFramesPerPeriod, - int numAudioFramesPerPeriod, float matrixSampleRate, - float audioSampleRate, void *userData) +bool initialise_render(int numMatrixChannels, int numAudioChannels, + int numMatrixFramesPerPeriod, + int numAudioFramesPerPeriod, + float matrixSampleRate, float audioSampleRate, + void *userData) { srandom(time(NULL)); // Verify we are running with matrix enabled - if(numMatrixFramesPerPeriod*2 != numAudioFramesPerPeriod) { - rt_printf("Error: this example needs the matrix enabled, running at half audio rate\n"); + if(numMatrixFramesPerPeriod == 0 || numMatrixChannels < 4) { + rt_printf("Error: this example needs the matrix enabled with at least 4 channels\n"); return false; }