From 9062721fa84322d794e9676974ad1a3e82913b91 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 4 Apr 2023 10:15:54 -0700 Subject: Simplify effect state buffer handling some --- al/auxeffectslot.cpp | 11 ++--------- alc/alc.cpp | 9 ++------- alc/effects/autowah.cpp | 4 ++-- alc/effects/chorus.cpp | 4 ++-- alc/effects/compressor.cpp | 4 ++-- alc/effects/convolution.cpp | 44 +++++++++++++++++++++----------------------- alc/effects/dedicated.cpp | 4 ++-- alc/effects/distortion.cpp | 4 ++-- alc/effects/echo.cpp | 4 ++-- alc/effects/equalizer.cpp | 4 ++-- alc/effects/fshifter.cpp | 4 ++-- alc/effects/modulator.cpp | 4 ++-- alc/effects/null.cpp | 4 ++-- alc/effects/pshifter.cpp | 4 ++-- alc/effects/reverb.cpp | 4 ++-- alc/effects/vmorpher.cpp | 4 ++-- core/effects/base.h | 7 +------ 17 files changed, 52 insertions(+), 71 deletions(-) diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index a559a063..285da1d4 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -125,13 +125,6 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept } -inline auto GetEffectBuffer(ALbuffer *buffer) noexcept -> EffectState::Buffer -{ - if(!buffer) return EffectState::Buffer{}; - return EffectState::Buffer{buffer, buffer->mData}; -} - - void AddActiveEffectSlots(const al::span auxslots, ALCcontext *context) { if(auxslots.empty()) return; @@ -673,7 +666,7 @@ START_API_FUNC FPUCtl mixer_mode{}; auto *state = slot->Effect.State.get(); - state->deviceUpdate(device, GetEffectBuffer(buffer)); + state->deviceUpdate(device, buffer); } break; @@ -952,7 +945,7 @@ ALenum ALeffectslot::initEffect(ALenum effectType, const EffectProps &effectProp state->mOutTarget = device->Dry.Buffer; { FPUCtl mixer_mode{}; - state->deviceUpdate(device, GetEffectBuffer(Buffer)); + state->deviceUpdate(device, Buffer); } Effect.Type = newtype; diff --git a/alc/alc.cpp b/alc/alc.cpp index eb3873f2..af8ff55d 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2318,11 +2318,6 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) { auto *context = static_cast(ctxbase); - auto GetEffectBuffer = [](ALbuffer *buffer) noexcept -> EffectState::Buffer - { - if(!buffer) return EffectState::Buffer{}; - return EffectState::Buffer{buffer, buffer->mData}; - }; std::unique_lock proplock{context->mPropLock}; std::unique_lock slotlock{context->mEffectSlotLock}; @@ -2359,7 +2354,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) EffectState *state{slot->Effect.State.get()}; state->mOutTarget = device->Dry.Buffer; - state->deviceUpdate(device, GetEffectBuffer(slot->Buffer)); + state->deviceUpdate(device, slot->Buffer); slot->updateProps(context); } @@ -2378,7 +2373,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) EffectState *state{slot->Effect.State.get()}; state->mOutTarget = device->Dry.Buffer; - state->deviceUpdate(device, GetEffectBuffer(slot->Buffer)); + state->deviceUpdate(device, slot->Buffer); slot->updateProps(context); } } diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index f32c69b8..4f874ef2 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -81,7 +81,7 @@ struct AutowahState final : public EffectState { alignas(16) float mBufferOut[BufferLineSize]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -90,7 +90,7 @@ struct AutowahState final : public EffectState { DEF_NEWDEL(AutowahState) }; -void AutowahState::deviceUpdate(const DeviceBase*, const Buffer&) +void AutowahState::deviceUpdate(const DeviceBase*, const BufferStorage*) { /* (Re-)initializing parameters and clear the buffers. */ diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 4997a448..10ccf9f6 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -78,7 +78,7 @@ struct ChorusState final : public EffectState { void calcTriangleDelays(const size_t todo); void calcSinusoidDelays(const size_t todo); - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -87,7 +87,7 @@ struct ChorusState final : public EffectState { DEF_NEWDEL(ChorusState) }; -void ChorusState::deviceUpdate(const DeviceBase *Device, const Buffer&) +void ChorusState::deviceUpdate(const DeviceBase *Device, const BufferStorage*) { constexpr float max_delay{maxf(ChorusMaxDelay, FlangerMaxDelay)}; diff --git a/alc/effects/compressor.cpp b/alc/effects/compressor.cpp index 299394cf..0a7ed67a 100644 --- a/alc/effects/compressor.cpp +++ b/alc/effects/compressor.cpp @@ -76,7 +76,7 @@ struct CompressorState final : public EffectState { float mEnvFollower{1.0f}; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -85,7 +85,7 @@ struct CompressorState final : public EffectState { DEF_NEWDEL(CompressorState) }; -void CompressorState::deviceUpdate(const DeviceBase *device, const Buffer&) +void CompressorState::deviceUpdate(const DeviceBase *device, const BufferStorage*) { /* Number of samples to do a full attack and release (non-integer sample * counts are okay). diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index e526e009..7f36c415 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -217,7 +217,7 @@ struct ConvolutionState final : public EffectState { void (ConvolutionState::*mMix)(const al::span,const size_t) {&ConvolutionState::NormalMix}; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -246,7 +246,7 @@ void ConvolutionState::UpsampleMix(const al::span samplesOut, } -void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buffer) +void ConvolutionState::deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) { using UhjDecoderType = UhjDecoder<512>; static constexpr auto DecoderPadding = UhjDecoderType::sInputPadding; @@ -266,16 +266,16 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff mComplexData = nullptr; /* An empty buffer doesn't need a convolution filter. */ - if(!buffer.storage || buffer.storage->mSampleLen < 1) return; + if(!buffer || buffer->mSampleLen < 1) return; - mChannels = buffer.storage->mChannels; - mAmbiLayout = IsUHJ(mChannels) ? AmbiLayout::FuMa : buffer.storage->mAmbiLayout; - mAmbiScaling = IsUHJ(mChannels) ? AmbiScaling::UHJ : buffer.storage->mAmbiScaling; - mAmbiOrder = minu(buffer.storage->mAmbiOrder, MaxConvolveAmbiOrder); + mChannels = buffer->mChannels; + mAmbiLayout = IsUHJ(mChannels) ? AmbiLayout::FuMa : buffer->mAmbiLayout; + mAmbiScaling = IsUHJ(mChannels) ? AmbiScaling::UHJ : buffer->mAmbiScaling; + mAmbiOrder = minu(buffer->mAmbiOrder, MaxConvolveAmbiOrder); constexpr size_t m{ConvolveUpdateSize/2 + 1}; - const auto bytesPerSample = BytesFromFmt(buffer.storage->mType); - const auto realChannels = buffer.storage->channelsFromFmt(); + const auto bytesPerSample = BytesFromFmt(buffer->mType); + const auto realChannels = buffer->channelsFromFmt(); const auto numChannels = (mChannels == FmtUHJ2) ? 3u : ChannelsFromFmt(mChannels, mAmbiOrder); mChans = ChannelDataArray::Create(numChannels); @@ -286,11 +286,11 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff * called very infrequently, go ahead and use the polyphase resampler. */ PPhaseResampler resampler; - if(device->Frequency != buffer.storage->mSampleRate) - resampler.init(buffer.storage->mSampleRate, device->Frequency); + if(device->Frequency != buffer->mSampleRate) + resampler.init(buffer->mSampleRate, device->Frequency); const auto resampledCount = static_cast( - (uint64_t{buffer.storage->mSampleLen}*device->Frequency+(buffer.storage->mSampleRate-1)) / - buffer.storage->mSampleRate); + (uint64_t{buffer->mSampleLen}*device->Frequency+(buffer->mSampleRate-1)) / + buffer->mSampleRate); const BandSplitter splitter{device->mXOverFreq / static_cast(device->Frequency)}; for(auto &e : *mChans) @@ -312,12 +312,12 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff std::fill_n(mComplexData.get(), complex_length, complex_f{}); /* Load the samples from the buffer. */ - const size_t srclinelength{RoundUp(buffer.storage->mSampleLen+DecoderPadding, 16)}; + const size_t srclinelength{RoundUp(buffer->mSampleLen+DecoderPadding, 16)}; auto srcsamples = std::make_unique(srclinelength * numChannels); std::fill_n(srcsamples.get(), srclinelength * numChannels, 0.0f); for(size_t c{0};c < numChannels && c < realChannels;++c) - LoadSamples(srcsamples.get() + srclinelength*c, buffer.samples.data() + bytesPerSample*c, - realChannels, buffer.storage->mType, buffer.storage->mSampleLen); + LoadSamples(srcsamples.get() + srclinelength*c, buffer->mData.data() + bytesPerSample*c, + realChannels, buffer->mType, buffer->mSampleLen); if(IsUHJ(mChannels)) { @@ -325,11 +325,10 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff std::array samples{}; for(size_t c{0};c < numChannels;++c) samples[c] = srcsamples.get() + srclinelength*c; - decoder->decode({samples.data(), numChannels}, buffer.storage->mSampleLen, - buffer.storage->mSampleLen); + decoder->decode({samples.data(), numChannels}, buffer->mSampleLen, buffer->mSampleLen); } - auto ressamples = std::make_unique(buffer.storage->mSampleLen + + auto ressamples = std::make_unique(buffer->mSampleLen + (resampler ? resampledCount : 0)); complex_f *filteriter = mComplexData.get() + mNumConvolveSegs*m; for(size_t c{0};c < numChannels;++c) @@ -337,14 +336,13 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const Buffer &buff /* Resample to match the device. */ if(resampler) { - std::copy_n(srcsamples.get() + srclinelength*c, buffer.storage->mSampleLen, + std::copy_n(srcsamples.get() + srclinelength*c, buffer->mSampleLen, ressamples.get() + resampledCount); - resampler.process(buffer.storage->mSampleLen, ressamples.get()+resampledCount, + resampler.process(buffer->mSampleLen, ressamples.get()+resampledCount, resampledCount, ressamples.get()); } else - std::copy_n(srcsamples.get() + srclinelength*c, buffer.storage->mSampleLen, - ressamples.get()); + std::copy_n(srcsamples.get() + srclinelength*c, buffer->mSampleLen, ressamples.get()); /* Store the first segment's samples in reverse in the time-domain, to * apply as a FIR filter. diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp index e666df9f..047e6761 100644 --- a/alc/effects/dedicated.cpp +++ b/alc/effects/dedicated.cpp @@ -51,7 +51,7 @@ struct DedicatedState final : public EffectState { float mTargetGains[MAX_OUTPUT_CHANNELS]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -60,7 +60,7 @@ struct DedicatedState final : public EffectState { DEF_NEWDEL(DedicatedState) }; -void DedicatedState::deviceUpdate(const DeviceBase*, const Buffer&) +void DedicatedState::deviceUpdate(const DeviceBase*, const BufferStorage*) { std::fill(std::begin(mCurrentGains), std::end(mCurrentGains), 0.0f); } diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index 5e277619..b4e2167e 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -56,7 +56,7 @@ struct DistortionState final : public EffectState { alignas(16) float mBuffer[2][BufferLineSize]{}; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -65,7 +65,7 @@ struct DistortionState final : public EffectState { DEF_NEWDEL(DistortionState) }; -void DistortionState::deviceUpdate(const DeviceBase*, const Buffer&) +void DistortionState::deviceUpdate(const DeviceBase*, const BufferStorage*) { mLowpass.clear(); mBandpass.clear(); diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 7f9edf82..a69529dc 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -69,7 +69,7 @@ struct EchoState final : public EffectState { alignas(16) float mTempBuffer[2][BufferLineSize]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -78,7 +78,7 @@ struct EchoState final : public EffectState { DEF_NEWDEL(EchoState) }; -void EchoState::deviceUpdate(const DeviceBase *Device, const Buffer&) +void EchoState::deviceUpdate(const DeviceBase *Device, const BufferStorage*) { const auto frequency = static_cast(Device->Frequency); diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index 9d7cccef..50bec4ad 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -100,7 +100,7 @@ struct EqualizerState final : public EffectState { alignas(16) FloatBufferLine mSampleBuffer{}; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -109,7 +109,7 @@ struct EqualizerState final : public EffectState { DEF_NEWDEL(EqualizerState) }; -void EqualizerState::deviceUpdate(const DeviceBase*, const Buffer&) +void EqualizerState::deviceUpdate(const DeviceBase*, const BufferStorage*) { for(auto &e : mChans) { diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index 147f7d08..3e6a7385 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -97,7 +97,7 @@ struct FshifterState final : public EffectState { } mGains[2]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -106,7 +106,7 @@ struct FshifterState final : public EffectState { DEF_NEWDEL(FshifterState) }; -void FshifterState::deviceUpdate(const DeviceBase*, const Buffer&) +void FshifterState::deviceUpdate(const DeviceBase*, const BufferStorage*) { /* (Re-)initializing parameters and clear the buffers. */ mCount = 0; diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index 79993c0d..14ee5004 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -93,7 +93,7 @@ struct ModulatorState final : public EffectState { } mChans[MaxAmbiChannels]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -102,7 +102,7 @@ struct ModulatorState final : public EffectState { DEF_NEWDEL(ModulatorState) }; -void ModulatorState::deviceUpdate(const DeviceBase*, const Buffer&) +void ModulatorState::deviceUpdate(const DeviceBase*, const BufferStorage*) { for(auto &e : mChans) { diff --git a/alc/effects/null.cpp b/alc/effects/null.cpp index cda1420e..1f9ae67b 100644 --- a/alc/effects/null.cpp +++ b/alc/effects/null.cpp @@ -20,7 +20,7 @@ struct NullState final : public EffectState { NullState(); ~NullState() override; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -44,7 +44,7 @@ NullState::~NullState() = default; * format) have been changed. Will always be followed by a call to the update * method, if successful. */ -void NullState::deviceUpdate(const DeviceBase* /*device*/, const Buffer& /*buffer*/) +void NullState::deviceUpdate(const DeviceBase* /*device*/, const BufferStorage* /*buffer*/) { } diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index 731a5baf..426a2264 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -105,7 +105,7 @@ struct PshifterState final : public EffectState { float mTargetGains[MaxAmbiChannels]; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -114,7 +114,7 @@ struct PshifterState final : public EffectState { DEF_NEWDEL(PshifterState) }; -void PshifterState::deviceUpdate(const DeviceBase*, const Buffer&) +void PshifterState::deviceUpdate(const DeviceBase*, const BufferStorage*) { /* (Re-)initializing parameters and clear the buffers. */ mCount = 0; diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 83e1207e..3875bedb 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -622,7 +622,7 @@ struct ReverbState final : public EffectState { void allocLines(const float frequency); - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -717,7 +717,7 @@ void ReverbState::allocLines(const float frequency) } } -void ReverbState::deviceUpdate(const DeviceBase *device, const Buffer&) +void ReverbState::deviceUpdate(const DeviceBase *device, const BufferStorage*) { const auto frequency = static_cast(device->Frequency); diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index 97267ad9..872c7add 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -163,7 +163,7 @@ struct VmorpherState final : public EffectState { alignas(16) float mSampleBufferB[MAX_UPDATE_SAMPLES]{}; alignas(16) float mLfo[MAX_UPDATE_SAMPLES]{}; - void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override; + void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override; void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) override; void process(const size_t samplesToDo, const al::span samplesIn, @@ -227,7 +227,7 @@ std::array VmorpherState::getFiltersByPhoneme(VMorpherPhenome p } -void VmorpherState::deviceUpdate(const DeviceBase*, const Buffer&) +void VmorpherState::deviceUpdate(const DeviceBase*, const BufferStorage*) { for(auto &e : mChans) { diff --git a/core/effects/base.h b/core/effects/base.h index 3094f627..0d01044f 100644 --- a/core/effects/base.h +++ b/core/effects/base.h @@ -178,17 +178,12 @@ struct EffectTarget { }; struct EffectState : public al::intrusive_ref { - struct Buffer { - const BufferStorage *storage; - al::span samples; - }; - al::span mOutTarget; virtual ~EffectState() = default; - virtual void deviceUpdate(const DeviceBase *device, const Buffer &buffer) = 0; + virtual void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) = 0; virtual void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props, const EffectTarget target) = 0; virtual void process(const size_t samplesToDo, const al::span samplesIn, -- cgit v1.2.3