41 using namespace Nsound;
48 static const char *
THIS_FILE =
"FFTransform_UnitTest.cc";
70 cout <<
TEST_HEADER <<
"Testing FFTransform::fft(), ifft() ..." << flush;
72 vec = fft.
fft(input, 128, 0);
74 if(vec.size() != 512 / 128)
77 <<
"Output did not match!"
79 <<
"vec.size() = " << vec.size() <<
" != " << 512 / 128
93 <<
"Output did not match!"
95 <<
"result.getLength() = " << data.
getLength() <<
" != "
105 gold =
Buffer(
"gold/FFTransform_out1.wav");
107 Buffer diff = data - gold;
112 <<
"Output did not match gold file!"
115 diff.
plot(
"input - gold");
125 cout <<
TEST_HEADER <<
"Testing FFTChunk::getReal(), getImaginary() ..." << flush;
127 vec = fft.
fft(input, 128, 0);
129 Buffer real = vec[0].getReal();
130 Buffer img = vec[0].getImaginary();
136 gold =
Buffer(
"gold/FFTransform_out2.wav");
143 <<
"Output did not match gold file!"
146 diff.
plot(
"real - gold");
154 gold =
Buffer(
"gold/FFTransform_out3.wav");
162 <<
"Output did not match gold file!"
165 diff.
plot(
"img - gold");
175 cout <<
TEST_HEADER <<
"Testing FFTChunk::getMagnitude(), getPhase() ..." << flush;
177 vec = fft.
fft(input, 128, 0);
179 Buffer mag = vec[0].getMagnitude();
180 Buffer phase = vec[0].getPhase();
186 gold =
Buffer(
"gold/FFTransform_out4.wav");
193 <<
"Output did not match gold file!"
196 diff.
plot(
"data - gold");
204 gold =
Buffer(
"gold/FFTransform_out5.wav");
208 diff(diff > 2.0 *
M_PI - 0.01) = 0.0;
209 diff(diff < 2.0 *
M_PI - 0.01) = 0.0;
214 <<
"Output did not match gold file!"
217 diff.
plot(
"phase - gold");
227 cout <<
TEST_HEADER <<
"Testing FFTChunk::toCartesian(), toPolar() ..." << flush;
231 mag = vec[0].getMagnitude();
232 phase = vec[0].getPhase();
234 gold =
Buffer(
"gold/FFTransform_out4.wav");
241 <<
"Output did not match gold file!"
244 diff.
plot(
"data - gold");
252 gold =
Buffer(
"gold/FFTransform_out5.wav");
259 <<
"Output did not match gold file!"
262 diff.
plot(
"phase - gold");
272 cout <<
TEST_HEADER <<
"Testing FFTChunk::setCartesian(), setPolar() ..." << flush;
274 vec = fft.
fft(input, 512, 0);
276 mag = vec[0].getMagnitude();
277 phase = vec[0].getPhase();
286 data = fft.
ifft(vec);
293 <<
"Output did not match gold file!"
296 diff.
plot(
"data - gold");
308 data = fft.
ifft(vec);
315 <<
"Output did not match gold file!"
318 diff.
plot(
"data - gold");
328 cout <<
TEST_HEADER <<
"Testing FFTChunk::getFrequencyAxis() ..." << flush;
330 data = vec[0].getFrequencyAxis();
335 gold =
Buffer(
"gold/FFTransform_out6.wav");
342 <<
"Output did not match gold file!"
345 diff.
plot(
"data - gold");
353 cout << SUCCESS << endl;
Buffer getImaginary() const
static void show()
Acutally draw the plots to the screen.
Results of performing an FFT are stored in this class.
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
Buffer getAbs() const
Modifies a copy of the Buffer by making any negative value positive.
void setPolar(const Buffer &magnitude, const Buffer &phase)
Sets up an FFTChunk to use the provided magnitude & phase.
uint32 getLength() const
Returns the number of samples in the Buffer.
#define TEST_ERROR_HEADER
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 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)
float64 getMax() const
Returns the maximum sample value in the Buffer.
void setCartesian(const Buffer &real, const Buffer &imaginary)
Sets up an FFTChunk to use the provided real & imaginary.
std::vector< FFTChunk > FFTChunkVector