16 using namespace Nsound;
33 std::string input_filename =
"walle.wav";
67 cerr <<
"N = " << N << endl;
68 cerr <<
"M = " << M << endl;
69 cerr <<
"M/2 + 1 = " << (M / 2 + 1) << endl;
71 cerr <<
"spectrum.size = " << magnitude.
getNChannels() << endl;
77 float64 vstep = freq_axis[1] - vmin;
79 uint32 fmin_index =
static_cast<uint32>( (FMIN - vmin) / vstep + 0.5);
80 uint32 fmax_index =
static_cast<uint32>( (FMAX - vmin) / vstep + 0.5);
88 Buffer quefrency_axis = (N * n) / (M * sr);
90 Buffer pitch_axis = 1.0 / quefrency_axis;
92 cerr <<
"quefrency_axis.getLength() = " << quefrency_axis.
getLength() << endl;
93 cerr <<
"pitch_axis.getLength() = " << pitch_axis.
getLength() << endl;
97 uint32 pmax_index = (pitch_axis - PMAX).getAbs().argmin();
100 pitch_axis = pitch_axis.
subbuffer(pmax_index);
115 for(
uint32 i = 0; i < n_time_steps; ++i)
117 Buffer spectrum = magnitude[i];
120 spectrum = spectrum.
subbuffer(fmin_index, fmax_index - fmin_index);
123 spectrum = 10.0 * (1.0 + spectrum).getdB();
132 Buffer cepstrum = vec[0].getMagnitude();
137 cerr <<
"cepstrum.getLength() = " << cepstrum.
getLength() << endl;
141 cepstrum = cepstrum.
subbuffer(pmax_index);
145 pitch_path << pitch_axis[p_index];
147 cep_space[i] << cepstrum;
152 spec.
plot(input_filename);
154 for(
float64 i = 1.0; i <= 20.0; i += 1.0)
156 pylab.
plot(time_axis, i * pitch_path,
"r+-");
160 pylab.
ylim(0, 2000.0);
161 pylab.
xlim(0.4, 1.6);
163 pylab.
title(
"Spectrogram + Estimated Pitch Path");
175 cout <<
"cep_space.getLength() = " << cep_space.
getLength() << endl;
176 cout <<
"cep_space.getNChannels() = " << cep_space.
getNChannels() << endl;
177 cout <<
"time_axis.getLength() = " << time_axis.
getLength() << endl;
178 cout <<
"bin_axis.getLength() = " << bin_axis.
getLength() << endl;
180 pylab.
imagesc(time_axis, bin_axis, cep_space);
181 pylab.
title(
"Cepstrum");
183 pylab.
ylabel(
"Cepstral bin (not frequency!)");
185 pylab.
xlim(0.4, 1.6);
199 catch(std::exception & e)
201 cerr <<
"Exception: " << e.what() << endl;
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.
static void show()
Acutally draw the plots to the screen.
Buffer getTimeAxis() const
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
float64 getSampleRate() const
Returns the sample rate of the stream.
uint32 getLength() const
Returns the number of samples of audio data in the stream.
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 xlim(const float64 &xmin, const float64 &xmax)
Sets the limit for the x & y axis.
Buffer drawWindowHanning(const float64 &duration) const
Draws a Hanning window.
uint32 getLength() const
Returns the number of samples in the Buffer.
void ylim(const float64 &ymin, const float64 &ymax)
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
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.
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 plot(const std::string &title="", const boolean &use_dB=true, const float64 &squash=0.5) const
AudioStream getMagnitude() const
void setSampleRate(uint32 sample_rate)
std::vector< FFTChunk > FFTChunkVector
A class the provides draw utilities and a wavetable oscillator.
void resample(float64 factor)
Resample by a non-integer factor.
uint32 argmax() const
Retruns the index of the maximum value in the Buffer.