swift
SimpleComp.h
1 /*
2  * Simple Compressor (header)
3  *
4  * File : SimpleComp.h
5  * Library : SimpleSource
6  * Version : 1.12
7  * Class : SimpleComp, SimpleCompRms
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 #ifndef chunkware_simple_SIMPLE_COMP_H
31 #define chunkware_simple_SIMPLE_COMP_H
32 
33 #include "SimpleHeader.h" // common header
34 #include "SimpleEnvelope.h" // for base class
35 #include "SimpleGain.h" // for gain functions
36 
37 namespace chunkware_simple
38 {
40  class SimpleComp : public AttRelEnvelope
41  {
42  public:
44  SimpleComp();
45 
47  virtual ~SimpleComp() {}
48 
51  virtual void setThresh(double dB);
52  virtual void setRatio(double dB);
53  void setMakeUpGain(double gain);
55 
58  virtual double getThresh(void) const { return threshdB_; }
59  virtual double getRatio(void) const { return ratio_; }
60  double getMakeUpGain(void) const { return makeUpGain_; }
62 
65  virtual void initRuntime(void);
66 
68  void process(double &in1, double &in2);
69 
71  void process(double &in1, double &in2, double keyLinked);
72 
73  private:
74  // transfer function
75  double threshdB_; // threshold (dB)
76  double ratio_; // ratio (compression: < 1 ; expansion: > 1)
77 
78  // runtime variables
79  double envdB_; // over-threshold envelope (dB)
80  double makeUpGain_ = 1.0;
81 
82  }; // end SimpleComp class
83 
85  class SimpleCompRms : public SimpleComp
86  {
87  public:
89  SimpleCompRms();
90 
92  virtual ~SimpleCompRms() override {}
93 
95  virtual void setSampleRate(double sampleRate) override;
96 
99  virtual void setWindow(double ms);
100  virtual double getWindow(void) const { return ave_.getTc(); }
102 
105  virtual void initRuntime(void) override; // call before runtime (in resume())
106  void process(double &in1, double &in2); // compressor runtime process
108 
109  private:
110 
111  EnvelopeDetector ave_; // averager
112  double aveOfSqrs_; // average of squares
113 
114  }; // end SimpleCompRms class
115 
116 } // end namespace chunkware_simple
117 
118 // include inlined process function
119 #include "SimpleCompProcess.inl"
120 
121 #endif // guard
attack/release envelope
virtual double getTc(void) const
get time constant
simple compressor
Definition: SimpleComp.h:41
virtual void setThresh(double dB)
set parameters
Definition: SimpleComp.cpp:48
void setMakeUpGain(double gain)
set parameters
Definition: SimpleComp.cpp:61
double getMakeUpGain(void) const
get parameters
Definition: SimpleComp.h:60
virtual double getThresh(void) const
get parameters
Definition: SimpleComp.h:58
virtual ~SimpleComp()
Dtor.
Definition: SimpleComp.h:47
virtual void initRuntime(void)
Init runtime.
Definition: SimpleComp.cpp:67
virtual double getRatio(void) const
get parameters
Definition: SimpleComp.h:59
virtual void setRatio(double dB)
set parameters
Definition: SimpleComp.cpp:54
void process(double &in1, double &in2)
compressor runtime process
Simple compressor with RMS detection.
Definition: SimpleComp.h:86
virtual void setSampleRate(double sampleRate)
Sample rate.
Definition: SimpleComp.cpp:82
virtual void setWindow(double ms)
RMS window.
Definition: SimpleComp.cpp:89
virtual double getWindow(void) const
RMS window.
Definition: SimpleComp.h:100
void process(double &in1, double &in2)
Runtime process.
virtual void initRuntime(void)
Runtime process.
Definition: SimpleComp.cpp:95