Nsound  0.9.4
FilterCombLowPassFeedback_UnitTest.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FilterCombLowPassFeedback_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/Nsound.h>
30 
31 #include <Nsound/Buffer.h>
32 
34 #include <Nsound/Plotter.h>
35 #include <Nsound/Sine.h>
36 #include <Nsound/Wavefile.h>
37 
38 #include "UnitTest.h"
39 
40 #include <cmath>
41 #include <stdlib.h>
42 #include <iostream>
43 
44 using namespace Nsound;
45 
46 using std::cerr;
47 using std::cout;
48 using std::endl;
49 
50 // The __FILE__ macro includes the path, I don't want the whole path.
51 static const char * THIS_FILE = "FilterCombLowPassFeedback_UnitTest.cc";
52 
53 static const float64 GAMMA = 1.5e-14;
54 
56 {
57  cout << endl << THIS_FILE;
58 
60 
61  FilterCombLowPassFeedback f(100.0, 0.1, 0.66, 12.0);
62 
63  // Create some noise!
64  Sine sine(100);
65 
66  Buffer noise;
67 
68  noise << "gold/Filter_noise.wav";
69 
70  cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input) ...";
71 
72  Buffer data;
73 
74  data = f.filter(noise);
75  data.normalize();
76 
77  // Create the gold file
78 //~ data >> "gold/FilterCombLowPassFeedback_out1.wav";
79 
80  Buffer gold;
81 
82  gold << "gold/FilterCombLowPassFeedback_out1.wav";
83 
84  Buffer diff = data - gold;
85 
86  Buffer abs_diff(diff);
87  abs_diff.abs();
88 
89  if(abs_diff.getMax() > GAMMA)
90  {
91  cerr << TEST_ERROR_HEADER
92  << "Output did not match gold file!"
93  << endl;
94 
95  diff.plot("data - gold");
96  data.plot("data");
97  gold.plot("gold");
98 
99  Plotter::show();
100 
101  exit(1);
102  }
103 
104  cout << SUCCESS;
105 
106  cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input, freqs) ...";
107 
108  Buffer freqs = sine.drawLine(1.0, 6.0, 50.0);
109 
110  data = f.filter(noise, freqs);
111  data.normalize();
112 
113  // Create the gold file
114 //~ data >> "gold/FilterCombLowPassFeedback_out2.wav";
115 
116  gold = Buffer();
117 
118  gold << "gold/FilterCombLowPassFeedback_out2.wav";
119 
120  diff = data - gold;
121 
122  abs_diff = diff;
123  abs_diff.abs();
124 
125  if(abs_diff.getMax() > GAMMA)
126  {
127  cerr << TEST_ERROR_HEADER
128  << "Output did not match gold file!"
129  << endl;
130 
131  diff.plot("data - gold");
132  data.plot("data");
133  gold.plot("gold");
134 
135  Plotter::show();
136 
137  exit(1);
138  }
139 
140 //~ cout << SUCCESS;
141 
142 
143  cout << SUCCESS << endl;
144 
145 }
146 
147 
static const char * THIS_FILE
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
static const float64 GAMMA
void plot(const std::string &title="Buffer") const
Requires matplotlib. Creates a plot of this Buffer.
Definition: Buffer.cc:1551
AudioStream filter(const AudioStream &x)
#define TEST_HEADER
Definition: Test.h:45
double float64
Definition: Nsound.h:146
#define TEST_ERROR_HEADER
Definition: Test.h:49
void FilterCombLowPassFeedback_UnitTest()
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition: Buffer.cc:1064
void abs()
Modifies the Buffer by making any negative value positive.
Definition: Buffer.cc:119
#define SUCCESS
Definition: UnitTest.h:42
A class for filtering audio in the frequecy domain.
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