From 8a86ec8ac5cb9ae1f766bd33893bf2e6729b1025 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 26 Dec 2020 05:23:08 -0800 Subject: Add a crossover frequency field for the device Used when upsampling low-order ambisonic signals to higher order. Rather than a hardcoded 400hz, it ensures a consistent crossover point when an ambdec configuration is used. It can also allow for an alsoft config option. --- alc/alc.cpp | 3 ++- alc/alcmain.h | 1 + alc/effects/convolution.cpp | 2 +- alc/effects/reverb.cpp | 2 +- alc/hrtf.cpp | 4 ++-- alc/hrtf.h | 2 +- alc/panning.cpp | 5 ++++- 7 files changed, 12 insertions(+), 7 deletions(-) (limited to 'alc') diff --git a/alc/alc.cpp b/alc/alc.cpp index d42d055b..b833cb80 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2219,7 +2219,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) AmbiIndex::OrderFrom2DChannel.data() : AmbiIndex::OrderFromChannel.data()}; - const BandSplitter splitter{400.0f / static_cast(device->Frequency)}; + const BandSplitter splitter{device->mXOverFreq / + static_cast(device->Frequency)}; const auto scales = BFormatDec::GetHFOrderScales(voice->mAmbiOrder, device->mAmbiOrder); diff --git a/alc/alcmain.h b/alc/alcmain.h index 3362c011..92c69b74 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -205,6 +205,7 @@ struct ALCdevice : public al::intrusive_ref { */ DevAmbiLayout mAmbiLayout{DevAmbiLayout::Default}; DevAmbiScaling mAmbiScale{DevAmbiScaling::Default}; + float mXOverFreq{400.0f}; ALCenum LimiterState{ALC_DONT_CARE_SOFT}; diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index bf439721..c072653d 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -247,7 +247,7 @@ void ConvolutionState::setBuffer(const ALCdevice *device, const BufferStorage *b (uint64_t{buffer->mSampleLen}*device->Frequency + (buffer->mSampleRate-1)) / buffer->mSampleRate); - const BandSplitter splitter{400.0f / static_cast(device->Frequency)}; + const BandSplitter splitter{device->mXOverFreq / static_cast(device->Frequency)}; for(auto &e : *mChans) e.mFilter = splitter; diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 646ac624..2bf09bef 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -672,7 +672,7 @@ void ReverbState::deviceUpdate(const ALCdevice *device) mMixOut = &ReverbState::MixOutPlain; mOrderScales.fill(1.0f); } - mAmbiSplitter[0][0].init(400.0f / frequency); + 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]); } diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index f8a5f214..28d85177 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -279,7 +279,7 @@ std::unique_ptr DirectHrtfState::Create(size_t num_chans) void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const al::span AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels], - const al::span AmbiOrderHFGain) + const float XOverFreq, const al::span AmbiOrderHFGain) { using double2 = std::array; struct ImpulseResponse { @@ -287,7 +287,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, uint ldelay, rdelay; }; - const double xover_norm{400.0 / Hrtf->sampleRate}; + const double xover_norm{double{XOverFreq} / Hrtf->sampleRate}; for(size_t i{0};i < mChannels.size();++i) { const size_t order{AmbiIndex::OrderFromChannel[i]}; diff --git a/alc/hrtf.h b/alc/hrtf.h index 56839abd..a46b64e2 100644 --- a/alc/hrtf.h +++ b/alc/hrtf.h @@ -73,7 +73,7 @@ struct DirectHrtfState { */ void build(const HrtfStore *Hrtf, const uint irSize, const al::span AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels], - const al::span AmbiOrderHFGain); + const float XOverFreq, const al::span AmbiOrderHFGain); static std::unique_ptr Create(size_t num_chans); diff --git a/alc/panning.cpp b/alc/panning.cpp index b9ddd2e8..2da5d490 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -595,6 +595,7 @@ void InitCustomPanning(ALCdevice *device, const bool hqdec, const bool stablize, if(!hqdec && conf->FreqBands != 1) ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n", conf->XOverFreq); + device->mXOverFreq = conf->XOverFreq; const ALuint order{(conf->ChanMask > Ambi2OrderMask) ? 3u : (conf->ChanMask > Ambi1OrderMask) ? 2u : 1u}; @@ -813,7 +814,8 @@ void InitHrtfPanning(ALCdevice *device) HrtfStore *Hrtf{device->mHrtf.get()}; auto hrtfstate = DirectHrtfState::Create(count); - hrtfstate->build(Hrtf, device->mIrSize, AmbiPoints, AmbiMatrix, AmbiOrderHFGain); + hrtfstate->build(Hrtf, device->mIrSize, AmbiPoints, AmbiMatrix, device->mXOverFreq, + AmbiOrderHFGain); device->mHrtfState = std::move(hrtfstate); InitNearFieldCtrl(device, Hrtf->field[0].distance, ambi_order, true); @@ -848,6 +850,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq device->mHrtf = nullptr; device->mIrSize = 0; device->HrtfName.clear(); + device->mXOverFreq = 400.0f; device->mRenderMode = RenderMode::Normal; if(device->FmtChans != DevFmtStereo) -- cgit v1.2.3