Nsound  0.9.4
FilterParametricEqualizer_UnitTest.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FilterParametricEqualizer_UnitTest.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2006 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/Buffer.h>
30 #include <Nsound/Plotter.h>
31 #include <Nsound/Sine.h>
32 #include <Nsound/Wavefile.h>
34 
35 #include "UnitTest.h"
36 
37 #include <cmath>
38 #include <stdlib.h>
39 
40 #include <iostream>
41 
42 using namespace Nsound;
43 
44 using std::cerr;
45 using std::cout;
46 using std::endl;
47 
48 // The __FILE__ macro includes the path, I don't want the whole path.
49 #define THIS_FILE "FilterParametricEqualizer_UnitTest.cc"
50 #define GAMMA 1.5e-14
51 
53 {
54  cout << endl << THIS_FILE;
55 
58 
59  Sine sine(100);
60 
63  100,
64  12,
65  0.2,
66  4.0);
67 
70  100,
71  12,
72  0.2,
73  4.0);
74 
77  100,
78  12,
79  0.2,
80  4.0);
81 
82  Buffer freqs = sine.drawLine(5.0, 24, 6);
83 
84  static const std::string titles[3] =
85  {
86  "Testing Peaking filter ...",
87  "Testing Low Shelf filter ...",
88  "Testing High Shelf filter ..."
89  };
90 
91  static const std::string types[3] =
92  {
93  "peaking",
94  "low",
95  "high"
96  };
97 
98  static const std::string gold_filenames[3] =
99  {
100  "gold/FilterParametricEqualizer_out_peaking.wav",
101  "gold/FilterParametricEqualizer_out_low.wav",
102  "gold/FilterParametricEqualizer_out_high.wav"
103  };
104 
105  FilterParametricEqualizer * filters[3] =
106  {
107  &peaking,
108  &low,
109  &high
110  };
111 
112  Buffer noise;
113  Buffer data;
114  Buffer gold;
115  Buffer diff;
116 
117  noise << "gold/Filter_noise.wav";
118  noise << "gold/Filter_noise.wav";
119 
120  for(int i = 0; i < 3; ++i)
121  {
122  cout << TEST_HEADER << titles[i];
123 
124  data = filters[i]->filter(noise, freqs);
125 
126  // Create gold file
127 //~ data >> gold_filenames[i].c_str();
128 
129  gold = Buffer(gold_filenames[i]);
130 
131  diff = data - gold;
132  diff.abs();
133 
134  if(diff.getMax() > GAMMA)
135  {
136  cerr << TEST_ERROR_HEADER
137  << "Output did not match gold file!"
138  << endl;
139 
140  diff.plot("data - gold");
141  data.plot("data");
142  gold.plot("gold");
143 
144  Plotter::show();
145 
146  exit(1);
147  }
148 
149  cout << SUCCESS;
150 
151  }
152 
153  cout << endl;
154 }
155 
156 
Implementation of Zoelzer's parametric equalizer filters, with some modifications by the author...
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
void FilterParametricEqualizer_UnitTest()
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
Definition: Buffer.cc:1551
#define TEST_HEADER
Definition: Test.h:45
#define TEST_ERROR_HEADER
Definition: Test.h:49
AudioStream filter(const AudioStream &x)
static void setIEEEFloat(boolean flag)
Definition: Wavefile.cc:98
void abs()
Modifies the Buffer by making any negative value positive.
Definition: Buffer.cc:119
#define SUCCESS
Definition: UnitTest.h:42
A Buffer for storing audio samples.
Definition: Buffer.h:60
static void setDefaultSampleSize(uint32 size)
Definition: Wavefile.cc:79
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
float64 getMax() const
Returns the maximum sample value in the Buffer.
Definition: Buffer.cc:951
DOXME.
Definition: Sine.h:43