Jamoma API  0.6.0.a19
GainDataspace.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Unit tests for the #GainDataspace.
6  *
7  * @authors Trond Lossius, Tim Place, Nils Peters, ...
8  *
9  * @copyright Copyright © 2011 Trond Lossius @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 // Dataspaces and Units employ C++ double-inheritance and are thus unsuitable for direct use
16 // through the usual TTObject API
17 #define TT_NO_DEPRECATION_WARNINGS
18 
19 #include "GainDataspace.h"
20 
21 
22 TTErr GainDataspace::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26 
27  // Create dataspace object and set to temperature
28  try {
29 
30  TTObject myDataspace("dataspace");
31  myDataspace.set(TT("dataspace"), TT("gain"));
32 
33  TTValue v;
34  TTValue expected;
35 
36 
37  /************************************************/
38  /* */
39  /* Test conversions to neutral unit */
40  /* */
41  /************************************************/
42 
43 
44  // Linear => Linear
45 
46  myDataspace.set(TT("inputUnit"), TT("linear"));
47  myDataspace.set(TT("outputUnit"), TT("linear"));
48 
49  v = TTValue(1.23);
50  expected = TTValue(1.23);
51 
52  myDataspace.send(TT("convert"), v, v);
53 
54  TTTestAssertion("linear to linear",
55  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
56  testAssertionCount,
57  errorCount);
58 
59 
60 
61  // dB => Linear
62 
63  myDataspace.set(TT("inputUnit"), TT("dB"));
64  myDataspace.set(TT("outputUnit"), TT("linear"));
65 
66  v = TTValue(0.);
67  expected = TTValue(1.0);
68 
69  myDataspace.send(TT("convert"), v, v);
70 
71  TTTestAssertion("0 dB to linear",
72  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
73  testAssertionCount,
74  errorCount);
75 
76 
77  // midi gain => Linear
78 
79  myDataspace.set(TT("inputUnit"), TT("midigain"));
80  myDataspace.set(TT("outputUnit"), TT("linear"));
81 
82  v = TTValue(100.0);
83  expected = TTValue(1.0);
84 
85  myDataspace.send(TT("convert"), v, v);
86 
87  TTTestAssertion("100 midi gain to linear",
88  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
89  testAssertionCount,
90  errorCount);
91 
92 
93 
94  /************************************************/
95  /* */
96  /* Test conversions from neutral unit */
97  /* */
98  /************************************************/
99 
100  // linear => dB
101 
102  myDataspace.set(TT("inputUnit"), TT("linear"));
103  myDataspace.set(TT("outputUnit"), TT("dB"));
104 
105  v = TTValue(1.0);
106  expected = TTValue(0.0);
107 
108  myDataspace.send(TT("convert"), v, v);
109 
110  TTTestAssertion("1.0 linear to dB",
111  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
112  testAssertionCount,
113  errorCount);
114 
115  myDataspace.set(TT("inputUnit"), TT("linear"));
116  myDataspace.set(TT("outputUnit"), TT("dB"));
117 
118  v = TTValue(0.0);
119  expected = TTValue(-144.49);
120 
121  myDataspace.send(TT("convert"), v, v);
122 
123  TTTestAssertion("0.0 linear to dB, avoid -inf dB by clipping to 24bit resolution (-144.49 dB).",
124  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
125  testAssertionCount,
126  errorCount);
127 
128 
129  // linear => midi gain
130 
131  myDataspace.set(TT("inputUnit"), TT("linear"));
132  myDataspace.set(TT("outputUnit"), TT("midigain"));
133 
134  v = TTValue(1.0);
135  expected = TTValue(100.0);
136 
137  myDataspace.send(TT("convert"), v, v);
138 
139  TTTestAssertion("1.0 linear to midi gain",
140  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
141  testAssertionCount,
142  errorCount);
143 
144  /*****************************************************/
145  /* */
146  /* Some additional important midi gain relationships */
147  /* */
148  /*****************************************************/
149 
150  // 127 midi gain => 10 dB
151 
152  myDataspace.set(TT("inputUnit"), TT("midigain"));
153  myDataspace.set(TT("outputUnit"), TT("dB"));
154 
155  v = TTValue(127.0);
156  expected = TTValue(10.0);
157 
158  myDataspace.send(TT("convert"), v, v);
159 
160  TTTestAssertion("127 midi gain to 10 dB",
161  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
162  testAssertionCount,
163  errorCount);
164 
165  // 10 dB => 127 midi gain
166 
167  myDataspace.set(TT("inputUnit"), TT("dB"));
168  myDataspace.set(TT("outputUnit"), TT("midigain"));
169 
170  v = TTValue(10.0);
171  expected = TTValue(127.0);
172 
173  myDataspace.send(TT("convert"), v, v);
174 
175  TTTestAssertion("10 dB to 127 midi gain",
176  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
177  testAssertionCount,
178  errorCount);
179 
180  // 0 midi gain => 0 linear
181 
182  myDataspace.set(TT("inputUnit"), TT("midigain"));
183  myDataspace.set(TT("outputUnit"), TT("linear"));
184 
185  v = TTValue(0.0);
186  expected = TTValue(0.0);
187 
188  myDataspace.send(TT("convert"), v, v);
189 
190  TTTestAssertion("0 midi gain to 0 linear",
191  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
192  testAssertionCount,
193  errorCount);
194 
195  // 0 linear => 0 midi gain
196 
197  myDataspace.set(TT("inputUnit"), TT("linear"));
198  myDataspace.set(TT("outputUnit"), TT("midigain"));
199 
200  v = TTValue(0.0);
201  expected = TTValue(0.0);
202 
203  myDataspace.send(TT("convert"), v, v);
204 
205  TTTestAssertion("0 linear to 0 midigain",
206  TTTestFloatEquivalence(TTFloat64(v), TTFloat64(expected)),
207  testAssertionCount,
208  errorCount);
209 
210  }
211  catch (...) {
212  TTLogMessage("GainDataspace::test TOTAL FAILURE");
213  errorCount = 1;
214  testAssertionCount = 1;
215  }
216 
217  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
218 }
Create and use Jamoma object instances.
Definition: TTObject.h:29
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
The GainDataspace converts between different measurement untis describing audio gain.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
Definition: TTValue.h:569
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Definition: TTBase.cpp:534
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34