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

Go to the source code of this file.

Functions

void Triangle_UnitTest ()
 

Variables

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

Function Documentation

void Triangle_UnitTest ( )

Definition at line 51 of file Triangle_UnitTest.cc.

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

Referenced by main().

52 {
53  cout << endl << THIS_FILE;
54 
55  Wavefile::setDefaultSampleSize(64);
56  Wavefile::setIEEEFloat(true);
57 
58  Triangle tri(100);
59 
60  Buffer data;
61  Buffer gold;
62  Buffer diff;
63 
64  // Test 7 Hz wave
65  cout << TEST_HEADER << "Testing Triangle::generate(1.01, 2.0) ...";
66 
67  data = tri.generate(1.01, 2.0);
68 
69  // Create the gold file
70 //~ data >> "gold/Triangle_2Hz.wav";
71 
72  gold = Buffer("gold/Triangle_2Hz.wav");
73 
74  diff = data - gold;
75 
76  diff.abs();
77 
78  if(diff.getMax() > GAMMA)
79  {
80  cerr << TEST_ERROR_HEADER
81  << "Output did not match gold file!"
82  << endl;
83 
84  diff.plot("data - gold");
85  data.plot("data");
86  gold.plot("gold");
87 
88  Plotter::show();
89 
90  exit(1);
91  }
92 
93  cout << SUCCESS;
94 
95  // Test 3.5 Hz wave
96  cout << TEST_HEADER << "Testing Triangle::generate(1.01, 1.0) ...";
97 
98  data = tri.generate(1.01, 1.0);
99 
100  // Create the gold file
101 //~ data >> "gold/Triangle_1.0Hz.wav";
102 
103  gold = Buffer("gold/Triangle_1.0Hz.wav");
104 
105  diff = data - gold;
106 
107  diff.abs();
108 
109  if(diff.getMax() > GAMMA)
110  {
111  cerr << TEST_ERROR_HEADER
112  << "Output did not match gold file!"
113  << endl;
114 
115  diff.plot("data - gold");
116  data.plot("data");
117  gold.plot("gold");
118 
119  Plotter::show();
120 
121  exit(1);
122  }
123 
124  cout << SUCCESS;
125 
126  // Test dynamic
127  cout << TEST_HEADER << "Testing Triangle::generate(1.01, frequencies) ...";
128 
129  Buffer freqs = tri.drawLine(1.01, 1.0, 5.0);
130 
131  data = tri.generate(1.01, freqs);
132 
133  // Create the gold file
134 //~ data >> "gold/Triangle_1_to_5Hz.wav";
135 
136  gold = Buffer("gold/Triangle_1_to_5Hz.wav");
137 
138  diff = data - gold;
139 
140  diff.abs();
141 
142  if(diff.getMax() > GAMMA)
143  {
144  cerr << TEST_ERROR_HEADER
145  << "Output did not match gold file!"
146  << endl;
147 
148  diff.plot("data - gold");
149  data.plot("data");
150  gold.plot("gold");
151 
152  Plotter::show();
153 
154  exit(1);
155  }
156 
157  Plotter::show();
158 
159  cout << SUCCESS << endl;
160 }
Triangle generator.
Definition: Triangle.h:48
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
static const char * THIS_FILE
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
static const float64 GAMMA

Variable Documentation

const char* THIS_FILE = "Triangle_UnitTest.cc"
static

Definition at line 47 of file Triangle_UnitTest.cc.

Referenced by Triangle_UnitTest().

const float64 GAMMA = 1.5e-14
static

Definition at line 49 of file Triangle_UnitTest.cc.

Referenced by Triangle_UnitTest().