Nsound  0.9.4
test_plotter.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: test_plotter.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2005-2007 Nick Hilton
6 //
7 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
8 //
9 //-----------------------------------------------------------------------------
10 
11 //-----------------------------------------------------------------------------
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation; either version 2 of the License, or
16 // (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Library General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 //
27 //-----------------------------------------------------------------------------
28 
29 #include <Nsound/AudioStream.h>
30 #include <Nsound/Buffer.h>
31 #include <Nsound/Nsound.h>
32 #include <Nsound/Generator.h>
33 #include <Nsound/Plotter.h>
34 #include <Nsound/Sine.h>
35 
36 #include <cmath>
37 #include <iostream>
38 
39 using namespace Nsound;
40 
41 using std::cerr;
42 using std::cout;
43 using std::endl;
44 
45 void testBuffer();
46 
47 int main(int argc, char ** argv)
48 {
49  Generator generator(5000);
50  Sine sine(5000);
51 
52  AudioStream as(5000, 2);
53 
54  // Draw some signals.
55  as[0] = sine.drawGaussian(2.0, 1.0, 0.10);
56  as[1] = sine.drawFatGaussian(2.0, 0.3);
57 
58  Plotter pylab;
59 
60  // Plot a buffer in blue.
61  pylab.plot(as[0],"b");
62 
63  // Plot a buffer in red.
64  pylab.plot(as[1],"r");
65 
66  // Set the title.
67  pylab.title("blue = default gaussian, red = gaussian with 30% pass band");
68 
69  // Set the axis labels.
70  pylab.xlabel("sample");
71  pylab.ylabel("amplitude");
72 
73  // Creating a plot with two subplots
74  Buffer x_axis = sine.drawLine(2.0, 0.0, 2.0);
75 
76  pylab.figure();
77  pylab.subplot(2,1,1);
78  pylab.title("default gaussian");
79  pylab.plot(x_axis, as[0], "b");
80  pylab.ylabel("amplitude");
81 
82  pylab.subplot(2,1,2);
83  pylab.title("gaussian with 30% pass band");
84  pylab.plot(x_axis, as[1], "r");
85  pylab.xlabel("seconds");
86  pylab.ylabel("amplitude");
87 
88  // simple plot of AudioStream
89  as.plot("quick plot from AudioStream");
90 
91  // simple plots of Buffers
92  as[1].plot("quick plot, gaussian with 30% pass band");
93  as[0].plot("quick plot, default gaussian");
94 
95  Plotter::show();
96 
97  return 0;
98 }
99 
100 
void xlabel(const std::string &label, const std::string &kwargs="")
Add a label x axis.
Definition: Plotter.cc:1154
void testBuffer()
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
Buffer drawFatGaussian(const float64 &duration, const float64 &pass_band_percent=0.01) const
This method draws a standard Gaussian curve over duration seconds, with a specified pass band...
Definition: Generator.cc:434
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
Definition: Plotter.cc:765
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
Definition: Plotter.cc:455
void title(const std::string &title, const std::string &kwargs="")
Add a title to the plot at the top and centered.
Definition: Plotter.cc:1127
Buffer drawGaussian(const float64 &duration, const float64 &mu, const float64 &sigma, const boolean &normalize=true) const
This method draws a Gaussian curve over duration seconds.
Definition: Generator.cc:403
int main(int argc, char **argv)
Definition: test_plotter.cc:47
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)
Definition: Plotter.cc:1031
void plot(const std::string &title="AudioStream") const
Definition: AudioStream.cc:661
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
Definition: Plotter.cc:1180
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer drawLine(const float64 &duration, const float64 &amplitude_start, const float64 &amplitude_finish) const
This method draws a linear line beteween 2 points.
Definition: Generator.cc:464
DOXME.
Definition: Sine.h:43
A class the provides draw utilities and a wavetable oscillator.
Definition: Generator.h:50