aboutsummaryrefslogtreecommitdiffstats
path: root/alc/effects/modulator.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-01-04 22:02:29 -0800
committerChris Robinson <[email protected]>2023-01-04 23:03:15 -0800
commit078b50e0ed6a0b89aa2e1f84bbbebbf24b885a4e (patch)
treedb7bee5d11af40ae01d6210cfd41f6fa60a247f9 /alc/effects/modulator.cpp
parente38413a4fbb0b4f85950c929141856a767993f4f (diff)
Simplify handling effect output for spatial effects
Effects are given a 3D ambisonic buffer of the same order as the device, for processing surround sound. Effects that pass input channels to matching output channels as it processes them don't need to mix each input channel to all output channels. At most, an input channel may mix to a different output channel, if the target buffer uses a different channel layout, and need a gain adjustment, if it uses a different scaling. With a 2D output buffer, a number of channels can be skipped altogether.
Diffstat (limited to 'alc/effects/modulator.cpp')
-rw-r--r--alc/effects/modulator.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp
index c854f1e9..29009247 100644
--- a/alc/effects/modulator.cpp
+++ b/alc/effects/modulator.cpp
@@ -84,10 +84,12 @@ struct ModulatorState final : public EffectState {
uint mStep{1};
struct {
- BiquadFilter Filter;
+ uint mTargetChannel{INVALID_CHANNEL_INDEX};
- float CurrentGains[MaxAmbiChannels]{};
- float TargetGains[MaxAmbiChannels]{};
+ BiquadFilter mFilter;
+
+ float mCurrentGain{};
+ float mTargetGain{};
} mChans[MaxAmbiChannels];
@@ -104,8 +106,9 @@ void ModulatorState::deviceUpdate(const DeviceBase*, const Buffer&)
{
for(auto &e : mChans)
{
- e.Filter.clear();
- std::fill(std::begin(e.CurrentGains), std::end(e.CurrentGains), 0.0f);
+ e.mTargetChannel = INVALID_CHANNEL_INDEX;
+ e.mFilter.clear();
+ e.mCurrentGain = 0.0f;
}
}
@@ -129,14 +132,17 @@ void ModulatorState::update(const ContextBase *context, const EffectSlot *slot,
float f0norm{props->Modulator.HighPassCutoff / static_cast<float>(device->Frequency)};
f0norm = clampf(f0norm, 1.0f/512.0f, 0.49f);
/* Bandwidth value is constant in octaves. */
- mChans[0].Filter.setParamsFromBandwidth(BiquadType::HighPass, f0norm, 1.0f, 0.75f);
+ mChans[0].mFilter.setParamsFromBandwidth(BiquadType::HighPass, f0norm, 1.0f, 0.75f);
for(size_t i{1u};i < slot->Wet.Buffer.size();++i)
- mChans[i].Filter.copyParamsFrom(mChans[0].Filter);
+ mChans[i].mFilter.copyParamsFrom(mChans[0].mFilter);
mOutTarget = target.Main->Buffer;
- auto set_gains = [slot,target](auto &chan, al::span<const float,MaxAmbiChannels> coeffs)
- { ComputePanGains(target.Main, coeffs.data(), slot->Gain, chan.TargetGains); };
- SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains);
+ auto set_channel = [this](size_t idx, uint target, float gain)
+ {
+ mChans[idx].mTargetChannel = target;
+ mChans[idx].mTargetGain = gain;
+ };
+ target.Main->setAmbiMixParams(slot->Wet, slot->Gain, set_channel);
}
void ModulatorState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
@@ -153,14 +159,18 @@ void ModulatorState::process(const size_t samplesToDo, const al::span<const Floa
auto chandata = std::begin(mChans);
for(const auto &input : samplesIn)
{
- alignas(16) float temps[MAX_UPDATE_SAMPLES];
-
- chandata->Filter.process({&input[base], td}, temps);
- for(size_t i{0u};i < td;i++)
- temps[i] *= modsamples[i];
-
- MixSamples({temps, td}, samplesOut, chandata->CurrentGains, chandata->TargetGains,
- samplesToDo-base, base);
+ const size_t outidx{chandata->mTargetChannel};
+ if(outidx != INVALID_CHANNEL_INDEX)
+ {
+ alignas(16) float temps[MAX_UPDATE_SAMPLES];
+
+ chandata->mFilter.process({&input[base], td}, temps);
+ for(size_t i{0u};i < td;i++)
+ temps[i] *= modsamples[i];
+
+ MixSamples({temps, td}, {&samplesOut[outidx], 1}, &chandata->mCurrentGain,
+ &chandata->mTargetGain, samplesToDo-base, base);
+ }
++chandata;
}