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

Go to the source code of this file.

Functions

void Wavefile_UnitTest ()
 

Variables

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

Function Documentation

void Wavefile_UnitTest ( )

Definition at line 54 of file Wavefile_UnitTest.cc.

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

Referenced by main().

55 {
56  cout << endl << THIS_FILE;
57 
58  Wavefile::setDefaultSampleSize(48);
59 
60  Sine sin(100);
61 
62  AudioStream data1(100, 3);
63 
64  data1 << sin.generate(1.0, 13.0);
65 
66  data1[1] *= 0.666666666666666;
67  data1[2] *= 0.333333333333333;
68 
69  // Write out 10 channel 13 Hz wave.
70  cout << TEST_HEADER << "Testing Wavefile::write(48-bit), read(48-bit) ..." << flush;
71 
72  data1 >> "test_wavefile.wav";
73 
74  AudioStream data(100, 3);
75 
76  data << "test_wavefile.wav";
77 
78  AudioStream gold(100, 3);
79 
80  // Create gold file
81 //~ data >> "gold/Wavefile_out1.wav";
82 
83  gold << "gold/Wavefile_out1.wav";
84 
85  AudioStream diff = data - gold;
86 
87  AudioStream abs_diff(diff);
88  abs_diff.abs();
89 
90  for(int32 i = 0; i < 3; ++i)
91  {
92  if(abs_diff[i].getMax() > GAMMA)
93  {
94  cerr << TEST_ERROR_HEADER
95  << "Output did not match gold file!"
96  << endl;
97 
98  diff[i].plot("data - gold");
99  data[i].plot("data");
100  gold[i].plot("gold");
101 
102  Plotter::show();
103 
104  exit(1);
105  }
106  }
107 
108  cout << SUCCESS;
109 
110  // Write out 10 channel 13 Hz wave again but with 24 bits per sample
111  cout << TEST_HEADER << "Testing Wavefile::write(24-bit), read(24-bit) ..." << flush;
112 
113  Wavefile::setDefaultSampleSize(24);
114 
115  data1 >> "test_wavefile2.wav";
116 
117  data = AudioStream(100, 3);
118  data << "test_wavefile2.wav";
119 
120  // Create gold file
121 //~ data >> "gold/Wavefile_out2.wav";
122 
123  gold = AudioStream(100, 3);
124  gold << "gold/Wavefile_out2.wav";
125 
126  diff = data - gold;
127 
128  abs_diff = diff;
129  abs_diff.abs();
130 
131  for(int32 i = 0; i < 1; ++i)
132  {
133  if(abs_diff[i].getMax() > 0.5 * GAMMA)
134  {
135  cerr << TEST_ERROR_HEADER
136  << "Output did not match gold file!"
137  << endl;
138 
139  diff[i].plot("data - gold");
140  data[i].plot("data");
141  gold[i].plot("gold");
142 
143  Plotter::show();
144 
145  exit(1);
146  }
147  }
148 
149  cout << SUCCESS << endl;
150 }
static const float64 GAMMA
#define TEST_HEADER
Definition: Test.h:45
#define TEST_ERROR_HEADER
Definition: Test.h:49
void plot(const std::string &title="AudioStream") const
Definition: AudioStream.cc:661
#define SUCCESS
Definition: UnitTest.h:42
static const char * THIS_FILE
signed int int32
Definition: Nsound.h:142
void abs()
This method calls abs on all buffers held in the stream.
Definition: AudioStream.cc:114
DOXME.
Definition: Sine.h:43

Variable Documentation

const char* THIS_FILE = "Wavefile_UnitTest.cc"
static

Definition at line 49 of file Wavefile_UnitTest.cc.

Referenced by Wavefile_UnitTest().

const float64 GAMMA = 1.5e-14
static

Definition at line 51 of file Wavefile_UnitTest.cc.

Referenced by Wavefile_UnitTest().