Nsound  0.9.4
test_convolve.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: test_convolve.cc 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Copyright (c) 2008-Present 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 <cmath>
34 #include <iostream>
35 #include <sstream>
36 
37 using namespace Nsound;
38 
39 using std::cerr;
40 using std::cout;
41 using std::endl;
42 using std::flush;
43 
44 static const char * THIS_FILE = "test_convolve.cc";
45 
46 int main(int argc, char ** argv)
47 {
48  AudioStream x("../examples/california.wav");
49  AudioStream h("../examples/walle.wav");
50 
51  x.resample2(8000);
52  h.resample2(8000);
53 
54  cout << TEST_HEADER
55  << "AudioStream::getConvolve(x) ... " << flush;
56 
57  Tic();
58 
59  AudioStream y = h.getConvolve(x[0]);
60 
61  float64 delta_t = Toc();
62 
63  y.normalize();
64  y *= 0.6;
65 
66  cout << endl << "writing convolved2.wav ..." << flush;
67 
68  y >> "convolved2.wav";
69 
70  cout << " done " << delta_t << " seconds" << endl;
71 
72  return 0;
73 }
74 
75 
int main(int argc, char **argv)
static const char * THIS_FILE
#define TEST_HEADER
Definition: Test.h:45
double float64
Definition: Nsound.h:146
void normalize()
Multiplies the AudioStream by a constant gain so the peak sample has magnitude 1.0.
Definition: AudioStream.cc:285
AudioStream getConvolve(const Buffer &b) const
Convolves every channel in the AudioStream with the Buffer.
Definition: AudioStream.h:133
void resample2(float64 new_sample_rate)
Resample to the specified sample rate.
Definition: AudioStream.cc:720
Nsound::float64 Toc()
Definition: TicToc.cc:42
void Tic()
Definition: TicToc.cc:37