41 using namespace Nsound;
48 static const char *
THIS_FILE =
"Generator_UnitTest.cc";
63 cout <<
TEST_HEADER <<
"Testing Generator::drawLine(1.0, 1.0, 0.0) ...";
72 gold <<
"gold/Generator_line1.wav";
82 <<
"Output did not match gold file!"
87 diff.
plot(
"data - gold");
96 cout << TEST_HEADER <<
"Testing Generator::drawLine(1.26, -0.26, 0.26) ...";
98 data = gen.
drawLine(1.26, -0.26, 0.26);
105 gold <<
"gold/Generator_line2.wav";
115 <<
"Output did not match gold file!"
120 diff.
plot(
"data - gold");
130 cout << TEST_HEADER <<
"Testing Generator::buzz(1.0, 4.0, 3, 0.0) ...";
132 data = cos.
buzz(1.0, 4.0, 3, 0.0);
139 gold <<
"gold/Generator_buzz1.wav";
149 <<
"Output did not match gold file!"
154 diff.
plot(
"data - gold");
164 cout << TEST_HEADER <<
"Testing Generator::buzz(1.0, 4.0, 3, 0.5) ...";
166 data = cos.
buzz(1.0, 4.0, 3, 0.5);
173 gold <<
"gold/Generator_buzz2.wav";
183 <<
"Output did not match gold file!"
188 diff.
plot(
"data - gold");
197 cout << TEST_HEADER <<
"Testing Generator::buzz(1.0, 4.0, 4, 0.5) ...";
199 data = cos.
buzz(1.0, 4.0, 4, 0.5);
206 gold <<
"gold/Generator_buzz3.wav";
216 <<
"Output did not match gold file!"
221 diff.
plot(
"data - gold");
230 cout << TEST_HEADER <<
"Testing Generator::drawSine(1.0, 10.0) ...";
240 gold =
Buffer(
"gold/Generator_sine1.wav");
250 <<
"Output did not match gold file!"
255 diff.
plot(
"data - gold");
264 cout << TEST_HEADER <<
"Testing Generator::drawSine(1.0, freqs) ...";
275 gold =
Buffer(
"gold/Generator_sine2.wav");
285 <<
"Output did not match gold file!"
290 diff.
plot(
"data - gold");
299 cout << TEST_HEADER <<
"Testing Generator::drawSine2(1.0, 3.0, 0.5) ...";
308 gold =
Buffer(
"gold/Generator_sine3.wav");
318 <<
"Output did not match gold file!"
323 diff.
plot(
"data - gold");
332 cout << TEST_HEADER <<
"Testing Generator::drawSine2(1.0, 3.0, phase) ...";
337 phase << gen.
drawLine(1.0, 0.0, 1.0);
344 gold =
Buffer(
"gold/Generator_sine4.wav");
354 <<
"Output did not match gold file!"
359 diff.
plot(
"data - gold");
368 cout << TEST_HEADER <<
"Testing Generator::drawSine2(1.0, freqs, 0.5) ...";
373 freqs << gen.
drawLine(1.0, 0.0, 10.0);
380 gold =
Buffer(
"gold/Generator_sine5.wav");
390 <<
"Output did not match gold file!"
395 diff.
plot(
"data - gold");
404 cout << TEST_HEADER <<
"Testing Generator::drawSine2(1.0, freqs, phase) ...";
408 data << gen.
drawSine2(1.0, freqs, phase);
413 gold =
Buffer(
"gold/Generator_sine6.wav");
423 <<
"Output did not match gold file!"
428 diff.
plot(
"data - gold");
437 cout << TEST_HEADER <<
"Testing Generator::generate(1.0, freq) with chorus ...";
453 gold =
Buffer(
"gold/Generator_chorus1.wav");
463 <<
"Output did not match gold file!"
467 pylab.
plot(data,
"r",
"label='data'");
468 pylab.
plot(gold,
"b",
"label='gold', lw=2");
Buffer drawSine2(const float64 &duration, const float64 &frequency, const float64 &phase)
This method draws a static sine wave.
void grid(boolean flag)
Sets the grid state.
static void show()
Acutally draw the plots to the screen.
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
static const char * THIS_FILE
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
void legend(const std::string &kwargs="")
Shows the legend on the current axes.
Buffer drawSine(const float64 &duration, const float64 &frequency)
This method draws a static sine wave.
#define TEST_ERROR_HEADER
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
void setChorus(const uint32 n_voices, const float64 &sigma=0.02)
Chorus or Unison.
void Generator_UnitTest()
float64 buzz(const float64 &frequency, const float64 &n_harmonics, const float64 &delay)
Returns sample from a set of harmonics. Based on the Csound buzz opcode.
static const float64 GAMMA
static void setIEEEFloat(boolean flag)
void abs()
Modifies the Buffer by making any negative value positive.
A Buffer for storing audio samples.
static void setDefaultSampleSize(uint32 size)
Buffer drawLine(const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const
This method draws a linear line beteween 2 points.
float64 getMax() const
Returns the maximum sample value in the Buffer.
void setSeed(const uint32 seed)
Sets the seed for the Generator's random number generator (rng).
A class the provides draw utilities and a wavetable oscillator.