comparison data/fileio/test/AudioFileReaderTest.h @ 1314:00cae2d5ee7e 3.0-integration

More faffing with tests, to no great effect
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 01 Dec 2016 20:49:55 +0000
parents ff9697592bef
children af0ccbb3e3d7
comparison
equal deleted inserted replaced
1313:ff9697592bef 1314:00cae2d5ee7e
84 maxLimit = 0.1; 84 maxLimit = 0.1;
85 rmsLimit = 0.03; 85 rmsLimit = 0.03;
86 86
87 } else if (extension == "m4a" || extension == "aac") { 87 } else if (extension == "m4a" || extension == "aac") {
88 88
89 //!!! to be worked out 89 // Like ogg but more so, quite far off in signal terms
90 maxLimit = 1e-10; 90 // and even worse if normalised
91 rmsLimit = 1e-10; 91 maxLimit = 0.1;
92 rmsLimit = 0.1;
92 93
93 } else if (extension == "mp3") { 94 } else if (extension == "mp3") {
94 95
95 if (resampled && !gapless) { 96 if (resampled && !gapless) {
96 97
129 maxLimit = 0.06; 130 maxLimit = 0.06;
130 rmsLimit = 0.03; 131 rmsLimit = 0.03;
131 132
132 } else if (extension == "m4a" || extension == "aac") { 133 } else if (extension == "m4a" || extension == "aac") {
133 134
134 //!!! to be worked out 135 maxLimit = 0.06;
135 maxLimit = 1e-10; 136 rmsLimit = 0.03;
136 rmsLimit = 1e-10;
137 137
138 } else if (extension == "mp3") { 138 } else if (extension == "mp3") {
139 139
140 // all mp3 figures are worse when not normalising 140 // all mp3 figures are worse when not normalising
141 maxLimit = 0.1; 141 maxLimit = 0.1;
299 299
300 int offset = 0; 300 int offset = 0;
301 301
302 if (perceptual) { 302 if (perceptual) {
303 303
304 // Look for an initial offset. What we're looking for is 304 // Look for an initial offset.
305 // the first peak of the sinusoid in the first channel 305 //
306 // (since we may have only the one channel). This should 306 // We know the first channel has a sinusoid in it. It
307 // appear at 0.4ms (see AudioTestData.h). 307 // should have a peak at 0.4ms (see AudioTestData.h) but
308 308 // that might have been clipped, which would make it
309 // imprecise. We can tell if it's clipped, though, as
310 // there will be samples having exactly identical
311 // values. So what we look for is the peak if it's not
312 // clipped and, if it is, the first zero crossing after
313 // the peak, which should be at 0.8ms.
314
309 int expectedPeak = int(0.0004 * readRate); 315 int expectedPeak = int(0.0004 * readRate);
310 for (int i = 1; i < read; ++i) { 316 int expectedZC = int(0.0008 * readRate);
311 if (test[i * channels] > 0.8 && 317 bool foundPeak = false;
312 test[(i+1) * channels] < test[i * channels]) { 318 for (int i = 1; i+1 < read; ++i) {
313 offset = i - expectedPeak - 1; 319 float prevSample = test[(i-1) * channels];
320 float thisSample = test[i * channels];
321 float nextSample = test[(i+1) * channels];
322 if (thisSample > 0.8 && nextSample < thisSample) {
323 foundPeak = true;
324 if (thisSample > prevSample) {
325 // not clipped
326 offset = i - expectedPeak - 1;
327 break;
328 }
329 }
330 if (foundPeak && (thisSample >= 0.0 && nextSample < 0.0)) {
331 cerr << "thisSample = " << thisSample << ", nextSample = "
332 << nextSample << endl;
333 offset = i - expectedZC - 1;
314 break; 334 break;
315 } 335 }
316 } 336 }
317 337
338 int fileRateEquivalent = int((offset / readRate) * fileRate);
339
318 std::cerr << "offset = " << offset << std::endl; 340 std::cerr << "offset = " << offset << std::endl;
319 std::cerr << "at file rate would be " << (offset / readRate) * fileRate << std::endl; 341 std::cerr << "at file rate would be " << fileRateEquivalent << std::endl;
320 342
321 // Previously our m4a test file had a fixed offset of 1024 343 // Previously our m4a test file had a fixed offset of 1024
322 // at the file sample rate -- this may be because it was 344 // at the file sample rate -- this may be because it was
323 // produced by FAAC which did not write in the delay as 345 // produced by FAAC which did not write in the delay as
324 // metadata? We now have an m4a produced by Core Audio 346 // metadata? We now have an m4a produced by Core Audio
339 double maxDiff = 0.0; 361 double maxDiff = 0.0;
340 double totalDiff = 0.0; 362 double totalDiff = 0.0;
341 double totalSqrDiff = 0.0; 363 double totalSqrDiff = 0.0;
342 int maxIndex = 0; 364 int maxIndex = 0;
343 365
344 // cerr << "\nchannel " << c << ": ";
345
346 for (int i = 0; i < refFrames; ++i) { 366 for (int i = 0; i < refFrames; ++i) {
347 int ix = i + offset; 367 int ix = i + offset;
348 if (ix >= read) { 368 if (ix >= read) {
349 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl; 369 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl;
350 QVERIFY(ix < read); 370 QVERIFY(ix < read);
382 } 402 }
383 403
384 double meanDiff = totalDiff / double(refFrames); 404 double meanDiff = totalDiff / double(refFrames);
385 double rmsDiff = sqrt(totalSqrDiff / double(refFrames)); 405 double rmsDiff = sqrt(totalSqrDiff / double(refFrames));
386 406
407 /*
387 cerr << "channel " << c << ": mean diff " << meanDiff << endl; 408 cerr << "channel " << c << ": mean diff " << meanDiff << endl;
388 cerr << "channel " << c << ": rms diff " << rmsDiff << endl; 409 cerr << "channel " << c << ": rms diff " << rmsDiff << endl;
389 cerr << "channel " << c << ": max diff " << maxDiff << " at " << maxIndex << endl; 410 cerr << "channel " << c << ": max diff " << maxDiff << " at " << maxIndex << endl;
390 411 */
391 if (rmsDiff >= rmsLimit) { 412 if (rmsDiff >= rmsLimit) {
392 cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl; 413 cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl;
393 QVERIFY(rmsDiff < rmsLimit); 414 QVERIFY(rmsDiff < rmsLimit);
394 } 415 }
395 if (maxDiff >= maxLimit) { 416 if (maxDiff >= maxLimit) {