Jamoma API  0.6.0.a19
TTMuteSolo.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief Unit tests for #TTMuteSolo
6  *
7  * @authors Timothy Place, Trond Lossius
8  *
9  * @copyright Copyright © 2014, 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 "TTMuteSolo.h"
16 
17 
18 TTUInt16 verifyOutputSignal(TTAudio &output, TTFloat64 f0, TTFloat64 f1, TTFloat64 f2, TTFloat64 f3)
19 {
20  int validSampleCount = 0;
21 
22  TTSampleValuePtr outSamples0 = output.rawSamples()[0];
23  TTSampleValuePtr outSamples1 = output.rawSamples()[1];
24  TTSampleValuePtr outSamples2 = output.rawSamples()[2];
25  TTSampleValuePtr outSamples3 = output.rawSamples()[3];
26 
27  for (int i=0; i<64; i++) {
28  validSampleCount += TTTestFloatEquivalence(f0, outSamples0[i]);
29  validSampleCount += TTTestFloatEquivalence(f1, outSamples1[i]);
30  validSampleCount += TTTestFloatEquivalence(f2, outSamples2[i]);
31  validSampleCount += TTTestFloatEquivalence(f3, outSamples3[i]);
32  }
33  return 256 - validSampleCount; // 4 channels * 64 samples = 256 samples
34 
35 }
36 
37 TTErr TTMutesolo::test(TTValue& returnedTestInfo)
38 {
39  int errorCount = 0;
40  int testAssertionCount = 0;
41  TTUInt16 invalidSampleCount;
42 
43  // Test 1: Test how many channels we store info for initially
44  TTTestAssertion("Default number of channels stored is 1",
45  this->mStoredStateNumChannels == 1,
46  testAssertionCount,
47  errorCount);
48 
49 
50  // Test 2a: Mute a channel and confirm that the number of channels stored have been increased accordingly
51  TTValue argIn = 2;
52  argIn.append(1);
53  TTValue argOut;
54  this->setChannelMute(argIn, argOut);
55  this->getChannelMute(argIn, argOut);
56 
57  // Test how many channels we store info for initially
58  TTTestAssertion("Number of channels correctly increased",
59  argOut.size() == 3,
60  testAssertionCount,
61  errorCount);
62 
63  // Test 2b: Test that we have correct mute settings:
64  TTFloat64 absdiff = fabs((TTFloat64)argOut[0]) + fabs((TTFloat64)argOut[1]) + fabs(((TTFloat64)argOut[2]-1.));
65  TTTestAssertion("Channel mute set correctly",
66  TTTestFloatEquivalence(absdiff, 0.0),
67  testAssertionCount,
68  errorCount);
69 
70 
71 
72  // TEST 3: Set solo on a new channel and test that the number of channels stored have been increased accordingly
73  argIn = 3;
74  argIn.append(1);
75  this->setChannelSolo(argIn, argOut);
76  this->getChannelSolo(argIn, argOut);
77 
78  // TEST 3A: Test how many channels we store info for initially
79  TTTestAssertion("Number of channels correctly increased",
80  argOut.size() == 4,
81  testAssertionCount,
82  errorCount);
83 
84  // TEST 3B: Test that we have correct solo settings:
85  absdiff = fabs((TTFloat64)argOut[0]) + fabs((TTFloat64)argOut[1]) + fabs((TTFloat64)argOut[2]) + fabs(((TTFloat64)argOut[3]-1.));
86  TTTestAssertion("Channel mute set correctly",
87  TTTestFloatEquivalence(absdiff, 0.0),
88  testAssertionCount,
89  errorCount);
90 
91  // TEST 3C: Test that we have maintained correct mute settings:
92  this->getChannelMute(argIn, argOut);
93  absdiff = fabs((TTFloat64)argOut[0]) + fabs((TTFloat64)argOut[1]) + fabs(((TTFloat64)argOut[2]-1.)) + fabs((TTFloat64)argOut[3]);
94  TTTestAssertion("Channel mute set correctly",
95  TTTestFloatEquivalence(absdiff, 0.0),
96  testAssertionCount,
97  errorCount);
98 
99 
100 
101  // Preparing to test processed audio signals:
102 
103  // Set the object to process 4 channels
104  this->set(kTTSym_maxNumChannels, 4);
105 
106  // Create two 4-channel audio signals
107  TTAudio input(4);
108  TTAudio output(4);
109 
110  input.allocWithVectorSize(64);
111  output.allocWithVectorSize(64);
112 
113  // Fill the input vectors:
114  for (int i=0; i<64; i++) {
115  input.rawSamples()[0][i] = 1.;
116  input.rawSamples()[1][i] = 2.;
117  input.rawSamples()[2][i] = 4.;
118  input.rawSamples()[3][i] = 8.;
119  }
120 
121 
122 
123  // TEST 4: Are we about to process 4 channels?
124  TTTestAssertion("Ensuring that 4 channels are to be processed",
125  this->mMaxNumChannels == 4,
126  testAssertionCount,
127  errorCount);
128 
129 
130 
131  // TEST 5: Testing that soloing works
132  this->process(input, output);
133 
134  invalidSampleCount = verifyOutputSignal(output, 0., 0., 0., 8.);
135  TTTestAssertion("Soloing seems to work",
136  invalidSampleCount == 0, //
137  testAssertionCount,
138  errorCount);
139  if (invalidSampleCount)
140  TTTestLog("Number of bad samples: %i", invalidSampleCount);;
141 
142 
143 
144  // TEST 6: testing that muting works
145  argIn = 3;
146  argIn.append(0); // Disable soloing again
147  this->setChannelSolo(argIn, argOut);
148  this->getChannelSolo(argIn, argOut);
149 
150  this->process(input, output);
151 
152  invalidSampleCount = verifyOutputSignal(output, 1., 2., 0., 8.);
153  TTTestAssertion("Muting seems to work",
154  invalidSampleCount == 0, //
155  testAssertionCount,
156  errorCount);
157  if (invalidSampleCount)
158  TTTestLog("Number of bad samples: %i", invalidSampleCount);;
159 
160 
161 
162  // TEST 7: Testing clear()
163  this->clear();
164 
165  this->process(input, output);
166 
167  invalidSampleCount = verifyOutputSignal(output, 1., 2., 4., 8.);
168  TTTestAssertion("clear() seems to work",
169  invalidSampleCount == 0, //
170  testAssertionCount,
171  errorCount);
172  if (invalidSampleCount)
173  TTTestLog("Number of bad samples: %i", invalidSampleCount);;
174 
175  // Wrap up the test results to pass back to whoever called this test
176  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
177 }
TTErr getChannelSolo(const TTValue &, TTValue &aSoloValues)
Get current solo settings for all channels as an array.
Definition: TTMuteSolo.cpp:148
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
TTErr setChannelMute(const TTValue &aValue, TTValue &)
Set whether one of the channels is muted or not.
Definition: TTMuteSolo.cpp:90
size_type size() const noexcept
Return the number of elements.
TTErr test(TTValue &returnedTestInfo)
Unit testing.
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
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTChannelCount mStoredStateNumChannels
The number of channels that mute and solo states are currently stored for. This might be higher than ...
Definition: TTMuteSolo.h:33
TTErr clear()
Clear all current mute and solo settings.
Definition: TTMuteSolo.cpp:56
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
Definition: TTValue.h:243
TTMutesolo mutes and soloes channels.
TTErr getChannelMute(const TTValue &, TTValue &aMuteValues)
Get current mute settings for all channels as an array.
Definition: TTMuteSolo.cpp:136
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
TTErr setChannelSolo(const TTValue &aValue, TTValue &)
Set whether one of the channels is soloed or not.
Definition: TTMuteSolo.cpp:113
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
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25