forked from RebelTechnology/OwlProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleBufferTest.cpp
More file actions
178 lines (151 loc) · 4.84 KB
/
SampleBufferTest.cpp
File metadata and controls
178 lines (151 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
g++ -Wall -g -I/opt/local/include -L/opt/local/lib -o SampleBufferTest SampleBufferTest.cpp -lboost_unit_test_framework && ./SampleBufferTest
*/
#include <stdint.h>
typedef int16_t q15_t;
typedef int32_t q31_t;
#define AUDIO_BITDEPTH 16
#define AUDIO_CHANNELS 2
#include "SampleBuffer.hpp"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Test
#include <boost/test/unit_test.hpp>
// tolerance for test comparison in percentage units
#define TEST_PRECISION 0.00001f
BOOST_AUTO_TEST_CASE(universeInOrder){
BOOST_CHECK(2+2 == 4);
}
BOOST_AUTO_TEST_CASE(testSplit){
SampleBuffer buffer;
buffer.setSize(128);
float samples[256];
for(int i=0; i<256; ++i)
samples[i] = i/128.0 - 1.0f;
int16_t input[512];
for(int i=0; i<256; ++i){
#if AUDIO_BITDEPTH == 24
#ifdef AUDIO_BIGEND
// // big endian
input[i*2] = (((int32_t)(samples[i]*2147483648.0f)) >> 16) & 0xffff; // MSB
input[i*2+1] = ((int32_t)(samples[i]*2147483648.0f)) & 0xffff; // LSB
#else
// little endian
input[i*2] = ((int32_t)(samples[i]*2147483648.0f)) & 0xffff; // LSB
input[i*2+1] = (((int32_t)(samples[i]*2147483648.0f)) >> 16) & 0xffff; // MSB
#endif
#else /* AUDIO_BITDEPTH == 24 */
input[i] = ((int16_t)(samples[i]*32768.0f));
#endif
}
// input[i] = ((int32_t)(samples[i]*8388608.0f))<<8;
buffer.split(input, 256);
for(int i=0; i<128; ++i){
BOOST_CHECK_CLOSE(buffer.getSamples(0)[i], samples[i*2], TEST_PRECISION);
BOOST_CHECK_CLOSE(buffer.getSamples(1)[i], samples[i*2+1], TEST_PRECISION);
}
}
// BOOST_AUTO_TEST_CASE(testComb){
// SampleBuffer<128> buffer;
// float samples[128];
// for(int i=0; i<128; ++i)
// samples[i] = i/64.0 - 1.0f;
// for(int i=0; i<128; ++i){
// buffer.getSamples(0)[i] = samples[i];
// buffer.getSamples(1)[i] = samples[i];
// }
// int16_t output[512];
// buffer.comb(output);
// for(int i=0; i<512; ++i){
// }
// for(int i=0; i<256; ++i){
// input[i*2] = (((int32_t)(samples[i]*2147483648.0f)) >> 16) & 0xffff;
// input[i*2+1] = ((int32_t)(samples[i]*2147483648.0f)) & 0xffff;
// }
// // input[i] = ((int32_t)(samples[i]*8388608.0f))<<8;
// buffer.split(input);
// for(int i=0; i<128; ++i){
// BOOST_CHECK_CLOSE(buffer.getSamples(0)[i], samples[i*2], TEST_PRECISION);
// BOOST_CHECK_CLOSE(buffer.getSamples(1)[i], samples[i*2+1], TEST_PRECISION);
// }
// }
BOOST_AUTO_TEST_CASE(testCombAndSplit){
SampleBuffer buffer;
buffer.setSize(128);
float samples[128];
int16_t output[512];
for(int i=0; i<128; ++i)
samples[i] = i/64.0 - 1.0f;
for(int i=0; i<128; ++i){
buffer.getSamples(0)[i] = samples[i];
buffer.getSamples(1)[i] = samples[i];
}
buffer.comb(output);
buffer.split(output, 256);
for(int i=0; i<128; ++i){
BOOST_CHECK_CLOSE(buffer.getSamples(0)[i], samples[i], TEST_PRECISION);
BOOST_CHECK_CLOSE(buffer.getSamples(1)[i], samples[i], TEST_PRECISION);
}
}
BOOST_AUTO_TEST_CASE(testMultiplyAndCombSplit){
SampleBuffer buffer;
buffer.setSize(128);
float samples[128];
int16_t output[512];
for(int i=0; i<128; ++i)
samples[i] = i/64.0 - 1.0f;
for(int i=0; i<buffer.getSize(); ++i){
buffer.getSamples(0)[i] = samples[i];
buffer.getSamples(1)[i] = samples[i];
}
buffer.comb(output);
buffer.split(output, 256);
for(int i=0; i<buffer.getSize(); ++i){
// buffer.getSamples(0)[i] = samples[i] * 0.9;
// buffer.getSamples(1)[i] = samples[i] * 0.1;
buffer.getSamples(0)[i] *= 0.9;
buffer.getSamples(1)[i] *= 0.1;
}
for(int i=0; i<128; ++i){
BOOST_CHECK_CLOSE(buffer.getSamples(0)[i], samples[i]*0.9, TEST_PRECISION);
BOOST_CHECK_CLOSE(buffer.getSamples(1)[i], samples[i]*0.1, TEST_PRECISION);
}
// buffer.comb(output);
// buffer.split(output, 256);
// for(int i=0; i<128; ++i){
// BOOST_CHECK_CLOSE(buffer.getSamples(0)[i], samples[i]*0.9, TEST_PRECISION);
// BOOST_CHECK_CLOSE(buffer.getSamples(1)[i], samples[i]*0.1, TEST_PRECISION);
// }
}
BOOST_AUTO_TEST_CASE(testCombAndSplitAndComb){
SampleBuffer buffer;
buffer.setSize(128);
float samples[128];
int16_t output[512];
int16_t input[512];
for(int i=0; i<128; ++i)
samples[i] = i/64.0 - 1.0f;
for(int i=0; i<128; ++i){
buffer.getSamples(0)[i] = samples[i];
buffer.getSamples(1)[i] = samples[i];
}
buffer.comb(output);
buffer.split(output, 256);
buffer.comb(input);
for(int i=0; i<256; ++i)
BOOST_CHECK_EQUAL(input[i], output[i]);
}
// BOOST_AUTO_TEST_CASE(testSplitAndComb){
// SampleBuffer<128> buffer;
// int32_t input[256];
// int32_t output[256];
// // input[0] = -1;
// // input[1] = 2;
// for(int i=0; i<256; ++i)
// input[i] = (831828-i)<<8;
// // input[i] = input[i-2]*input[i-1];
// buffer.split((int16_t*)input);
// buffer.comb((int16_t*)output);
// for(int i=0; i<256; ++i)
// BOOST_CHECK_EQUAL(input[i], output[i]);
// }
AudioBuffer::~AudioBuffer(){}