diff options
author | Chris Robinson <[email protected]> | 2019-02-20 21:01:08 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-02-20 21:01:08 -0800 |
commit | c43381d811f436187b99c51951365c33fc735dc5 (patch) | |
tree | d7c542ccf07bd04f45902b4dfa1f5cf401951ce5 | |
parent | 77ba61ecb3973dab4fff5fdc8bc237a6f4cd0056 (diff) |
Allocate the effect slot wet buffer dynamically
-rw-r--r-- | Alc/alc.cpp | 7 | ||||
-rw-r--r-- | Alc/alu.cpp | 37 | ||||
-rw-r--r-- | Alc/panning.cpp | 14 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 17 |
4 files changed, 38 insertions, 37 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index a08b1261..55104f9e 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2068,8 +2068,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(context->DefaultSlot) { ALeffectslot *slot = context->DefaultSlot.get(); - EffectState *state = slot->Effect.State; + aluInitEffectPanning(slot); + EffectState *state{slot->Effect.State}; state->mOutBuffer = device->Dry.Buffer; state->mOutChannels = device->Dry.NumChannels; if(state->deviceUpdate(device) == AL_FALSE) @@ -2082,8 +2083,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) std::unique_lock<std::mutex> slotlock{context->EffectSlotLock}; for(auto &slot : context->EffectSlotList) { - EffectState *state = slot->Effect.State; + if(!slot) continue; + aluInitEffectPanning(slot.get()); + EffectState *state{slot->Effect.State}; state->mOutBuffer = device->Dry.Buffer; state->mOutChannels = device->Dry.NumChannels; if(state->deviceUpdate(device) == AL_FALSE) diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 39d75954..1888bf3c 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -446,8 +446,8 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) auto iter = std::copy(std::begin(target->ChanMap), std::end(target->ChanMap), std::begin(params.AmbiMap)); std::fill(iter, std::end(params.AmbiMap), BFChannelConfig{}); - params.Buffer = target->WetBuffer; - params.NumChannels = target->NumChannels; + params.Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(target->WetBuffer[0]); + params.NumChannels = target->WetBuffer.size(); output = EffectTarget{¶ms, ¶ms, nullptr}; } @@ -651,7 +651,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev for(ALsizei i{0};i < NumSends;i++) { if(const ALeffectslot *Slot{SendSlots[i]}) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i]*scale0, voice->Send[i].Params[0].Gains.Target); } } @@ -714,7 +714,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev { if(const ALeffectslot *Slot{SendSlots[i]}) for(ALsizei c{0};c < num_channels;c++) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, matrix[c].data(), + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), matrix[c].data(), WetGain[i], voice->Send[i].Params[c].Gains.Target ); } @@ -745,7 +745,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev for(ALsizei i{0};i < NumSends;i++) { if(const ALeffectslot *Slot{SendSlots[i]}) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target ); } @@ -790,7 +790,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev { /* Skip LFE */ if(chans[c].channel != LFE) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i]*downmix_gain, voice->Send[i].Params[c].Gains.Target ); } @@ -824,7 +824,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev for(ALsizei i{0};i < NumSends;i++) { if(const ALeffectslot *Slot{SendSlots[i]}) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target ); } @@ -890,7 +890,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev { /* Skip LFE */ if(chans[c].channel != LFE) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i]*downmix_gain, voice->Send[i].Params[c].Gains.Target ); } @@ -942,7 +942,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev for(ALsizei i{0};i < NumSends;i++) { if(const ALeffectslot *Slot{SendSlots[i]}) - ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, + ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target ); } @@ -1016,8 +1016,8 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons } else { - voice->Send[i].Buffer = SendSlots[i]->WetBuffer; - voice->Send[i].Channels = SendSlots[i]->NumChannels; + voice->Send[i].Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(SendSlots[i]->WetBuffer[0]); + voice->Send[i].Channels = SendSlots[i]->WetBuffer.size(); } } @@ -1124,8 +1124,8 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A } else { - voice->Send[i].Buffer = SendSlots[i]->WetBuffer; - voice->Send[i].Channels = SendSlots[i]->NumChannels; + voice->Send[i].Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(SendSlots[i]->WetBuffer[0]); + voice->Send[i].Channels = SendSlots[i]->WetBuffer.size(); } } @@ -1465,10 +1465,8 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) std::for_each(auxslots->begin(), auxslots->end(), [SamplesToDo](ALeffectslot *slot) -> void { - std::for_each(slot->WetBuffer, slot->WetBuffer+slot->NumChannels, - [SamplesToDo](ALfloat *buffer) -> void - { std::fill_n(buffer, SamplesToDo, 0.0f); } - ); + for(auto &buffer : slot->WetBuffer) + std::fill_n(buffer.begin(), SamplesToDo, 0.0f); } ); @@ -1529,8 +1527,9 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) [SamplesToDo](const ALeffectslot *slot) -> void { EffectState *state{slot->Params.mEffectState}; - state->process(SamplesToDo, slot->WetBuffer, state->mOutBuffer, - state->mOutChannels); + state->process(SamplesToDo, + &reinterpret_cast<const ALfloat(&)[BUFFERSIZE]>(slot->WetBuffer[0]), + state->mOutBuffer, state->mOutChannels); } ); } diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 01ac5ad7..d92570f3 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -861,7 +861,7 @@ void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, con } void ComputePanGains(const ALeffectslot *slot, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]) -{ ComputePanningGainsBF(slot->ChanMap, slot->NumChannels, coeffs, ingain, gains); } +{ ComputePanningGainsBF(slot->ChanMap, slot->WetBuffer.size(), coeffs, ingain, gains); } void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appreq, HrtfRequestMode hrtf_userreq) @@ -1121,10 +1121,12 @@ no_hrtf: void aluInitEffectPanning(ALeffectslot *slot) { - const size_t count{countof(slot->ChanMap)}; + const size_t count{4u}; + slot->WetBuffer.resize(count); + slot->WetBuffer.shrink_to_fit(); + auto acnmap_end = AmbiIndex::From3D.begin() + count; - std::transform(AmbiIndex::From3D.begin(), acnmap_end, std::begin(slot->ChanMap), - [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } - ); - slot->NumChannels = static_cast<ALsizei>(count); + auto iter = std::transform(AmbiIndex::From3D.begin(), acnmap_end, std::begin(slot->ChanMap), + [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; }); + std::fill(iter, std::end(slot->ChanMap), BFChannelConfig{}); } diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index de9e14a4..ccb01266 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -1,8 +1,11 @@ #ifndef _AL_AUXEFFECTSLOT_H_ #define _AL_AUXEFFECTSLOT_H_ +#include <array> + #include "alMain.h" #include "alEffect.h" +#include "ambidefs.h" #include "almalloc.h" #include "atomic.h" @@ -99,19 +102,13 @@ struct ALeffectslot { /* Self ID */ ALuint id{}; - ALsizei NumChannels{}; - BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS]; - /* Wet buffer configuration is ACN channel order with N3D scaling: - * * Channel 0 is the unattenuated mono signal. - * * Channel 1 is OpenAL -X * sqrt(3) - * * Channel 2 is OpenAL Y * sqrt(3) - * * Channel 3 is OpenAL -Z * sqrt(3) + /* Wet buffer configuration is ACN channel order with N3D scaling. * Consequently, effects that only want to work with mono input can use * channel 0 by itself. Effects that want multichannel can process the - * ambisonics signal and make a B-Format source pan for first-order device - * output (FOAOut). + * ambisonics signal and make a B-Format source pan. */ - alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE]; + al::vector<std::array<ALfloat,BUFFERSIZE>,16> WetBuffer; + BFChannelConfig ChanMap[MAX_AMBI_CHANNELS]; ALeffectslot() { PropsClean.test_and_set(std::memory_order_relaxed); } ALeffectslot(const ALeffectslot&) = delete; |