Jamoma API  0.6.0.a19
TTAverage.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspAnalysisLib
4  *
5  * @brief #TTAverage - measuring of averaged and RMS signal energy
6  *
7  * @details
8  *
9  * @authors Nils Peters, Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2011, Nils Peters, Tim Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #ifndef __TT_AVERAGE_H__
18 #define __TT_AVERAGE_H__
19 
20 #include "TTDSP.h"
21 #include "TTDelayBuffer.h"
22 
23 /** TTAverage - measuring averaged and RMS signal energy
24  */
27 
28 protected:
29 
30  TTUInt64 mMaxInterval; ///< The largest possible interval or window to do running averaging over.
31  TTUInt64 mInterval; ///< The interval to do running averaging over.
32  TTFloat64 mIntervalReciprocal; ///< The inverse of #mInterval. Calculated and stored for conviniency and efficiency.
33  TTSampleVector mAccumulator; ///< An accumulator used for calculation of running averages.
34  TTSymbol mMode; ///< Averaging mode, options are absolute, bipolar and rms.
35  TTDelayBufferVector mBins;
36 
37 
38  /** This method gets called when the inherited maxNumChannels attribute is changed.
39  @param aNotUsed1 Not used
40  @param aNotUsed2 Not used
41  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
42  */
43  TTErr updateMaxNumChannels(const TTValue& anOldMaxNumChannels, TTValue& aNotUsed);
44 
45 
46  /** Receives notifications when there are changes to the inherited sr attribute.
47  @todo When window length is set with time, we have to recompute the length in samples and resize mBins
48  @param aNotUsed1 Not used
49  @param aNotUsed2 Not used
50  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
51  */
52  TTErr updateSampleRate(const TTValue& aNotUsed1, TTValue& aNotUsed2);
53 
54 
55  /** Internal method - set up the buffer memory.
56  @param newDelayMaxInSamples New value for maximum samples to permit.
57  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
58  */
59  TTErr init(TTUInt64 newDelayMaxInSamples);
60 
61 
62  /** Internal method - Position the buffer pointers
63  */
64  void reset();
65 
66 
67  /** Audio process method to use when doing bipolar averaging.
68  @param anInputs A pointer to a TTAudioSignal object that may contain any number of channels. This signal is considered the master, and thus it provides the vectorsize and number of channels should the two signals not be matched.
69  @param anOutputs A pointer to a TTAudioSignal object that has the output sample vectors.
70  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
71  */
73 
74 
75  /** An inline method for single sample calculation of bipolar average value.
76  @param anInput An input sample value
77  @param anOutput An output (processed) sample value
78  @param aDelayBuffer Delay buffer used for calculation of running averages
79  @param aChannel The audio channel to perform to processing for
80  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
81  */
82  TTErr calculateBipolarValue(const TTFloat64& anInput, TTFloat64& anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel);
83 
84 
85  /** Audio process method to use when doing absolute value averaging.
86  @param anInputs A pointer to a TTAudioSignal object that may contain any number of channels. This signal is considered the master, and thus it provides the vectorsize and number of channels should the two signals not be matched.
87  @param anOutputs A pointer to a TTAudioSignal object that has the output sample vectors.
88  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
89  */
91 
92 
93  /** An inline method for single sample calculation of absolute average value.
94  @param anInput An input sample value
95  @param anOutput An output (processed) sample value
96  @param aDelayBuffer Delay buffer used for calculation of running averages
97  @param aChannel The audio channel to perform to processing for
98  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
99  */
100  TTErr calculateAbsoluteValue(const TTFloat64& anInput, TTFloat64& anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel);
101 
102 
103  /** Audio process method to use when doing root-mean-square averaging.
104  @param anInputs A pointer to a TTAudioSignal object that may contain any number of channels. This signal is considered the master, and thus it provides the vectorsize and number of channels should the two signals not be matched.
105  @param anOutputs A pointer to a TTAudioSignal object that has the output sample vectors.
106  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
107  */
109 
110 
111  /** An inline method for single sample calculation of rms (root mean square) average value.
112  @param anInput An input sample value
113  @param anOutput An output (processed) sample value
114  @param aDelayBuffer Delay buffer used for calculation of running averages
115  @param aChannel The audio channel to perform to processing for
116  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
117  */
118  TTErr calculateRmsValue(const TTFloat64& anInput, TTFloat64& anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel);
119 
120 
121  /** Unit test.
122  @param returnedTestInfo The outcome from the performed unit test.
123  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
124  */
125  virtual TTErr test(TTValue& returnedTestInfo);
126 
127 public:
128 
129  /** A method for single sample calculation of bipolar average value.
130  @param anInput An input sample value
131  @param anOutput An output (processed) sample value
132  @param aChannel The audio channel to perform to processing for
133  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
134  */
135  TTErr calculateBipolarValue(const TTFloat64& anInput, TTFloat64& anOutput, TTPtrSizedInt aChannel);
136 
137 
138  /** A method for single sample calculation of absolute average value.
139  @param anInput An input sample value
140  @param anOutput An output (processed) sample value
141  @param aChannel The audio channel to perform to processing for
142  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
143  */
144  TTErr calculateAbsoluteValue(const TTFloat64& anInput, TTFloat64& anOutput, TTPtrSizedInt aChannel);
145 
146 
147  /** A method for single sample calculation of rms (root mean square) average value.
148  @param anInput An input sample value
149  @param anOutput An output (processed) sample value
150  @param aChannel The audio channel to perform to processing for
151  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
152  */
153  TTErr calculateRmsValue(const TTFloat64& anInput, TTFloat64& anOutput, TTPtrSizedInt aChannel);
154 
155 
156  /** Reset (clear) the history used in the analysis.
157  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
158  */
159  TTErr clear();
160 
161  /** Set the mode attribute that controlles what averaging mode to use.
162  @details Options are bipolar, absolute and rms. This method also ensures that the correct process method will be used.
163  @param aNewMode The new mode to use.
164  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
165  */
166  TTErr setMode(const TTValue& newValue);
167 
168 
169  /** Set the interval to use when averaging.
170  @param aNewInterval The new interval to use when averaging.
171  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
172  */
173  TTErr setInterval(const TTValue& aNewInterval);
174 
175 
176  /** Set the maximum interval that can be used when averaging.
177  @param aNewMaxInterval The outcome from the performed unit test.
178  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
179  */
180  TTErr setMaxInterval(const TTValue& aNewMaxInterval);
181 
182 };
183 
184 
185 #endif // __TT_AVERAGE_H__
TTSampleVector mAccumulator
An accumulator used for calculation of running averages.
Definition: TTAverage.h:33
TTErr updateMaxNumChannels(const TTValue &anOldMaxNumChannels, TTValue &aNotUsed)
This method gets called when the inherited maxNumChannels attribute is changed.
Definition: TTAverage.cpp:73
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
TTErr setInterval(const TTValue &aNewInterval)
Set the interval to use when averaging.
Definition: TTAverage.cpp:118
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr clear()
Reset (clear) the history used in the analysis.
Definition: TTAverage.cpp:88
TTUInt64 mInterval
The interval to do running averaging over.
Definition: TTAverage.h:31
Jamoma DSP Library.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
Audio delay buffer object.
virtual TTErr test(TTValue &returnedTestInfo)
Unit test.
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTErr setMode(const TTValue &newValue)
Set the mode attribute that controlles what averaging mode to use.
Definition: TTAverage.cpp:96
TTErr updateSampleRate(const TTValue &aNotUsed1, TTValue &aNotUsed2)
Receives notifications when there are changes to the inherited sr attribute.
Definition: TTAverage.cpp:135
std::vector< TTSampleValue > TTSampleVector
A TTSampleVector is simply a pointer to the first of an array of TTSampleValues.
Definition: TTBase.h:233
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTAverage - measuring averaged and RMS signal energy.
Definition: TTAverage.h:25
TTErr setMaxInterval(const TTValue &aNewMaxInterval)
Set the maximum interval that can be used when averaging.
Definition: TTAverage.cpp:127
TTErr processBipolarAverage(TTAudioSignalArrayPtr anInputs, TTAudioSignalArrayPtr anOutputs)
Audio process method to use when doing bipolar averaging.
Definition: TTAverage.cpp:208
TTErr calculateBipolarValue(const TTFloat64 &anInput, TTFloat64 &anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel)
An inline method for single sample calculation of bipolar average value.
Definition: TTAverage.cpp:213
TTSymbol mMode
Averaging mode, options are absolute, bipolar and rms.
Definition: TTAverage.h:34
TTErr init(TTUInt64 newDelayMaxInSamples)
Internal method - set up the buffer memory.
Definition: TTAverage.cpp:60
TTFloat64 mIntervalReciprocal
The inverse of mInterval. Calculated and stored for conviniency and efficiency.
Definition: TTAverage.h:32
TTErr processRmsAverage(TTAudioSignalArrayPtr anInputs, TTAudioSignalArrayPtr anOutputs)
Audio process method to use when doing root-mean-square averaging.
Definition: TTAverage.cpp:235
A simple container for an array of TTAudioSignal pointers.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTErr processAbsoluteAverage(TTAudioSignalArrayPtr anInputs, TTAudioSignalArrayPtr anOutputs)
Audio process method to use when doing absolute value averaging.
Definition: TTAverage.cpp:180
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr calculateAbsoluteValue(const TTFloat64 &anInput, TTFloat64 &anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel)
An inline method for single sample calculation of absolute average value.
Definition: TTAverage.cpp:186
void reset()
Internal method - Position the buffer pointers.
Definition: TTAverage.cpp:80
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTUInt64 mMaxInterval
The largest possible interval or window to do running averaging over.
Definition: TTAverage.h:30
TTDelayBuffer is a container object that holds some audio in a chunk of memory, with accessors for us...
Definition: TTDelayBuffer.h:27
TTErr calculateRmsValue(const TTFloat64 &anInput, TTFloat64 &anOutput, TTDelayBufferPtr aDelayBuffer, TTPtrSizedInt aChannel)
An inline method for single sample calculation of rms (root mean square) average value.
Definition: TTAverage.cpp:241