swift
SimpleLimit.h
1 /*
2  * Simple Limiter (header)
3  *
4  * File : SimpleLimit.h
5  * Library : SimpleSource
6  * Version : 1.12
7  * Class : SimpleLimit
8  *
9  * 2006, ChunkWare Music Software, OPEN-SOURCE
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29 
30 
31 #ifndef chunkware_SIMPLE_LIMIT_H
32 #define chunkware_SIMPLE_LIMIT_H
33 
34 #include "SimpleHeader.h" // common header
35 #include "SimpleEnvelope.h" // for base class of FastEnvelope
36 #include "SimpleGain.h" // for gain functions
37 #include <vector>
38 
39 namespace chunkware_simple
40 {
43  {
44  public:
46  SimpleLimit();
47 
49  virtual ~SimpleLimit() {}
50 
53  virtual void setThresh(double dB);
54  virtual void setAttack(double ms) { this->setAttackImpl(ms); } // used in ctor
55  virtual void setRelease(double ms);
57 
60  virtual double getThresh(void) const { return threshdB_; }
61  virtual double getAttack(void) const { return att_.getTc(); }
62  virtual double getRelease(void) const { return rel_.getTc(); }
64 
66  virtual unsigned int getLatency(void) const { return peakHold_; }
67 
70  virtual void setSampleRate(double sampleRate);
71  virtual double getSampleRate(void) { return att_.getSampleRate(); }
73 
75  virtual void initRuntime(void);
76 
78  void process(double &in1, double &in2);
79 
80  protected:
81 
84  {
85  public:
87  FastEnvelope(double ms = 1.0, double sampleRate = 44100.0)
88  : EnvelopeDetector(ms, sampleRate)
89  {}
90 
92  virtual ~FastEnvelope() override {}
93 
94  protected:
96  virtual void setCoef(void) override;
97  };
98 
99  private:
101  void setAttackImpl(double ms);
102 
103  // transfer function
104  double threshdB_; // threshold (dB)
105  double thresh_; // threshold (linear)
106 
107  // max peak
108  unsigned int peakHold_; // peak hold (samples)
109  unsigned int peakTimer_; // peak hold timer
110  double maxPeak_; // max peak
111 
112  // attack/release envelope
113  FastEnvelope att_; // attack
114  FastEnvelope rel_; // release
115  double env_; // over-threshold envelope (linear)
116 
117  // buffer
118  // BUFFER_SIZE default can handle up to ~10ms at 96kHz
119  // change this if you require more
120  static const int BUFFER_SIZE = 1024; // buffer size (always a power of 2!)
121  unsigned int mask_; // buffer mask
122  unsigned int cur_; // cursor
123  std::vector< double > outBuffer_[ 2 ]; // output buffer
124 
125  }; // end SimpleLimit class
126 
127 } // end namespace chunkware_simple
128 
129 // include inlined process function
130 #include "SimpleLimitProcess.inl"
131 
132 #endif // guard
virtual double getTc(void) const
get time constant
virtual double getSampleRate(void) const
get sample rate
Class for faster attack/release.
Definition: SimpleLimit.h:84
FastEnvelope(double ms=1.0, double sampleRate=44100.0)
Ctor.
Definition: SimpleLimit.h:87
virtual void setCoef(void)
Override setCoef() - coefficient calculation.
Definition: SimpleLimit.cpp:96
virtual unsigned int getLatency(void) const
get latency
Definition: SimpleLimit.h:66
virtual double getSampleRate(void)
sample rate
Definition: SimpleLimit.h:71
virtual double getAttack(void) const
get parameters
Definition: SimpleLimit.h:61
virtual void setThresh(double dB)
set parameters
Definition: SimpleLimit.cpp:54
virtual double getThresh(void) const
get parameters
Definition: SimpleLimit.h:60
virtual double getRelease(void) const
get parameters
Definition: SimpleLimit.h:62
virtual void setSampleRate(double sampleRate)
sample rate
Definition: SimpleLimit.cpp:78
virtual void setAttack(double ms)
set parameters
Definition: SimpleLimit.h:54
virtual void setRelease(double ms)
set parameters
Definition: SimpleLimit.cpp:72
virtual void initRuntime(void)
call before runtime (in resume())
Definition: SimpleLimit.cpp:85
void process(double &in1, double &in2)
limiter runtime process