Jamoma API  0.6.0.a19
TTSpatSnap.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSpatLib
4  *
5  * @brief Unit tests for the SpatSnap SpatLib spatialisation renderer.
6  *
7  * @details
8  *
9  * @authors Trond Lossius, Nils Peters, Timothy Place
10  *
11  * @copyright Copyright © 2011 by Trond Lossius, Nils Peters, and 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 "TTDSP.h"
18 #include "TTSpatSnap.h"
19 
20 
21 
22 
23 TTErr TTSpatSnap::test(TTValue& aReturnedTestInfo)
24 {
25  // preliminary setup
26  int errorCount = 0;
27  int testAssertionCount = 0;
28 
29  // Attributes and messages
30  TTSpatSnap::testSourceAndSinkCountSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo);
31  TTSpatSnap::testSourcePositionSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo);
32  TTSpatSnap::testSinkPositionSetterAndGetter(testAssertionCount, errorCount, aReturnedTestInfo);
33 
34  // Inspect matrix coefficients
35  TTSpatSnap::testMatrixCoefficients(testAssertionCount, errorCount, aReturnedTestInfo);
36 
37  // Test audio processing
38  TTSpatSnap::testAudioProcessing(testAssertionCount, errorCount, aReturnedTestInfo);
39 
40  // Wrap up the test results to pass back to whoever called this test
41  return TTTestFinish(testAssertionCount, errorCount, aReturnedTestInfo);
42 }
43 
44 TTErr TTSpatSnap::testSourceAndSinkCountSetterAndGetter(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo)
45 {
46 
47  TTTestLog(" ");
48  TTTestLog("Changing number of sources and sinks");
49  TTTestLog(" ");
50 
51  // Check that sourceCount defaults to 1
52 
53  TTFloat64 sourceCountTest;
54  TTFloat64 sinkCountTest;
55 
56  this->getAttributeValue("sourceCount", sourceCountTest);
57  TTTestAssertion("sourceCount attribute defaults to 1",
58  TTTestFloatEquivalence(sourceCountTest, 1.),
59  aTestAssertionCount,
60  anErrorCount);
61 
62  // Check that sinkCount defaults to 1
63 
64  this->getAttributeValue("sinkCount", sinkCountTest);
65  TTTestAssertion("sinkCount attribute attribute defaults to 1",
66  TTTestFloatEquivalence(sinkCountTest, 1.),
67  aTestAssertionCount,
68  anErrorCount);
69 
70  // Test initial matrix size:
71 
72  TTTestAssertion("Initial matrix has 1 row",
73  (this->mRenderer->mMixerMatrixCoefficients->getRowCount())==1,
74  aTestAssertionCount,
75  anErrorCount);
76 
77  TTTestAssertion("Initial matrix has 1 column",
78  (this->mRenderer->mMixerMatrixCoefficients->getColumnCount())==1,
79  aTestAssertionCount,
80  anErrorCount);
81 
82  // Test setter and getter for sourceCount attribute
83 
84  this->setAttributeValue("sourceCount", 7);
85  this->getAttributeValue("sourceCount", sourceCountTest);
86  TTTestAssertion("setter and getter for sourceCount attribute",
87  TTTestFloatEquivalence(sourceCountTest, 7.),
88  aTestAssertionCount,
89  anErrorCount);
90 
91  // Test setter and getter for sinkCount attribute
92 
93  this->setAttributeValue("sinkCount", 5);
94  this->getAttributeValue("sinkCount", sinkCountTest);
95  TTTestAssertion("setter and getter for sinkCount attribute",
96  TTTestFloatEquivalence(sinkCountTest, 5.),
97  aTestAssertionCount,
98  anErrorCount);
99 
100  // Test initial matrix size:
101 
102  TTTestAssertion("Matrix now has 7 rows",
103  (this->mRenderer->mMixerMatrixCoefficients->getRowCount())==7,
104  aTestAssertionCount,
105  anErrorCount);
106 
107  TTTestAssertion("Initial matrix has 5 columns",
108  (this->mRenderer->mMixerMatrixCoefficients->getColumnCount())==5,
109  aTestAssertionCount,
110  anErrorCount);
111 
112 
113  TTTestLog("testing");
114  return kTTErrNone;
115 }
116 
117 
118 TTErr TTSpatSnap::testSourcePositionSetterAndGetter(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo)
119 {
120  TTValue anEntity;
121  TTValue unused;
122  anEntity.resize(4);
123 
124  anEntity.resize(4);
125 
126  // Set source 1: (-2., -3.14, -4.2)
127  anEntity[0] = 1;
128  anEntity[1] = -2.;
129  anEntity[2] = -3.14;
130  anEntity[3] = -4.2;
131  this->sendMessage("setSourcePosition", anEntity, unused);
132 
133  // Source 2: Default = (0., 0., 0.) so we don't set it.
134 
135  // Set source 3: (3.1, 0.2, -0.2)
136 
137  anEntity[0] = 3;
138  anEntity[1] = 3.1;
139  anEntity[2] = 0.2;
140  anEntity[3] = -0.2;
141  this->sendMessage("setSourcePosition", anEntity, unused);
142 
143  // Set source 4: (0., 4.6, 0.)
144 
145  anEntity[0] = 4;
146  anEntity[1] = 0.;
147  anEntity[2] = 4.6;
148  anEntity[3] = 0.;
149  this->sendMessage("setSourcePosition", anEntity, unused);
150 
151  // Set source 5: (-0.1, 0.1, 5.5)
152 
153  anEntity[0] = 5;
154  anEntity[1] = -0.1;
155  anEntity[2] = 0.1;
156  anEntity[3] = 5.5;
157  this->sendMessage("setSourcePosition", anEntity, unused);
158 
159  // Now we test five source positions:
160 
161  TTValue getChannel;
162  TTFloat64 x, y, z;
163  TTInt16 channelNumber;
164 
165  getChannel.resize(1);
166 
167  getChannel.resize(1);
168 
169 
170  // Get and test source 1:
171 
172  TTTestLog(" ");
173  TTTestLog("Setting and getting position of source 1");
174  TTTestLog(" ");
175 
176  anEntity.clear();
177  getChannel[0] = 1;
178 
179  this->sendMessage("getSourcePosition", getChannel, anEntity);
180 
181  TTTestAssertion("getSourcePosition[1]: Returning TTValue array with four members",
182  (anEntity.size() == 4),
183  aTestAssertionCount,
184  anErrorCount);
185 
186  channelNumber = anEntity[0];
187  x = anEntity[1];
188  y = anEntity[2];
189  z = anEntity[3];
190 
191  TTTestAssertion("getSourcePosition[1]: Returning position for correct channel",
192  (channelNumber==1),
193  aTestAssertionCount,
194  anErrorCount);
195 
196  TTTestAssertion("getSourcePosition[1]: Returning correct x-position",
197  TTTestFloatEquivalence(x, -2.),
198  aTestAssertionCount,
199  anErrorCount);
200 
201  TTTestAssertion("getSourcePosition[1]: Returning correct y-position",
202  TTTestFloatEquivalence(y, -3.14),
203  aTestAssertionCount,
204  anErrorCount);
205 
206  TTTestAssertion("getSourcePosition[1]: Returning correct z-position",
207  TTTestFloatEquivalence(z, -4.2),
208  aTestAssertionCount,
209  anErrorCount);
210 
211  // Get and test source 2:
212 
213  TTTestLog(" ");
214  TTTestLog("Getting default position of source 2");
215  TTTestLog(" ");
216 
217  anEntity.clear();
218  getChannel[0] = 2;
219 
220  this->sendMessage("getSourcePosition", getChannel, anEntity);
221 
222  TTTestAssertion("getSourcePosition[2]: Returning TTValue array with four members",
223  (anEntity.size() == 4),
224  aTestAssertionCount,
225  anErrorCount);
226 
227  channelNumber = anEntity[0];
228  x = anEntity[1];
229  y = anEntity[2];
230  z = anEntity[3];
231 
232  TTTestAssertion("getSourcePosition[2]: Returning position for correct channel",
233  (channelNumber==2),
234  aTestAssertionCount,
235  anErrorCount);
236 
237  TTTestAssertion("getSourcePosition[2]: Returning correct default x-position",
238  TTTestFloatEquivalence(x, 0.),
239  aTestAssertionCount,
240  anErrorCount);
241 
242  TTTestAssertion("getSourcePosition[2]: Returning correct default y-position",
243  TTTestFloatEquivalence(y, 0.),
244  aTestAssertionCount,
245  anErrorCount);
246 
247  TTTestAssertion("getSourcePosition[2]: Returning correct default z-position",
248  TTTestFloatEquivalence(z, 0.),
249  aTestAssertionCount,
250  anErrorCount);
251 
252  // Get and test source 3:
253 
254  TTTestLog(" ");
255  TTTestLog("Setting and getting position of source 3");
256  TTTestLog(" ");
257 
258  anEntity.clear();
259  getChannel[0] = 3;
260 
261  this->sendMessage("getSourcePosition", getChannel, anEntity);
262 
263  TTTestAssertion("getSourcePosition[3]: Returning TTValue array with four members",
264  (anEntity.size() == 4),
265  aTestAssertionCount,
266  anErrorCount);
267 
268  channelNumber = anEntity[0];
269  x = anEntity[1];
270  y = anEntity[2];
271  z = anEntity[3];
272 
273  TTTestAssertion("getSourcePosition[3]: Returning position for correct channel",
274  (channelNumber==3),
275  aTestAssertionCount,
276  anErrorCount);
277 
278  TTTestAssertion("getSourcePosition[3]: Returning correct x-position",
279  TTTestFloatEquivalence(x, 3.1),
280  aTestAssertionCount,
281  anErrorCount);
282 
283  TTTestAssertion("getSourcePosition[3]: Returning correct y-position",
284  TTTestFloatEquivalence(y, 0.2),
285  aTestAssertionCount,
286  anErrorCount);
287 
288  TTTestAssertion("getSourcePosition[3]: Returning correct z-position",
289  TTTestFloatEquivalence(z, -0.2),
290  aTestAssertionCount,
291  anErrorCount);
292 
293  // Get and test source 4:
294 
295  TTTestLog(" ");
296  TTTestLog("Setting and getting position of source 4");
297  TTTestLog(" ");
298 
299  anEntity.clear();
300  getChannel[0] = 4;
301 
302  this->sendMessage("getSourcePosition", getChannel, anEntity);
303 
304  TTTestAssertion("getSourcePosition[4]: Returning TTValue array with four members",
305  (anEntity.size() == 4),
306  aTestAssertionCount,
307  anErrorCount);
308 
309  channelNumber = anEntity[0];
310  x = anEntity[1];
311  y = anEntity[2];
312  z = anEntity[3];
313 
314  TTTestAssertion("getSourcePosition[4]: Returning position for correct channel",
315  (channelNumber==4),
316  aTestAssertionCount,
317  anErrorCount);
318 
319  TTTestAssertion("getSourcePosition[4]: Returning correct x-position",
320  TTTestFloatEquivalence(x, 0.),
321  aTestAssertionCount,
322  anErrorCount);
323 
324  TTTestAssertion("getSourcePosition[4]: Returning correct y-position",
325  TTTestFloatEquivalence(y, 4.6),
326  aTestAssertionCount,
327  anErrorCount);
328 
329  TTTestAssertion("getSourcePosition[4]: Returning correct z-position",
330  TTTestFloatEquivalence(z, 0.),
331  aTestAssertionCount,
332  anErrorCount);
333 
334 
335  // Get and test source 5:
336 
337  TTTestLog(" ");
338  TTTestLog("Setting and getting position of source 5");
339  TTTestLog(" ");
340 
341  anEntity.clear();
342  getChannel[0] = 5;
343 
344  this->sendMessage("getSourcePosition", getChannel, anEntity);
345 
346  TTTestAssertion("getSourcePosition[5]: Returning TTValue array with four members",
347  (anEntity.size() == 4),
348  aTestAssertionCount,
349  anErrorCount);
350 
351  channelNumber = anEntity[0];
352  x = anEntity[1];
353  y = anEntity[2];
354  z = anEntity[3];
355 
356  TTTestAssertion("getSourcePosition[5]: Returning position for correct channel",
357  (channelNumber==5),
358  aTestAssertionCount,
359  anErrorCount);
360 
361  TTTestAssertion("getSourcePosition[5]: Returning correct x-position",
362  TTTestFloatEquivalence(x, -0.1),
363  aTestAssertionCount,
364  anErrorCount);
365 
366  TTTestAssertion("getSourcePosition[5]: Returning correct y-position",
367  TTTestFloatEquivalence(y, 0.1),
368  aTestAssertionCount,
369  anErrorCount);
370 
371  TTTestAssertion("getSourcePosition[5]: Returning correct z-position",
372  TTTestFloatEquivalence(z, 5.5),
373  aTestAssertionCount,
374  anErrorCount);
375 
376  return kTTErrNone;
377 }
378 
379 TTErr TTSpatSnap::testSinkPositionSetterAndGetter(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo)
380 {
381  // Set the location of five sinks:
382 
383  TTValue anEntity;
384  TTValue unused;
385  anEntity.resize(4);
386 
387  // Sink 1: Default = (0., 0., 0.) so we don't set it.
388 
389  // Sink 2: (2.2, 0., 0.)
390 
391  anEntity[0] = 2;
392  anEntity[1] = 2.2;
393  anEntity[2] = 0.;
394  anEntity[3] = 0.;
395  this->sendMessage("setSinkPosition", anEntity, unused);
396 
397  // Sink 3: (0., 3.3, 0.)
398 
399  anEntity[0] = 3;
400  anEntity[1] = 0.;
401  anEntity[2] = 3.3;
402  anEntity[3] = 0.;
403  this->sendMessage("setSinkPosition", anEntity, unused);
404 
405  // Sink 4: (0., 0., 4.4)
406 
407  anEntity[0] = 4;
408  anEntity[1] = 0.;
409  anEntity[2] = 0.;
410  anEntity[3] = 4.4;
411  this->sendMessage("setSinkPosition", anEntity, unused);
412 
413  // Sink 5: (-2., -3.14, -4.)
414 
415  anEntity[0] = 5;
416  anEntity[1] = -2.;
417  anEntity[2] = -3.14;
418  anEntity[3] = -4.;
419  this->sendMessage("setSinkPosition", anEntity, unused);
420 
421  // Now we test five sink positions:
422 
423  TTValue getChannel;
424  TTFloat64 x, y, z;
425  TTInt16 channelNumber;
426 
427  getChannel.resize(1);
428 
429  // Get and test sink 1:
430 
431  TTTestLog(" ");
432  TTTestLog("Getting default position of sink 1");
433  TTTestLog(" ");
434 
435  anEntity.clear();
436  getChannel[0] = 1;
437 
438  this->sendMessage("getSinkPosition", getChannel, anEntity);
439 
440  TTTestAssertion("getSinkPosition[1]: Returning TTValue array with four members",
441  (anEntity.size() == 4),
442  aTestAssertionCount,
443  anErrorCount);
444 
445  channelNumber = anEntity[0];
446  x = anEntity[1];
447  y = anEntity[2];
448  z = anEntity[3];
449 
450  TTTestAssertion("getSinkPosition[1]: Returning position for correct channel",
451  (channelNumber==1),
452  aTestAssertionCount,
453  anErrorCount);
454 
455  TTTestAssertion("getSinkPosition[1]: Returning correct default x-position",
456  TTTestFloatEquivalence(x, 0.),
457  aTestAssertionCount,
458  anErrorCount);
459 
460  TTTestAssertion("getSinkPosition[1]: Returning correct default y-position",
461  TTTestFloatEquivalence(y, 0.),
462  aTestAssertionCount,
463  anErrorCount);
464 
465  TTTestAssertion("getSinkPosition[1]: Returning correct default z-position",
466  TTTestFloatEquivalence(z, 0.),
467  aTestAssertionCount,
468  anErrorCount);
469 
470 
471  // Get and test sink 2:
472 
473  TTTestLog(" ");
474  TTTestLog("Setting and getting position of sink 2");
475  TTTestLog(" ");
476 
477  anEntity.clear();
478  getChannel[0] = 2;
479 
480  this->sendMessage("getSinkPosition", getChannel, anEntity);
481 
482  TTTestAssertion("getSinkPosition[2]: Returning TTValue array with four members",
483  (anEntity.size() == 4),
484  aTestAssertionCount,
485  anErrorCount);
486 
487  channelNumber = anEntity[0];
488  x = anEntity[1];
489  y = anEntity[2];
490  z = anEntity[3];
491 
492  TTTestAssertion("getSinkPosition[2]: Returning position for correct channel",
493  (channelNumber==2),
494  aTestAssertionCount,
495  anErrorCount);
496 
497  TTTestAssertion("getSinkPosition[2]: Returning correct x-position",
498  TTTestFloatEquivalence(x, 2.2),
499  aTestAssertionCount,
500  anErrorCount);
501 
502  TTTestAssertion("getSinkPosition[2]: Returning correct y-position",
503  TTTestFloatEquivalence(y, 0.),
504  aTestAssertionCount,
505  anErrorCount);
506 
507  TTTestAssertion("getSinkPosition[2]: Returning correct z-position",
508  TTTestFloatEquivalence(z, 0.),
509  aTestAssertionCount,
510  anErrorCount);
511 
512 
513  // Get and test sink 3:
514 
515  TTTestLog(" ");
516  TTTestLog("Setting and getting position of sink 3");
517  TTTestLog(" ");
518 
519  anEntity.clear();
520  getChannel[0] = 3;
521 
522  this->sendMessage("getSinkPosition", getChannel, anEntity);
523 
524  TTTestAssertion("getSinkPosition[3]: Returning TTValue array with four members",
525  (anEntity.size() == 4),
526  aTestAssertionCount,
527  anErrorCount);
528 
529  channelNumber = anEntity[0];
530  x = anEntity[1];
531  y = anEntity[2];
532  z = anEntity[3];
533 
534  TTTestAssertion("getSinkPosition[3]: Returning position for correct channel",
535  (channelNumber==3),
536  aTestAssertionCount,
537  anErrorCount);
538 
539  TTTestAssertion("getSinkPosition[3]: Returning correct x-position",
540  TTTestFloatEquivalence(x, 0.),
541  aTestAssertionCount,
542  anErrorCount);
543 
544  TTTestAssertion("getSinkPosition[3]: Returning correct y-position",
545  TTTestFloatEquivalence(y, 3.3),
546  aTestAssertionCount,
547  anErrorCount);
548 
549  TTTestAssertion("getSinkPosition[3]: Returning correct z-position",
550  TTTestFloatEquivalence(z, 0.),
551  aTestAssertionCount,
552  anErrorCount);
553 
554 
555  // Get and test sink 4:
556 
557  TTTestLog(" ");
558  TTTestLog("Setting and getting position of sink 4");
559  TTTestLog(" ");
560 
561  anEntity.clear();
562  getChannel[0] = 4;
563 
564  this->sendMessage("getSinkPosition", getChannel, anEntity);
565 
566  TTTestAssertion("getSinkPosition[4]: Returning TTValue array with four members",
567  (anEntity.size() == 4),
568  aTestAssertionCount,
569  anErrorCount);
570 
571  channelNumber = anEntity[0];
572  x = anEntity[1];
573  y = anEntity[2];
574  z = anEntity[3];
575 
576  TTTestAssertion("getSinkPosition[4]: Returning position for correct channel",
577  (channelNumber==4),
578  aTestAssertionCount,
579  anErrorCount);
580 
581  TTTestAssertion("getSinkPosition[4]: Returning correct x-position",
582  TTTestFloatEquivalence(x, 0.),
583  aTestAssertionCount,
584  anErrorCount);
585 
586  TTTestAssertion("getSinkPosition[4]: Returning correct y-position",
587  TTTestFloatEquivalence(y, 0.),
588  aTestAssertionCount,
589  anErrorCount);
590 
591  TTTestAssertion("getSinkPosition[4]: Returning correct z-position",
592  TTTestFloatEquivalence(z, 4.4),
593  aTestAssertionCount,
594  anErrorCount);
595 
596 
597  // Get and test sink 5:
598 
599  TTTestLog(" ");
600  TTTestLog("Setting and getting position of sink 5");
601  TTTestLog(" ");
602 
603  anEntity.clear();
604  getChannel[0] = 5;
605 
606  this->sendMessage("getSinkPosition", getChannel, anEntity);
607 
608  TTTestAssertion("getSinkPosition[5]: Returning TTValue array with four members",
609  (anEntity.size() == 4),
610  aTestAssertionCount,
611  anErrorCount);
612 
613  channelNumber = anEntity[0];
614  x = anEntity[1];
615  y = anEntity[2];
616  z = anEntity[3];
617 
618  TTTestAssertion("getSinkPosition[5]: Returning position for correct channel",
619  (channelNumber==5),
620  aTestAssertionCount,
621  anErrorCount);
622 
623  TTTestAssertion("getSinkPosition[5]: Returning correct x-position",
624  TTTestFloatEquivalence(x, -2.),
625  aTestAssertionCount,
626  anErrorCount);
627 
628  TTTestAssertion("getSinkPosition[5]: Returning correct y-position",
629  TTTestFloatEquivalence(y, -3.14),
630  aTestAssertionCount,
631  anErrorCount);
632 
633  TTTestAssertion("getSinkPosition[5]: Returning correct z-position",
634  TTTestFloatEquivalence(z, -4.),
635  aTestAssertionCount,
636  anErrorCount);
637 
638  return kTTErrNone;
639 }
640 
641 TTErr TTSpatSnap::testMatrixCoefficients(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo)
642 {
643  TTFloat64 expectedValues[7][5];
644  TTFloat64 retrievedCoefficientValues[7][5];
645  TTFloat64 diff;
646  TTFloat64 absDiffSum=0;
647 
648  // Extected matrix values based on matrix size and source/sink positions as set in previous methods
649  expectedValues[0][0] = 0.;
650  expectedValues[0][1] = 0.;
651  expectedValues[0][2] = 0.;
652  expectedValues[0][3] = 0.;
653  expectedValues[0][4] = 1.;
654 
655  expectedValues[1][0] = 1.;
656  expectedValues[1][1] = 0.;
657  expectedValues[1][2] = 0.;
658  expectedValues[1][3] = 0.;
659  expectedValues[1][4] = 0.;
660 
661  expectedValues[2][0] = 0.;
662  expectedValues[2][1] = 1.;
663  expectedValues[2][2] = 0.;
664  expectedValues[2][3] = 0.;
665  expectedValues[2][4] = 0.;
666 
667  expectedValues[3][0] = 0.;
668  expectedValues[3][1] = 0.;
669  expectedValues[3][2] = 1.;
670  expectedValues[3][3] = 0.;
671  expectedValues[3][4] = 0.;
672 
673  expectedValues[4][0] = 0.;
674  expectedValues[4][1] = 0.;
675  expectedValues[4][2] = 0.;
676  expectedValues[4][3] = 1.;
677  expectedValues[4][4] = 0.;
678 
679  expectedValues[5][0] = 1.;
680  expectedValues[5][1] = 0.;
681  expectedValues[5][2] = 0.;
682  expectedValues[5][3] = 0.;
683  expectedValues[5][4] = 0.;
684 
685  expectedValues[6][0] = 1.;
686  expectedValues[6][1] = 0.;
687  expectedValues[6][2] = 0.;
688  expectedValues[6][3] = 0.;
689  expectedValues[6][4] = 0.;
690 
691  // Get all current matrix coefficients
692  for (TTInt16 row=0; row<7; row++) {
693  for (TTInt16 col=0; col<5; col++) {
694  this->mRenderer->mMixerMatrixCoefficients->get2d(row, col, retrievedCoefficientValues[row][col]);
695  diff = retrievedCoefficientValues[row][col] - expectedValues[row][col];
696  absDiffSum += diff*diff;
697  }
698  }
699 
700  TTTestLog("");
701  TTTestAssertion("Correct matrix coefficients",
702  TTTestFloatEquivalence(absDiffSum, 0.),
703  aTestAssertionCount,
704  anErrorCount);
705 
706  return kTTErrNone;
707 }
708 
709 TTErr TTSpatSnap::testAudioProcessing(int& aTestAssertionCount, int& anErrorCount, TTValue& aReturnedTestInfo)
710 {
711  TTAudioSignalPtr input = NULL;
712  TTAudioSignalPtr output = NULL;
713 
714  // create audio signal objects
715  TTObjectBaseInstantiate(kTTSym_audiosignal, &input, 7);
716  TTObjectBaseInstantiate(kTTSym_audiosignal, &output, 5);
717 
718  input->allocWithVectorSize(64);
719  output->allocWithVectorSize(64);
720 
721  for (TTInt16 sample=0; sample<64; sample++)
722  input->mSampleVectors[0][sample] = 1.0;
723 
724  for (TTInt16 sample=0; sample<64; sample++)
725  input->mSampleVectors[1][sample] = 2.0;
726 
727  for (TTInt16 sample=0; sample<64; sample++)
728  input->mSampleVectors[2][sample] = 4.0;
729 
730  for (TTInt16 sample=0; sample<64; sample++)
731  input->mSampleVectors[3][sample] = 8.0;
732 
733  for (TTInt16 sample=0; sample<64; sample++)
734  input->mSampleVectors[4][sample] = 16.0;
735 
736  for (TTInt16 sample=0; sample<64; sample++)
737  input->mSampleVectors[5][sample] = 32.0;
738 
739  for (TTInt16 sample=0; sample<64; sample++)
740  input->mSampleVectors[6][sample] = 64.0;
741 
742  this->process(input, output);
743 
744 
745  // Test processed audio
746  TTTestLog("");
747 
748  // Sink 1 receieves signal fra source 2, 6 and 7: Expected value equals 2. + 32. +64. = 98.
749 
750  int validSampleCount = 0;
751  TTSampleValuePtr samples = output->mSampleVectors[0];
752 
753  for (int i=0; i<64; i++) {
754  validSampleCount += TTTestFloatEquivalence(98., samples[i]);
755  }
756  TTTestAssertion("Correct audio signal processed to sink 1",
757  validSampleCount == 64,
758  aTestAssertionCount,
759  anErrorCount);
760  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
761 
762  // Sink 2 receieves signal fra source 3: Expected value equals 4.
763 
764  validSampleCount = 0;
765  samples = output->mSampleVectors[1];
766 
767  for (int i=0; i<64; i++) {
768  validSampleCount += TTTestFloatEquivalence(4., samples[i]);
769  }
770  TTTestAssertion("Correct audio signal processed to sink 2",
771  validSampleCount == 64,
772  aTestAssertionCount,
773  anErrorCount);
774  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
775 
776  // Sink 3 receieves signal fra source 4: Expected value equals 8.
777 
778  validSampleCount = 0;
779  samples = output->mSampleVectors[2];
780 
781  for (int i=0; i<64; i++) {
782  validSampleCount += TTTestFloatEquivalence(8., samples[i]);
783  }
784  TTTestAssertion("Correct audio signal processed to sink 3",
785  validSampleCount == 64,
786  aTestAssertionCount,
787  anErrorCount);
788  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
789 
790  // Sink 4 receieves signal fra source 5: Expected value equals 16.
791 
792  validSampleCount = 0;
793  samples = output->mSampleVectors[3];
794 
795  for (int i=0; i<64; i++) {
796  validSampleCount += TTTestFloatEquivalence(16., samples[i]);
797  }
798  TTTestAssertion("Correct audio signal processed to sink 4",
799  validSampleCount == 64,
800  aTestAssertionCount,
801  anErrorCount);
802  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
803 
804  // Sink 5 receieves signal fra source 1: Expected value equals 1.
805 
806  validSampleCount = 0;
807  samples = output->mSampleVectors[4];
808 
809  for (int i=0; i<64; i++) {
810  validSampleCount += TTTestFloatEquivalence(1., samples[i]);
811  }
812  TTTestAssertion("Correct audio signal processed to sink 5",
813  validSampleCount == 64,
814  aTestAssertionCount,
815  anErrorCount);
816  TTTestLog("Number of bad samples: %i", 64-validSampleCount);
817 
818  TTObjectBaseRelease(&input);
819  TTObjectBaseRelease(&output);
820 
821  return kTTErrNone;
822 }
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
size_type size() const noexcept
Return the number of elements.
TTErr getAttributeValue(const TTSymbol name, TTValue &value)
Get an attribute value for an object.
Jamoma DSP Library.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
A basic proof-of-concept spatial renderer where the audio of a source will snap to the nearest sink...
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTBoolean unused
Old var that is not used anymore, but we want to keep the struct size the same.
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
No Error.
Definition: TTBase.h:343
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34