Jamoma API  0.6.0.a19
split-gain-join.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup audioGraphLibrary
4  *
5  * @brief Jamoma Audio Graph integration test
6  *
7  * @details Implemented as a unit test for TTAudioGraphGenerator for the time-being...
8  *
9  * @authors Timothy Place, Trond Lossius
10  *
11  * @copyright Copyright © 2011, Timothy Place @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 "TTAudioGraphObject.h"
18 #include "TTAudioGraphGenerator.h"
19 #include "TTAudioGraphInlet.h" // required for windows build
20 
21 /*
22 TTErr TTAudioGraphGenerator::test(TTValue& returnedTestInfo)
23 {
24  int errorCount = 0;
25  int testAssertionCount = 0;
26  int badSampleCount = 0;
27 // TTAudioSignalPtr input = NULL;
28  TTAudioSignalPtr output = NULL;
29  TTAudioGraphPreprocessData mInitData;
30 // TTAudioSignalPtr mAudioSignal = NULL;
31  TTAudioGraphObjectPtr obj0 = NULL;
32  TTAudioGraphObjectPtr obj1 = NULL;
33  TTAudioGraphObjectPtr obj2 = NULL;
34  TTAudioGraphObjectPtr obj3 = NULL;
35  TTAudioGraphObjectPtr obj4 = NULL;
36  TTAudioGraphObjectPtr obj5 = NULL;
37  TTAudioGraphObjectPtr obj6 = NULL;
38  TTAudioGraphObjectPtr obj7 = NULL;
39 // TTAudioGraphObjectPtr obj8 = NULL;
40  TTAudioGraphObjectPtr obj9 = NULL;
41  TTAudioGraphObjectPtr obj10 = NULL;
42 // TTAudioGraphObjectPtr obj11 = NULL;
43  TTAudioGraphObjectPtr obj12 = NULL;
44  TTAudioGraphObjectPtr obj13 = NULL;
45  TTValue audioObjectArguments;
46 
47  memset(&mInitData, 0, sizeof(mInitData));
48  audioObjectArguments.resize(3);
49 
50  // Create the Graph
51 
52  audioObjectArguments.set(0, TT("thru")); // <<-- THIS IS THE SINK ON WHICH WE WILL PULL
53  audioObjectArguments.set(1, 1); // <<-- NUMBER OF INLETS
54  audioObjectArguments.set(2, 1);
55  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj0, audioObjectArguments);
56  obj0->mKernel->setAttributeValue(TT("maxNumChannels"), 0);
57  obj0->mKernel->setAttributeValue(TT("mute"), 0);
58  obj0->mKernel->setAttributeValue(TT("bypass"), 0);
59  obj0->mKernel->setAttributeValue(TT("sampleRate"), 44100);
60 
61  audioObjectArguments.set(0, TT("audio.join"));
62  audioObjectArguments.set(1, 2);
63  audioObjectArguments.set(2, 1);
64  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj1, audioObjectArguments);
65  obj1->mKernel->setAttributeValue(TT("maxNumChannels"), 1);
66  obj1->mKernel->setAttributeValue(TT("mute"), 0);
67  obj1->mKernel->setAttributeValue(TT("bypass"), 0);
68  obj1->mKernel->setAttributeValue(TT("sampleRate"), 44100);
69 
70  audioObjectArguments.set(0, TT("gain"));
71  audioObjectArguments.set(1, 1);
72  audioObjectArguments.set(2, 1);
73  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj2, audioObjectArguments);
74  //obj2->mKernel->setAttributeValue(TT("midiGain"), 86.639865);
75  obj2->mKernel->setAttributeValue(TT("maxNumChannels"), 0);
76  obj2->mKernel->setAttributeValue(TT("interpolated"), 0);
77  obj2->mKernel->setAttributeValue(TT("mute"), 0);
78  obj2->mKernel->setAttributeValue(TT("bypass"), 0);
79  //obj2->mKernel->setAttributeValue(TT("gain"), -6.000000);
80  //obj2->mKernel->setAttributeValue(TT("linearGain"), 0.501187);
81  obj2->mKernel->setAttributeValue(TT("linearGain"), 0.25);
82  obj2->mKernel->setAttributeValue(TT("sampleRate"), 44100);
83 
84  audioObjectArguments.set(0, TT("audio.split"));
85  audioObjectArguments.set(1, 1);
86  audioObjectArguments.set(2, 2);
87  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj3, audioObjectArguments);
88  obj3->mKernel->setAttributeValue(TT("maxNumChannels"), 1);
89  TTValue v(1,1);
90  obj3->mKernel->setAttributeValue(TT("groups"), v);
91  obj3->mKernel->setAttributeValue(TT("mute"), 0);
92  obj3->mKernel->setAttributeValue(TT("bypass"), 0);
93  obj3->mKernel->setAttributeValue(TT("sampleRate"), 44100);
94 
95  audioObjectArguments.set(0, TT("audio.generator"));
96  audioObjectArguments.set(1, 0);
97  audioObjectArguments.set(2, 1);
98  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj4, audioObjectArguments);
99  obj4->mKernel->setAttributeValue(TT("maxNumChannels"), 2);
100  obj4->mKernel->setAttributeValue(TT("mute"), 0);
101  obj4->mKernel->setAttributeValue(TT("bypass"), 0);
102  obj4->mKernel->setAttributeValue(TT("vectorSize"), 64);
103  obj4->mKernel->setAttributeValue(TT("sampleRate"), 44100);
104  obj4->addAudioFlag(kTTAudioGraphGenerator);
105  obj4->setOutputNumChannels(0, 2);
106 
107  obj3->connectAudio(obj4, 0, 0);
108  obj2->connectAudio(obj3, 0, 0);
109 
110 // TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&obj8, TTValue(TT("plugtastic.parameter")));
111 // ((PlugtasticParameter*)obj8->mKernel)->setOwner(obj8);
112 // obj8->mKernel->setAttributeValue(TT("rangeTop"), 24.000000);
113 // obj8->mKernel->setAttributeValue(TT("bypass"), 0);
114 // obj8->mKernel->setAttributeValue(TT("name"), TT("gain"));
115 // obj8->mKernel->setAttributeValue(TT("style"), TT("decibels"));
116 // obj8->mKernel->setAttributeValue(TT("default"), -6.000000);
117 // obj8->mKernel->setAttributeValue(TT("value"), 0.000000);
118 // obj8->mKernel->setAttributeValue(TT("rangeBottom"), -96.000000);
119 
120 // obj2->connect(obj8);
121  obj1->connectAudio(obj2, 0, 0);
122  audioObjectArguments.set(0, TT("gain"));
123  audioObjectArguments.set(1, 1);
124  audioObjectArguments.set(2, 1);
125  TTObjectBaseInstantiate(TT("audio.object"), (TTObjectBasePtr*)&obj9, audioObjectArguments);
126 // obj9->mKernel->setAttributeValue(TT("midiGain"), 86.639865);
127  obj9->mKernel->setAttributeValue(TT("maxNumChannels"), 0);
128  obj9->mKernel->setAttributeValue(TT("interpolated"), 0);
129  obj9->mKernel->setAttributeValue(TT("mute"), 0);
130  obj9->mKernel->setAttributeValue(TT("bypass"), 0);
131 // obj9->mKernel->setAttributeValue(TT("gain"), -6.000000);
132 // obj9->mKernel->setAttributeValue(TT("linearGain"), 0.501187);
133  obj9->mKernel->setAttributeValue(TT("linearGain"), 0.25);
134  obj9->mKernel->setAttributeValue(TT("sampleRate"), 44100);
135 
136  obj9->connectAudio(obj3, 1, 0);
137 
138 // TTObjectBaseInstantiate(TT("graph.object"), (TTObjectBasePtr*)&obj11, TTValue(TT("plugtastic.parameter")));
139 // ((PlugtasticParameter*)obj11->mKernel)->setOwner(obj11);
140 // obj11->mKernel->setAttributeValue(TT("rangeTop"), 24.000000);
141 // obj11->mKernel->setAttributeValue(TT("bypass"), 0);
142 // obj11->mKernel->setAttributeValue(TT("name"), TT("gain"));
143 // obj11->mKernel->setAttributeValue(TT("style"), TT("decibels"));
144 // obj11->mKernel->setAttributeValue(TT("default"), -6.000000);
145 // obj11->mKernel->setAttributeValue(TT("value"), 0.000000);
146 // obj11->mKernel->setAttributeValue(TT("rangeBottom"), -96.000000);
147 
148 // obj9->connect(obj11);
149  obj1->connectAudio(obj9, 0, 1);
150  obj0->connectAudio(obj1, 0, 0);
151 
152  // SET UP SOME AUDIO AND PULL ON THE GRAPH
153  // obj4 is the source
154  // obj0 is the sink
155 
156  TTSampleValue chan1input[64] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
157  TTSampleValue chan2input[64] = {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
158  TTSampleValue chan1output[64];
159  TTSampleValue chan2output[64];
160 
161 
162  mInitData.vectorSize = 64;
163 
164 
165  TTTestLog("Processing First Pull");
166 
167  TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(0, 64, chan1input);
168  TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(1, 64, chan2input);
169 
170  obj0->lockProcessing();
171  obj0->preprocess(mInitData);
172  obj0->process(output, 0);
173  obj0->unlockProcessing();
174 
175  output->getVectorCopy(0, 64, chan1output);
176  output->getVectorCopy(1, 64, chan2output);
177 
178 
179  // CHECK THE RESULTS
180  for (int i=0; i<64; i++) {
181  TTBoolean result = TTTestFloatEquivalence(chan1output[i], chan1input[i] * 0.25);
182  badSampleCount += !result;
183  if (!result)
184  TTTestLog("CHAN1 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan1output[i], chan1input[i] * 0.25);
185 
186  result = TTTestFloatEquivalence(chan2output[i], chan2input[i] * 0.25);
187  badSampleCount += !result;
188  if (!result)
189  TTTestLog("CHAN2 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan2output[i], chan2input[i] * 0.25);
190  }
191 
192  TTTestAssertion("Produces correct results for first pull",
193  badSampleCount == 0,
194  testAssertionCount,
195  errorCount);
196  if (badSampleCount)
197  TTTestLog("badSampleCount is %i", badSampleCount);
198 
199 
200 
201 
202  TTTestLog("Processing Second Pull");
203 
204  TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(0, 64, chan1input);
205  TTAudioGraphGeneratorPtr(obj4->getUnitGenerator())->mBuffer->setVector64Copy(1, 64, chan2input);
206 
207  obj0->lockProcessing();
208  obj0->preprocess(mInitData);
209  obj0->process(output, 64);
210  obj0->unlockProcessing();
211 
212  output->getVectorCopy(0, 64, chan1output);
213  output->getVectorCopy(1, 64, chan2output);
214 
215 
216  // CHECK THE RESULTS
217  for (int i=0; i<64; i++) {
218  TTBoolean result = TTTestFloatEquivalence(chan1output[i], chan1input[i] * 0.25);
219  badSampleCount += !result;
220  if (!result)
221  TTTestLog("CHAN1 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan1output[i], chan1input[i] * 0.25);
222 
223  result = TTTestFloatEquivalence(chan2output[i], chan2input[i] * 0.25);
224  badSampleCount += !result;
225  if (!result)
226  TTTestLog("CHAN2 BAD SAMPLE @ i=%i ( value=%.10f expected=%.10f )", i, chan2output[i], chan2input[i] * 0.25);
227  }
228 
229  TTTestAssertion("Produces correct results for second pull",
230  badSampleCount == 0,
231  testAssertionCount,
232  errorCount);
233  if (badSampleCount)
234  TTTestLog("badSampleCount is %i", badSampleCount);
235 
236 
237 
238 
239 
240  // FREE MEMORY FROM OUR GRAPH
241 
242  TTObjectBaseRelease((TTObjectBasePtr*)&obj0);
243  TTObjectBaseRelease((TTObjectBasePtr*)&obj1);
244  TTObjectBaseRelease((TTObjectBasePtr*)&obj2);
245  TTObjectBaseRelease((TTObjectBasePtr*)&obj3);
246  TTObjectBaseRelease((TTObjectBasePtr*)&obj4);
247  TTObjectBaseRelease((TTObjectBasePtr*)&obj5);
248  TTObjectBaseRelease((TTObjectBasePtr*)&obj6);
249  TTObjectBaseRelease((TTObjectBasePtr*)&obj7);
250 // TTObjectBaseRelease((TTObjectBasePtr*)&obj8);
251  TTObjectBaseRelease((TTObjectBasePtr*)&obj9);
252  TTObjectBaseRelease((TTObjectBasePtr*)&obj10);
253 // TTObjectBaseRelease((TTObjectBasePtr*)&obj11);
254  TTObjectBaseRelease((TTObjectBasePtr*)&obj12);
255  TTObjectBaseRelease((TTObjectBasePtr*)&obj13);
256 
257 
258  // Wrap up the test results to pass back to whoever called this test
259  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
260 }
261  */
262 
Generates the AudioGraph structure.
Defines a single 'inlet' from an individual AudioGraph object.
Wraps an object from Jamoma DSP to function within AudioGraph.