Jamoma API  0.6.0.a19
TTSoundfile.test.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSoundFileLib
4  *
5  * @brief Tests for the #TTSoundfile class
6  *
7  * @details Tests the core functions of the TTSoundfile class in order to ensure that things are working after a build. It also demostrate how to make calls to common methods within the class.@n
8  * IMPORTANT NOTE: Because POSIX filepaths will be specific to your system, this test will attempt to find the path to the SoundfileLib extension using the TTFoundationBinaryPath environment variable. If you wish to test with a different sound file, you will need to place in that extension folder and change the relevant macros in the header of this class.
9  *
10  * @authors Nathan Wolek
11  *
12  * @copyright Copyright © 2013 by Nathan Wolek @n
13  * This code is licensed under the terms of the "New BSD License" @n
14  * http://creativecommons.org/licenses/BSD/
15  */
16 
17 #include "TTSoundfile.h"
18 #include "TTUnitTest.h"
19 
20 /*
21 
22  It is possible to change the target sound file for this test using the macros below.
23  Both sound files are included in the Jamoma respository at the following path:
24  {JAMOMA_ROOT}/Core/DSP/extensions/SoundfileLib/
25 
26  This test should look for the named TESTFILE at this path.
27 
28  */
29 
30 /*
31  #define TESTFILE "geese_clip.aif"
32  #define TESTNUMCHANNELS 2
33  #define TESTSAMPLERATE 44100
34  #define TESTDURATIONINSAMPLES 88202
35  #define TESTDURATIONINSECONDS 2.00004535
36  #define TESTTITLE ""
37  #define TESTARTIST ""
38  #define TESTDATE ""
39  #define TESTANNOTATION ""
40  */
41 
42 /* */
43  #define TESTFILE "ding_b2.aiff"
44 #define TESTNUMCHANNELS 1
45 #define TESTSAMPLERATE 44100
46 #define TESTDURATIONINSAMPLES 39493
47 #define TESTDURATIONINSECONDS 0.89553288
48 #define TESTTITLE ""
49 #define TESTARTIST ""
50 #define TESTDATE ""
51 #define TESTANNOTATION ""
52 /* */
53 
54 
55 TTErr TTSoundfile::test(TTValue& returnedTestInfo)
56 {
57  int errorCount = 0;
58  int testAssertionCount = 0;
59 
60  // assemble the full path of the target sound file
61 
62  TTString testSoundPath = TTFoundationBinaryPath;
63  int pos = testSoundPath.find_last_of('/');
64  testSoundPath = testSoundPath.substr(0,pos+1);
65  testSoundPath += TESTFILE;
66 
67  std::cout << "We will be using the following path for testing: " << testSoundPath << "\n";
68 
69  {
70 
71 
72  TTTestLog("\n");
73  TTTestLog("Testing TTSoundfile Basics...");
74 
75  // TEST 0: instantiate the object to a pointer
76  // ** REMOVED **
77 
78  // TEST 1: set the filepath
79  TTBoolean result1 = { this->setFilePath(TT(testSoundPath)) == kTTErrNone };
80 
81  TTTestAssertion("setFilePath operates successfully",
82  result1,
83  testAssertionCount,
84  errorCount);
85 
86  // TEST 2: reports correct number of channels
87  TTColumnID return2 = this->getNumChannels();
88  TTBoolean result2 = { return2 == TESTNUMCHANNELS };
89 
90  TTTestAssertion("reports the correct number of channels",
91  result2,
92  testAssertionCount,
93  errorCount);
94 
95  if(!result2)
96  {
97  TTTestLog("Expected a value of %i, but returned value was %i", TESTNUMCHANNELS, return2);
98  }
99 
100  // TEST 3: reports correct sample rate
101  TTFloat64 return3 = this->getSampleRate();
102  TTBoolean result3 = TTTestFloatEquivalence(return3, TESTSAMPLERATE, true, 0.0000001);
103 
104  TTTestAssertion("reports the correct sample rate",
105  result3,
106  testAssertionCount,
107  errorCount);
108 
109  if(!result3)
110  {
111  TTTestLog("Expected a value of %f, but returned value was %f", TESTSAMPLERATE, return3);
112  }
113 
114  // TEST 4: reports correct duration in samples
115  TTRowID return4 = this->getLengthInSamples();
116  TTBoolean result4 = { return4 == TESTDURATIONINSAMPLES };
117 
118  TTTestAssertion("reports the correct duration in samples",
119  result4,
120  testAssertionCount,
121  errorCount);
122 
123  if(!result4)
124  {
125  TTTestLog("Expected a value of %i, but returned value was %i", TESTDURATIONINSAMPLES, return4);
126  }
127 
128  // TEST 5: reports correct duration in seconds
129  TTFloat64 return5 = this->getLengthInSeconds();
130  TTBoolean result5 = TTTestFloatEquivalence(return5, TESTDURATIONINSECONDS, true, 0.0000001);
131 
132  TTTestAssertion("reports the correct duration in seconds",
133  result5,
134  testAssertionCount,
135  errorCount);
136 
137  if(!result5)
138  {
139  TTTestLog("Expected a value of %f, but returned value was %f", TESTDURATIONINSECONDS, return5);
140  }
141 
142  TTTestLog("\n");
143  TTTestLog("Testing TTSoundfile Metadata...");
144 
145  // TEST 6: reports correct title from metadata
146  TTSymbol return6 = this->getTitle();
147 
148  TTTestLog("Expected metadata title:");
149  TTTestLog(TESTTITLE);
150  TTTestLog("Returned metadata title:");
151  TTTestLog(return6.c_str());
152 
153  // TEST 7: reports correct artist from metadata
154  TTSymbol return7 = this->getArtist();
155 
156  TTTestLog("Expected metadata artist:");
157  TTTestLog(TESTARTIST);
158  TTTestLog("Returned metadata artist:");
159  TTTestLog(return7.c_str());
160 
161  // TEST 8: reports correct title from metadata
162  TTSymbol return8 = this->getDate();
163 
164  TTTestLog("Expected metadata date:");
165  TTTestLog(TESTDATE);
166  TTTestLog("Returned metadata date:");
167  TTTestLog(return8.c_str());
168 
169  // TEST 9: reports correct artist from metadata
170  TTSymbol return9 = this->getAnnotation();
171 
172  TTTestLog("Expected metadata comment:");
173  TTTestLog(TESTANNOTATION);
174  TTTestLog("Returned metadata comment:");
175  TTTestLog(return9.c_str());
176 
177  TTTestLog("\n");
178  TTTestLog("Testing peek method on first 10 sample values...");
179 
180  TTSampleValue return10;
181  TTErr error10;
182 
183  for (int channel=0;channel<return2;channel++)
184  {
185  TTTestLog("Channel %i", channel);
186  for (int sample=0;sample<10;sample++)
187  {
188  error10 = this->peek(sample,channel,return10);
189  if (error10 == kTTErrNone)
190  {
191  TTTestLog("peek sample %i returned the value %f", sample, return10);
192  } else {
193  TTTestLog("peek returned an error for sample %i", sample);
194  }
195  }
196  }
197 
198  TTTestLog("\n");
199  TTTestLog("Testing peeki between samples 2 & 3...");
200 
201  TTSampleValue return11;
202  TTErr error11;
203  TTFloat64 floatIndex;
204 
205  for (int channel=0;channel<return2;channel++)
206  {
207  TTTestLog("Channel %i", channel);
208  for (int sample=0;sample<11;sample++)
209  {
210  floatIndex = 2 + sample*0.1;
211 
212  error11 = this->peeki(floatIndex,channel,return11);
213  if (error11 == kTTErrNone)
214  {
215  TTTestLog("peek sample %f returned the value %f", floatIndex, return11);
216  } else {
217  TTTestLog("peek returned an error for sample %f", floatIndex);
218  }
219  }
220  }
221 
222 
223  }
224 
225  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
226 }
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTSymbol getDate()
Simple data accessor.
Definition: TTSoundfile.h:99
TTRowID getLengthInSamples()
Simple data accessor.
Definition: TTSoundfile.h:71
TTSymbol getTitle()
Simple data accessor.
Definition: TTSoundfile.h:85
TTInt32 TTColumnID
Datatype for any number used to indicate a column index within the matrix.
Definition: TTBase.h:216
TTErr peek(const TTRowID frame, const TTColumnID channel, TTSampleValue &value)
Get the value stored at a specified frame and channel.
TTInt32 TTRowID
Datatype for any number used to indicate a row index within a matrix.
Definition: TTBase.h:207
virtual TTErr test(TTValue &returnedTestInfo)
Unit test for this object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTSymbol getAnnotation()
Simple data accessor.
Definition: TTSoundfile.h:106
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTFloat64 getSampleRate()
Simple data accessor.
Definition: TTSoundfile.h:64
TTColumnID getNumChannels()
Simple data accessor.
Definition: TTSoundfile.h:57
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
TTString substr(size_t pos=0, size_t n=1) const
Returns a string object with its contents initialized to a substring of the current object...
Definition: TTString.h:342
Provides a common interface to soundfile data.
size_t find_last_of(const char aChar)
Return the index of the last instance of a specified char in the string.
Definition: TTString.h:316
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFloat64 getLengthInSeconds()
Simple data accessor.
Definition: TTSoundfile.h:78
TTErr setFilePath(const TTValue &newValue)
Atribute accessor.
Definition: TTSoundfile.cpp:68
TTErr peeki(const TTFloat64 frame, const TTColumnID channel, TTSampleValue &value)
Interpolate a value using a floating-point frame and integer channel.
No Error.
Definition: TTBase.h:343
The TTString class is used to represent a string.
Definition: TTString.h:34
TTSymbol getArtist()
Simple data accessor.
Definition: TTSoundfile.h:92
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34