Nsound  0.9.4
DelayLine_UnitTest.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: DelayLine_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 #include <Nsound/DelayLine.h>
33 #include <Nsound/Plotter.h>
34 #include <Nsound/Sine.h>
35 #include <Nsound/Wavefile.h>
36 
37 #include "UnitTest.h"
38 
39 #include <stdlib.h>
40 #include <math.h>
41 #include <iostream>
42 
43 using namespace Nsound;
44 
45 using std::cout;
46 using std::cerr;
47 using std::endl;
48 using std::flush;
49 
50 static const char * THIS_FILE = "DelayLine_UnitTest.cc";
51 
52 static const float64 GAMMA = 1.5e-14;
53 
54 void
56 {
57  cout << endl << THIS_FILE;
58 
61 
62  DelayLine dl(1.0, 10.0);
63  Sine sine(100.0);
64 
65  Buffer input;
66  Buffer data;
67  Buffer gold;
68  Buffer diff;
69 
70  cout << TEST_HEADER << "Testing DelayLine::write() & read() ...";
71 
72  input = sine.generate(1.0, 2.0) * sine.drawLine(1.0, 1.0, 0.0);
73 
74  for(uint32 i = 0; i < 100; ++i)
75  {
76  dl.write(input[i]);
77  data << dl.read();
78  }
79 
80  // Create Gold files
81 //~ data >> "gold/DelayLine_out1.wav";
82 
83  gold = Buffer("gold/DelayLine_out1.wav");
84 
85  diff = data - gold;
86  diff.abs();
87 
88  if(diff.getMax() > GAMMA)
89  {
90  cerr << TEST_ERROR_HEADER
91  << "Output did not match gold file!"
92  << endl;
93 
94  diff.plot("data - gold");
95  data.plot("data");
96  gold.plot("gold");
97 
98  Plotter::show();
99 
100  exit(1);
101  }
102 
103  cout << SUCCESS << endl;
104 }
unsigned int uint32
Definition: Nsound.h:153
static const float64 GAMMA
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
static const char * THIS_FILE
void DelayLine_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
double float64
Definition: Nsound.h:146
#define TEST_ERROR_HEADER
Definition: Test.h:49
virtual float64 generate(const float64 &frequency)
This is a real-time method for the wavetable oscillator.
Definition: Generator.cc:972
float64 read()
Definition: DelayLine.cc:97
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
void write(float64 x)
Definition: DelayLine.cc:133