]> git.sesse.net Git - nageru/blob - stereocompressor.h
Let settings follow buses when editing the mapping.
[nageru] / stereocompressor.h
1 #ifndef _STEREOCOMPRESSOR_H
2 #define _STEREOCOMPRESSOR_H 1
3
4 // A simple compressor based on absolute values, with independent
5 // attack/release times. There is no sidechain or lookahead, but the
6 // peak value is shared between both channels.
7 //
8 // The compressor was originally written by, and is copyrighted by, Rune Holm.
9 // It has been adapted and relicensed under GPLv3 (or, at your option,
10 // any later version) for Nageru, so that its license matches the rest of the code.
11
12 class StereoBuffer;
13
14 class StereoCompressor {
15 public:
16         StereoCompressor(float sample_rate)
17                 : sample_rate(sample_rate) {
18                 reset();
19         }
20
21         void reset() {
22                 peak_level = compr_level = 0.1f;
23                 scalefactor = 0.0f;
24         }
25
26         // Process <num_samples> interleaved stereo data in-place.
27         // Attack and release times are in seconds.
28         void process(float *buf, size_t num_samples, float threshold, float ratio,
29                      float attack_time, float release_time, float makeup_gain);
30
31         // Last level estimated (after attack/decay applied).
32         float get_level() { return compr_level; }
33
34         // Last attenuation factor applied, e.g. if 5x compression is currently applied,
35         // this number will be 0.2.
36         float get_attenuation() { return scalefactor; }
37
38 private:
39         float sample_rate;
40         float peak_level;
41         float compr_level;
42         float scalefactor;
43 };
44
45 #endif /* !defined(_STEREOCOMPRESSOR_H) */