Nsound  0.9.4
test_filters.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: test_filters.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2005-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/NsoundAll.h>
30 
31 #include "Test.h"
32 
33 #include <iostream>
34 
35 using namespace Nsound;
36 
37 using std::cout;
38 using std::endl;
39 using std::flush;
40 
41 static const char * THIS_FILE = "test_filters.cc";
42 
43 int main(int argc, char ** argv)
44 {
45  Sine sin(44100);
46 
47  Buffer frequency_sweep = sin.drawLine(5.0, 0.0, 1720.0);
48 
49  AudioStream output(44100, 1);
50  AudioStream input(44100, 1);
51 
52  input = sin.generate(5.0, frequency_sweep);
53 
54  input >> "filters_input.wav";
55 
56  Buffer low_freqs = 200.0 * sin.generate(5.0, 1.0) + frequency_sweep;
57 
58  Buffer high_freqs = 200.0 + low_freqs;
59 
60  cout << TEST_HEADER
61  << "testing FilterLowPassFIR ... " << flush;
62 
63  FilterLowPassFIR f1(44100, 256, 880.0);
64 
65  Tic();
66 
67  output = f1.filter(input);
68 
69  cout << Toc() << " seconds"
70  << endl;
71 
72  output >> "filters_fir_low_pass.wav";
73 
74  cout << TEST_HEADER
75  << "testing FilterLowPassIIR ... " << flush;
76 
77  Tic();
78 
79  FilterLowPassIIR f2(44100, 4, 880.0, 0.01);
80 
81  output = f2.filter(input);
82 
83  cout << Toc() << " seconds"
84  << endl;
85 
86  output >> "filters_iir_low_pass.wav";
87 
88  cout << TEST_HEADER
89  << "testing FilterLowPassFIR dynamic filtering... " << flush;
90 
91  Tic();
92 
93  output = f1.filter(input, low_freqs);
94 
95  cout << Toc() << " seconds"
96  << endl;
97 
98  output >> "filters_fir_low_pass_dynamic.wav";
99 
100  cout << TEST_HEADER
101  << "testing FilterLowPassIIR dynamic filtering... " << flush;
102 
103  Tic();
104 
105  output = f2.filter(input, low_freqs);
106 
107  cout << Toc() << " seconds"
108  << endl;
109 
110  output >> "filters_iir_low_pass_dynamic.wav";
111 
112  cout << TEST_HEADER
113  << "testing FilterHighPassFIR ... " << flush;
114 
115  FilterHighPassFIR f3(44100, 256, 880.0);
116 
117  Tic();
118  output = f3.filter(input);
119 
120  cout << Toc() << " seconds"
121  << endl;
122 
123  output >> "filters_fir_high_pass.wav";
124 
125  cout << TEST_HEADER
126  << "testing FilterHighPassIIR ... " << flush;
127 
128  FilterHighPassIIR f4(44100, 4, 880.0, 0.01);
129 
130  Tic();
131  output = f4.filter(input);
132 
133  cout << Toc() << " seconds"
134  << endl;
135 
136  output >> "filters_iir_high_pass.wav";
137 
138  cout << TEST_HEADER
139  << "testing FilterHighPassFIR dynamic filtering... " << flush;
140 
141  Tic();
142  output = f3.filter(input, high_freqs);
143 
144  cout << Toc() << " seconds"
145  << endl;
146 
147  output >> "filters_fir_high_pass_dynamic.wav";
148 
149  cout << TEST_HEADER
150  << "testing FilterHighPassIIR dynamic filtering... " << flush;
151 
152  Tic();
153  output = f4.filter(input, high_freqs);
154 
155  cout << Toc() << " seconds"
156  << endl;
157 
158  output >> "filters_iir_high_pass_dynamic.wav";
159 
160  cout << TEST_HEADER
161  << "testing FilterBandRejectFIR ... " << flush;
162 
163  FilterBandRejectFIR f5(44100, 512, 450.0, 870.0);
164 
165  Tic();
166  output = f5.filter(input);
167 
168  cout << Toc() << " seconds"
169  << endl;
170 
171  output >> "filters_fir_band_reject.wav";
172 
173  cout << TEST_HEADER
174  << "testing FilterBandRejectIIR ... " << flush;
175 
176  FilterBandRejectIIR f6(44100, 4, 440.0, 880.0, 0.01);
177 
178  Tic();
179  output = f6.filter(input);
180 
181  cout << Toc() << " seconds"
182  << endl;
183 
184  output >> "filters_iir_band_reject.wav";
185 
186  cout << TEST_HEADER
187  << "testing FilterBandRejectFIR dynamic filtering... " << flush;
188 
189  Tic();
190 
191  output = f5.filter(input, low_freqs, high_freqs);
192 
193  cout << Toc() << " seconds"
194  << endl;
195 
196  output >> "filters_fir_band_reject_dynamic.wav";
197 
198  cout << TEST_HEADER
199  << "testing FilterBandRejectIIR dynamic filtering... " << flush;
200 
201  Tic();
202 
203  output = f6.filter(input, low_freqs, high_freqs);
204 
205  cout << Toc() << " seconds"
206  << endl;
207 
208  output >> "filters_iir_band_reject_dynamic.wav";
209 
210  cout << TEST_HEADER
211  << "testing FilterBandPassFIR ... " << flush;
212 
213  FilterBandPassFIR f7(44100, 512, 440, 880);
214 
215  Tic();
216  output = f7.filter(input);
217 
218  cout << Toc() << " seconds"
219  << endl;
220 
221  output >> "filters_fir_band_pass.wav";
222 
223  cout << TEST_HEADER
224  << "testing FilterBandPassIIR ... " << flush;
225 
226  FilterBandPassIIR f8(44100, 4, 440.0, 880.0, 0.01);
227 
228  Tic();
229  output = f8.filter(input);
230 
231  cout << Toc() << " seconds"
232  << endl;
233 
234  output >> "filters_iir_band_pass.wav";
235 
236  cout << TEST_HEADER
237  << "testing FilterBandPassFIR dynamic filtering... " << flush;
238 
239  Tic();
240  output = f7.filter(input, low_freqs, high_freqs);
241 
242  cout << Toc() << " seconds"
243  << endl;
244 
245  output >> "filters_fir_band_pass_dynamic.wav";
246 
247  cout << TEST_HEADER
248  << "testing FilterBandPassIIR dynamic filtering... " << flush;
249 
250  Tic();
251  output = f8.filter(input, low_freqs, high_freqs);
252 
253  cout << Toc() << " seconds"
254  << endl;
255 
256  output >> "filters_iir_band_pass_dynamic.wav";
257 
258  return 0;
259 }
AudioStream filter(const AudioStream &x)
AudioStream filter(const AudioStream &x)
#define TEST_HEADER
Definition: Test.h:45
int main(int argc, char **argv)
Definition: test_filters.cc:43
AudioStream filter(const AudioStream &x)
A class for filtering audio in the frequecy domain.
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
A class for filtering audio in the frequecy domain.
AudioStream filter(const AudioStream &x)
A Buffer for storing audio samples.
Definition: Buffer.h:60
AudioStream filter(const AudioStream &x)
static const char * THIS_FILE
Definition: test_filters.cc:41
Nsound::float64 Toc()
Definition: TicToc.cc:42
AudioStream filter(const AudioStream &x)
AudioStream filter(const AudioStream &x)
void Tic()
Definition: TicToc.cc:37
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
AudioStream filter(const AudioStream &x)