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

Go to the source code of this file.

Macros

#define THIS_FILE   "FilterParametricEqualizer_UnitTest.cc"
 
#define GAMMA   1.5e-14
 

Functions

void FilterParametricEqualizer_UnitTest ()
 

Macro Definition Documentation

#define THIS_FILE   "FilterParametricEqualizer_UnitTest.cc"
#define GAMMA   1.5e-14

Function Documentation

void FilterParametricEqualizer_UnitTest ( )

Definition at line 52 of file FilterParametricEqualizer_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), Nsound::FilterParametricEqualizer::filter(), GAMMA, Nsound::Buffer::getMax(), Nsound::FilterParametricEqualizer::HIGH_SHELF, Nsound::FilterParametricEqualizer::LOW_SHELF, Nsound::FilterParametricEqualizer::PEAKING, Nsound::Buffer::plot(), Nsound::Wavefile::setDefaultSampleSize(), Nsound::Wavefile::setIEEEFloat(), Nsound::Plotter::show(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, and THIS_FILE.

Referenced by main().

53 {
54  cout << endl << THIS_FILE;
55 
56  Wavefile::setDefaultSampleSize(64);
57  Wavefile::setIEEEFloat(true);
58 
59  Sine sine(100);
60 
62  FilterParametricEqualizer::PEAKING,
63  100,
64  12,
65  0.2,
66  4.0);
67 
69  FilterParametricEqualizer::LOW_SHELF,
70  100,
71  12,
72  0.2,
73  4.0);
74 
76  FilterParametricEqualizer::HIGH_SHELF,
77  100,
78  12,
79  0.2,
80  4.0);
81 
82  Buffer freqs = sine.drawLine(5.0, 24, 6);
83 
84  static const std::string titles[3] =
85  {
86  "Testing Peaking filter ...",
87  "Testing Low Shelf filter ...",
88  "Testing High Shelf filter ..."
89  };
90 
91  static const std::string types[3] =
92  {
93  "peaking",
94  "low",
95  "high"
96  };
97 
98  static const std::string gold_filenames[3] =
99  {
100  "gold/FilterParametricEqualizer_out_peaking.wav",
101  "gold/FilterParametricEqualizer_out_low.wav",
102  "gold/FilterParametricEqualizer_out_high.wav"
103  };
104 
105  FilterParametricEqualizer * filters[3] =
106  {
107  &peaking,
108  &low,
109  &high
110  };
111 
112  Buffer noise;
113  Buffer data;
114  Buffer gold;
115  Buffer diff;
116 
117  noise << "gold/Filter_noise.wav";
118  noise << "gold/Filter_noise.wav";
119 
120  for(int i = 0; i < 3; ++i)
121  {
122  cout << TEST_HEADER << titles[i];
123 
124  data = filters[i]->filter(noise, freqs);
125 
126  // Create gold file
127 //~ data >> gold_filenames[i].c_str();
128 
129  gold = Buffer(gold_filenames[i]);
130 
131  diff = data - gold;
132  diff.abs();
133 
134  if(diff.getMax() > GAMMA)
135  {
136  cerr << TEST_ERROR_HEADER
137  << "Output did not match gold file!"
138  << endl;
139 
140  diff.plot("data - gold");
141  data.plot("data");
142  gold.plot("gold");
143 
144  Plotter::show();
145 
146  exit(1);
147  }
148 
149  cout << SUCCESS;
150 
151  }
152 
153  cout << endl;
154 }
Implementation of Zoelzer's parametric equalizer filters, with some modifications by the author...
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
AudioStream filter(const AudioStream &x)
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
float64 getMax() const
Returns the maximum sample value in the Buffer.
Definition: Buffer.cc:951
DOXME.
Definition: Sine.h:43