void AudioProcessing::convolution( const juce::AudioSampleBuffer & a, const juce::AudioSampleBuffer & b, juce::AudioSampleBuffer & result ) { jassert( b.getNumChannels() == 1 ); int sampleSize = a.getNumSamples() + b.getNumSamples(); result.setSize( a.getNumChannels(), sampleSize ); const float * bSignal = b.getArrayOfReadPointers()[ 0 ]; for ( int ch = 0 ; ch < a.getNumChannels() ; ++ch ) { const float * aSignal = a.getArrayOfReadPointers()[ ch ]; float * res = result.getArrayOfWritePointers()[ ch ]; for ( int i = 0 ; i < sampleSize ; ++i ) { float sum = 0.f; for ( int j = 0 ; j < b.getNumSamples() ; ++j ) { int indexA = i - j; if ( ( indexA >= 0 ) && ( indexA < a.getNumSamples() ) ) sum += ( aSignal[indexA] * bSignal[j] ); } res[i] = sum; } } }
/** Upsample by 4 signal (polyphase coefficients are for a 48 kHz signal). Processes 4 samples of the output signal in a single loop iteration. In one loop, each of the 4 processed samples is filtered with its own set of coefficients */ void AudioProcessing::polyphase4( const juce::AudioSampleBuffer & source, juce::AudioSampleBuffer & result ) { int sampleSize = source.getNumSamples(); result.setSize( source.getNumChannels(), 4*source.getNumSamples() + numCoeffs, false, false, true ); for ( int ch = 0 ; ch < source.getNumChannels() ; ++ch ) { const float * input = source.getArrayOfReadPointers()[ ch ]; float * res = result.getArrayOfWritePointers()[ ch ]; for ( int i = 0 ; i < sampleSize ; ++i ) { res[4*i] = polyphase4ComputeSum( input, i, source.getNumSamples(), filterPhase0, numCoeffs ); res[4*i+1] = polyphase4ComputeSum( input, i, source.getNumSamples(), filterPhase1, numCoeffs ); res[4*i+2] = polyphase4ComputeSum( input, i, source.getNumSamples(), filterPhase2, numCoeffs ); res[4*i+3] = polyphase4ComputeSum( input, i, source.getNumSamples(), filterPhase3, numCoeffs ); } } }