diff options
-rw-r--r-- | alc/alu.h | 19 | ||||
-rw-r--r-- | alc/effects/autowah.cpp | 8 | ||||
-rw-r--r-- | alc/effects/compressor.cpp | 8 | ||||
-rw-r--r-- | alc/effects/equalizer.cpp | 8 | ||||
-rw-r--r-- | alc/effects/modulator.cpp | 8 | ||||
-rw-r--r-- | alc/effects/vmorpher.cpp | 8 |
6 files changed, 30 insertions, 29 deletions
@@ -4,6 +4,7 @@ #include <array> #include <cmath> #include <cstddef> +#include <type_traits> #include "AL/al.h" @@ -134,11 +135,21 @@ void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const fl const al::span<float,MAX_OUTPUT_CHANNELS> gains); -inline std::array<float,MAX_AMBI_CHANNELS> GetAmbiIdentityRow(size_t i) noexcept +/** Helper to set an identity/pass-through panning for ambisonic mixing (3D input). */ +template<typename T, typename I, typename F> +auto SetAmbiPanIdentity(T iter, I count, F func) -> std::enable_if_t<std::is_integral<I>::value> { - std::array<float,MAX_AMBI_CHANNELS> ret{}; - ret[i] = 1.0f; - return ret; + if(count < 1) return; + + std::array<float,MAX_AMBI_CHANNELS> coeffs{{1.0f}}; + func(*iter, coeffs); + ++iter; + for(I i{1};i < count;++i,++iter) + { + coeffs[i-1] = 0.0f; + coeffs[i ] = 1.0f; + func(*iter, coeffs); + } } diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index 0bf2450d..3ebb1544 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -118,11 +118,9 @@ void AutowahState::update(const ALCcontext *context, const ALeffectslot *slot, c mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / frequency; mOutTarget = target.Main->Buffer; - for(size_t i{0u};i < slot->Wet.Buffer.size();++i) - { - auto coeffs = GetAmbiIdentityRow(i); - ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); - } + auto set_gains = [slot,target](auto &chan, al::span<const float,MAX_AMBI_CHANNELS> coeffs) + { ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, chan.TargetGains); }; + SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains); } void AutowahState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) diff --git a/alc/effects/compressor.cpp b/alc/effects/compressor.cpp index 03751ef0..6724482e 100644 --- a/alc/effects/compressor.cpp +++ b/alc/effects/compressor.cpp @@ -76,11 +76,9 @@ void CompressorState::update(const ALCcontext*, const ALeffectslot *slot, const mEnabled = props->Compressor.OnOff; mOutTarget = target.Main->Buffer; - for(size_t i{0u};i < slot->Wet.Buffer.size();++i) - { - auto coeffs = GetAmbiIdentityRow(i); - ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mGain[i]); - } + auto set_gains = [slot,target](auto &gains, al::span<const float,MAX_AMBI_CHANNELS> coeffs) + { ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, gains); }; + SetAmbiPanIdentity(std::begin(mGain), slot->Wet.Buffer.size(), set_gains); } void CompressorState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index 14ef1758..3005f2f7 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -147,11 +147,9 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot, } mOutTarget = target.Main->Buffer; - for(size_t i{0u};i < slot->Wet.Buffer.size();++i) - { - auto coeffs = GetAmbiIdentityRow(i); - ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); - } + auto set_gains = [slot,target](auto &chan, al::span<const float,MAX_AMBI_CHANNELS> coeffs) + { ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, chan.TargetGains); }; + SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains); } void EqualizerState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index 051f631a..f75e4dc6 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -122,11 +122,9 @@ void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot, mChans[i].Filter.copyParamsFrom(mChans[0].Filter); mOutTarget = target.Main->Buffer; - for(size_t i{0u};i < slot->Wet.Buffer.size();++i) - { - auto coeffs = GetAmbiIdentityRow(i); - ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); - } + auto set_gains = [slot,target](auto &chan, al::span<const float,MAX_AMBI_CHANNELS> coeffs) + { ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, chan.TargetGains); }; + SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains); } void ModulatorState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index 249958c3..8b412d22 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -237,11 +237,9 @@ void VmorpherState::update(const ALCcontext *context, const ALeffectslot *slot, } mOutTarget = target.Main->Buffer; - for(size_t i{0u};i < slot->Wet.Buffer.size();++i) - { - auto coeffs = GetAmbiIdentityRow(i); - ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains); - } + auto set_gains = [slot,target](auto &chan, al::span<const float,MAX_AMBI_CHANNELS> coeffs) + { ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, chan.TargetGains); }; + SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains); } void VmorpherState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) |