21
21
const std::string projectBuildDirectory = PROJECT_BINARY_DIR;
22
22
23
23
// =============================================================
24
- TEST_SUITE (" AiffLoadingTests" )
24
+ TEST_SUITE (" AiffLoadingTests - Floating Point Types - 8-bit File " )
25
25
{
26
26
// =============================================================
27
27
TEST_CASE (" AiffLoadingTests_Stereo_8bit_44100" )
@@ -43,7 +43,32 @@ TEST_SUITE ("AiffLoadingTests")
43
43
}
44
44
}
45
45
}
46
+
47
+ // =============================================================
48
+ TEST_CASE (" AiffLoadingTests_Stereo_8bit_48000" )
49
+ {
50
+ AudioFile<double > audioFile;
51
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_8bit_48000.aif" );
52
+
53
+ CHECK (loadedOK);
54
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_8bit_48000::numSamplesPerChannel);
55
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_8bit_48000::bitDepth);
56
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_8bit_48000::sampleRate);
57
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_8bit_48000::numChannels);
58
+
59
+ for (size_t i = 0 ; i < aiff_stereo_8bit_48000::testBuffer[0 ].size (); i++)
60
+ {
61
+ for (int k = 0 ; k < audioFile.getNumChannels (); k++)
62
+ {
63
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_8bit_48000::testBuffer[k][i]).epsilon (0.01 ));
64
+ }
65
+ }
66
+ }
67
+ }
46
68
69
+ // =============================================================
70
+ TEST_SUITE (" AiffLoadingTests - Floating Point Types - 16-bit File" )
71
+ {
47
72
// =============================================================
48
73
TEST_CASE (" AiffLoadingTests_Stereo_16bit_44100" )
49
74
{
@@ -64,7 +89,32 @@ TEST_SUITE ("AiffLoadingTests")
64
89
}
65
90
}
66
91
}
92
+
93
+ // =============================================================
94
+ TEST_CASE (" AiffLoadingTests_Stereo_16bit_48000" )
95
+ {
96
+ AudioFile<double > audioFile;
97
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_16bit_48000.aif" );
98
+
99
+ CHECK (loadedOK);
100
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_16bit_48000::numSamplesPerChannel);
101
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_16bit_48000::bitDepth);
102
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_16bit_48000::sampleRate);
103
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_16bit_48000::numChannels);
104
+
105
+ for (size_t i = 0 ; i < aiff_stereo_16bit_48000::testBuffer[0 ].size (); i++)
106
+ {
107
+ for (int k = 0 ; k < audioFile.getNumChannels (); k++)
108
+ {
109
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_16bit_48000::testBuffer[k][i]).epsilon (0.00001 ));
110
+ }
111
+ }
112
+ }
113
+ }
67
114
115
+ // =============================================================
116
+ TEST_SUITE (" AiffLoadingTests - Floating Point Types - 24-bit File" )
117
+ {
68
118
// =============================================================
69
119
TEST_CASE (" AiffLoadingTests_Stereo_24bit_44100" )
70
120
{
@@ -85,7 +135,32 @@ TEST_SUITE ("AiffLoadingTests")
85
135
}
86
136
}
87
137
}
138
+
139
+ // =============================================================
140
+ TEST_CASE (" AiffLoadingTests_Stereo_24bit_48000" )
141
+ {
142
+ AudioFile<double > audioFile;
143
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_24bit_48000.aif" );
144
+
145
+ CHECK (loadedOK);
146
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_24bit_48000::numSamplesPerChannel);
147
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_24bit_48000::bitDepth);
148
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_24bit_48000::sampleRate);
149
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_24bit_48000::numChannels);
150
+
151
+ for (size_t i = 0 ; i < aiff_stereo_24bit_48000::testBuffer[0 ].size (); i++)
152
+ {
153
+ for (int k = 0 ; k < audioFile.getNumChannels (); k++)
154
+ {
155
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_24bit_48000::testBuffer[k][i]).epsilon (0.00001 ));
156
+ }
157
+ }
158
+ }
159
+ }
88
160
161
+ // =============================================================
162
+ TEST_SUITE (" AiffLoadingTests - Floating Point Types - 32-bit File" )
163
+ {
89
164
// =============================================================
90
165
TEST_CASE (" AiffLoadingTests_Stereo_32bit_44100" )
91
166
{
@@ -108,86 +183,170 @@ TEST_SUITE ("AiffLoadingTests")
108
183
}
109
184
110
185
// =============================================================
111
- TEST_CASE (" AiffLoadingTests_Stereo_8bit_48000 " )
186
+ TEST_CASE (" AiffLoadingTests_Stereo_32bit_48000 " )
112
187
{
113
188
AudioFile<double > audioFile;
114
- bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_8bit_48000 .aif" );
189
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_32bit_48000 .aif" );
115
190
116
191
CHECK (loadedOK);
117
- CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_8bit_48000 ::numSamplesPerChannel);
118
- CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_8bit_48000 ::bitDepth);
119
- CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_8bit_48000 ::sampleRate);
120
- CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_8bit_48000 ::numChannels);
192
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_32bit_48000 ::numSamplesPerChannel);
193
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_32bit_48000 ::bitDepth);
194
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_32bit_48000 ::sampleRate);
195
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_32bit_48000 ::numChannels);
121
196
122
- for (size_t i = 0 ; i < aiff_stereo_8bit_48000 ::testBuffer[0 ].size (); i++)
197
+ for (size_t i = 0 ; i < aiff_stereo_32bit_48000 ::testBuffer[0 ].size (); i++)
123
198
{
124
199
for (int k = 0 ; k < audioFile.getNumChannels (); k++)
125
200
{
126
- CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_8bit_48000 ::testBuffer[k][i]).epsilon (0.01 ));
201
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_32bit_48000 ::testBuffer[k][i]).epsilon (0.00001 ));
127
202
}
128
203
}
129
204
}
205
+ }
130
206
207
+ // =============================================================
208
+ TEST_SUITE (" AiffLoadingTests - Integer Types - 8-bit File" )
209
+ {
131
210
// =============================================================
132
- TEST_CASE (" AiffLoadingTests_Stereo_16bit_48000" )
211
+ template <typename T>
212
+ void test8Bit44100WithInteger (bool expectFailure = false )
133
213
{
134
- AudioFile<double > audioFile;
135
- bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_16bit_48000 .aif" );
214
+ AudioFile<T > audioFile;
215
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_8bit_44100 .aif" );
136
216
137
217
CHECK (loadedOK);
138
- CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_16bit_48000 ::numSamplesPerChannel);
139
- CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_16bit_48000 ::bitDepth);
140
- CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_16bit_48000 ::sampleRate);
141
- CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_16bit_48000 ::numChannels);
218
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_8bit_44100 ::numSamplesPerChannel);
219
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_8bit_44100 ::bitDepth);
220
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_8bit_44100 ::sampleRate);
221
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_8bit_44100 ::numChannels);
142
222
143
- for (size_t i = 0 ; i < aiff_stereo_16bit_48000::testBuffer[0 ].size (); i++)
223
+ int offset = std::is_signed_v<T> ? 0 : 128 ;
224
+
225
+ for (size_t i = 0 ; i < aiff_stereo_8bit_44100::testBuffer[0 ].size (); i++)
144
226
{
145
227
for (int k = 0 ; k < audioFile.getNumChannels (); k++)
146
228
{
147
- CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_16bit_48000 ::testBuffer[k][i]).epsilon (0.00001 ));
229
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_8bit_44100 ::testBuffer[k][i] * 127 + offset ).epsilon (0.01 ));
148
230
}
149
231
}
150
232
}
233
+
234
+ // =============================================================
235
+ TEST_CASE (" AiffLoadingTests_Stereo_8bit_44100_integers" )
236
+ {
237
+ test8Bit44100WithInteger<int8_t >();
238
+ test8Bit44100WithInteger<uint8_t >();
239
+ test8Bit44100WithInteger<int16_t >();
240
+ test8Bit44100WithInteger<uint16_t >();
241
+ test8Bit44100WithInteger<int32_t >();
242
+ test8Bit44100WithInteger<uint32_t >();
243
+ test8Bit44100WithInteger<int64_t >();
244
+ test8Bit44100WithInteger<uint64_t >();
245
+ }
246
+ }
151
247
248
+ // =============================================================
249
+ TEST_SUITE (" AiffLoadingTests - Integer Types - 16-bit File" )
250
+ {
152
251
// =============================================================
153
- TEST_CASE (" AiffLoadingTests_Stereo_24bit_48000" )
252
+ template <typename T>
253
+ void test16Bit44100WithInteger (bool expectFailure = false )
154
254
{
155
- AudioFile<double > audioFile;
156
- bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_24bit_48000.aif" );
255
+ AudioFile<T> audioFile;
256
+
257
+ if (expectFailure)
258
+ audioFile.shouldLogErrorsToConsole (false );
259
+
260
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_16bit_44100.aif" );
261
+
262
+ if (expectFailure)
263
+ {
264
+ CHECK_EQ (loadedOK, false );
265
+ return ;
266
+ }
157
267
158
268
CHECK (loadedOK);
159
- CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_24bit_48000 ::numSamplesPerChannel);
160
- CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_24bit_48000 ::bitDepth);
161
- CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_24bit_48000 ::sampleRate);
162
- CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_24bit_48000 ::numChannels);
269
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_16bit_44100 ::numSamplesPerChannel);
270
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_16bit_44100 ::bitDepth);
271
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_16bit_44100 ::sampleRate);
272
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_16bit_44100 ::numChannels);
163
273
164
- for (size_t i = 0 ; i < aiff_stereo_24bit_48000::testBuffer[0 ].size (); i++)
274
+ int offset = std::is_signed_v<T> ? 0 : 32768 ;
275
+
276
+ for (size_t i = 0 ; i < aiff_stereo_16bit_44100::testBuffer[0 ].size (); i++)
165
277
{
166
278
for (int k = 0 ; k < audioFile.getNumChannels (); k++)
167
279
{
168
- CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_24bit_48000 ::testBuffer[k][i]).epsilon (0.00001 ));
280
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_16bit_44100 ::testBuffer[k][i] * 32767 + offset ).epsilon (0.0001 ));
169
281
}
170
282
}
171
283
}
284
+
285
+ // =============================================================
286
+ TEST_CASE (" AiffLoadingTests_Stereo_16bit_44100_integers" )
287
+ {
288
+ test16Bit44100WithInteger<uint16_t >();
289
+ test16Bit44100WithInteger<int16_t >();
290
+ test16Bit44100WithInteger<uint32_t >();
291
+ test16Bit44100WithInteger<int32_t >();
292
+ test16Bit44100WithInteger<uint64_t >();
293
+ test16Bit44100WithInteger<int64_t >();
294
+
295
+ // check these fail...
296
+ test16Bit44100WithInteger<uint8_t > (true );
297
+ test16Bit44100WithInteger<int8_t > (true );
298
+ }
299
+ }
172
300
301
+ // =============================================================
302
+ TEST_SUITE (" AiffLoadingTests - Integer Types - 24-bit File" )
303
+ {
173
304
// =============================================================
174
- TEST_CASE (" AiffLoadingTests_Stereo_32bit_48000" )
305
+ template <typename T>
306
+ void test24Bit44100WithInteger (bool expectFailure = false )
175
307
{
176
- AudioFile<double > audioFile;
177
- bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_32bit_48000.aif" );
308
+ AudioFile<T> audioFile;
309
+
310
+ if (expectFailure)
311
+ audioFile.shouldLogErrorsToConsole (false );
312
+
313
+ bool loadedOK = audioFile.load (projectBuildDirectory + " /test-audio/aiff_stereo_24bit_44100.aif" );
314
+
315
+ if (expectFailure)
316
+ {
317
+ REQUIRE_EQ (loadedOK, false );
318
+ return ;
319
+ }
178
320
179
321
CHECK (loadedOK);
180
- CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_32bit_48000 ::numSamplesPerChannel);
181
- CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_32bit_48000 ::bitDepth);
182
- CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_32bit_48000 ::sampleRate);
183
- CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_32bit_48000 ::numChannels);
322
+ CHECK_EQ (audioFile.getNumSamplesPerChannel (), aiff_stereo_24bit_44100 ::numSamplesPerChannel);
323
+ CHECK_EQ (audioFile.getBitDepth (), aiff_stereo_24bit_44100 ::bitDepth);
324
+ CHECK_EQ (audioFile.getSampleRate (), aiff_stereo_24bit_44100 ::sampleRate);
325
+ CHECK_EQ (audioFile.getNumChannels (), aiff_stereo_24bit_44100 ::numChannels);
184
326
185
- for (size_t i = 0 ; i < aiff_stereo_32bit_48000::testBuffer[0 ].size (); i++)
327
+ int offset = std::is_signed_v<T> ? 0 : 8388608 ;
328
+
329
+ for (size_t i = 0 ; i < aiff_stereo_24bit_44100::testBuffer[0 ].size (); i++)
186
330
{
187
331
for (int k = 0 ; k < audioFile.getNumChannels (); k++)
188
332
{
189
- CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_32bit_48000 ::testBuffer[k][i]).epsilon (0.00001 ));
333
+ CHECK (audioFile.samples [k][i] == doctest::Approx (aiff_stereo_24bit_44100 ::testBuffer[k][i] * 8388607 + offset ).epsilon (0.00001 ));
190
334
}
191
335
}
192
336
}
337
+
338
+ // =============================================================
339
+ TEST_CASE (" AiffLoadingTests_Stereo_24bit_44100_integers" )
340
+ {
341
+ test24Bit44100WithInteger<int32_t >();
342
+ test24Bit44100WithInteger<uint32_t >();
343
+ test24Bit44100WithInteger<int64_t >();
344
+ test24Bit44100WithInteger<uint64_t >();
345
+
346
+ // check these fail...
347
+ test24Bit44100WithInteger<int8_t > (true );
348
+ test24Bit44100WithInteger<uint8_t > (true );
349
+ test24Bit44100WithInteger<int16_t > (true );
350
+ test24Bit44100WithInteger<uint16_t > (true );
351
+ }
193
352
}
0 commit comments