Skip to content

Commit

Permalink
Pass a span to Compressor::process
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Aug 2, 2024
1 parent a546042 commit a217938
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion alc/alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions core/mastering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ std::unique_ptr<Compressor> 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;
Expand Down Expand Up @@ -382,15 +381,11 @@ std::unique_ptr<Compressor> 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<FloatBufferLine> 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)
{
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions core/mastering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +74,7 @@ class SIMDALIGN Compressor {

public:
~Compressor();
void process(const uint SamplesToDo, FloatBufferLine *OutBuffer);
void process(const uint SamplesToDo, al::span<FloatBufferLine> InOut);
[[nodiscard]] auto getLookAhead() const noexcept -> uint { return mLookAhead; }

/**
Expand Down

0 comments on commit a217938

Please sign in to comment.