Mercurial > hg > beaglert
diff examples/basic_FFT_phase_vocoder/render.cpp @ 373:3bed6b09223c prerelease
Updated NE10 library to the latest version; needs a corresponding update to the /usr/include/ne10 header files on the SD image. Updated examples to compile against new version, and reordered D-Box channels to account for new PRU-based DAC channel reordering.
author | andrewm |
---|---|
date | Thu, 09 Jun 2016 20:03:09 +0100 |
parents | db2fe4e1b88e |
children | 24c3a0663d54 |
line wrap: on
line diff
--- a/examples/basic_FFT_phase_vocoder/render.cpp Thu Jun 09 18:16:05 2016 +0100 +++ b/examples/basic_FFT_phase_vocoder/render.cpp Thu Jun 09 20:03:09 2016 +0100 @@ -80,7 +80,10 @@ float gDryWet = 1; // mix between the unprocessed and processed sound float gPlaybackLive = 0.5f; // mix between the file playback and the live audio input float gGain = 1; // overall gain +float *gInputAudio = NULL; Midi midi; + + void midiCallback(MidiChannelMessage message, void* arg){ if(message.getType() == kmmNoteOn){ if(message.getDataByte(1) > 0){ @@ -133,11 +136,16 @@ 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)); frequencyDomain = (ne10_fft_cpx_float32_t*) NE10_MALLOC (gFFTSize * sizeof (ne10_fft_cpx_float32_t)); - cfg = ne10_fft_alloc_c2c_float32 (gFFTSize); + cfg = ne10_fft_alloc_c2c_float32_neon (gFFTSize); memset(timeDomainOut, 0, gFFTSize * sizeof (ne10_fft_cpx_float32_t)); memset(gOutputBuffer, 0, BUFFER_SIZE * sizeof(float)); + // Allocate buffer to mirror and modify the input + gInputAudio = (float *)malloc(context->audioFrames * context->audioChannels * sizeof(float)); + if(gInputAudio == 0) + return false; + // Allocate the window buffer based on the FFT size gWindowBuffer = (float *)malloc(gFFTSize * sizeof(float)); if(gWindowBuffer == 0) @@ -177,7 +185,7 @@ } // Run the FFT - ne10_fft_c2c_1d_float32_neon (frequencyDomain, timeDomainIn, cfg->twiddles, cfg->factors, gFFTSize, 0); + ne10_fft_c2c_1d_float32_neon (frequencyDomain, timeDomainIn, cfg, 0); switch (gEffect){ case kRobot : @@ -202,7 +210,7 @@ } // Run the inverse FFT - ne10_fft_c2c_1d_float32_neon (timeDomainOut, frequencyDomain, cfg->twiddles, cfg->factors, gFFTSize, 1); + ne10_fft_c2c_1d_float32_neon (timeDomainOut, frequencyDomain, cfg, 1); // Overlap-and-add timeDomainOut into the output buffer pointer = outWritePointer; for(int n = 0; n < gFFTSize; n++) { @@ -226,7 +234,6 @@ // will be 0. void render(BelaContext* context, void* userData) { - float* audioIn = context->audioIn; float* audioOut = context->audioOut; int numAudioFrames = context->audioFrames; int numAudioChannels = context->audioChannels; @@ -235,21 +242,21 @@ // Prep the "input" to be the sound file played in a loop for(int n = 0; n < numAudioFrames; n++) { if(gReadPtr < gSampleData.sampleLen) - audioIn[2*n] = audioIn[2*n+1] = gSampleData.samples[gReadPtr]*(1-gPlaybackLive) + + gInputAudio[2*n] = gInputAudio[2*n+1] = gSampleData.samples[gReadPtr]*(1-gPlaybackLive) + gPlaybackLive*0.5f*(audioRead(context,n,0)+audioRead(context,n,1)); else - audioIn[2*n] = audioIn[2*n+1] = 0; + gInputAudio[2*n] = gInputAudio[2*n+1] = 0; if(++gReadPtr >= gSampleData.sampleLen) gReadPtr = 0; } // ------------------------------------------------------------------- for(int n = 0; n < numAudioFrames; n++) { - gInputBuffer[gInputBufferPointer] = ((audioIn[n*numAudioChannels] + audioIn[n*numAudioChannels+1]) * 0.5); + gInputBuffer[gInputBufferPointer] = ((gInputAudio[n*numAudioChannels] + gInputAudio[n*numAudioChannels+1]) * 0.5); // Copy output buffer to output for(int channel = 0; channel < numAudioChannels; channel++){ - audioOut[n * numAudioChannels + channel] = gOutputBuffer[gOutputBufferReadPointer] * gGain * gDryWet + (1 - gDryWet) * audioIn[n * numAudioChannels + channel]; + audioOut[n * numAudioChannels + channel] = gOutputBuffer[gOutputBufferReadPointer] * gGain * gDryWet + (1 - gDryWet) * gInputAudio[n * numAudioChannels + channel]; } // Clear the output sample in the buffer so it is ready for the next overlap-add @@ -287,5 +294,6 @@ NE10_FREE(timeDomainOut); NE10_FREE(frequencyDomain); NE10_FREE(cfg); + free(gInputAudio); free(gWindowBuffer); }