From a217938275e02349efd47db178cfc067e62e8f1d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 2 Aug 2024 01:35:44 -0700 Subject: [PATCH] Pass a span to Compressor::process --- alc/alu.cpp | 2 +- core/mastering.cpp | 15 +++++---------- core/mastering.h | 4 +--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/alc/alu.cpp b/alc/alu.cpp index 7f8503dce8..644974da41 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -2207,7 +2207,7 @@ uint DeviceBase::renderSamples(const uint numSamples) postProcess(samplesToDo); /* Apply compression, limiting sample amplitude if needed or desired. */ - if(Limiter) Limiter->process(samplesToDo, RealOut.Buffer.data()); + if(Limiter) Limiter->process(samplesToDo, RealOut.Buffer); /* Apply delays and attenuation for mismatched speaker distances. */ if(ChannelDelays) diff --git a/core/mastering.cpp b/core/mastering.cpp index 67fa1c91c2..e31c3e9207 100644 --- a/core/mastering.cpp +++ b/core/mastering.cpp @@ -334,7 +334,6 @@ std::unique_ptr Compressor::Create(const size_t NumChans, const floa BufferLineSize-1.0f)); auto Comp = CompressorPtr{new Compressor{}}; - Comp->mNumChans = NumChans; Comp->mAuto.Knee = AutoKnee; Comp->mAuto.Attack = AutoAttack; Comp->mAuto.Release = AutoRelease; @@ -382,15 +381,11 @@ std::unique_ptr Compressor::Create(const size_t NumChans, const floa Compressor::~Compressor() = default; -void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer) +void Compressor::process(const uint SamplesToDo, const al::span InOut) { - const size_t numChans{mNumChans}; - ASSUME(SamplesToDo > 0); ASSUME(SamplesToDo <= BufferLineSize); - ASSUME(numChans > 0); - const auto output = al::span{OutBuffer, numChans}; const float preGain{mPreGain}; if(preGain != 1.0f) { @@ -400,10 +395,10 @@ void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer) std::transform(buffer.cbegin(), buffer.cend(), buffer.begin(), [preGain](const float s) noexcept { return s * preGain; }); }; - std::for_each(output.begin(), output.end(), apply_gain); + std::for_each(InOut.begin(), InOut.end(), apply_gain); } - linkChannels(SamplesToDo, output); + linkChannels(SamplesToDo, InOut); if(mAuto.Attack || mAuto.Release) crestDetector(SamplesToDo); @@ -416,7 +411,7 @@ void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer) gainCompressor(SamplesToDo); if(!mDelay.empty()) - signalDelay(SamplesToDo, output); + signalDelay(SamplesToDo, InOut); const auto gains = assume_aligned_span<16>(al::span{mSideChain}.first(SamplesToDo)); auto apply_comp = [gains](const FloatBufferSpan inout) noexcept -> void @@ -425,7 +420,7 @@ void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer) std::transform(gains.cbegin(), gains.cend(), buffer.cbegin(), buffer.begin(), std::multiplies{}); }; - for(const FloatBufferSpan inout : output) + for(const FloatBufferSpan inout : InOut) apply_comp(inout); const auto delayedGains = al::span{mSideChain}.subspan(SamplesToDo, mLookAhead); diff --git a/core/mastering.h b/core/mastering.h index 0fafff91e2..0af9a3da67 100644 --- a/core/mastering.h +++ b/core/mastering.h @@ -26,8 +26,6 @@ using uint = unsigned int; * http://c4dm.eecs.qmul.ac.uk/audioengineering/compressors/ */ class SIMDALIGN Compressor { - size_t mNumChans{0u}; - struct AutoFlags { bool Knee : 1; bool Attack : 1; @@ -76,7 +74,7 @@ class SIMDALIGN Compressor { public: ~Compressor(); - void process(const uint SamplesToDo, FloatBufferLine *OutBuffer); + void process(const uint SamplesToDo, al::span InOut); [[nodiscard]] auto getLookAhead() const noexcept -> uint { return mLookAhead; } /**