Jamoma API  0.6.0.a19
GainDataspace.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief The #GainDataspace converts between different measurement untis describing audio gain.
6  *
7  * @details The neutral unit of the gain dataspace is _linear gain_.
8  *
9  * @authors Trond Lossius, Tim Place, Nils Peters, ...
10  *
11  * @copyright Copyright © 2007 by Trond Lossius @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 #include "GainDataspace.h"
18 #include <math.h>
19 
20 
21 #define thisTTClass LinearAmplitudeUnit
22 #define thisTTClassName "unit.linear"
23 #define thisTTClassTags "dataspace.unit, gain"
24 
26 TTDataspaceUnit(arguments)
27 {;}
28 
29 LinearAmplitudeUnit::~LinearAmplitudeUnit(){;}
30 
32 {
33  output = input;
34  output.cliplow(0.0);
35 }
36 
37 
39 {
40  output = input;
41 }
42 
43 
44 #undef thisTTClass
45 #undef thisTTClassName
46 #undef thisTTClassTags
47 
48 /***********************************************************************************************/
49 
50 #define thisTTClass MidiGainUnit
51 #define thisTTClassName "unit.midi.gain"
52 #define thisTTClassTags "dataspace.unit, gain"
53 
55 TTDataspaceUnit(arguments)
56 {;}
57 
58 MidiGainUnit::~MidiGainUnit(){;}
59 
60 void MidiGainUnit::convertToNeutral(const TTValue& input, TTValue& output)
61 {
62  output = pow(TTFloat64(input)*0.01, kTTGainMidiPower);
63 }
64 
65 
67 {
68  output = 100.0 * pow(TTFloat64(input), kTTGainMidiPowerInv);
69 }
70 
71 
72 #undef thisTTClass
73 #undef thisTTClassName
74 #undef thisTTClassTags
75 
76 /***********************************************************************************************/
77 
78 #define thisTTClass DecibelUnit
79 #define thisTTClassName "unit.db"
80 #define thisTTClassTags "dataspace.unit, gain"
81 
83 TTDataspaceUnit(arguments)
84 {;}
85 
86 DecibelUnit::~DecibelUnit(){;}
87 
88 void DecibelUnit::convertToNeutral(const TTValue& input, TTValue& output)
89 {
90  output = pow(10.0, TTFloat64(input) * 0.05);
91 }
92 
93 
94 void DecibelUnit::convertFromNeutral(const TTValue& input, TTValue& output)
95 {
96  TTFloat64 temp;
97 
98  // The conversion
99  temp = log10(TTFloat64(input)) * 20.0;
100 
101  // Output decibel range is limited to 24 bit range, avoids problems with singularities (-inf) when using dataspace in ramps
102  if (temp < -144.49)
103  temp = -144.49;
104  output = temp;
105 }
106 
107 
108 #undef thisTTClass
109 #undef thisTTClassName
110 #undef thisTTClassTags
111 
112 /***********************************************************************************************/
113 
114 #define thisTTClass GainDataspace
115 #define thisTTClassName "dataspace.gain"
116 #define thisTTClassTags "foundationDataspaceLib, dataspace, gain"
117 
119 {
120  // Create one of each kind of unit, and cache them in a hash
121  registerUnit(TT("unit.linear"), TT("linear"));
122  registerUnit(TT("unit.midi.gain"), TT("midigain"));
123  registerUnit(TT("unit.db"), TT("dB"));
124  registerUnit(TT("unit.db"), TT("db"));
125 
126  // Set our neutral unit (the unit through which all conversions are made)
127  neutralUnit = TT("linear");
128 
129  // Now that the cache is created, we can create a set of default units
130  setInputUnit(neutralUnit);
131  setOutputUnit(neutralUnit);
132 }
133 
134 
135 GainDataspace::~GainDataspace()
136 {
137  ;
138 }
139 
140 #undef thisTTClass
141 #undef thisTTClassName
142 #undef thisTTClassTags
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to linear.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTFOUNDATION_EXPORT const TTFloat64 kTTGainMidiPowerInv
Invverse power constant used when calculating MID gain.
Definition: TTBase.cpp:35
void cliplow(const TTFloat64 &aLowBound)
Clip numerical values below a specified boundary.
Definition: TTValue.h:289
Specification for the base class of each DataspaceUnit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to midi value.
The GainDataspace converts between different measurement untis describing audio gain.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to decibels.
TTFOUNDATION_EXPORT const TTFloat64 kTTGainMidiPower
Power constant used when calculating MID gain.
Definition: TTBase.cpp:34
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from MIDI units to neutral unit.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from decibel to neutral unit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from linear to neutral unit.