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

Go to the source code of this file.

Functions

void FilterCombLowPassFeedback_UnitTest ()
 

Variables

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

Function Documentation

void FilterCombLowPassFeedback_UnitTest ( )

Definition at line 55 of file FilterCombLowPassFeedback_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), Nsound::FilterCombLowPassFeedback::filter(), GAMMA, Nsound::Buffer::getMax(), Nsound::Buffer::normalize(), Nsound::Buffer::plot(), Nsound::Wavefile::setDefaultSampleSize(), Nsound::Plotter::show(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

56 {
57  cout << endl << THIS_FILE;
58 
59  Wavefile::setDefaultSampleSize(48);
60 
61  FilterCombLowPassFeedback f(100.0, 0.1, 0.66, 12.0);
62 
63  // Create some noise!
64  Sine sine(100);
65 
66  Buffer noise;
67 
68  noise << "gold/Filter_noise.wav";
69 
70  cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input) ...";
71 
72  Buffer data;
73 
74  data = f.filter(noise);
75  data.normalize();
76 
77  // Create the gold file
78 //~ data >> "gold/FilterCombLowPassFeedback_out1.wav";
79 
80  Buffer gold;
81 
82  gold << "gold/FilterCombLowPassFeedback_out1.wav";
83 
84  Buffer diff = data - gold;
85 
86  Buffer abs_diff(diff);
87  abs_diff.abs();
88 
89  if(abs_diff.getMax() > GAMMA)
90  {
91  cerr << TEST_ERROR_HEADER
92  << "Output did not match gold file!"
93  << endl;
94 
95  diff.plot("data - gold");
96  data.plot("data");
97  gold.plot("gold");
98 
99  Plotter::show();
100 
101  exit(1);
102  }
103 
104  cout << SUCCESS;
105 
106  cout << TEST_HEADER << "Testing FilterCombLowPassFeedback::filter(input, freqs) ...";
107 
108  Buffer freqs = sine.drawLine(1.0, 6.0, 50.0);
109 
110  data = f.filter(noise, freqs);
111  data.normalize();
112 
113  // Create the gold file
114 //~ data >> "gold/FilterCombLowPassFeedback_out2.wav";
115 
116  gold = Buffer();
117 
118  gold << "gold/FilterCombLowPassFeedback_out2.wav";
119 
120  diff = data - gold;
121 
122  abs_diff = diff;
123  abs_diff.abs();
124 
125  if(abs_diff.getMax() > GAMMA)
126  {
127  cerr << TEST_ERROR_HEADER
128  << "Output did not match gold file!"
129  << endl;
130 
131  diff.plot("data - gold");
132  data.plot("data");
133  gold.plot("gold");
134 
135  Plotter::show();
136 
137  exit(1);
138  }
139 
140 //~ cout << SUCCESS;
141 
142 
143  cout << SUCCESS << endl;
144 
145 }
static const char * THIS_FILE
static const float64 GAMMA
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
#define TEST_ERROR_HEADER
Definition: Test.h:49
void normalize()
Multiplies the Buffer by a constant gain so the peak sample has magnitude 1.0.
Definition: Buffer.cc:1064
void abs()
Modifies the Buffer by making any negative value positive.
Definition: Buffer.cc:119
#define SUCCESS
Definition: UnitTest.h:42
A class for filtering audio in the frequecy domain.
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43

Variable Documentation

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