Audacity 3.2.0
GainReductionComputer.h
Go to the documentation of this file.
1/*
2 This file is part of the SimpleCompressor project.
3 https://github.com/DanielRudrich/SimpleCompressor
4 Copyright (c) 2019 Daniel Rudrich
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <vector>
22#include <limits>
23#include <cmath>
24#include <atomic>
25
26namespace DanielRudrich {
31{
32public:
35
36 static float getCharacteristicSample(float inputLevelInDecibels,
37 float kneeInDecibels,
38 float thresholdInDecibels, float ratio,
39 float makeUpGainInDecibels);
40
41 // ======================================================================
45 void setAttackTime (const float attackTimeInSeconds);
46
50 void setReleaseTime (const float releaseTimeInSeconds);
51
55 void setKnee (const float kneeInDecibels);
56 const float getKnee() { return knee; }
57
61 void setThreshold (const float thresholdInDecibels);
62 const float getThreshold() { return threshold; }
63
67 void setMakeUpGain (const float makeUpGainInDecibels);
68 const float getMakeUpGain() { return makeUpGain; }
69
73 void setRatio (const float ratio);
74
75 // ======================================================================
79 void getCharacteristic (float* inputLevelsInDecibels, float* destination, const int numSamples);
80
84 float getCharacteristicSample (const float inputLevelInDecibels);
85
86 // ======================================================================
90 void prepare (const double sampleRate);
91
95 void reset() { state = 0.0f; }
96
100 void computeGainInDecibelsFromSidechainSignal (const float* sideChainSignal, float* destination, const int numSamples);
101
105 void computeLinearGainFromSidechainSignal (const float* sideChainSignal, float* destination, const int numSamples);
106
109
110private:
111 static float applyCharacteristicToOverShoot(float overShootInDecibels,
112 float knee, float slope);
113
114 inline const float timeToGain (const float timeInSeconds);
115 inline const float applyCharacteristicToOverShoot (const float overShootInDecibels);
116
118
119 // parameters
124 float slope;
126
127 std::atomic<float> maxInputLevel {-std::numeric_limits<float>::infinity()};
128 std::atomic<float> maxGainReduction {0};
129
130 //state variable
131 float state;
132
135};
136} // namespace DanielRudrich
void prepare(const double sampleRate)
void setMakeUpGain(const float makeUpGainInDecibels)
void getCharacteristic(float *inputLevelsInDecibels, float *destination, const int numSamples)
static float getCharacteristicSample(float inputLevelInDecibels, float kneeInDecibels, float thresholdInDecibels, float ratio, float makeUpGainInDecibels)
void computeGainInDecibelsFromSidechainSignal(const float *sideChainSignal, float *destination, const int numSamples)
static float applyCharacteristicToOverShoot(float overShootInDecibels, float knee, float slope)
void setThreshold(const float thresholdInDecibels)
void setReleaseTime(const float releaseTimeInSeconds)
void setAttackTime(const float attackTimeInSeconds)
void setKnee(const float kneeInDecibels)
const float timeToGain(const float timeInSeconds)
void computeLinearGainFromSidechainSignal(const float *sideChainSignal, float *destination, const int numSamples)