38 using namespace Nsound;
43 sample_rate_(sample_rate),
44 two_pi_over_sample_rate_(2.0 *
M_PI / sample_rate),
45 sample_time_(1.0 / sample_rate),
61 M_THROW(
"In real-time mode, a filter per audio channel must be used!");
66 for(
uint32 channel = 0; channel < n_channels; ++channel)
68 y[channel] =
filter(x[channel]);
84 M_THROW(
"In real-time mode, a filter per audio channel must be used!");
89 for(
uint32 channel = 0; channel < n_channels; ++channel)
91 y[channel] =
filter(x[channel], frequency);
107 M_THROW(
"In real-time mode, a filter per audio channel must be used!");
112 for(
uint32 channel = 0; channel < n_channels; ++channel)
114 y[channel] =
filter(x[channel], frequency);
130 for(
uint32 i = 0; i < x_samples; ++i)
151 y <<
filter(*itor, frequency);
174 y <<
filter(*itor, *freq);
188 static_cast<int32>(n_fft));
190 uint32 n_samples = fft_chunk_size / 2 + 1;
192 float64 f_step = (1.0 / (
static_cast<float64>(fft_chunk_size) / 2.0))
199 for(
uint32 i = 0; i < n_samples; ++i)
220 return vec[0].getMagnitude();
229 Buffer response(n_samples);
233 for(
uint32 i = 1; i < n_samples; ++i)
255 Buffer phase = vec[0].getPhase();
279 pylab.
subplot(n_rows, n_cols, 1);
282 pylab.
plot(x,fr,
"blue");
284 pylab.
xlabel(
"Frequency (Hz)");
285 pylab.
ylabel(
"Frequency Response (dB)");
290 pylab.
subplot(n_rows, n_cols, 2);
296 pylab.
xlabel(
"Frequency (Hz)");
297 pylab.
ylabel(
"Phase Response (dB)");
303 pylab.
ylim(-60.0, ymax + 0.05 * height);
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.
float64 getSampleRate() const
Returns the sample rate of the stream.
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
Buffer getPhaseResponse()
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
uint32 getLength() const
Returns the number of samples in the Buffer.
Buffer getImpulseResponse(const uint32 n_samples=8192)
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 ylim(const float64 &ymin, const float64 &ymax)
iterator end()
Retruns the itreator at the end of the Buffer.
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
FloatVector::const_iterator const_iterator
Buffer getFrequencyAxis(const uint32 n_fft=8192)
iterator begin()
Retruns the itreator at the start of the Buffer.
void plot(boolean show_phase=false)
AudioStream filter(const AudioStream &x)
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
Filter(const float64 &sample_rate)
A Buffer for storing audio samples.
Buffer getFrequencyResponse(const uint32 n_fft=8192)
float64 getMax() const
Returns the maximum sample value in the Buffer.
std::vector< FFTChunk > FFTChunkVector
Buffer getdB() const
Returns the Buffer in dB.