Mercurial > hg > svcore
comparison data/fileio/test/AudioFileReaderTest.h @ 757:b98f5daab19e
More on tests, and not the right way to do it with end of resampled file
author | Chris Cannam |
---|---|
date | Fri, 08 Mar 2013 18:19:05 +0000 |
parents | 02390a4c2abe |
children | a43acbe3988f |
comparison
equal
deleted
inserted
replaced
756:02390a4c2abe | 757:b98f5daab19e |
---|---|
61 | 61 |
62 void read() | 62 void read() |
63 { | 63 { |
64 QFETCH(QString, audiofile); | 64 QFETCH(QString, audiofile); |
65 | 65 |
66 int readRate = 48000; | |
67 | |
66 AudioFileReader *reader = | 68 AudioFileReader *reader = |
67 AudioFileReaderFactory::createReader | 69 AudioFileReaderFactory::createReader |
68 (audioDir + "/" + audiofile, 48000); | 70 (audioDir + "/" + audiofile, readRate); |
71 | |
72 QStringList fileAndExt = audiofile.split("."); | |
73 QStringList bits = fileAndExt[0].split("-"); | |
74 QString extension = fileAndExt[1]; | |
75 int nominalRate = bits[0].toInt(); | |
76 int nominalChannels = bits[1].toInt(); | |
77 int nominalDepth = 16; | |
78 if (bits.length() > 2) nominalDepth = bits[2].toInt(); | |
69 | 79 |
70 if (!reader) { | 80 if (!reader) { |
71 QSKIP(strOf(QString("File format for \"%1\" not supported, skipping").arg(audiofile)), SkipSingle); | 81 QSKIP("Unsupported file, skipping", SkipSingle); |
72 } | 82 } |
73 | 83 |
84 QCOMPARE((int)reader->getChannelCount(), nominalChannels); | |
85 QCOMPARE((int)reader->getNativeRate(), nominalRate); | |
86 QCOMPARE((int)reader->getSampleRate(), readRate); | |
87 | |
74 int channels = reader->getChannelCount(); | 88 int channels = reader->getChannelCount(); |
75 AudioTestData tdata(48000, channels); | 89 AudioTestData tdata(readRate, channels); |
76 | 90 |
77 float *reference = tdata.getInterleavedData(); | 91 float *reference = tdata.getInterleavedData(); |
78 int refsize = tdata.getFrameCount() * channels; | 92 int refsize = tdata.getFrameCount() * channels; |
79 | 93 |
80 vector<float> test; | 94 vector<float> test; |
81 | 95 |
82 // The reader should give us exactly the expected number of | 96 // The reader should give us exactly the expected number of |
83 // frames -- so we ask for one more, just to check we don't | 97 // frames, except for mp3 files -- so we ask for one more, |
84 // get it! | 98 // just to check we don't get it! |
85 reader->getInterleavedFrames | 99 reader->getInterleavedFrames |
86 (0, tdata.getFrameCount() + 1, test); | 100 (0, tdata.getFrameCount() + 1, test); |
87 int read = test.size() / channels; | 101 int read = test.size() / channels; |
88 | |
89 // need to resolve questions about frame count at end of | |
90 // resampled file before we can do this | |
91 //!!! QCOMPARE(read, tdata.getFrameCount()); | |
92 | 102 |
93 float limit = 0.011; | 103 if (extension == "mp3") { |
104 // mp3s round up | |
105 QVERIFY(read >= tdata.getFrameCount()); | |
106 } else { | |
107 QCOMPARE(read, tdata.getFrameCount()); | |
108 } | |
109 | |
110 // Our limits are pretty relaxed -- we're not testing decoder | |
111 // or resampler quality here, just whether the results are | |
112 // plainly wrong (e.g. at wrong samplerate or with an offset) | |
113 | |
114 float limit = 0.01; | |
115 if (nominalDepth < 16) { | |
116 limit = 0.02; | |
117 } | |
118 if (extension == "ogg" || extension == "mp3" || extension == "aac") { | |
119 limit = 0.04; | |
120 } | |
121 | |
122 int edgeSize = 100; | |
123 float edgeLimit = limit * 10; // in first or final edgeSize frames | |
94 | 124 |
95 for (int c = 0; c < channels; ++c) { | 125 for (int c = 0; c < channels; ++c) { |
96 float maxdiff = 0.f; | 126 float maxdiff = 0.f; |
97 int maxAt = 0; | 127 int maxAt = 0; |
98 float totdiff = 0.f; | 128 float totdiff = 0.f; |
99 for (int i = 0; i < read; ++i) { | 129 for (int i = 0; i < read; ++i) { |
100 float diff = fabsf(test[i * channels + c] - | 130 float diff = fabsf(test[i * channels + c] - |
101 reference[i * channels + c]); | 131 reference[i * channels + c]); |
102 totdiff += diff; | 132 totdiff += diff; |
103 if (diff > maxdiff) { | 133 // in edge areas, record this only if it exceeds edgeLimit |
104 maxdiff = diff; | 134 if (i < edgeSize || i + edgeSize >= read) { |
105 maxAt = i; | 135 if (diff > edgeLimit) { |
136 maxdiff = diff; | |
137 maxAt = i; | |
138 } | |
139 } else { | |
140 if (diff > maxdiff) { | |
141 maxdiff = diff; | |
142 maxAt = i; | |
143 } | |
106 } | 144 } |
107 } | 145 } |
108 float meandiff = totdiff / read; | 146 float meandiff = totdiff / read; |
109 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; | 147 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; |
110 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; | 148 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; |