From d30d9a2c9f74f1bbede11c1f7f8b7a6aada2bf7b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 22 Mar 2020 10:06:23 -0700 Subject: Clean up the pitch and frequency shifter some --- alc/effects/pshifter.cpp | 59 +++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'alc/effects/pshifter.cpp') diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index 7b00a87e..53b5318b 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -98,8 +98,8 @@ struct PshifterState final : public EffectState { ALfloat mFreqPerBin; /* Effects buffers */ - ALfloat mInFIFO[STFT_SIZE]; - ALfloat mOutFIFO[STFT_STEP]; + double mInFIFO[STFT_SIZE]; + double mOutFIFO[STFT_STEP]; ALdouble mLastPhase[STFT_HALF_SIZE+1]; ALdouble mSumPhase[STFT_HALF_SIZE+1]; ALdouble mOutputAccum[STFT_SIZE]; @@ -169,25 +169,26 @@ void PshifterState::process(const size_t samplesToDo, const al::span::Tau() / OVERSAMP}; const ALdouble freq_per_bin{mFreqPerBin}; - ALfloat *RESTRICT bufferOut{mBufferOut}; - size_t count{mCount}; - for(size_t i{0u};i < samplesToDo;) + for(size_t base{0u};base < samplesToDo;) { - do { - /* Fill FIFO buffer with samples data */ - mInFIFO[count] = samplesIn[0][i]; - bufferOut[i] = mOutFIFO[count - FIFO_LATENCY]; + size_t todo{minz(STFT_SIZE-mCount, samplesToDo-base)}; - count++; - } while(++i < samplesToDo && count < STFT_SIZE); + /* Fill FIFO buffer with samples data */ + size_t count{mCount}; + do { + mInFIFO[count] = samplesIn[0][base]; + mBufferOut[base] = static_cast(mOutFIFO[count-FIFO_LATENCY]); + ++base; ++count; + } while(--todo); + mCount = count; /* Check whether FIFO buffer is filled */ - if(count < STFT_SIZE) break; - count = FIFO_LATENCY; + if(mCount < STFT_SIZE) break; + mCount = FIFO_LATENCY; /* Real signal windowing and store in FFTbuffer */ - for(ALuint k{0u};k < STFT_SIZE;k++) + for(size_t k{0u};k < STFT_SIZE;k++) { mFFTbuffer[k].real(mInFIFO[k] * HannWindow[k]); mFFTbuffer[k].imag(0.0); @@ -200,7 +201,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span(mOutputAccum[k]); - for(j = 0;k < STFT_SIZE;k++,j++) mOutputAccum[j] = mOutputAccum[k]; - for(;j < STFT_SIZE;j++) mOutputAccum[j] = 0.0; - for(k = 0;k < FIFO_LATENCY;k++) - mInFIFO[k] = mInFIFO[k+STFT_STEP]; + std::copy_n(mOutputAccum, STFT_STEP, mOutFIFO); + auto accum_iter = std::copy(std::begin(mOutputAccum)+STFT_STEP, std::end(mOutputAccum), + std::begin(mOutputAccum)); + std::fill(accum_iter, std::end(mOutputAccum), 0.0); + std::copy(std::begin(mInFIFO)+STFT_STEP, std::end(mInFIFO), std::begin(mInFIFO)); } - mCount = count; /* Now, mix the processed sound data to the output. */ - MixSamples({bufferOut, samplesToDo}, samplesOut, mCurrentGains, mTargetGains, + MixSamples({mBufferOut, samplesToDo}, samplesOut, mCurrentGains, mTargetGains, maxz(samplesToDo, 512), 0); } -- cgit v1.2.3