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

Go to the source code of this file.

Functions

void DelayLine_UnitTest ()
 

Variables

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

Function Documentation

void DelayLine_UnitTest ( )

Definition at line 55 of file DelayLine_UnitTest.cc.

References Nsound::Buffer::abs(), Nsound::Generator::drawLine(), GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getMax(), Nsound::Buffer::plot(), Nsound::DelayLine::read(), Nsound::Wavefile::setDefaultSampleSize(), Nsound::Wavefile::setIEEEFloat(), Nsound::Plotter::show(), SUCCESS, TEST_ERROR_HEADER, TEST_HEADER, THIS_FILE, and Nsound::DelayLine::write().

Referenced by main().

56 {
57  cout << endl << THIS_FILE;
58 
59  Wavefile::setDefaultSampleSize(64);
60  Wavefile::setIEEEFloat(true);
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 const char * THIS_FILE
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
std::istream & read(std::istream &stream_in)
Constructs a Buffer from seralized data in the inputstream.
Definition: Buffer.cc:1945
std::ostream & write(std::ostream &out) const
Serializes the Buffer to output stream, no endian checks.
Definition: Buffer.cc:1922
#define TEST_ERROR_HEADER
Definition: Test.h:49
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

Variable Documentation

const char* THIS_FILE = "DelayLine_UnitTest.cc"
static

Definition at line 50 of file DelayLine_UnitTest.cc.

Referenced by DelayLine_UnitTest().

const float64 GAMMA = 1.5e-14
static

Definition at line 52 of file DelayLine_UnitTest.cc.

Referenced by DelayLine_UnitTest().