31 return netGain - tfEval;
44 : mGainReductionComputer {
std::make_unique<
46 , mLookAheadGainReduction {
std::make_unique<
60 const auto lookaheadNeedsReinit =
71 if (lookaheadNeedsReinit)
92 const float*
const* inBlock,
float*
const* outBlock,
int blockLen)
102 while (processed < blockLen)
106 in[i] = inBlock[i] + processed;
107 out[i] = outBlock[i] + processed;
113 float delayedInputAbsMax = 0;
114 int delayedInputAbsMaxIndex = 0;
116 out.data(), toProcess, delayedInputAbsMax, delayedInputAbsMaxIndex);
126 processed += toProcess;
130const std::vector<std::vector<float>>&
150 for (
auto i = 0; i < blockLen; ++i)
155 const auto x = std::abs(in[j][i]);
182 float*
const* out,
int blockLen,
float& delayedInputAbsMax,
183 int& delayedInputAbsMaxIndex)
187 std::array<float, 2> chanAbsMax { 0.f, 0.f };
188 std::array<int, 2> chanAbsMaxIndex { 0, 0 };
192 for (
auto j = 0; j < blockLen; ++j)
194 if (std::abs(in[j]) > chanAbsMax[i])
196 chanAbsMax[i] = std::abs(in[j]);
197 chanAbsMaxIndex[i] = j;
200 in[j] * std::pow(10.f, 0.05f * (
mEnvelope[j] + makeupGainDb));
202 std::move(in + blockLen, in + blockLen + d, in);
204 const auto i = chanAbsMax[0] > chanAbsMax[1] ? 0 : 1;
205 delayedInputAbsMax = chanAbsMax[i];
206 delayedInputAbsMaxIndex = chanAbsMaxIndex[i];
218 const auto maxDelay =
222 assert(d <= maxDelay);
225 v.reserve(maxDelay + mBlockSize);
226 v.resize(d + mBlockSize);
227 std::fill(v.begin(), v.end(), 0.f);
constexpr double compressorMaxLookaheadMs
constexpr double limiterMaxLookaheadMs
constexpr float FastLog2(float x)
Approximates the base-2 logarithm of a float to two decimal places, adapted from https://stackoverflo...
static constexpr float log2ToDb
static Settings & settings()
std::array< float, maxBlockSize > mEnvelope
void Init(int sampleRate, int numChannels, int blockSize)
const std::vector< std::vector< float > > & GetDelayedInput() const
void ApplyEnvelope(float *const *outBlock, int blockLen, float &delayedInputMax, int &delayedInputMaxIndex)
void ApplySettingsIfNeeded(const DynamicRangeProcessorSettings &settings)
void CopyWithDelay(const float *const *inBlock, int blockLen)
DynamicRangeProcessorSettings mSettings
void UpdateEnvelope(const float *const *inBlock, int blockLen)
void Process(const float *const *inBlock, float *const *outBlock, int blockLen)
const FrameStats & GetLastFrameStats() const
const std::unique_ptr< DanielRudrich::GainReductionComputer > mGainReductionComputer
std::vector< std::vector< float > > mDelayedInput
static constexpr auto maxBlockSize
const DynamicRangeProcessorSettings & GetSettings() const
static float GetMakeupGainDb(const DynamicRangeProcessorSettings &settings)
FrameStats mLastFrameStats
static float EvaluateTransferFunction(const DynamicRangeProcessorSettings &settings, float inputDb)
const std::unique_ptr< DanielRudrich::LookAheadGainReduction > mLookAheadGainReduction
CompressorProcessor(const DynamicRangeProcessorSettings &settings={ CompressorSettings {} })
static float GetMaxCompressionDb(const DynamicRangeProcessorSettings &settings)
static float getCharacteristicSample(float inputLevelInDecibels, float kneeInDecibels, float thresholdInDecibels, float ratio, float makeUpGainInDecibels)
constexpr auto sampleRate
void copy(const T *src, T *dst, int32_t n)
float dbGainOfMaxInputSample