From 893ffe9a84d497d38e6e472b0cffbd9c37e0c366 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 29 May 2019 21:58:37 -0700 Subject: Use span for MixSamples --- Alc/effects/autowah.cpp | 19 +++++++++---------- Alc/effects/chorus.cpp | 14 ++++++-------- Alc/effects/dedicated.cpp | 5 ++--- Alc/effects/echo.cpp | 6 +++--- Alc/effects/equalizer.cpp | 6 +++--- Alc/effects/fshifter.cpp | 4 ++-- Alc/effects/modulator.cpp | 10 +++++----- Alc/effects/pshifter.cpp | 4 ++-- Alc/effects/reverb.cpp | 24 ++++++++++-------------- 9 files changed, 42 insertions(+), 50 deletions(-) (limited to 'Alc/effects') diff --git a/Alc/effects/autowah.cpp b/Alc/effects/autowah.cpp index 2b01f70a..2b0cb610 100644 --- a/Alc/effects/autowah.cpp +++ b/Alc/effects/autowah.cpp @@ -136,11 +136,9 @@ void ALautowahState::process(const ALsizei samplesToDo, const FloatBufferLine *R const ALfloat peak_gain = mPeakGain; const ALfloat freq_min = mFreqMinNorm; const ALfloat bandwidth = mBandwidthNorm; - ALfloat env_delay; - ALsizei c, i; - env_delay = mEnvDelay; - for(i = 0;i < samplesToDo;i++) + ALfloat env_delay{mEnvDelay}; + for(ALsizei i{0};i < samplesToDo;i++) { ALfloat w0, sample, a; @@ -158,8 +156,9 @@ void ALautowahState::process(const ALsizei samplesToDo, const FloatBufferLine *R } mEnvDelay = env_delay; + const al::span output{samplesOut, samplesOut+numOutput}; ASSUME(numInput > 0); - for(c = 0;c < numInput;++c) + for(ALsizei c{0};c < numInput;++c) { /* This effectively inlines BiquadFilter_setParams for a peaking * filter and BiquadFilter_processC. The alpha and cosine components @@ -167,10 +166,10 @@ void ALautowahState::process(const ALsizei samplesToDo, const FloatBufferLine *R * envelope. Because the filter changes for each sample, the * coefficients are transient and don't need to be held. */ - ALfloat z1 = mChans[c].Filter.z1; - ALfloat z2 = mChans[c].Filter.z2; + ALfloat z1{mChans[c].Filter.z1}; + ALfloat z2{mChans[c].Filter.z2}; - for(i = 0;i < samplesToDo;i++) + for(ALsizei i{0};i < samplesToDo;i++) { const ALfloat alpha = mEnv[i].alpha; const ALfloat cos_w0 = mEnv[i].cos_w0; @@ -194,8 +193,8 @@ void ALautowahState::process(const ALsizei samplesToDo, const FloatBufferLine *R mChans[c].Filter.z2 = z2; /* Now, mix the processed sound data to the output. */ - MixSamples(mBufferOut, numOutput, &reinterpret_cast(samplesOut[0]), - mChans[c].CurrentGains, mChans[c].TargetGains, samplesToDo, 0, samplesToDo); + MixSamples(mBufferOut, output, mChans[c].CurrentGains, mChans[c].TargetGains, samplesToDo, + 0, samplesToDo); } } diff --git a/Alc/effects/chorus.cpp b/Alc/effects/chorus.cpp index e953d3e3..cdbb2036 100644 --- a/Alc/effects/chorus.cpp +++ b/Alc/effects/chorus.cpp @@ -205,10 +205,9 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST const ALsizei avgdelay{(mDelay + (FRACTIONONE>>1)) >> FRACTIONBITS}; ALfloat *RESTRICT delaybuf{mSampleBuffer.data()}; ALsizei offset{mOffset}; - ALsizei i, c; - ALsizei base; - for(base = 0;base < samplesToDo;) + const al::span output{samplesOut, samplesOut+numOutput}; + for(ALsizei base{0};base < samplesToDo;) { const ALsizei todo = mini(256, samplesToDo-base); ALint moddelays[2][256]; @@ -230,7 +229,7 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST } mLfoOffset = (mLfoOffset+todo) % mLfoRange; - for(i = 0;i < todo;i++) + for(ALsizei i{0};i < todo;i++) { // Feed the buffer's input first (necessary for delays < 1). delaybuf[offset&bufmask] = samplesIn[0][base+i]; @@ -254,10 +253,9 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST offset++; } - for(c = 0;c < 2;c++) - MixSamples(temps[c], numOutput, - &reinterpret_cast(samplesOut[0]), mGains[c].Current, - mGains[c].Target, samplesToDo-base, base, todo); + for(ALsizei c{0};c < 2;c++) + MixSamples(temps[c], output, mGains[c].Current, mGains[c].Target, samplesToDo-base, + base, todo); base += todo; } diff --git a/Alc/effects/dedicated.cpp b/Alc/effects/dedicated.cpp index 7b44e392..b4eaa8e8 100644 --- a/Alc/effects/dedicated.cpp +++ b/Alc/effects/dedicated.cpp @@ -92,9 +92,8 @@ void DedicatedState::update(const ALCcontext* UNUSED(context), const ALeffectslo void DedicatedState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei /*numInput*/, FloatBufferLine *RESTRICT samplesOut, const ALsizei numOutput) { - MixSamples(samplesIn[0].data(), numOutput, - &reinterpret_cast(samplesOut[0]), mCurrentGains, mTargetGains, - samplesToDo, 0, samplesToDo); + MixSamples(samplesIn[0].data(), {samplesOut, samplesOut+numOutput}, mCurrentGains, + mTargetGains, samplesToDo, 0, samplesToDo); } diff --git a/Alc/effects/echo.cpp b/Alc/effects/echo.cpp index e684039d..e82e75bd 100644 --- a/Alc/effects/echo.cpp +++ b/Alc/effects/echo.cpp @@ -157,10 +157,10 @@ void EchoState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRI mFilter.setComponents(z1, z2); mOffset = offset; + const al::span output{samplesOut, samplesOut+numOutput}; for(ALsizei c{0};c < 2;c++) - MixSamples(mTempBuffer[c], numOutput, - &reinterpret_cast(samplesOut[0]), mGains[c].Current, - mGains[c].Target, samplesToDo, 0, samplesToDo); + MixSamples(mTempBuffer[c], output, mGains[c].Current, mGains[c].Target, samplesToDo, 0, + samplesToDo); } diff --git a/Alc/effects/equalizer.cpp b/Alc/effects/equalizer.cpp index 53f8e153..f6be258b 100644 --- a/Alc/effects/equalizer.cpp +++ b/Alc/effects/equalizer.cpp @@ -160,6 +160,7 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot, void EqualizerState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei numInput, FloatBufferLine *RESTRICT samplesOut, const ALsizei numOutput) { + const al::span output{samplesOut, samplesOut+numOutput}; ASSUME(numInput > 0); for(ALsizei c{0};c < numInput;c++) { @@ -168,9 +169,8 @@ void EqualizerState::process(const ALsizei samplesToDo, const FloatBufferLine *R mChans[c].filter[2].process(mSampleBuffer, mSampleBuffer, samplesToDo); mChans[c].filter[3].process(mSampleBuffer, mSampleBuffer, samplesToDo); - MixSamples(mSampleBuffer, numOutput, - &reinterpret_cast(samplesOut[0]), mChans[c].CurrentGains, - mChans[c].TargetGains, samplesToDo, 0, samplesToDo); + MixSamples(mSampleBuffer, output, mChans[c].CurrentGains, mChans[c].TargetGains, + samplesToDo, 0, samplesToDo); } } diff --git a/Alc/effects/fshifter.cpp b/Alc/effects/fshifter.cpp index 0b8d33e4..56068b06 100644 --- a/Alc/effects/fshifter.cpp +++ b/Alc/effects/fshifter.cpp @@ -198,8 +198,8 @@ void FshifterState::process(const ALsizei samplesToDo, const FloatBufferLine *RE } /* Now, mix the processed sound data to the output. */ - MixSamples(BufferOut, numOutput, &reinterpret_cast(samplesOut[0]), - mCurrentGains, mTargetGains, maxi(samplesToDo, 512), 0, samplesToDo); + MixSamples(BufferOut, {samplesOut, samplesOut+numOutput}, mCurrentGains, mTargetGains, + maxi(samplesToDo, 512), 0, samplesToDo); } diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp index ec0b6184..9b7abbb7 100644 --- a/Alc/effects/modulator.cpp +++ b/Alc/effects/modulator.cpp @@ -143,10 +143,10 @@ void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot, void ModulatorState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei numInput, FloatBufferLine *RESTRICT samplesOut, const ALsizei numOutput) { - const ALsizei step = mStep; - ALsizei base; + const ALsizei step{mStep}; - for(base = 0;base < samplesToDo;) + const al::span output{samplesOut, samplesOut+numOutput}; + for(ALsizei base{0};base < samplesToDo;) { alignas(16) ALfloat modsamples[MAX_UPDATE_SAMPLES]; ALsizei td = mini(MAX_UPDATE_SAMPLES, samplesToDo-base); @@ -165,8 +165,8 @@ void ModulatorState::process(const ALsizei samplesToDo, const FloatBufferLine *R for(i = 0;i < td;i++) temps[i] *= modsamples[i]; - MixSamples(temps, numOutput, &reinterpret_cast(samplesOut[0]), - mChans[c].CurrentGains, mChans[c].TargetGains, samplesToDo-base, base, td); + MixSamples(temps, output, mChans[c].CurrentGains, mChans[c].TargetGains, + samplesToDo-base, base, td); } base += td; diff --git a/Alc/effects/pshifter.cpp b/Alc/effects/pshifter.cpp index a3e946c0..34f442bc 100644 --- a/Alc/effects/pshifter.cpp +++ b/Alc/effects/pshifter.cpp @@ -321,8 +321,8 @@ void PshifterState::process(const ALsizei samplesToDo, const FloatBufferLine *RE mCount = count; /* Now, mix the processed sound data to the output. */ - MixSamples(bufferOut, numOutput, &reinterpret_cast(samplesOut[0]), - mCurrentGains, mTargetGains, maxi(samplesToDo, 512), 0, samplesToDo); + MixSamples(bufferOut, {samplesOut, samplesOut+numOutput}, mCurrentGains, mTargetGains, + maxi(samplesToDo, 512), 0, samplesToDo); } diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp index 74c9d3fc..5d2f25f9 100644 --- a/Alc/effects/reverb.cpp +++ b/Alc/effects/reverb.cpp @@ -375,7 +375,7 @@ struct ReverbState final : public EffectState { alignas(16) FloatBufferLine mEarlyBuffer[NUM_LINES]{}; alignas(16) FloatBufferLine mLateBuffer[NUM_LINES]{}; - using MixOutT = void (ReverbState::*)(const ALsizei numOutput, FloatBufferLine *samplesOut, + using MixOutT = void (ReverbState::*)(const al::span samplesOut, const ALsizei todo); MixOutT mMixOut{&ReverbState::MixOutPlain}; @@ -383,7 +383,7 @@ struct ReverbState final : public EffectState { std::array,2> mAmbiSplitter; - void MixOutPlain(const ALsizei numOutput, FloatBufferLine *samplesOut, const ALsizei todo) + void MixOutPlain(const al::span samplesOut, const ALsizei todo) { ASSUME(todo > 0); @@ -392,8 +392,7 @@ struct ReverbState final : public EffectState { { std::fill_n(mTempSamples[0].begin(), todo, 0.0f); MixRowSamples(mTempSamples[0], A2B[c], mEarlyBuffer, 0, todo); - MixSamples(mTempSamples[0].data(), numOutput, - &reinterpret_cast(samplesOut[0]), mEarly.CurrentGain[c], + MixSamples(mTempSamples[0].data(), samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], todo, 0, todo); } @@ -401,13 +400,12 @@ struct ReverbState final : public EffectState { { std::fill_n(mTempSamples[0].begin(), todo, 0.0f); MixRowSamples(mTempSamples[0], A2B[c], mLateBuffer, 0, todo); - MixSamples(mTempSamples[0].data(), numOutput, - &reinterpret_cast(samplesOut[0]), mLate.CurrentGain[c], - mLate.PanGain[c], todo, 0, todo); + MixSamples(mTempSamples[0].data(), samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], + todo, 0, todo); } } - void MixOutAmbiUp(const ALsizei numOutput, FloatBufferLine *samplesOut, const ALsizei todo) + void MixOutAmbiUp(const al::span samplesOut, const ALsizei todo) { ASSUME(todo > 0); @@ -422,8 +420,7 @@ struct ReverbState final : public EffectState { const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; mAmbiSplitter[0][c].applyHfScale(mTempSamples[0].data(), hfscale, todo); - MixSamples(mTempSamples[0].data(), numOutput, - &reinterpret_cast(samplesOut[0]), mEarly.CurrentGain[c], + MixSamples(mTempSamples[0].data(), samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], todo, 0, todo); } @@ -435,9 +432,8 @@ struct ReverbState final : public EffectState { const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; mAmbiSplitter[1][c].applyHfScale(mTempSamples[0].data(), hfscale, todo); - MixSamples(mTempSamples[0].data(), numOutput, - &reinterpret_cast(samplesOut[0]), mLate.CurrentGain[c], - mLate.PanGain[c], todo, 0, todo); + MixSamples(mTempSamples[0].data(), samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], + todo, 0, todo); } } @@ -1530,7 +1526,7 @@ void ReverbState::process(const ALsizei samplesToDo, const FloatBufferLine *REST mFadeCount = fadeCount; /* Finally, mix early reflections and late reverb. */ - (this->*mMixOut)(numOutput, samplesOut, samplesToDo); + (this->*mMixOut)({samplesOut, samplesOut+numOutput}, samplesToDo); } -- cgit v1.2.3