Nsound  0.9.4
Functions | Variables
FilterDelay_UnitTest.cc File Reference
#include <Nsound/AudioStream.h>
#include <Nsound/Buffer.h>
#include <Nsound/FilterDelay.h>
#include <Nsound/Plotter.h>
#include <Nsound/Sine.h>
#include <Nsound/Wavefile.h>
#include "UnitTest.h"
#include <stdlib.h>
#include <iostream>
Include dependency graph for FilterDelay_UnitTest.cc:

Go to the source code of this file.

Functions

void FilterDelay_UnitTest ()
 

Variables

static const char * THIS_FILE = "FilterDelay_UnitTest.cc"
 
static const float64 GAMMA = 1.5e-14
 

Function Documentation

void FilterDelay_UnitTest ( )

Definition at line 52 of file FilterDelay_UnitTest.cc.

References Nsound::FilterDelay::filter(), GAMMA, Nsound::Generator::generate(), Nsound::AudioStream::getAbs(), Nsound::AudioStream::getMax(), Nsound::AudioStream::plot(), Nsound::Wavefile::setDefaultSampleSize(), Nsound::Plotter::show(), Nsound::Generator::silence(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

53 {
54  cout << endl << THIS_FILE;
55 
56  Wavefile::setDefaultSampleSize(48);
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 }
#define TEST_HEADER
Definition: Test.h:45
static const char * THIS_FILE
float64 getMax() const
Returns the maximum sample value in the Audiostream.
Definition: AudioStream.cc:225
#define TEST_ERROR_HEADER
Definition: Test.h:49
void plot(const std::string &title="AudioStream") const
Definition: AudioStream.cc:661
#define SUCCESS
Definition: UnitTest.h:42
A class for filtering audio in the frequecy domain.
Definition: FilterDelay.h:47
static const float64 GAMMA
AudioStream getAbs() const
Modifies the AudioStream by making any negative value positive.
Definition: AudioStream.h:81
DOXME.
Definition: Sine.h:43

Variable Documentation

const char* THIS_FILE = "FilterDelay_UnitTest.cc"
static

Definition at line 48 of file FilterDelay_UnitTest.cc.

Referenced by FilterDelay_UnitTest().

const float64 GAMMA = 1.5e-14
static

Definition at line 50 of file FilterDelay_UnitTest.cc.

Referenced by FilterDelay_UnitTest().