Jamoma API  0.6.0.a19
TTGain.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief #TTGain adjusts adio gain
6  *
7  * @authors Timothy Place, Trond Lossius
8  *
9  * @copyright Copyright © 2010, Timothy Place @n
10  * License: This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 #include "TTGain.h"
16 
17 #define thisTTClass TTGain
18 #define thisTTClassName "gain"
19 #define thisTTClassTags "dspEffectsLib, audio, processor, dynamics"
20 
21 
22 TT_AUDIO_CONSTRUCTOR
23 , oldGain(0.0), mInterpolated(0)
24 {
25  registerAttribute(TT("linearGain"), kTypeFloat64, &mGain);
26  registerAttribute(TT("gain"), kTypeFloat64, NULL, (TTGetterMethod)&TTGain::getGain, (TTSetterMethod)&TTGain::setGain);
27  registerAttribute(TT("midiGain"), kTypeFloat64, NULL, (TTGetterMethod)&TTGain::getMidiGain, (TTSetterMethod)&TTGain::setMidiGain);
28  addAttribute(Interpolated, kTypeBoolean);
29  // Set Defaults...
30  setAttributeValue(TT("linearGain"), 0.0);
31  setProcessMethod(processAudio);
32 }
33 
34 
35 TTGain::~TTGain()
36 {
37  ;
38 }
39 
40 
41 
42 TTErr TTGain::setGain(const TTValue& newValue)
43 {
44  mGain = TTDecibelsToLinearGain(newValue);
45  if (mInterpolated)
47  return kTTErrNone;
48 }
49 
50 
52 {
54  if (mInterpolated)
56  return kTTErrNone;
57 }
58 
59 
61 {
62  mGain = TTMidiToLinearGain(newValue);
63  if (mInterpolated)
65  return kTTErrNone;
66 }
67 
68 
70 {
71  value = TTLinearGainToMidi(mGain);
72  return kTTErrNone;
73 }
74 
75 
77 {
78  TTAudioSignal& in = inputs->getSignal(0);
79  TTAudioSignal& out = outputs->getSignal(0);
80  TTUInt16 vs;
81  TTSampleValue *inSample, *outSample;
83  TTChannelCount channel;
84 
85  for (channel=0; channel<numchannels; channel++) {
86  inSample = in.mSampleVectors[channel];
87  outSample = out.mSampleVectors[channel];
88  vs = in.getVectorSizeAsInt();
89  while (vs--)
90  *outSample++ = (*inSample++) * mGain;
91  }
92  return kTTErrNone;
93 }
94 
95 
97 {
98  TTAudioSignal& in = inputs->getSignal(0);
99  TTAudioSignal& out = outputs->getSignal(0);
100  TTUInt16 vs = in.getVectorSizeAsInt();
101  TTSampleValue *inSample, *outSample;
102  TTChannelCount numchannels = TTAudioSignal::getMinChannelCount(in, out);
103  TTChannelCount channel;
104  TTFloat64 increment, temp;
105  increment = (mGain-oldGain)/vs;
106  TTAntiDenormal(increment);
107 
108  for (channel=0; channel<numchannels; channel++) {
109  inSample = in.mSampleVectors[channel];
110  outSample = out.mSampleVectors[channel];
111  vs = in.getVectorSizeAsInt();
112  temp = oldGain;
113  while (vs--){
114  temp = temp + increment;
115  *outSample++ = (*inSample++) * temp;
116  }
117  }
118  oldGain = mGain;
120  return kTTErrNone;
121 }
122 
TTFloat64 TTDecibelsToLinearGain(TTFloat64 value)
Convert decibels into linear ampliude.
TTErr(TTObjectBase::* TTSetterMethod)(const TTAttribute &attribute, const TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:78
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTFloat64 TTLinearGainToDecibels(const TTFloat64 value)
Convert linear amplitude into deciBels.
TTErr getMidiGain(TTValue &value)
Retreive current gain in MIDI units.
Definition: TTGain.cpp:69
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTBoolean mInterpolated
Flag indicating whether interpolation will be applied when gain is changed.
Definition: TTGain.h:34
TTErr processAudioInterpolated(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Alternative audio processing method that might be used temporarily when gain value has been changed i...
Definition: TTGain.cpp:96
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTErr setMidiGain(const TTValue &newValue)
Set the gain using MIDI units.
Definition: TTGain.cpp:60
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTFloat64 TTLinearGainToMidi(TTFloat64 value)
Convert linear amplitude into midi.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr getGain(TTValue &value)
Get current gain in dB units.
Definition: TTGain.cpp:51
64-bit floating point
Definition: TTBase.h:272
Boolean (1/0) or (true/false) flag.
Definition: TTBase.h:281
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTFloat64 TTMidiToLinearGain(TTFloat64 value)
Convert midi into linear amplitude.
A simple container for an array of TTAudioSignal pointers.
TTGain adjusts adio gain
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFloat64 mGain
Linear gain to be applied to the input signal.
Definition: TTGain.h:32
TTErr setGain(const TTValue &newValue)
Set the gain using dB units.
Definition: TTGain.cpp:42
No Error.
Definition: TTBase.h:343
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
Definition: TTGain.cpp:76
TTErr(TTObjectBase::* TTGetterMethod)(const TTAttribute &attribute, TTValue &value)
A type that can be used to store a pointer to a message for an object.
Definition: TTObjectBase.h:73
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34