42 using namespace Nsound;
51 #define THIS_TEST_HEADER \
61 for(
uint32 i = start_index; i < start_index + n_samples; ++i)
63 if(buffer[i] != value)
67 <<
"sample should be "
82 main(
int argc,
char ** argv)
84 cout <<
"////////////////////////////////////////////////////////////"
86 <<
"// Testing class Nsound::Mixer"
88 <<
"////////////////////////////////////////////////////////////"
94 <<
"Mixer::add(), Mixer::getStream() ... " << flush;
96 uint32 SAMPLES_PER_SECOND = 10;
98 Sine sine(SAMPLES_PER_SECOND);
108 mixer.
add(0.0, 30.0, as1);
116 if(result.
getLength() != 4.0 * (1.0 * SAMPLES_PER_SECOND))
120 <<
"result has incorrect length! FAILURE"
135 testRange(result[0], 0, 10, 1.0, __LINE__);
136 testRange(result[0], 10, 10, 0.0, __LINE__);
137 testRange(result[0], 20, 10, 1.0, __LINE__);
138 testRange(result[0], 30, 10, 0.0, __LINE__);
140 cout <<
Toc() <<
" seconds: SUCCESS"
143 <<
"Mixer::add(), Mixer::getStream() ... " << flush;
146 mixer.
add(0.0, 30.0, as1);
158 testRange(result[0], 0, 10, 2.0, __LINE__);
159 testRange(result[0], 10, 10, 0.0, __LINE__);
160 testRange(result[0], 20, 10, 2.0, __LINE__);
161 testRange(result[0], 30, 10, 0.0, __LINE__);
163 cout <<
Toc() <<
" seconds: SUCCESS"
166 <<
"Mixer::add(), Mixer::getStream() with offset ... " << flush;
170 if(result.
getLength() != 4.0 * (1.0 * SAMPLES_PER_SECOND))
174 <<
"result has incorrect length! FAILURE"
190 testRange(result[0], 0, 5, 2.0, __LINE__);
191 testRange(result[0], 5, 10, 0.0, __LINE__);
192 testRange(result[0], 15, 10, 2.0, __LINE__);
193 testRange(result[0], 25, 10, 0.0, __LINE__);
194 testRange(result[0], 35, 5, 2.0, __LINE__);
196 cout <<
Toc() <<
" seconds: SUCCESS"
199 <<
"Mixer::add(), Mixer::clear() ... " << flush;
203 if(mixer.
size() != 0)
206 <<
"mixer.size() should be 0.0, found "
212 cout <<
Toc() <<
" seconds: SUCCESS"
215 <<
"Mixer::add(), Mixer::add() with different BPM ... " << flush;
219 mixer.
add(0.0, 30.0, as1);
220 mixer.
add(0.5, 30.0, as1);
239 testRange(result[0], 0, 5, 1.0, __LINE__);
240 testRange(result[0], 5, 5, 2.0, __LINE__);
241 testRange(result[0], 10, 5, 1.0, __LINE__);
242 testRange(result[0], 15, 5, 0.0, __LINE__);
243 testRange(result[0], 20, 5, 1.0, __LINE__);
244 testRange(result[0], 25, 5, 2.0, __LINE__);
245 testRange(result[0], 30, 5, 1.0, __LINE__);
246 testRange(result[0], 35, 5, 0.0, __LINE__);
248 cout <<
Toc() <<
" seconds: SUCCESS"
251 <<
"Mixer::add(), Mixer::getStream() with offset ... " << flush;
257 if(result.
getLength() != 4.0 * (1.0 * SAMPLES_PER_SECOND))
261 <<
"result has incorrect length! FAILURE"
280 testRange(result[0], 0, 5, 2.0, __LINE__);
281 testRange(result[0], 5, 5, 1.0, __LINE__);
282 testRange(result[0], 10, 5, 0.0, __LINE__);
283 testRange(result[0], 15, 5, 1.0, __LINE__);
284 testRange(result[0], 20, 5, 2.0, __LINE__);
285 testRange(result[0], 25, 5, 1.0, __LINE__);
286 testRange(result[0], 30, 5, 0.0, __LINE__);
287 testRange(result[0], 35, 5, 1.0, __LINE__);
289 cout <<
Toc() <<
" seconds: SUCCESS"
292 <<
"Mixer::add(), Mixer::getStream() with zero bpm ... " << flush;
298 mixer.
add(1.5, 0.0, as2);
319 testRange(result[0], 0, 5, 2.0, __LINE__);
320 testRange(result[0], 5, 5, 1.0, __LINE__);
321 testRange(result[0], 10, 5, 3.0, __LINE__);
322 testRange(result[0], 15, 5, 1.0, __LINE__);
323 testRange(result[0], 20, 5, 2.0, __LINE__);
324 testRange(result[0], 25, 5, 1.0, __LINE__);
325 testRange(result[0], 30, 5, 0.0, __LINE__);
326 testRange(result[0], 35, 5, 1.0, __LINE__);
328 cout <<
Toc() <<
" seconds: SUCCESS"
int main(int argc, char **argv)
void add(float64 first_beat_time, float64 beats_per_minute, const AudioStream &audio_stream)
This method inserts the AudioStream to the Mixer's LinkList.
uint32 getLength() const
Returns the number of samples of audio data in the stream.
This class enables easy scheduling and mixing of multiple AudioStreams.
#define TEST_HEADER2(line)
#define TEST_ERROR_HEADER
AudioStream getStream(float64 end_time)
This method returns one AudioStream composed of all AudioStreams stored in the Mixer's LinkList...
void testRange(const Buffer &buffer, uint32 start_index, uint32 n_samples, float64 value, unsigned int line)
static const char * THIS_FILE
void clear()
This method removes all streams from the mixer.
A Buffer for storing audio samples.
Buffer drawLine(const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const
This method draws a linear line beteween 2 points.
uint32 size() const
This method returns the number of stream stored in it.