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