Mercurial > hg > svcore
comparison data/fileio/test/AudioFileReaderTest.h @ 1308:80c77916fe85 mp3-gapless
Update m4a files to exports from CoreAudio, rather than FAAC; update tests accordingly, and add test for spurious data after end of decode
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 29 Nov 2016 14:25:57 +0000 |
parents | fc9cef5e988d |
children | 2e7fcdd5f627 |
comparison
equal
deleted
inserted
replaced
1307:c84629395040 | 1308:80c77916fe85 |
---|---|
110 QCOMPARE(read, refFrames); | 110 QCOMPARE(read, refFrames); |
111 } | 111 } |
112 | 112 |
113 // Our limits are pretty relaxed -- we're not testing decoder | 113 // Our limits are pretty relaxed -- we're not testing decoder |
114 // or resampler quality here, just whether the results are | 114 // or resampler quality here, just whether the results are |
115 // plainly wrong (e.g. at wrong samplerate or with an offset) | 115 // plainly wrong (e.g. at wrong samplerate or with an offset). |
116 | 116 |
117 double limit = 0.01; | 117 double maxLimit = 0.01; |
118 double edgeLimit = limit * 10; // in first or final edgeSize frames | 118 double meanLimit = 0.001; |
119 double edgeLimit = maxLimit * 10; // in first or final edgeSize frames | |
119 int edgeSize = 100; | 120 int edgeSize = 100; |
120 | 121 |
121 if (nominalDepth < 16) { | 122 if (nominalDepth < 16) { |
122 limit = 0.02; | 123 maxLimit *= 2; |
123 } | 124 meanLimit *= 20; |
124 if (extension == "ogg" || extension == "mp3" || | 125 } else if (extension == "ogg" || extension == "mp3") { |
125 extension == "aac" || extension == "m4a") { | 126 maxLimit *= 10; |
126 limit = 0.1; | 127 meanLimit *= 10; |
127 edgeLimit = limit * 3; | 128 edgeLimit = maxLimit * 3; |
129 } else if (extension == "aac" || extension == "m4a") { | |
130 maxLimit *= 30; // seems max diff can be quite large here | |
131 // even when mean is fairly small | |
132 meanLimit *= 10; | |
133 edgeLimit = maxLimit * 3; | |
128 } | 134 } |
129 | 135 |
130 // And we ignore completely the last few frames when upsampling | 136 // And we ignore completely the last few frames when upsampling |
131 int discard = 1 + int(round(readRate / nominalRate)); | 137 int discard = 1 + int(round(readRate / nominalRate)); |
132 | 138 |
133 int offset = 0; | 139 int offset = 0; |
134 | 140 |
135 if (extension == "aac" || extension == "m4a") { | 141 if (extension == "aac" || extension == "m4a") { |
136 // our m4a file appears to have a fixed offset of 1024 (at | 142 // our m4a file appears to have a fixed offset of 1024 (at |
137 // file sample rate) | 143 // file sample rate) |
138 offset = int(round((1024 / nominalRate) * readRate)); | 144 // offset = int(round((1024 / nominalRate) * readRate)); |
145 offset = 0; | |
139 } | 146 } |
140 | 147 |
141 if (extension == "mp3") { | 148 if (extension == "mp3") { |
142 // ...while mp3s appear to vary. What we're looking for is | 149 // ...while mp3s appear to vary. What we're looking for is |
143 // the first peak of the sinusoid in the first channel | 150 // the first peak of the sinusoid in the first channel |
155 } | 162 } |
156 // std::cerr << "offset = " << offset << std::endl; | 163 // std::cerr << "offset = " << offset << std::endl; |
157 } | 164 } |
158 | 165 |
159 for (int c = 0; c < channels; ++c) { | 166 for (int c = 0; c < channels; ++c) { |
167 | |
160 float maxdiff = 0.f; | 168 float maxdiff = 0.f; |
161 int maxAt = 0; | 169 int maxAt = 0; |
162 float totdiff = 0.f; | 170 float totdiff = 0.f; |
171 | |
163 for (int i = 0; i < refFrames; ++i) { | 172 for (int i = 0; i < refFrames; ++i) { |
164 int ix = i + offset; | 173 int ix = i + offset; |
165 if (ix >= read) { | 174 if (ix >= read) { |
166 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward are lost)" << endl; | 175 cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward, of " << refFrames << ", are lost)" << endl; |
167 QVERIFY(ix < read); | 176 QVERIFY(ix < read); |
168 } | 177 } |
169 if (ix + discard >= read) { | 178 if (ix + discard >= read) { |
170 // we forgive the very edge samples when | 179 // we forgive the very edge samples when |
171 // resampling (discard > 0) | 180 // resampling (discard > 0) |
172 continue; | 181 continue; |
173 } | 182 } |
174 float diff = fabsf(test[(ix) * channels + c] - | 183 float diff = fabsf(test[ix * channels + c] - |
175 reference[i * channels + c]); | 184 reference[i * channels + c]); |
176 totdiff += diff; | 185 totdiff += diff; |
177 // in edge areas, record this only if it exceeds edgeLimit | 186 // in edge areas, record this only if it exceeds edgeLimit |
178 if (i < edgeSize || i + edgeSize >= read - offset) { | 187 if (i < edgeSize || i + edgeSize >= read - offset) { |
179 if (diff > edgeLimit && diff > maxdiff) { | 188 if (diff > edgeLimit && diff > maxdiff) { |
185 maxdiff = diff; | 194 maxdiff = diff; |
186 maxAt = i; | 195 maxAt = i; |
187 } | 196 } |
188 } | 197 } |
189 } | 198 } |
199 | |
200 // check for spurious material at end | |
201 for (int i = refFrames; i + offset < read; ++i) { | |
202 int ix = i + offset; | |
203 float quiet = 1e-6; | |
204 float mag = fabsf(test[ix * channels + c]); | |
205 if (mag > quiet) { | |
206 cerr << "ERROR: audiofile " << audiofile << " contains spurious data after end of reference (found sample " << test[ix * channels + c] << " at index " << ix << " of channel " << c << ")" << endl; | |
207 QVERIFY(mag < quiet); | |
208 } | |
209 } | |
210 | |
190 float meandiff = totdiff / float(read); | 211 float meandiff = totdiff / float(read); |
191 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; | 212 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; |
192 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; | 213 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; |
193 if (meandiff >= limit) { | 214 if (meandiff >= meanLimit) { |
194 cerr << "ERROR: for audiofile " << audiofile << ": mean diff = " << meandiff << " for channel " << c << endl; | 215 cerr << "ERROR: for audiofile " << audiofile << ": mean diff = " << meandiff << " for channel " << c << endl; |
195 QVERIFY(meandiff < limit); | 216 QVERIFY(meandiff < meanLimit); |
196 } | 217 } |
197 if (maxdiff >= limit) { | 218 if (maxdiff >= maxLimit) { |
198 cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxdiff << " at frame " << maxAt << " of " << read << " on channel " << c << " (mean diff = " << meandiff << ")" << endl; | 219 cerr << "ERROR: for audiofile " << audiofile << ": max diff = " << maxdiff << " at frame " << maxAt << " of " << read << " on channel " << c << " (mean diff = " << meandiff << ")" << endl; |
199 QVERIFY(maxdiff < limit); | 220 QVERIFY(maxdiff < maxLimit); |
200 } | 221 } |
201 } | 222 } |
202 } | 223 } |
203 }; | 224 }; |
204 | 225 |