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

Go to the source code of this file.

Macros

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

Functions

void BufferResample_UnitTest ()
 

Macro Definition Documentation

#define THIS_FILE   "BufferResample_UnitTest.cc"

Definition at line 49 of file BufferResample_UnitTest.cc.

Referenced by BufferResample_UnitTest().

#define GAMMA   1.5e-14

Definition at line 50 of file BufferResample_UnitTest.cc.

Referenced by BufferResample_UnitTest().

Function Documentation

void BufferResample_UnitTest ( )

Definition at line 52 of file BufferResample_UnitTest.cc.

References GAMMA, Nsound::Generator::generate(), Nsound::Buffer::getAbs(), Nsound::Buffer::getLength(), Nsound::Buffer::getMax(), Nsound::Buffer::getResample(), 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  static const uint32 LM[4] = { 2,3,5,7 };
60 
61  Sine sin(150);
62 
63  Buffer input = sin.generate(1.0, 3.0);
64 
65  cout << TEST_HEADER << "Testing Buffer:getResample(L,M) ...";
66 
67  Buffer data;
68  Buffer gold;
69  Buffer diff;
70 
71  std::stringstream ss;
72 
73  for(uint32 i = 1; i <= 4; ++i)
74  {
75 
76  std::string gold_filename;
77 
78  ss.str("");
79  ss << "gold/BufferResample_out_" << i << "_" << LM[i-1] << ".wav";
80 
81  data = input.getResample(i, LM[i-1]);
82 
83  // Create gold file
84 //~ data >> ss.str().c_str();
85 
86  gold = Buffer(ss.str().c_str());
87 
88  diff = data - gold;
89 
90  if(gold.getLength() != data.getLength() ||
91  diff.getAbs().getMax() > GAMMA)
92  {
93  cerr << TEST_ERROR_HEADER
94  << "Output did not match gold file!"
95  << endl;
96 
97  diff.plot("data - gold");
98  data.plot("data");
99  gold.plot("gold");
100 
101  Plotter::show();
102 
103  exit(1);
104  }
105 
106  // Reverse L & M
107  ss.str("");
108  ss << "gold/BufferResample_out_" << LM[i-1] << "_" << i << ".wav";
109 
110  data = input.getResample(LM[i-1], i);
111 
112  // Create gold file
113 //~ data >> ss.str().c_str();
114 
115  gold = Buffer(ss.str().c_str());
116 
117  diff = data - gold;
118 
119  if(gold.getLength() != data.getLength() ||
120  diff.getAbs().getMax() > GAMMA)
121  {
122  cerr << TEST_ERROR_HEADER
123  << "Output did not match gold file!"
124  << endl;
125 
126  diff.plot("data - gold");
127  data.plot("data");
128  gold.plot("gold");
129 
130  Plotter::show();
131 
132  exit(1);
133  }
134 
135  }
136 
137  cout << SUCCESS << endl;
138 }
unsigned int uint32
Definition: Nsound.h:153
#define GAMMA
#define 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
Buffer getAbs() const
Modifies a copy of the Buffer by making any negative value positive.
Definition: Buffer.h:174
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
#define TEST_ERROR_HEADER
Definition: Test.h:49
#define SUCCESS
Definition: UnitTest.h:42
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer getResample(float64 factor, const uint32 N=10, float64 beta=5.0) const
Resamples a copy of this Buffer using discrete-time resampling.
Definition: Buffer.cc:1607
float64 getMax() const
Returns the maximum sample value in the Buffer.
Definition: Buffer.cc:951
DOXME.
Definition: Sine.h:43