Jamoma API  0.6.0.a19
TTLimiter.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief #TTLimiter implements a lookahead limiter processor for controlling the dynamics of an input.
6  *
7  * @details The way this works is by buffering the input, and delaying it by N samples. That way we are able to see what the output will be some amount of time prior to actually outputting it, and adjust the gain accordingly. @n
8  * @n
9  * After some preprocessing to adjust gain and filter DC offsets on the input, we have an analysis stage. The analysis stage looks at the sample value for each channel at the input, and then uses the hottest sample to calculate the gain adjust that needs to be applied. @n
10  * @n
11  * The release attribute (specified in seconds) determines how long it takes for a gain reduction to "wear off" once the amplitude level of the input has been reduced.
12  *
13  * @authors Tim Place, Trond Lossius
14  *
15  * @copyright Copyright © 2008, Tim Place @n
16  * This code is licensed under the terms of the "New BSD License" @n
17  * http://creativecommons.org/licenses/BSD/
18  */
19 
20 
21 #ifndef __TT_LIMITER_H__
22 #define __TT_LIMITER_H__
23 
24 #include "TTDSP.h"
25 
26 
27 /** TTLimiter implements a lookahead limiter processor for controlling the dynamics of an input.
28 
29  The way this works is by buffering the input, and delaying it by N samples.
30  That way we are able to see what the output will be some amount of time prior to actually outputting it,
31  and adjust the gain accordingly.
32 
33  After some preprocessing to adjust gain and filter DC offsets on the input, we have an analysis stage.
34  The analysis stage looks at the sample value for each channel at the input,
35  and then uses the hottest sample to calculate the gain adjust that needs to be applied.
36 
37  The release attribute (specified in seconds) determines how long it takes for a gain reduction to "wear off"
38  once the amplitude level of the input has been reduced.
39 */
40 class TTLimiter : public TTAudioObjectBase {
42 
43 protected:
44 
45  TTFloat64 recover; ///<
46  TTFloat64 lookaheadInv; ///< reciprocal (inverse) of the lookahead attribute
47  TTUInt32 lookaheadBufferIndex;
48  TTSampleValue** lookaheadBuffer; ///< keep a lookahead buffer for each channel
49  TTSampleValue* gain;
50  TTSampleValue last;
51  TTBoolean isLinear; ///< is attrMode set to linear?
52 
53  TTAudioObject dcBlocker; ///< #TTDCBlock object
54  TTAudioObject preamp; ///< #TTGain object to apply preamp
55 
56  TTUInt32 maxBufferSize; ///< TODO: make this settable
57  TTBoolean attrDCBlocker; ///< If toggled to NO, the internal DC Blocker will be turned off.
58  TTSymbol attrMode; ///< may be one of two symbols: "linear" or "exponential".
59  TTFloat64 attrRelease; ///< number of seconds for the release to recover after a peak in the audio signal.
60  TTUInt32 attrLookahead; ///< number of samples by which to look forward.
61  TTFloat64 attrThreshold; ///< linear amplitude threshold at which the limiting should kick in (attr setter used dB).
62  //TTFloat64 attrPreamp; ///< linear gain scaling factor prior to limiting (attr setter used dB).
63  TTFloat64 attrPostamp; ///< linear gain scaling factor after the limiting (attr setter used dB).
64 
65  /** Override the setter for the inherited maxNumChannels attribute. */
66  TTErr updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&);
67 
68  /** Receives notifications when there are changes to the inherited sr attribute. */
69  TTErr updateSampleRate(const TTValue& oldSampleRate, TTValue&);
70 
71  /** Private utility used by the audio processing routine. */
72  void setRecover();
73 
74  /** Standard audio processing method as used by TTBlue objects. */
76 
77  /** Setter for the threshold attribute. */
78  TTErr setPreamp(TTValue& value);
79  /** Getter for the threshold attribute. */
80  TTErr getPreamp(TTValue& value);
81 
82  /** Setter for the threshold attribute. */
83  TTErr setPostamp(const TTValue& value);
84  /** Getter for the threshold attribute. */
85  TTErr getPostamp(TTValue& value);
86 
87  /** Setter for the threshold attribute. */
88  TTErr setThreshold(const TTValue& value);
89  /** Getter for the threshold attribute. */
90  TTErr getThreshold(TTValue& value);
91 
92  /** Setter for the lookahead attribute, value is in samples. */
93  TTErr setLookahead(TTValue& newValue);
94 
95  /** Setter for the mode attribute. */
96  TTErr setMode(TTValue& newValue);
97 
98  /** Setter for the release attribute. */
99  TTErr setRelease(TTValue& newValue);
100 
101  /** Setter for the dcblocker attribute. */
102  TTErr setDCBlocker(TTValue& newValue);
103 
104  /** Clear the history: reset the limiter. */
105  TTErr clear();
106 };
107 
108 
109 #endif // __TT_LIMITER_H__
TTErr setLookahead(TTValue &newValue)
Setter for the lookahead attribute, value is in samples.
Definition: TTLimiter.cpp:156
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTBoolean isLinear
is attrMode set to linear?
Definition: TTLimiter.h:51
TTErr setThreshold(const TTValue &value)
Setter for the threshold attribute.
Definition: TTLimiter.cpp:143
TTErr getPostamp(TTValue &value)
Getter for the threshold attribute.
Definition: TTLimiter.cpp:136
TTErr setPreamp(TTValue &value)
Setter for the threshold attribute.
Definition: TTLimiter.cpp:119
TTErr getPreamp(TTValue &value)
Getter for the threshold attribute.
Definition: TTLimiter.cpp:124
TTErr setDCBlocker(TTValue &newValue)
Setter for the dcblocker attribute.
Definition: TTLimiter.cpp:184
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTAudioObject dcBlocker
TTDCBlock object
Definition: TTLimiter.h:53
TTFloat64 lookaheadInv
reciprocal (inverse) of the lookahead attribute
Definition: TTLimiter.h:46
TTUInt32 maxBufferSize
TODO: make this settable.
Definition: TTLimiter.h:56
TTErr setPostamp(const TTValue &value)
Setter for the threshold attribute.
Definition: TTLimiter.cpp:130
TTSymbol attrMode
may be one of two symbols: "linear" or "exponential".
Definition: TTLimiter.h:58
Wrap audio objects for convenience.
Jamoma DSP Library.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
Override the setter for the inherited maxNumChannels attribute.
Definition: TTLimiter.cpp:86
TTFloat64 attrRelease
number of seconds for the release to recover after a peak in the audio signal.
Definition: TTLimiter.h:59
TTFloat64 attrThreshold
linear amplitude threshold at which the limiting should kick in (attr setter used dB)...
Definition: TTLimiter.h:61
void setRecover()
Private utility used by the audio processing routine.
Definition: TTLimiter.cpp:213
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
Definition: TTLimiter.cpp:223
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr setMode(TTValue &newValue)
Setter for the mode attribute.
Definition: TTLimiter.cpp:172
TTBoolean attrDCBlocker
If toggled to NO, the internal DC Blocker will be turned off.
Definition: TTLimiter.h:57
TTFloat64 attrPostamp
linear gain scaling factor after the limiting (attr setter used dB).
Definition: TTLimiter.h:63
A simple container for an array of TTAudioSignal pointers.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTUInt32 attrLookahead
number of samples by which to look forward.
Definition: TTLimiter.h:60
TTLimiter implements a lookahead limiter processor for controlling the dynamics of an input...
Definition: TTLimiter.h:40
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
TTErr getThreshold(TTValue &value)
Getter for the threshold attribute.
Definition: TTLimiter.cpp:149
TTErr setRelease(TTValue &newValue)
Setter for the release attribute.
Definition: TTLimiter.cpp:164
TTAudioObject preamp
TTGain object to apply preamp
Definition: TTLimiter.h:54
TTErr clear()
Clear the history: reset the limiter.
Definition: TTLimiter.cpp:191
TTSampleValue ** lookaheadBuffer
keep a lookahead buffer for each channel
Definition: TTLimiter.h:48
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr updateSampleRate(const TTValue &oldSampleRate, TTValue &)
Receives notifications when there are changes to the inherited sr attribute.
Definition: TTLimiter.cpp:112