33 std::string input_filename =
"walle.wav";
47 a.setSampleRate(static_cast<uint32>(sr));
53 Buffer freq_axis = spec.getFrequencyAxis();
56 Buffer time_axis = spec.getTimeAxis();
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);
84 Buffer n = gen.drawLine(M / 2 + 1, 0.0, M / 2 + 1);
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);
107 Buffer window = gen.drawWindowHanning(M / 2 + 1);
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");
170 Buffer bin_axis = gen.drawLine(
171 cep_space.getLength(), 0, cep_space.getLength());
173 cep_space.transpose();
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);
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.
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
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 plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
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.
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.
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
A Buffer for storing audio samples.
std::vector< FFTChunk > FFTChunkVector
A class the provides draw utilities and a wavetable oscillator.
uint32 argmax() const
Retruns the index of the maximum value in the Buffer.