37 using namespace Nsound;
50 sample_rate_(sample_rate),
51 original_size_(original_size),
67 real_(new
Buffer(copy.real_->getLength())),
68 imag_(new
Buffer(copy.real_->getLength())),
69 sample_rate_(copy.sample_rate_),
70 original_size_(copy.original_size_),
71 is_polar_(copy.is_polar_)
98 for(
uint32 i = 0; i < n_samples / 2; ++i)
101 out << (*real_)[i] * std::sin((*
imag_)[i]);
115 uint32 n_samples = chunk_size / 2 + 1;
118 / static_cast<float64>(chunk_size);
122 return gen.
drawLine(n_samples, 0.0, x_step * n_samples);
136 Buffer out(n_samples / 2);
138 for(
uint32 i = 0; i < n_samples / 2; ++i)
141 out << (*real_)[i] * std::cos((*
imag_)[i]);
161 Buffer out(n_samples / 2 + 1);
163 for(
uint32 i = 0; i < n_samples / 2 + 1; ++i)
167 out << std::sqrt(x*x + y*y);
188 Buffer out(n_samples / 2 + 1);
190 for(
uint32 j = 0; j < n_samples / 2 + 1; ++j)
197 phase = std::atan(i/r);
201 if(i < 0.0) phase -=
M_PI;
233 const std::string & title,
235 boolean show_phase)
const
274 if(title.length() <= 0)
276 pylab.
title(
"Magnitude");
286 pylab.
ylabel(
"Magnitude dB");
290 pylab.
ylabel(
"Magnitude");
300 pylab.
title(
"Phase");
302 pylab.
ylabel(
"Phase Radians");
305 pylab.
xlabel(
"Frequency Hz");
312 Buffer zeros = 0.0 * real;
332 *
imag_ = 2.0 * phase;
349 for(
uint32 j = 0; j < n_samples; ++j)
353 (*real_)[j] = m * std::cos(p);
354 (*imag_)[j] = m * std::sin(p);
371 for(
uint32 j = 0; j < n_samples; ++j)
376 (*real_)[j] = std::sqrt(r*r + i*i);
377 (*imag_)[j] = std::atan(i / r);
379 if(i < 0.0 && r < 0.0) (*imag_)[j] -=
M_PI;
380 if(i >= 0.0 && r < 0.0) (*imag_)[j] +=
M_PI;
Buffer subbuffer(uint32 start_index, uint32 n_samples=0) const
Slice the Buffer.
void xlabel(const std::string &label, const std::string &kwargs="")
Add a label x axis.
Buffer getFrequencyAxis() const
Buffer getImaginary() const
void dB()
Modifies the Buffer so each sample is converted to dB, 20 * log10(sample).
FFTChunk & operator=(const FFTChunk &rhs)
Results of performing an FFT are stored in this class.
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
void toCartesian()
convertes the magnitude & phase to cartesian form: real & imaginary
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
void title(const std::string &title, const std::string &kwargs="")
Add a title to the plot at the top and centered.
void plot(const std::string &title="", boolean dB=true, boolean show_phase=false) const
void setPolar(const Buffer &magnitude, const Buffer &phase)
Sets up an FFTChunk to use the provided magnitude & phase.
void toPolar()
convertes the real & imaginary unit to plor form: magnitude & phase
uint32 getLength() const
Returns the number of samples in the Buffer.
Buffer getMagnitude() const
Axes subplot(const uint32 n_rows, const uint32 n_cols, const uint32 n, const std::string &kwargs="", Axes *sharex=NULL, Axes *sharey=NULL)
Creates a figure in a subplot, subplot(A, B, C, **kwargs)
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
FFTChunk(uint32 size=32, uint32 sample_rate=44100, uint32 original_size=0)
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.
void setCartesian(const Buffer &real, const Buffer &imaginary)
Sets up an FFTChunk to use the provided real & imaginary.
A class the provides draw utilities and a wavetable oscillator.