diff options
author | Chris Robinson <[email protected]> | 2019-01-05 21:55:14 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-05 21:59:04 -0800 |
commit | 3f35fcc4b58df9625527155fe7362459bd8cecd3 (patch) | |
tree | 3840f49dcf6c3a6e0bcb0c606554ebbed0389d79 | |
parent | cff20c2fe8cdc34958c2634ad742491bd7389e13 (diff) |
Simplify MixParams and AmbiUpsampler
Since the dry buffer is always an ambisonic target now
-rw-r--r-- | Alc/alu.cpp | 18 | ||||
-rw-r--r-- | Alc/bformatdec.cpp | 138 | ||||
-rw-r--r-- | Alc/bformatdec.h | 12 | ||||
-rw-r--r-- | Alc/panning.cpp | 92 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 27 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 7 |
6 files changed, 78 insertions, 216 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 401856ac..58247631 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -127,11 +127,9 @@ inline HrtfDirectMixerFunc SelectHrtfMixer(void) void ProcessHrtf(ALCdevice *device, ALsizei SamplesToDo) { - const ALsizei num_chans{device->Dry.NumChannels}; - ASSUME(num_chans > 0); - if(AmbiUpsampler *ambiup{device->AmbiUp.get()}) - ambiup->process(device->Dry.Buffer, num_chans, device->FOAOut.Buffer, SamplesToDo); + ambiup->process(device->Dry.Buffer, device->FOAOut.Buffer, device->FOAOut.NumChannels, + SamplesToDo); /* HRTF is stereo output only. */ const int lidx{(device->RealOut.ChannelName[0]==FrontLeft) ? 0 : 1}; @@ -140,7 +138,8 @@ void ProcessHrtf(ALCdevice *device, ALsizei SamplesToDo) ALfloat *RightOut{device->RealOut.Buffer[ridx]}; DirectHrtfState *state{device->mHrtfState.get()}; - MixDirectHrtf(LeftOut, RightOut, device->Dry.Buffer, state, num_chans, SamplesToDo); + MixDirectHrtf(LeftOut, RightOut, device->Dry.Buffer, state, device->Dry.NumChannels, + SamplesToDo); state->Offset += SamplesToDo; } @@ -156,8 +155,8 @@ void ProcessAmbiDec(ALCdevice *device, ALsizei SamplesToDo) void ProcessAmbiUp(ALCdevice *device, ALsizei SamplesToDo) { - device->AmbiUp->process(device->RealOut.Buffer, device->RealOut.NumChannels, - device->FOAOut.Buffer, SamplesToDo); + device->AmbiUp->process(device->RealOut.Buffer, device->FOAOut.Buffer, + device->FOAOut.NumChannels, SamplesToDo); } void ProcessUhj(ALCdevice *device, ALsizei SamplesToDo) @@ -445,9 +444,8 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) if(ALeffectslot *target{slot->Params.Target}) { auto iter = std::copy(std::begin(target->ChanMap), std::end(target->ChanMap), - std::begin(params.Ambi.Map)); - std::fill(iter, std::end(params.Ambi.Map), BFChannelConfig{}); - params.CoeffCount = 0; + std::begin(params.AmbiMap)); + std::fill(iter, std::end(params.AmbiMap), BFChannelConfig{}); params.Buffer = target->WetBuffer; params.NumChannels = target->NumChannels; diff --git a/Alc/bformatdec.cpp b/Alc/bformatdec.cpp index 84f18833..79d42ec5 100644 --- a/Alc/bformatdec.cpp +++ b/Alc/bformatdec.cpp @@ -24,41 +24,17 @@ namespace { static_assert(BFormatDec::sNumBands == 2, "Unexpected BFormatDec::sNumBands"); static_assert(AmbiUpsampler::sNumBands == 2, "Unexpected AmbiUpsampler::sNumBands"); -/* These points are in AL coordinates! */ -constexpr ALfloat Ambi3DPoints[8][3] = { - { -0.577350269f, 0.577350269f, -0.577350269f }, - { 0.577350269f, 0.577350269f, -0.577350269f }, - { -0.577350269f, 0.577350269f, 0.577350269f }, - { 0.577350269f, 0.577350269f, 0.577350269f }, - { -0.577350269f, -0.577350269f, -0.577350269f }, - { 0.577350269f, -0.577350269f, -0.577350269f }, - { -0.577350269f, -0.577350269f, 0.577350269f }, - { 0.577350269f, -0.577350269f, 0.577350269f }, +constexpr ALfloat Ambi3DDecoderHFScale[MAX_AMBI_ORDER+1] = { + 2.00000000f, 1.15470054f }; -constexpr ALfloat Ambi3DDecoder[8][MAX_AMBI_COEFFS] = { - { 0.125f, 0.125f, 0.125f, 0.125f }, - { 0.125f, -0.125f, 0.125f, 0.125f }, - { 0.125f, 0.125f, 0.125f, -0.125f }, - { 0.125f, -0.125f, 0.125f, -0.125f }, - { 0.125f, 0.125f, -0.125f, 0.125f }, - { 0.125f, -0.125f, -0.125f, 0.125f }, - { 0.125f, 0.125f, -0.125f, -0.125f }, - { 0.125f, -0.125f, -0.125f, -0.125f }, +constexpr ALfloat Ambi3DDecoderHFScale2O[MAX_AMBI_ORDER+1] = { + 1.49071198f, 1.15470054f }; -constexpr ALfloat Ambi3DDecoderHFScale[MAX_AMBI_COEFFS] = { - 2.0f, - 1.15470054f, 1.15470054f, 1.15470054f -}; -constexpr ALfloat Ambi3DDecoderHFScale2O[MAX_AMBI_COEFFS] = { - 1.49071198f, - 1.15470054f, 1.15470054f, 1.15470054f -}; -constexpr ALfloat Ambi3DDecoderHFScale3O[MAX_AMBI_COEFFS] = { - 1.17958441f, - 1.01578297f, 1.01578297f, 1.01578297f +constexpr ALfloat Ambi3DDecoderHFScale3O[MAX_AMBI_ORDER+1] = { + 1.17958441f, 1.01578297f }; -inline auto GetDecoderHFScales(ALsizei order) noexcept -> const ALfloat(&)[MAX_AMBI_COEFFS] +inline auto GetDecoderHFScales(ALsizei order) noexcept -> const ALfloat(&)[MAX_AMBI_ORDER+1] { if(order >= 3) return Ambi3DDecoderHFScale3O; if(order == 2) return Ambi3DDecoderHFScale2O; @@ -105,7 +81,7 @@ void BFormatDec::reset(const AmbDecConf *conf, bool allow_2band, ALsizei inchans (conf->ChanMask > AMBI_2ORDER_MASK) ? 3 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 2 : 1}; { - const ALfloat (&hfscales)[MAX_AMBI_COEFFS] = GetDecoderHFScales(out_order); + const ALfloat (&hfscales)[MAX_AMBI_ORDER+1] = GetDecoderHFScales(out_order); /* The specified filter gain is for the mid-point/reference gain. The * gain at the shelf itself will be the square of that, so specify the * square-root of the desired shelf gain. @@ -192,7 +168,7 @@ void BFormatDec::reset(ALsizei inchans, ALuint srate, ALsizei chancount, const C (inchans > 5) ? 3 : (inchans > 3) ? 2 : 1}; { - const ALfloat (&hfscales)[MAX_AMBI_COEFFS] = GetDecoderHFScales(out_order); + const ALfloat (&hfscales)[MAX_AMBI_ORDER+1] = GetDecoderHFScales(out_order); /* The specified filter gain is for the mid-point/reference gain. The * gain at the shelf itself will be the square of that, so specify the * square-root of the desired shelf gain. @@ -208,7 +184,7 @@ void BFormatDec::reset(ALsizei inchans, ALuint srate, ALsizei chancount, const C mUpSampler[i].Shelf.copyParamsFrom(mUpSampler[1].Shelf); } - for(size_t i{0u};i < chancount;i++) + for(ALsizei i{0};i < chancount;i++) { const ALfloat (&coeffs)[MAX_AMBI_COEFFS] = chancoeffs[chanmap[i]]; ALfloat (&mtx)[MAX_AMBI_COEFFS] = mMatrix.Single[chanmap[i]]; @@ -281,88 +257,32 @@ void BFormatDec::upSample(ALfloat (*OutBuffer)[BUFFERSIZE], const ALfloat (*InSa } -void AmbiUpsampler::reset(const ALCdevice *device) +void AmbiUpsampler::reset(const ALsizei out_order, const ALfloat xover_norm) { - const ALfloat xover_norm{400.0f / (float)device->Frequency}; - - mSimpleUp = (device->Dry.CoeffCount == 0); - if(mSimpleUp) - { - const ALfloat (&hfscales)[MAX_AMBI_COEFFS] = GetDecoderHFScales( - (device->Dry.NumChannels > 16) ? 4 : - (device->Dry.NumChannels > 9) ? 3 : - (device->Dry.NumChannels > 4) ? 2 : 1); - const ALfloat gain0{std::sqrt(Ambi3DDecoderHFScale[0] / hfscales[0])}; - const ALfloat gain1{std::sqrt(Ambi3DDecoderHFScale[1] / hfscales[1])}; - - mShelf[0].setParams(BiquadType::HighShelf, gain0, xover_norm, - calc_rcpQ_from_slope(gain0, 1.0f)); - mShelf[1].setParams(BiquadType::HighShelf, gain1, xover_norm, - calc_rcpQ_from_slope(gain1, 1.0f)); - for(ALsizei i{2};i < 4;i++) - mShelf[i].copyParamsFrom(mShelf[1]); - } - else - { - mInput[0].XOver.init(xover_norm); - for(auto input = std::begin(mInput)+1;input != std::end(mInput);++input) - input->XOver = mInput[0].XOver; - - ALfloat encgains[8][MAX_OUTPUT_CHANNELS]; - for(size_t k{0u};k < COUNTOF(Ambi3DPoints);k++) - { - ALfloat coeffs[MAX_AMBI_COEFFS]; - CalcDirectionCoeffs(Ambi3DPoints[k], 0.0f, coeffs); - ComputePanGains(&device->Dry, coeffs, 1.0f, encgains[k]); - } - - /* Combine the matrices that do the in->virt and virt->out conversions - * so we get a single in->out conversion. NOTE: the Encoder matrix - * (encgains) and output are transposed, so the input channels line up - * with the rows and the output channels line up with the columns. - */ - const ALfloat (&hfscales)[MAX_AMBI_COEFFS] = GetDecoderHFScales( - (device->Dry.CoeffCount > 16) ? 4 : - (device->Dry.CoeffCount > 9) ? 3 : - (device->Dry.CoeffCount > 4) ? 2 : 1); - for(ALsizei i{0};i < 4;i++) - { - mInput[i].Gains.fill({}); - const ALdouble hfscale = static_cast<ALdouble>(Ambi3DDecoderHFScale[i]) / hfscales[i]; - for(ALsizei j{0};j < device->Dry.NumChannels;j++) - { - ALdouble gain{0.0}; - for(size_t k{0u};k < COUNTOF(Ambi3DDecoder);k++) - gain += (ALdouble)Ambi3DDecoder[k][i] * encgains[k][j]; - mInput[i].Gains[HF_BAND][j] = (ALfloat)(gain * hfscale); - mInput[i].Gains[LF_BAND][j] = (ALfloat)gain; - } - } - } + const ALfloat (&hfscales)[MAX_AMBI_ORDER+1] = GetDecoderHFScales(out_order); + const ALfloat gain0{std::sqrt(Ambi3DDecoderHFScale[0] / hfscales[0])}; + const ALfloat gain1{std::sqrt(Ambi3DDecoderHFScale[1] / hfscales[1])}; + + mShelf[0].setParams(BiquadType::HighShelf, gain0, xover_norm, + calc_rcpQ_from_slope(gain0, 1.0f)); + mShelf[1].setParams(BiquadType::HighShelf, gain1, xover_norm, + calc_rcpQ_from_slope(gain1, 1.0f)); + for(ALsizei i{2};i < 4;i++) + mShelf[i].copyParamsFrom(mShelf[1]); } -void AmbiUpsampler::process(ALfloat (*OutBuffer)[BUFFERSIZE], const ALsizei OutChannels, const ALfloat (*InSamples)[BUFFERSIZE], const ALsizei SamplesToDo) +void AmbiUpsampler::process(ALfloat (*OutBuffer)[BUFFERSIZE], const ALfloat (*InSamples)[BUFFERSIZE], const ALsizei InChannels, const ALsizei SamplesToDo) { ASSUME(SamplesToDo > 0); + ASSUME(InChannels > 0); + ASSUME(InChannels <= 4); - if(mSimpleUp) - { - for(ALsizei i{0};i < 4;i++) - { - mShelf[i].process(mSamples[0], InSamples[i], SamplesToDo); - - const ALfloat *RESTRICT src{al::assume_aligned<16>(mSamples[0])}; - ALfloat *dst{al::assume_aligned<16>(OutBuffer[i])}; - std::transform(src, src+SamplesToDo, dst, dst, std::plus<float>{}); - } - } - else for(auto input = std::begin(mInput);input != std::end(mInput);++input) + for(ALsizei i{0};i < InChannels;i++) { - input->XOver.process(mSamples[HF_BAND], mSamples[LF_BAND], *(InSamples++), SamplesToDo); + mShelf[i].process(mSamples[0], InSamples[i], SamplesToDo); - MixSamples(mSamples[HF_BAND], OutChannels, OutBuffer, input->Gains[HF_BAND].data(), - input->Gains[HF_BAND].data(), 0, 0, SamplesToDo); - MixSamples(mSamples[LF_BAND], OutChannels, OutBuffer, input->Gains[LF_BAND].data(), - input->Gains[LF_BAND].data(), 0, 0, SamplesToDo); + const ALfloat *RESTRICT src{al::assume_aligned<16>(mSamples[0])}; + ALfloat *dst{al::assume_aligned<16>(OutBuffer[i])}; + std::transform(src, src+SamplesToDo, dst, dst, std::plus<float>{}); } } diff --git a/Alc/bformatdec.h b/Alc/bformatdec.h index acc71b18..03deebe5 100644 --- a/Alc/bformatdec.h +++ b/Alc/bformatdec.h @@ -56,8 +56,7 @@ public: /* Stand-alone first-order upsampler. Kept here because it shares some stuff - * with bformatdec. Assumes a periphonic (4-channel) input mix! If output is - * B-Format, it must also be periphonic. + * with bformatdec. */ class AmbiUpsampler { public: @@ -66,16 +65,11 @@ public: private: alignas(16) ALfloat mSamples[sNumBands][BUFFERSIZE]; - bool mSimpleUp; BiquadFilter mShelf[4]; - struct { - BandSplitter XOver; - std::array<std::array<ALfloat,MAX_OUTPUT_CHANNELS>,sNumBands> Gains; - } mInput[4]; public: - void reset(const ALCdevice *device); - void process(ALfloat (*OutBuffer)[BUFFERSIZE], const ALsizei OutChannels, const ALfloat (*InSamples)[BUFFERSIZE], const ALsizei SamplesToDo); + void reset(const ALsizei out_order, const ALfloat xover_norm); + void process(ALfloat (*OutBuffer)[BUFFERSIZE], const ALfloat (*InSamples)[BUFFERSIZE], const ALsizei InChannels, const ALsizei SamplesToDo); DEF_NEWDEL(AmbiUpsampler) }; diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 820d2268..a89e0493 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -385,31 +385,29 @@ void InitPanning(ALCdevice *device) count = (device->mAmbiOrder == 3) ? 16 : (device->mAmbiOrder == 2) ? 9 : (device->mAmbiOrder == 1) ? 4 : 1; - std::transform(acnmap.begin(), acnmap.begin()+count, std::begin(device->Dry.Ambi.Map), + std::transform(acnmap.begin(), acnmap.begin()+count, std::begin(device->Dry.AmbiMap), [&n3dscale](const ALsizei &acn) noexcept -> BFChannelConfig { return BFChannelConfig{1.0f/n3dscale[acn], acn}; } ); - device->Dry.CoeffCount = 0; device->Dry.NumChannels = count; if(device->mAmbiOrder < 2) { - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; } else { - device->FOAOut.Ambi = AmbiConfig{}; + device->FOAOut.AmbiMap.fill(BFChannelConfig{}); std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+4, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } ); - device->FOAOut.CoeffCount = 0; device->FOAOut.NumChannels = 4; device->AmbiUp.reset(new AmbiUpsampler{}); - device->AmbiUp->reset(device); + device->AmbiUp->reset(device->mAmbiOrder, + 400.0f / static_cast<ALfloat>(device->Frequency)); } ALfloat nfc_delay{0.0f}; @@ -441,10 +439,9 @@ void InitPanning(ALCdevice *device) } std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+coeffcount, - std::begin(device->Dry.Ambi.Map), + std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); - device->Dry.CoeffCount = 0; device->Dry.NumChannels = coeffcount; TRACE("Enabling %s-order%s ambisonic decoder\n", @@ -457,18 +454,16 @@ void InitPanning(ALCdevice *device) if(coeffcount <= 4) { - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; } else { - device->FOAOut.Ambi = AmbiConfig{}; + device->FOAOut.AmbiMap.fill(BFChannelConfig{}); std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+3, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } ); - device->FOAOut.CoeffCount = 0; device->FOAOut.NumChannels = 3; } @@ -488,7 +483,7 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 16 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 9 : 4; std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, - std::begin(device->Dry.Ambi.Map), + std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -497,11 +492,10 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 7 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 5 : 3; std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, - std::begin(device->Dry.Ambi.Map), + std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } - device->Dry.CoeffCount = 0; device->Dry.NumChannels = count; TRACE("Enabling %s-order%s ambisonic decoder\n", @@ -514,18 +508,17 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei if(conf->ChanMask <= AMBI_1ORDER_MASK) { - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; } else { - device->FOAOut.Ambi = AmbiConfig{}; + device->FOAOut.AmbiMap.fill(BFChannelConfig{}); if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { count = 4; std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -533,11 +526,10 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei { count = 3; std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } - device->FOAOut.CoeffCount = 0; device->FOAOut.NumChannels = count; } @@ -557,7 +549,7 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 16 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 9 : 4; std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, - std::begin(device->Dry.Ambi.Map), + std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -566,11 +558,10 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 7 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 5 : 3; std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, - std::begin(device->Dry.Ambi.Map), + std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } - device->Dry.CoeffCount = 0; device->Dry.NumChannels = count; TRACE("Enabling %s-band %s-order%s ambisonic decoder\n", @@ -584,18 +575,17 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp if(conf->ChanMask <= AMBI_1ORDER_MASK) { - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; } else { - device->FOAOut.Ambi = AmbiConfig{}; + device->FOAOut.AmbiMap.fill(BFChannelConfig{}); if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { count = 4; std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -603,11 +593,10 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp { count = 3; std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, - std::begin(device->FOAOut.Ambi.Map), + std::begin(device->FOAOut.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } - device->FOAOut.CoeffCount = 0; device->FOAOut.NumChannels = count; } @@ -704,27 +693,24 @@ void InitHrtfPanning(ALCdevice *device) device->mHrtfState.reset( new (al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count))) DirectHrtfState{}); - std::transform(std::begin(IndexMap), std::begin(IndexMap)+count, std::begin(device->Dry.Ambi.Map), + std::transform(std::begin(IndexMap), std::begin(IndexMap)+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); - device->Dry.CoeffCount = 0; device->Dry.NumChannels = count; if(device->AmbiUp) { - device->FOAOut.Ambi = AmbiConfig{}; - std::transform(std::begin(IndexMap), std::begin(IndexMap)+4, std::begin(device->FOAOut.Ambi.Map), + device->FOAOut.AmbiMap.fill(BFChannelConfig{}); + std::transform(std::begin(IndexMap), std::begin(IndexMap)+4, std::begin(device->FOAOut.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); - device->FOAOut.CoeffCount = 0; device->FOAOut.NumChannels = 4; - device->AmbiUp->reset(device); + device->AmbiUp->reset(2, 400.0f / static_cast<ALfloat>(device->Frequency)); } else { - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; } @@ -744,15 +730,13 @@ void InitUhjPanning(ALCdevice *device) static constexpr ALsizei count{3}; auto acnmap_end = AmbiIndex::FromFuMa.begin() + count; - std::transform(AmbiIndex::FromFuMa.begin(), acnmap_end, std::begin(device->Dry.Ambi.Map), + std::transform(AmbiIndex::FromFuMa.begin(), acnmap_end, std::begin(device->Dry.AmbiMap), [](const ALsizei &acn) noexcept -> BFChannelConfig { return BFChannelConfig{1.0f/AmbiScale::FromFuMa[acn], acn}; } ); - device->Dry.CoeffCount = 0; device->Dry.NumChannels = count; - device->FOAOut.Ambi = device->Dry.Ambi; - device->FOAOut.CoeffCount = device->Dry.CoeffCount; + device->FOAOut.AmbiMap = device->Dry.AmbiMap; device->FOAOut.NumChannels = 0; device->RealOut.NumChannels = device->channelsFromFmt(); @@ -854,21 +838,6 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf } -void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]) -{ - ASSUME(numchans > 0); - auto iter = std::transform(chancoeffs, chancoeffs+numchans, std::begin(gains), - [numcoeffs,coeffs,ingain](const ChannelConfig &chancoeffs) -> ALfloat - { - ASSUME(numcoeffs > 0); - float gain{std::inner_product(std::begin(chancoeffs), std::begin(chancoeffs)+numcoeffs, - coeffs, float{0.0f})}; - return clampf(gain, 0.0f, 1.0f) * ingain; - } - ); - std::fill(iter, std::end(gains), 0.0f); -} - void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]) { ASSUME(numchans > 0); @@ -896,8 +865,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr device->HrtfName.clear(); device->mRenderMode = NormalRender; - device->Dry.Ambi = AmbiConfig{}; - device->Dry.CoeffCount = 0; + device->Dry.AmbiMap.fill(BFChannelConfig{}); device->Dry.NumChannels = 0; std::fill(std::begin(device->NumChannelsPerOrder), std::end(device->NumChannelsPerOrder), 0); diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 69ec9749..9fdec5ac 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -532,20 +532,6 @@ enum RenderMode { }; -using ChannelConfig = ALfloat[MAX_AMBI_COEFFS]; -struct BFChannelConfig { - ALfloat Scale; - ALsizei Index; -}; - -union AmbiConfig { - /* Ambisonic coefficients for mixing to the dry buffer. */ - ChannelConfig Coeffs[MAX_OUTPUT_CHANNELS]; - /* Coefficient channel mapping for mixing to the dry buffer. */ - BFChannelConfig Map[MAX_OUTPUT_CHANNELS]; -}; - - struct BufferSubList { uint64_t FreeMask{~uint64_t{}}; ALbuffer *Buffers{nullptr}; /* 64 */ @@ -635,6 +621,11 @@ public: const DistData& operator[](size_t o) const noexcept { return mChannel[o]; } }; +struct BFChannelConfig { + ALfloat Scale; + ALsizei Index; +}; + /* Size for temporary storage of buffer data, in ALfloats. Larger values need * more memory, while smaller values may need more iterations. The value needs * to be a sensible size, however, as it constrains the max stepping value used @@ -643,12 +634,8 @@ public: #define BUFFERSIZE 2048 struct MixParams { - AmbiConfig Ambi{}; - /* Number of coefficients in each Ambi.Coeffs to mix together (4 for first- - * order, 9 for second-order, etc). If the count is 0, Ambi.Map is used - * instead to map each output to a coefficient index. - */ - ALsizei CoeffCount{0}; + /* Coefficient channel mapping for mixing to the buffer. */ + std::array<BFChannelConfig,MAX_OUTPUT_CHANNELS> AmbiMap; ALfloat (*Buffer)[BUFFERSIZE]{nullptr}; ALsizei NumChannels{0}; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index b004fbf8..29667243 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -453,7 +453,6 @@ inline float ScaleAzimuthFront(float azimuth, float scale) } -void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]); void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]); /** @@ -466,11 +465,7 @@ void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, con */ inline void ComputePanGains(const MixParams *dry, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]) { - if(dry->CoeffCount > 0) - ComputePanningGainsMC(dry->Ambi.Coeffs, dry->NumChannels, dry->CoeffCount, - coeffs, ingain, gains); - else - ComputePanningGainsBF(dry->Ambi.Map, dry->NumChannels, coeffs, ingain, gains); + ComputePanningGainsBF(dry->AmbiMap.data(), dry->NumChannels, coeffs, ingain, gains); } void ComputePanGains(const ALeffectslot *slot, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]); |