Mercurial > hg > svcore
comparison data/fileio/test/AudioFileReaderTest.h @ 1346:75ad55315db4 3.0-integration
More work on getting tests (especially file encoding ones) running on Windows. Various problems here to do with interaction with test filenames in Hg repos
author | Chris Cannam |
---|---|
date | Fri, 06 Jan 2017 15:44:55 +0000 |
parents | 54af1e21705c |
children | 1c9bbbb6116a |
comparison
equal
deleted
inserted
replaced
1345:c0cdacc47f4e | 1346:75ad55315db4 |
---|---|
30 | 30 |
31 #include <iostream> | 31 #include <iostream> |
32 | 32 |
33 using namespace std; | 33 using namespace std; |
34 | 34 |
35 static QString audioDir = "svcore/data/fileio/test/testfiles"; | |
36 static QString diffDir = "svcore/data/fileio/test/diffs"; | |
37 | |
38 class AudioFileReaderTest : public QObject | 35 class AudioFileReaderTest : public QObject |
39 { | 36 { |
40 Q_OBJECT | 37 Q_OBJECT |
41 | 38 |
39 private: | |
40 QString testDirBase; | |
41 QString audioDir; | |
42 QString diffDir; | |
43 | |
44 public: | |
45 AudioFileReaderTest(QString base) { | |
46 if (base == "") { | |
47 base = "svcore/data/fileio/test"; | |
48 } | |
49 testDirBase = base; | |
50 audioDir = base + "/testfiles"; | |
51 diffDir = base + "/diffs"; | |
52 } | |
53 | |
54 private: | |
42 const char *strOf(QString s) { | 55 const char *strOf(QString s) { |
43 return strdup(s.toLocal8Bit().data()); | 56 return strdup(s.toLocal8Bit().data()); |
44 } | 57 } |
45 | 58 |
46 void getFileMetadata(QString filename, | 59 void getFileMetadata(QString filename, |
172 | 185 |
173 private slots: | 186 private slots: |
174 void init() | 187 void init() |
175 { | 188 { |
176 if (!QDir(audioDir).exists()) { | 189 if (!QDir(audioDir).exists()) { |
177 cerr << "ERROR: Audio test file directory \"" << audioDir << "\" does not exist" << endl; | 190 QString cwd = QDir::currentPath(); |
191 cerr << "ERROR: Audio test file directory \"" << audioDir << "\" does not exist (cwd = " << cwd << ")" << endl; | |
178 QVERIFY2(QDir(audioDir).exists(), "Audio test file directory not found"); | 192 QVERIFY2(QDir(audioDir).exists(), "Audio test file directory not found"); |
179 } | 193 } |
180 if (!QDir(diffDir).exists() && !QDir().mkpath(diffDir)) { | 194 if (!QDir(diffDir).exists() && !QDir().mkpath(diffDir)) { |
181 cerr << "ERROR: Audio diff directory \"" << diffDir << "\" does not exist and could not be created" << endl; | 195 cerr << "ERROR: Audio diff directory \"" << diffDir << "\" does not exist and could not be created" << endl; |
182 QVERIFY2(QDir(diffDir).exists(), "Audio diff directory not found and could not be created"); | 196 QVERIFY2(QDir(diffDir).exists(), "Audio diff directory not found and could not be created"); |
396 } | 410 } |
397 diffWriter.writeSamples(ptrs, refFrames); | 411 diffWriter.writeSamples(ptrs, refFrames); |
398 delete[] ptrs; | 412 delete[] ptrs; |
399 } | 413 } |
400 | 414 |
401 for (int c = 0; c < channels; ++c) { | 415 for (int c = 0; c < channels; ++c) { |
402 | 416 |
403 double maxDiff = 0.0; | 417 double maxDiff = 0.0; |
404 double totalDiff = 0.0; | 418 double totalDiff = 0.0; |
405 double totalSqrDiff = 0.0; | 419 double totalSqrDiff = 0.0; |
406 int maxIndex = 0; | 420 int maxIndex = 0; |
407 | 421 |
408 for (int i = 0; i < refFrames; ++i) { | 422 for (int i = 0; i < refFrames; ++i) { |
409 int ix = i + offset; | 423 int ix = i + offset; |
410 if (ix >= read) { | 424 if (ix >= read) { |
411 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl; | 425 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl; |
412 QVERIFY(ix < read); | 426 QVERIFY(ix < read); |
413 } | 427 } |
416 // we forgive the very edge samples when | 430 // we forgive the very edge samples when |
417 // resampling (discard > 0) | 431 // resampling (discard > 0) |
418 continue; | 432 continue; |
419 } | 433 } |
420 | 434 |
421 double diff = fabs(test[ix * channels + c] - | 435 double diff = fabs(test[ix * channels + c] - |
422 reference[i * channels + c]); | 436 reference[i * channels + c]); |
423 | 437 |
424 totalDiff += diff; | 438 totalDiff += diff; |
425 totalSqrDiff += diff * diff; | 439 totalSqrDiff += diff * diff; |
426 | 440 |
427 // in edge areas, record this only if it exceeds edgeLimit | 441 // in edge areas, record this only if it exceeds edgeLimit |
428 if (i < edgeSize || i + edgeSize >= refFrames) { | 442 if (i < edgeSize || i + edgeSize >= refFrames) { |
429 if (diff > edgeLimit && diff > maxDiff) { | 443 if (diff > edgeLimit && diff > maxDiff) { |
433 } else { | 447 } else { |
434 if (diff > maxDiff) { | 448 if (diff > maxDiff) { |
435 maxDiff = diff; | 449 maxDiff = diff; |
436 maxIndex = i; | 450 maxIndex = i; |
437 } | 451 } |
438 } | 452 } |
439 } | 453 } |
440 | 454 |
441 double meanDiff = totalDiff / double(refFrames); | 455 double meanDiff = totalDiff / double(refFrames); |
442 double rmsDiff = sqrt(totalSqrDiff / double(refFrames)); | 456 double rmsDiff = sqrt(totalSqrDiff / double(refFrames)); |
443 | 457 |
444 /* | 458 /* |
445 cerr << "channel " << c << ": mean diff " << meanDiff << endl; | 459 cerr << "channel " << c << ": mean diff " << meanDiff << endl; |
446 cerr << "channel " << c << ": rms diff " << rmsDiff << endl; | 460 cerr << "channel " << c << ": rms diff " << rmsDiff << endl; |
447 cerr << "channel " << c << ": max diff " << maxDiff << " at " << maxIndex << endl; | 461 cerr << "channel " << c << ": max diff " << maxDiff << " at " << maxIndex << endl; |
448 */ | 462 */ |
449 if (rmsDiff >= rmsLimit) { | 463 if (rmsDiff >= rmsLimit) { |
450 cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl; | 464 cerr << "ERROR: for audiofile " << audiofile << ": RMS diff = " << rmsDiff << " for channel " << c << " (limit = " << rmsLimit << ")" << endl; |
451 QVERIFY(rmsDiff < rmsLimit); | 465 QVERIFY(rmsDiff < rmsLimit); |
452 } | 466 } |
453 if (maxDiff >= maxLimit) { | 467 if (maxDiff >= maxLimit) { |
454 cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxDiff << " at frame " << maxIndex << " of " << read << " on channel " << c << " (limit = " << maxLimit << ", edge limit = " << edgeLimit << ", mean diff = " << meanDiff << ", rms = " << rmsDiff << ")" << endl; | 468 cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxDiff << " at frame " << maxIndex << " of " << read << " on channel " << c << " (limit = " << maxLimit << ", edge limit = " << edgeLimit << ", mean diff = " << meanDiff << ", rms = " << rmsDiff << ")" << endl; |
455 QVERIFY(maxDiff < maxLimit); | 469 QVERIFY(maxDiff < maxLimit); |
456 } | 470 } |
457 | 471 |
458 // and check for spurious material at end | 472 // and check for spurious material at end |
459 | 473 |
460 for (sv_frame_t i = refFrames; i + offset < read; ++i) { | 474 for (sv_frame_t i = refFrames; i + offset < read; ++i) { |
461 sv_frame_t ix = i + offset; | 475 sv_frame_t ix = i + offset; |