40 using namespace Nsound;
47 static const char *
THIS_FILE =
"test_audio_stream.cc";
51 int main(
int argc,
char ** argv)
53 cout <<
"////////////////////////////////////////////////////////////"
55 <<
"// Testing class Nsound::AudioStream"
57 <<
"////////////////////////////////////////////////////////////"
71 <<
"AudioStream::operator<<, AudioStream::operator[] ... " << flush;
75 uint32 test_size = 29 * 3 + 1;
79 for(
uint32 i = 0; i < test_size; ++i)
83 if(as1[0][i] != test_value || as1[1][i] != test_value)
97 cout <<
Toc() <<
" seconds: SUCCESS"
99 <<
TEST_HEADER <<
"testing AudioStream::getLength() ... " << flush;
106 <<
"as1.getLength() should equal "
116 cout <<
Toc() <<
" seconds: SUCCESS"
118 <<
TEST_HEADER <<
"testing AudioStream::operator== ... " << flush;
124 if(as1 == as2 || as2 == as1)
127 <<
"as1 should _NOT_ equal as2"
132 for(
uint32 i = 0; i < test_size; i++)
137 if(as1 != as2 || as2 != as1)
140 <<
"as1 _SHOULD_ equal as2"
145 cout <<
Toc() <<
" seconds: SUCCESS"
147 <<
TEST_HEADER <<
"testing AudioStream::AudioStream(&) ... " << flush;
153 if(as1 != as3 || as3 != as1)
156 <<
"as1 _SHOULD_ equal as3"
161 cout <<
Toc() <<
" seconds: SUCCESS"
163 <<
TEST_HEADER <<
"testing AudioStream::operator+,-,*,/ ... " << flush;
171 if(1 + as4 * 2 != 2 * as4 + 1)
174 <<
"left hand side _SHOULD_ equal right hand side"
179 if(1 - as4 / 2 != -1 * as4 / 2 + 1)
182 <<
"left hand side _SHOULD_ equal right hand side"
187 if(2.0 / as4 != 2.0 * (1.0 / as4))
190 <<
"left hand side _SHOULD_ equal right hand side"
195 cout <<
Toc() <<
" seconds: SUCCESS"
197 <<
TEST_HEADER <<
"test AudioStream::operator+= ... " << flush;
209 for(
uint32 i = 0; i < n_samples; ++i)
211 if(as5[0][i] != 0.0 || as5[1][i] != 0.0)
214 <<
"as5 + as6 _SHOULD_ be all zeros!"
220 cout <<
Toc() <<
" seconds: SUCCESS"
224 cout <<
TEST_HEADER <<
"test AudioStream::reverse() ... " << flush;
245 for(
uint32 i = 0; i < length; ++i)
247 if(as5[0][i] != 0.0 || as5[1][i] != 0.0)
250 <<
"as6 should be all zeros!"
256 cout <<
Toc() <<
" seconds: SUCCESS"
258 <<
TEST_HEADER <<
"test AudioStream::pan() ... " << flush;
281 if(as7[0][i] != 0.75 || as7[1][i] != 0.25)
284 <<
"AudioStream::pan(float64 d) is borken!"
292 as7[0] = sine.
drawLine(1.0,1.0,1.0);
293 as7[1] = sine.
drawLine(1.0,1.0,1.0);
300 if(as7[0][i] != 0.25 || as7[1][i] != 0.75)
303 <<
"AudioStream::pan(float64 d) is borken!"
309 cout <<
Toc() <<
" seconds: SUCCESS"
311 <<
TEST_HEADER <<
"test AudioStream::pan(Buffer b) ... " << flush;
319 as7[0] = sine.
drawLine(1.0,1.0,1.0);
320 as7[1] = sine.
drawLine(1.0,1.0,1.0);
329 Buffer left_test = (pan + 1) / 2;
333 if(as7[0] != left_test)
336 <<
"AudioStream::pan(Buffer b) is borken!"
346 Buffer right_test = left_test * -1.0 + 1.0;
350 Buffer difference = as7[1] - right_test;
359 if(difference[i] > 0.0000001 || difference[i] < -0.0000001)
362 <<
"AudioStream::pan(Buffer b) is borken!"
368 cout <<
Toc() <<
" seconds: SUCCESS"
374 cout <<
TEST_HEADER <<
"test AudioStream::substream() ... " << flush;
380 for(
uint32 i = 0; i < 44100; ++i)
382 as8 << static_cast<float64>(i);
391 for(
uint32 ch = 0; ch < 10; ++ch)
393 for(
uint32 i = 0; i < 44100; ++i)
395 if(static_cast<uint32>(substr[ch][i]) != i)
398 <<
"as8.substream() error!"
410 for(
uint32 ch = 0; ch < 10; ++ch)
412 for(
uint32 i = 1000; i < 1000; ++i)
414 if(static_cast<uint32>(substr[ch][i]) != i)
417 <<
"as8.substream() error!"
428 for(
uint32 ch = 0; ch < 10; ++ch)
430 for(
uint32 i = 0; i < 44100; ++i)
432 if(static_cast<uint32>(substr[ch][i]) != i)
435 <<
"as8.substream() error!"
442 substr = as8.
substream(1000.0 / 44100.0, 1000.0 / 44100.0);
444 for(
uint32 ch = 0; ch < 10; ++ch)
446 for(
uint32 i = 1000; i < 1000; ++i)
448 if(static_cast<uint32>(substr[ch][i]) != i)
451 <<
"as8.substream() error!"
458 cout <<
Toc() <<
" seconds: SUCCESS" << endl;
static const char * THIS_FILE
uint32 getLength() const
Returns the number of samples of audio data in the stream.
int main(int argc, char **argv)
void reverse()
Reverses the AudioStream.
AudioStream substream(uint32 start_index, uint32 n_samples=0) const
uint32 getLength() const
Returns the number of samples in the Buffer.
#define TEST_ERROR_HEADER
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
A Buffer for storing audio samples.
void pan(float64 pan)
Sets the amplitude level left vs right.
Buffer drawLine(const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const
This method draws a linear line beteween 2 points.