Nsound  0.9.4
FilterDelay_UnitTest.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FilterDelay_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/AudioStream.h>
30 #include <Nsound/Buffer.h>
31 #include <Nsound/FilterDelay.h>
32 #include <Nsound/Plotter.h>
33 #include <Nsound/Sine.h>
34 #include <Nsound/Wavefile.h>
35 
36 #include "UnitTest.h"
37 
38 #include <stdlib.h>
39 #include <iostream>
40 
41 using namespace Nsound;
42 
43 using std::cerr;
44 using std::cout;
45 using std::endl;
46 
47 // The __FILE__ macro includes the path, I don't want the whole path.
48 static const char * THIS_FILE = "FilterDelay_UnitTest.cc";
49 
50 static const float64 GAMMA = 1.5e-14;
51 
53 {
54  cout << endl << THIS_FILE;
55 
57 
58  FilterDelay f(100.0, 3.0);
59 
60  Sine sine(100);
61 
62  AudioStream input(100, 1);
63 
64  input << sine.generate(0.25, 4.0)
65  << sine.silence(0.75);
66 
67  cout << TEST_HEADER << "Testing FilterDelay::filter(input) ...";
68 
69  AudioStream data = f.filter(input, 0.333);
70 
71  // Create the gold file
72 //~ data >> "gold/FilterDelay_out1.wav";
73 
74  AudioStream gold;
75 
76  gold << "gold/FilterDelay_out1.wav";
77 
78  AudioStream diff = data - gold;
79 
80  if(diff.getAbs().getMax() > GAMMA)
81  {
82  cerr << TEST_ERROR_HEADER
83  << "Output did not match gold file!"
84  << endl;
85 
86  diff.plot("data - gold");
87  data.plot("data");
88  gold.plot("gold");
89 
90  Plotter::show();
91 
92  exit(1);
93  }
94 
95 
96  data = f.filter(input, 0.666);
97 
98  // Create the gold file
99 //~ data >> "gold/FilterDelay_out2.wav";
100 
101  gold = AudioStream("gold/FilterDelay_out2.wav");
102 
103  diff = data - gold;
104 
105  if(diff.getAbs().getMax() > GAMMA)
106  {
107  cerr << TEST_ERROR_HEADER
108  << "Output did not match gold file!"
109  << endl;
110 
111  diff.plot("data - gold");
112  data.plot("data");
113  gold.plot("gold");
114 
115  Plotter::show();
116 
117  exit(1);
118  }
119 
120 
121  FilterDelay f2(1.0, 5.0);
122 
123  input = AudioStream(1,1);
124 
125  input << 1.0 << 0.0 << 0.0 << 0.0 << 0.0
126  << 0.0 << 0.0 << 0.0 << 0.0 << 0.0;
127 
128  data = f2.filter(input, 60.0);
129 
130  // Create the gold file
131 //~ data >> "gold/FilterDelay_out3.wav";
132 
133  gold = AudioStream("gold/FilterDelay_out3.wav");
134 
135  diff = data - gold;
136 
137  if(diff.getAbs().getMax() > GAMMA)
138  {
139  cerr << TEST_ERROR_HEADER
140  << "Output did not match gold file!"
141  << endl;
142 
143  diff.plot("data - gold");
144  data.plot("data");
145  gold.plot("gold");
146 
147  Plotter::show();
148 
149  exit(1);
150  }
151 
152 
153  cout << SUCCESS << endl;
154 }
155 
156 
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
#define TEST_HEADER
Definition: Test.h:45
static const char * THIS_FILE
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
Definition: FilterDelay.cc:98
float64 getMax() const
Returns the maximum sample value in the Audiostream.
Definition: AudioStream.cc:225
Buffer silence(const float64 &duration) const
This method generates silence.
Definition: Generator.cc:1310
#define TEST_ERROR_HEADER
Definition: Test.h:49
void plot(const std::string &title="AudioStream") const
Definition: AudioStream.cc:661
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
#define SUCCESS
Definition: UnitTest.h:42
A class for filtering audio in the frequecy domain.
Definition: FilterDelay.h:47
static const float64 GAMMA
static void setDefaultSampleSize(uint32 size)
Definition: Wavefile.cc:79
AudioStream getAbs() const
Modifies the AudioStream by making any negative value positive.
Definition: AudioStream.h:81
void FilterDelay_UnitTest()
DOXME.
Definition: Sine.h:43