35 using namespace Nsound;
42 int main(
int argc,
char ** argv)
55 ref_response << g.
drawLine(0.25, 0.0, 0.8)
62 while( ref_response.
getLength() < 256 ) ref_response << 0.0;
71 pylab.
plot(ref_freq_axis, ref_response);
72 pylab.
title(
"desired frequency response");
76 cout <<
"f = " << endl << f << endl;
79 pylab.
plot(evolution);
82 pylab.
xlabel(
"Generation");
86 float64 error = evolution[n_generations - 1];
89 sprintf(buffer,
"%5.2f RMS error in %d generations",
93 pylab.
title(std::string(buffer));
99 pylab.
plot(ref_freq_axis, ref_response);
100 pylab.
plot(faxis, fr);
101 pylab.
xlabel(
"Frequency Hz");
102 pylab.
ylabel(
"Frequency Response");
104 pylab.
ylim(0.0, ref_response.
getMax() * 1.10);
106 sprintf(buffer,
"Generation %06d", n_generations);
108 pylab.
title(std::string(buffer));
112 sprintf(buffer,
"Error = %.3f RMS", error);
115 faxis[static_cast<uint32>(faxis.
getLength() * 0.5)],
117 std::string(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.
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.
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.
Buffer designFrequencyResponse(const Buffer &frequency_response, const float64 &max_error=0.01, const int32 max_iterations=1000)
Designs a filter kernel using a genetic algorithm that trys to match the provided frequency response...
void ylim(const float64 &ymin, const float64 &ymax)
Buffer getFrequencyAxis(const uint32 n_fft=8192)
void text(const float64 &x, const float64 &y, const std::string &text, const std::string &kwargs="")
Adds text at the x, y data point.
int main(int argc, char **argv)
void plot(boolean show_phase=false)
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
A Buffer for storing audio samples.
Buffer getFrequencyResponse(const uint32 n_fft=8192)
Buffer drawLine(const float64 &duration, const float64 &litude_start, const float64 &litude_finish) const
This method draws a linear line beteween 2 points.
float64 getMax() const
Returns the maximum sample value in the Buffer.
A class the provides draw utilities and a wavetable oscillator.