forked from nu774/qaac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressor.h
More file actions
62 lines (56 loc) · 1.55 KB
/
compressor.h
File metadata and controls
62 lines (56 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef COMPRESSOR_H
#define COMPRESSOR_H
#include "iointer.h"
#include "util.h"
class Compressor: public FilterBase {
const double m_threshold;
const double m_slope;
const double m_knee_width;
const double m_attack;
const double m_release;
const double m_Tlo;
const double m_Thi;
const double m_knee_factor;
double m_yR;
double m_yA;
std::vector<uint8_t > m_pivot;
AudioStreamBasicDescription m_asbd;
public:
Compressor(const std::shared_ptr<ISource> &src,
double threshold, double ratio, double knee_width,
double attack, double release);
const AudioStreamBasicDescription &getSampleFormat() const
{
return m_asbd;
}
size_t readSamples(void *buffer, size_t nsamples);
private:
template <typename T>
size_t readSamplesT(T *buffer, size_t nsamples);
/*
* gain computer, works on log domain
*/
double computeGain(double x)
{
if (x < m_Tlo)
return 0.0;
else if (x > m_Thi)
return m_slope * (x - m_threshold);
else {
double delta = x - m_Tlo;
return delta * delta * m_knee_factor;
}
}
/*
* smooth, level corrected decoupled peak detector
* works on log domain
*/
double smoothAverage(double x, double alphaA, double alphaR)
{
const double eps = 1e-120;
m_yR = std::min(x, alphaR * m_yR + (1.0 - alphaR) * x + eps - eps);
m_yA = alphaA * m_yA + (1.0 - alphaA) * m_yR + eps - eps;
return m_yA;
}
};
#endif