Audacity 3.2.0
CompressorProcessor.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 CompressorProcessor.h
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#pragma once
12
14#include <array>
15#include <limits>
16#include <memory>
17#include <vector>
18
20{
23} // namespace DanielRudrich
24
25class DYNAMIC_RANGE_PROCESSOR_API CompressorProcessor
26{
27public:
29 {
30 float maxInputSampleDb = -std::numeric_limits<float>::infinity();
31 float dbGainOfMaxInputSample = 0;
32 };
33
34 static float
35 GetMaxCompressionDb(const DynamicRangeProcessorSettings& settings);
36 static float GetMakeupGainDb(const DynamicRangeProcessorSettings& settings);
37 static float EvaluateTransferFunction(
38 const DynamicRangeProcessorSettings& settings, float inputDb);
39
42 // No reason to initialize with compressor settings other than
43 // convenience.
47
48 void ApplySettingsIfNeeded(const DynamicRangeProcessorSettings& settings);
49 void Init(int sampleRate, int numChannels, int blockSize);
50 void Reinit();
52 void
53 Process(const float* const* inBlock, float* const* outBlock, int blockLen);
54 const std::vector<std::vector<float>>& GetDelayedInput() const;
55 const FrameStats& GetLastFrameStats() const;
56 float EvaluateTransferFunction(float inputDb) const;
57
58private:
59 void UpdateEnvelope(const float* const* inBlock, int blockLen);
60 void CopyWithDelay(const float* const* inBlock, int blockLen);
61 void ApplyEnvelope(
62 float* const* outBlock, int blockLen, float& delayedInputMax,
63 int& delayedInputMaxIndex);
64 bool Initialized() const;
65
66 static constexpr auto maxBlockSize = 512;
67
68 const std::unique_ptr<DanielRudrich::GainReductionComputer>
70 const std::unique_ptr<DanielRudrich::LookAheadGainReduction>
73 int mSampleRate = 0;
74 int mNumChannels = 0;
75 int mBlockSize = 0;
76 std::array<float, maxBlockSize> mEnvelope;
77 std::vector<std::vector<float>>
78 mDelayedInput; // Can't conveniently use an array here, because neither
79 // delay time nor sample rate are known at compile time.
80 // Re-allocation during playback is only done if the user
81 // changes the look-ahead settings, in which case glitches
82 // are hardly avoidable anyway.
84};
static Settings & settings()
Definition: TrackInfo.cpp:51
std::array< float, maxBlockSize > mEnvelope
CompressorProcessor(const CompressorProcessor &other)=delete
DynamicRangeProcessorSettings mSettings
const std::unique_ptr< DanielRudrich::GainReductionComputer > mGainReductionComputer
std::vector< std::vector< float > > mDelayedInput
const std::unique_ptr< DanielRudrich::LookAheadGainReduction > mLookAheadGainReduction
DynamicRangeProcessorSettings GetSettings(EffectSettingsAccess &access)