diff options
author | Chris Robinson <[email protected]> | 2019-03-10 10:30:33 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-10 10:30:33 -0700 |
commit | 12721f94a72b94c9eab0fc861ad021d915fc0228 (patch) | |
tree | 971778d9143ba4233cc5654e834c0bb3f4ebf3e1 | |
parent | 6a95189ef66bee5dc600f33c5518a60de042a225 (diff) |
Add a method to apply an HF scale without band-splitting
-rw-r--r-- | Alc/effects/reverb.cpp | 23 | ||||
-rw-r--r-- | Alc/filters/splitter.cpp | 36 | ||||
-rw-r--r-- | Alc/filters/splitter.h | 3 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 15 |
4 files changed, 52 insertions, 25 deletions
diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp index 24107dc7..086ffed2 100644 --- a/Alc/effects/reverb.cpp +++ b/Alc/effects/reverb.cpp @@ -424,32 +424,23 @@ struct ReverbState final : public EffectState { for(ALsizei c{0};c < NUM_LINES;c++) { /* Apply scaling to the B-Format's HF response to "upsample" it to - * higher-order output. Use the early buffer to store the split - * signal since it's not needed anymore. + * higher-order output. */ const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; - ALfloat (&hfbuf)[BUFFERSIZE] = mEarlyBuffer[0]; - ALfloat (&lfbuf)[BUFFERSIZE] = mEarlyBuffer[1]; + mAmbiSplitter[0][c].applyHfScale(mTempSamples[c], hfscale, todo); - mAmbiSplitter[0][c].process(hfbuf, lfbuf, mTempSamples[c], todo); - MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, todo); - - MixSamples(lfbuf, numOutput, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], - todo, 0, todo); + MixSamples(mTempSamples[c], numOutput, samplesOut, mEarly.CurrentGain[c], + mEarly.PanGain[c], todo, 0, todo); } ConvertA2B(mTempSamples, mLateBuffer, todo); for(ALsizei c{0};c < NUM_LINES;c++) { const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; - ALfloat (&hfbuf)[BUFFERSIZE] = mLateBuffer[0]; - ALfloat (&lfbuf)[BUFFERSIZE] = mLateBuffer[1]; + mAmbiSplitter[1][c].applyHfScale(mTempSamples[c], hfscale, todo); - mAmbiSplitter[1][c].process(hfbuf, lfbuf, mTempSamples[c], todo); - MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, todo); - - MixSamples(lfbuf, numOutput, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], todo, - 0, todo); + MixSamples(mTempSamples[c], numOutput, samplesOut, mLate.CurrentGain[c], + mLate.PanGain[c], todo, 0, todo); } } diff --git a/Alc/filters/splitter.cpp b/Alc/filters/splitter.cpp index 004f8215..58a5029b 100644 --- a/Alc/filters/splitter.cpp +++ b/Alc/filters/splitter.cpp @@ -25,7 +25,7 @@ void BandSplitterR<Real>::init(Real f0norm) } template<typename Real> -void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, int count) +void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, const int count) { ASSUME(count > 0); @@ -60,6 +60,40 @@ void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, i this->ap_z1 = ap_z1; } +template<typename Real> +void BandSplitterR<Real>::applyHfScale(Real *RESTRICT samples, const Real hfscale, const int count) +{ + ASSUME(count > 0); + + const Real ap_coeff{this->coeff}; + const Real lp_coeff{this->coeff*0.5f + 0.5f}; + Real lp_z1{this->lp_z1}; + Real lp_z2{this->lp_z2}; + Real ap_z1{this->ap_z1}; + auto proc_sample = [hfscale,ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1](const Real in) noexcept -> Real + { + /* Low-pass sample processing. */ + Real d{(in - lp_z1) * lp_coeff}; + Real lp_y{lp_z1 + d}; + lp_z1 = lp_y + d; + + d = (lp_y - lp_z2) * lp_coeff; + lp_y = lp_z2 + d; + lp_z2 = lp_y + d; + + /* All-pass sample processing. */ + Real ap_y{in*ap_coeff + ap_z1}; + ap_z1 = in - ap_y*ap_coeff; + + /* High-pass generated from removing low-passed output. */ + return (ap_y-lp_y)*hfscale + lp_y; + }; + std::transform(samples, samples+count, samples, proc_sample); + this->lp_z1 = lp_z1; + this->lp_z2 = lp_z2; + this->ap_z1 = ap_z1; +} + template class BandSplitterR<float>; template class BandSplitterR<double>; diff --git a/Alc/filters/splitter.h b/Alc/filters/splitter.h index f7ea608b..83281366 100644 --- a/Alc/filters/splitter.h +++ b/Alc/filters/splitter.h @@ -16,7 +16,8 @@ class BandSplitterR { public: void init(Real f0norm); void clear() noexcept { lp_z1 = lp_z2 = ap_z1 = 0.0f; } - void process(Real *hpout, Real *lpout, const Real *input, int count); + void process(Real *hpout, Real *lpout, const Real *input, const int count); + void applyHfScale(Real *RESTRICT samples, const Real hfscale, const int count); }; using BandSplitter = BandSplitterR<float>; diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index 3366aa61..756b69ee 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -612,13 +612,14 @@ void MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, const * be desirable. */ const ALfloat hfscale{(chan==0) ? voice->AmbiScales[0] : voice->AmbiScales[1]}; - ALfloat (&hfbuf)[BUFFERSIZE] = Device->FilteredData; - ALfloat (&lfbuf)[BUFFERSIZE] = Device->ResampledData; - - voice->AmbiSplitter[chan].process(hfbuf, lfbuf, ResampledData, DstBufferSize); - MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, DstBufferSize); - - ResampledData = lfbuf; + /* Beware the evil const_cast. It's safe since it's pointing to + * either SrcData or Device->ResampledData (both non-const), + * but the resample method takes its input as const float* and + * may return it without copying to output, making it currently + * unavoidable. + */ + voice->AmbiSplitter[chan].applyHfScale(const_cast<ALfloat*>(ResampledData), + hfscale, DstBufferSize); } /* Now filter and mix to the appropriate outputs. */ |