Ardour  8.7-15-gadf511264b
private/limiter/limiter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2018 Fons Adriaensen <fons@linuxaudio.org>
3  * Copyright (C) 2021 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU 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 #ifndef _PEAKLIM_H
20 #define _PEAKLIM_H
21 
22 #include <stdint.h>
23 
24 namespace AudioGrapherDSP {
25 
26 class Limiter
27 {
28 public:
29  Limiter ();
31 
32  void init (float fsamp, int nchan);
33  void fini ();
34 
35  void set_inpgain (float);
36  void set_threshold (float);
37  void set_release (float);
38  void set_truepeak (bool);
39 
40  int
41  get_latency () const
42  {
43  return _delay;
44  }
45 
46  void
47  get_stats (float* peak, float* gmax, float* gmin)
48  {
49  *peak = _peak;
50  *gmax = _gmax;
51  *gmin = _gmin;
52  _rstat = true;
53  }
54 
55  void process (int nsamp, float const* inp, float* out);
56 
57 private:
58  class Histmin
59  {
60  public:
61  void init (int hlen);
62  float write (float v);
63  float vmin () { return _vmin; }
64 
65  private:
66  enum {
67  SIZE = 32,
68  MASK = SIZE - 1
69  };
70 
71  int _hlen;
72  int _hold;
73  int _wind;
74  float _vmin;
75  float _hist[SIZE];
76  };
77 
78  class Upsampler
79  {
80  public:
83 
84  void init (int nchan);
85  void fini ();
86 
87  int
88  get_latency () const
89  {
90  return 23;
91  }
92 
93  float process_one (int chn, float const x);
94 
95  private:
96  int _nchan;
97  float** _z;
98  };
99 
100  float _fsamp;
101  int _nchan;
102  bool _truepeak;
103 
104  float** _dly_buf;
105  float* _zlf;
106 
107  int _delay;
110  int _div1, _div2;
111  int _c1, _c2;
112  float _g0, _g1, _dg;
113  float _gt, _m1, _m2;
114  float _w1, _w2, _w3, _wlf;
115  float _z1, _z2, _z3;
116 
117  bool _rstat;
118  float _peak;
119  float _gmax;
120  float _gmin;
121 
125 };
126 
127 }
128 #endif
float process_one(int chn, float const x)
void init(float fsamp, int nchan)
void process(int nsamp, float const *inp, float *out)
void get_stats(float *peak, float *gmax, float *gmin)