Jamoma API  0.6.0.a19
TTGain.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief Unit tests for #TTGain
6  *
7  * @authors Timothy Place, Trond Lossius
8  *
9  * @copyright Copyright © 2011, Timothy Place, Trond Lossius @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 //! [doxygenChapter60_testExample]
18 TTErr TTGain::test(TTValue& returnedTestInfo)
19 {
20  // preliminary setup
21 
22  int errorCount = 0;
23  int testAssertionCount = 0;
24 
25  TTTestLog("Testing Parameter value conversions");
26 
27  // N test assertions
28 
29  // Test 1: trival value conversion
30  this->set("midiGain", 100);
31  TTTestAssertion("midi gain of 100 == linear gain of 1.",
32  TTTestFloatEquivalence(this->mGain, 1.0),
33  testAssertionCount,
34  errorCount);
35 
36  // Test 2: trival value conversion
37  this->set("midiGain", 99);
38  TTTestAssertion("midi gain of 99 != linear gain of 1.",
39  TTTestFloatEquivalence(this->mGain, 1.0, false),
40  testAssertionCount,
41  errorCount);
42 
43  // Test 3: audio test
44  // set the input signals 1
45  // apply -6 dB gain
46  // check that the signals are properly scaled
47 
48  // create 1 channel audio signals
49  TTAudio input(1);
50  TTAudio output(1);
51 
52  input.allocWithVectorSize(64);
53  output.allocWithVectorSize(64);
54 
55  for (int i=0; i<64; i++)
56  input.rawSamples()[0][i] = 1.0;
57 
58  this->set("gain", -6.0);
59  this->process(input, output);
60 
61  TTSampleValuePtr samples = output.rawSamples()[0];
62  int validSampleCount = 0;
63 
64  for (int i=0; i<64; i++)
65  validSampleCount += TTTestFloatEquivalence(0.5011872336272722, samples[i]);
66 
67  TTTestAssertion("accumulated audio error at gain = -6 dB",
68  validSampleCount == 64,
69  testAssertionCount,
70  errorCount);
71  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
72 
73  // Wrap up the test results to pass back to whoever called this test
74  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
75 }
76 //! [doxygenChapter60_testExample]
virtual TTErr test(TTValue &returnedTestInfo)
Gain unit test.
Definition: TTGain.test.cpp:18
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object This is the same as calling setAttributeValue().
Definition: TTObjectBase.h:251
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
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
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25