diff options
author | Chris Robinson <[email protected]> | 2022-09-02 09:41:19 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-09-02 09:41:19 -0700 |
commit | e5c49d019f41ac9b2d04f9cd04f6c3f8421703a6 (patch) | |
tree | 49279ead685246375a18453fce2f551424acda49 /alc/effects | |
parent | 02cf2bde7b513a67742dea38d949f9e4338e75c6 (diff) |
Revert "Don't apply the HF scaling for "upsampling" ambisonics"
This reverts commit bf3f63fb4c5faa45784d7433d68b7013e29ee2c1.
Diffstat (limited to 'alc/effects')
-rw-r--r-- | alc/effects/convolution.cpp | 13 | ||||
-rw-r--r-- | alc/effects/reverb.cpp | 33 |
2 files changed, 42 insertions, 4 deletions
diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index f72695bd..90220a50 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -194,6 +194,8 @@ struct ConvolutionState final : public EffectState { struct ChannelData { alignas(16) FloatBufferLine mBuffer{}; + float mHfScale{}; + BandSplitter mFilter{}; float Current[MAX_OUTPUT_CHANNELS]{}; float Target[MAX_OUTPUT_CHANNELS]{}; }; @@ -233,6 +235,7 @@ void ConvolutionState::UpsampleMix(const al::span<FloatBufferLine> samplesOut, for(auto &chan : *mChans) { const al::span<float> src{chan.mBuffer.data(), samplesToDo}; + chan.mFilter.processHfScale(src, chan.mHfScale); MixSamples(src, samplesOut, chan.Current, chan.Target, samplesToDo, 0); } } @@ -277,6 +280,10 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff (uint64_t{buffer.storage->mSampleLen}*device->Frequency+(buffer.storage->mSampleRate-1)) / buffer.storage->mSampleRate); + const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)}; + for(auto &e : *mChans) + e.mFilter = splitter; + mFilter.resize(numChannels, {}); mOutput.resize(numChannels, {}); @@ -411,7 +418,13 @@ void ConvolutionState::update(const ContextBase *context, const EffectSlot *slot { DeviceBase *device{context->mDevice}; if(device->mAmbiOrder > mAmbiOrder) + { mMix = &ConvolutionState::UpsampleMix; + const auto scales = AmbiScale::GetHFOrderScales(mAmbiOrder, true); + (*mChans)[0].mHfScale = scales[0]; + for(size_t i{1};i < mChans->size();++i) + (*mChans)[i].mHfScale = scales[1]; + } mOutTarget = target.Main->Buffer; auto&& scales = GetAmbiScales(mAmbiScaling); diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 72f58db5..ea3367d0 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -453,6 +453,8 @@ struct ReverbState final : public EffectState { bool mUpmixOutput{false}; + std::array<float,MaxAmbiOrder+1> mOrderScales{}; + std::array<std::array<BandSplitter,NUM_LINES>,2> mAmbiSplitter; static void DoMixRow(const al::span<float> OutBuffer, const al::span<const float,4> Gains, @@ -499,19 +501,30 @@ struct ReverbState final : public EffectState { { ASSUME(todo > 0); - /* TODO: If HF scaling isn't needed for upsampling, the A-to-B-Format - * matrix can be included with the panning gains like non-upsampled - * output. + /* When upsampling, the B-Format conversion needs to be done separately + * so the proper HF scaling can be applied to each B-Format channel. + * The panning gains then pan and upsample the B-Format channels. */ const al::span<float> tmpspan{al::assume_aligned<16>(mTempLine.data()), todo}; for(size_t c{0u};c < NUM_LINES;c++) { DoMixRow(tmpspan, EarlyA2B[c], mEarlySamples[0].data(), mEarlySamples[0].size()); + + /* Apply scaling to the B-Format's HF response to "upsample" it to + * higher-order output. + */ + const float hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; + mAmbiSplitter[0][c].processHfScale(tmpspan, hfscale); + MixSamples(tmpspan, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], todo, 0); } for(size_t c{0u};c < NUM_LINES;c++) { DoMixRow(tmpspan, LateA2B[c], mLateSamples[0].data(), mLateSamples[0].size()); + + const float hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; + mAmbiSplitter[1][c].processHfScale(tmpspan, hfscale); + MixSamples(tmpspan, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], todo, 0); } } @@ -670,7 +683,19 @@ void ReverbState::deviceUpdate(const DeviceBase *device, const Buffer&) mDoFading = true; mOffset = 0; - mUpmixOutput = (device->mAmbiOrder > 1); + if(device->mAmbiOrder > 1) + { + mUpmixOutput = true; + mOrderScales = AmbiScale::GetHFOrderScales(1, true); + } + else + { + mUpmixOutput = false; + mOrderScales.fill(1.0f); + } + mAmbiSplitter[0][0].init(device->mXOverFreq / frequency); + std::fill(mAmbiSplitter[0].begin()+1, mAmbiSplitter[0].end(), mAmbiSplitter[0][0]); + std::fill(mAmbiSplitter[1].begin(), mAmbiSplitter[1].end(), mAmbiSplitter[0][0]); } /************************************** |