38 using namespace Nsound;
51 sample_rate_(sample_rate),
52 frequency_axis_(NULL),
63 if(sample_rate <= 0.0)
65 cerr <<
"Nsound::Spectrogram(): "
66 <<
"sample_rate <= 0.0 ("
77 if(time_window <= 0.0)
79 cerr <<
"Nsound::Spectrogram(): "
80 <<
"time_window <= 0.0 ("
93 cerr <<
"Nsound::Spectrogram(): "
94 <<
"time_step <= 0.0 ("
104 uint32 window_step =
static_cast<int32>(time_s * sr + 0.5);
116 int32 i = - h_window_samples;
141 cerr <<
"Nsound::Spectrogram::Spectrogram(): "
142 <<
"failed to allocate memory for frequency_axis_"
150 cerr <<
"Nsound::Spectrogram::Spectrogram(): "
151 <<
"failed to allocate memory for time_axis_"
159 cerr <<
"Nsound::Spectrogram::Spectrogram(): "
160 <<
"failed to allocate memory for real_"
168 cerr <<
"Nsound::Spectrogram::Spectrogram(): "
169 <<
"failed to allocate memory for imag_"
178 i = - h_window_samples;
192 int32 n_zeros = n_window_samples_ - n_left;
216 (*real_)[k] = vec[0].getReal();
217 (*imag_)[k] = vec[0].getImaginary();
234 frequency_axis_(new
Buffer(*copy.frequency_axis_)),
235 time_axis_(new
Buffer(*copy.time_axis_)),
238 fft_window_(new
Buffer(*copy.fft_window_)),
240 n_window_samples_(copy.n_window_samples_),
302 const std::string & title,
303 const boolean & use_dB,
316 else if(squash > 0.0)
322 cerr <<
"Nsound::Spectrogram::plot(): "
323 <<
"use_dB is false and squash <= 0.0 ("
335 pylab.
xlabel(
"Time (sec)");
336 pylab.
ylabel(
"Frequency (Hz)");
352 signal = x.
subbuffer(index, n_window_samples_);
369 return vec[0].getMagnitude();
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 computeMagnitude(const Buffer &x)
Buffer getTimeAxis() const
Spectrogram & operator=(const Spectrogram &rhs)
static Buffer zeros(const uint32 n_samples)
Returns a Buffer full of zeros of length n_samples.
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.
Buffer drawWindow(const float64 &duration, WindowType type) const
Draws a window of the specified type.
uint32 getLength() const
Returns the number of samples in the Buffer.
Buffer silence(const float64 &duration) const
This method generates silence.
void imagesc(const AudioStream &Z, const std::string &kwargs="")
Plots the AudioStream like a 2D matrix.
Buffer getFrequencyAxis() const
void transpose()
Treating the AudioStream as a matrix, this peforms a matrix transpose.
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
void dB()
Modifies the AudioStream so each sample is converted to dB, 20 * log10(sample).
A Buffer for storing audio samples.
void plot(const std::string &title="", const boolean &use_dB=true, const float64 &squash=0.5) const
Spectrogram(const Buffer &x, const float64 &sample_rate, const float64 &time_window, const float64 &time_step, const WindowType &type)
AudioStream getMagnitude() const
std::vector< FFTChunk > FFTChunkVector
A class the provides draw utilities and a wavetable oscillator.