37 using namespace Nsound;
43 #define CERR_HEADER __FILE__ << ":" << __LINE__ << ": "
56 return 2595.0 * log10(1.0 + f / 700.0);
62 m = pow(10.0, m / 2595.0);
63 return (m - 1.0) * 700.0;
74 const bool use_mel_scale,
75 const bool plot_filter_bank)
77 sample_rate_(sample_rate),
78 window_size_(static_cast<
uint32>(window_length * sample_rate_)),
116 freq_centers << (i + 1) * band_width;
120 freq_centers -= band_width / 2.0;
127 freq_centers[i] =
mel_to_f(freq_centers[i]);
137 float64 freq = freq_centers[i];
145 f_lo = (freq + freq_centers[i - 1]) / 2.0;
152 f_hi = (freq + freq_centers[i + 1]) / 2.0;
200 pylab.
ylim(-40.0, 10.0);
201 pylab.
xlabel(
"Frequency (Hz)");
202 pylab.
ylabel(
"Filter Frequency Response (dB)");
242 for(
uint32 n = 0; n < n_samples; ++n, ++v)
265 float64 envelope = (*fi)->filter(voice);
268 envelope = std::fabs(envelope);
271 envelope = (*ma)->filter(envelope);
274 y += envelope * (*fo)->filter(x);
void xlabel(const std::string &label, const std::string &kwargs="")
Add a label x axis.
void grid(boolean flag)
Sets the grid state.
#define M_ASSERT_VALUE(a, op, value)
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
static float64 mel_to_f(float64 m)
void xlim(const float64 &xmin, const float64 &xmax)
Sets the limit for the x & y axis.
circular_iterator cbegin()
Retruns the itreator at the start of the Buffer.
uint32 getLength() const
Returns the number of samples in the Buffer.
void ylim(const float64 &ymin, const float64 &ymax)
FilterVector filters_input_
void hold(boolean flag)
Sets the hold state.
FilterVector filters_output_
static float64 f_to_mel(float64 f)
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
A Buffer for storing audio samples.
FilterVector moving_average_
Vocoder(const float64 &sample_rate, const float64 &window_length, const uint32 &n_bands, const float64 &freq_max=4000.0, const bool use_mel_scale=true, const bool plot_filter_bank=false)
Default Constructor.
Buffer filter(const Buffer &voice, const Buffer &carrier)