Mercurial > hg > svcore
comparison data/fileio/test/AudioFileReaderTest.h @ 1069:32ab6c48efaa
Merge from branch tonioni
| author | Chris Cannam |
|---|---|
| date | Mon, 20 Apr 2015 09:11:34 +0100 |
| parents | 843f67be0ed9 |
| children | abfc498c52bc |
comparison
equal
deleted
inserted
replaced
| 1036:682d64f05e72 | 1069:32ab6c48efaa |
|---|---|
| 61 | 61 |
| 62 void read() | 62 void read() |
| 63 { | 63 { |
| 64 QFETCH(QString, audiofile); | 64 QFETCH(QString, audiofile); |
| 65 | 65 |
| 66 int readRate = 48000; | 66 sv_samplerate_t readRate = 48000; |
| 67 | 67 |
| 68 AudioFileReader *reader = | 68 AudioFileReader *reader = |
| 69 AudioFileReaderFactory::createReader | 69 AudioFileReaderFactory::createReader |
| 70 (audioDir + "/" + audiofile, readRate); | 70 (audioDir + "/" + audiofile, readRate); |
| 71 | 71 |
| 72 QStringList fileAndExt = audiofile.split("."); | 72 QStringList fileAndExt = audiofile.split("."); |
| 73 QStringList bits = fileAndExt[0].split("-"); | 73 QStringList bits = fileAndExt[0].split("-"); |
| 74 QString extension = fileAndExt[1]; | 74 QString extension = fileAndExt[1]; |
| 75 int nominalRate = bits[0].toInt(); | 75 sv_samplerate_t nominalRate = bits[0].toInt(); |
| 76 int nominalChannels = bits[1].toInt(); | 76 int nominalChannels = bits[1].toInt(); |
| 77 int nominalDepth = 16; | 77 int nominalDepth = 16; |
| 78 if (bits.length() > 2) nominalDepth = bits[2].toInt(); | 78 if (bits.length() > 2) nominalDepth = bits[2].toInt(); |
| 79 | 79 |
| 80 if (!reader) { | 80 if (!reader) { |
| 84 QSKIP("Unsupported file, skipping", SkipSingle); | 84 QSKIP("Unsupported file, skipping", SkipSingle); |
| 85 #endif | 85 #endif |
| 86 } | 86 } |
| 87 | 87 |
| 88 QCOMPARE((int)reader->getChannelCount(), nominalChannels); | 88 QCOMPARE((int)reader->getChannelCount(), nominalChannels); |
| 89 QCOMPARE((int)reader->getNativeRate(), nominalRate); | 89 QCOMPARE(reader->getNativeRate(), nominalRate); |
| 90 QCOMPARE((int)reader->getSampleRate(), readRate); | 90 QCOMPARE(reader->getSampleRate(), readRate); |
| 91 | 91 |
| 92 int channels = reader->getChannelCount(); | 92 int channels = reader->getChannelCount(); |
| 93 AudioTestData tdata(readRate, channels); | 93 AudioTestData tdata(readRate, channels); |
| 94 | 94 |
| 95 float *reference = tdata.getInterleavedData(); | 95 float *reference = tdata.getInterleavedData(); |
| 96 int refFrames = tdata.getFrameCount(); | 96 sv_frame_t refFrames = tdata.getFrameCount(); |
| 97 | |
| 98 vector<float> test; | |
| 99 | 97 |
| 100 // The reader should give us exactly the expected number of | 98 // The reader should give us exactly the expected number of |
| 101 // frames, except for mp3/aac files. We ask for quite a lot | 99 // frames, except for mp3/aac files. We ask for quite a lot |
| 102 // more, though, so we can (a) check that we only get the | 100 // more, though, so we can (a) check that we only get the |
| 103 // expected number back (if this is not mp3/aac) or (b) take | 101 // expected number back (if this is not mp3/aac) or (b) take |
| 104 // into account silence at beginning and end (if it is). | 102 // into account silence at beginning and end (if it is). |
| 105 reader->getInterleavedFrames(0, refFrames + 5000, test); | 103 vector<float> test = reader->getInterleavedFrames(0, refFrames + 5000); |
| 106 int read = test.size() / channels; | 104 sv_frame_t read = test.size() / channels; |
| 107 | 105 |
| 108 if (extension == "mp3" || extension == "aac" || extension == "m4a") { | 106 if (extension == "mp3" || extension == "aac" || extension == "m4a") { |
| 109 // mp3s and aacs can have silence at start and end | 107 // mp3s and aacs can have silence at start and end |
| 110 QVERIFY(read >= refFrames); | 108 QVERIFY(read >= refFrames); |
| 111 } else { | 109 } else { |
| 114 | 112 |
| 115 // Our limits are pretty relaxed -- we're not testing decoder | 113 // Our limits are pretty relaxed -- we're not testing decoder |
| 116 // or resampler quality here, just whether the results are | 114 // or resampler quality here, just whether the results are |
| 117 // plainly wrong (e.g. at wrong samplerate or with an offset) | 115 // plainly wrong (e.g. at wrong samplerate or with an offset) |
| 118 | 116 |
| 119 float limit = 0.01; | 117 double limit = 0.01; |
| 120 float edgeLimit = limit * 10; // in first or final edgeSize frames | 118 double edgeLimit = limit * 10; // in first or final edgeSize frames |
| 121 int edgeSize = 100; | 119 int edgeSize = 100; |
| 122 | 120 |
| 123 if (nominalDepth < 16) { | 121 if (nominalDepth < 16) { |
| 124 limit = 0.02; | 122 limit = 0.02; |
| 125 } | 123 } |
| 128 limit = 0.2; | 126 limit = 0.2; |
| 129 edgeLimit = limit * 3; | 127 edgeLimit = limit * 3; |
| 130 } | 128 } |
| 131 | 129 |
| 132 // And we ignore completely the last few frames when upsampling | 130 // And we ignore completely the last few frames when upsampling |
| 133 int discard = 1 + readRate / nominalRate; | 131 int discard = 1 + int(round(readRate / nominalRate)); |
| 134 | 132 |
| 135 int offset = 0; | 133 int offset = 0; |
| 136 | 134 |
| 137 if (extension == "aac" || extension == "m4a") { | 135 if (extension == "aac" || extension == "m4a") { |
| 138 // our m4a file appears to have a fixed offset of 1024 (at | 136 // our m4a file appears to have a fixed offset of 1024 (at |
| 139 // file sample rate) | 137 // file sample rate) |
| 140 offset = (1024 / float(nominalRate)) * readRate; | 138 offset = int(round((1024 / nominalRate) * readRate)); |
| 141 } | 139 } |
| 142 | 140 |
| 143 if (extension == "mp3") { | 141 if (extension == "mp3") { |
| 144 // while mp3s appear to vary | 142 // while mp3s appear to vary |
| 145 for (int i = 0; i < read; ++i) { | 143 for (int i = 0; i < read; ++i) { |
| 146 bool any = false; | 144 bool any = false; |
| 147 float thresh = 0.01; | 145 double thresh = 0.01; |
| 148 for (int c = 0; c < channels; ++c) { | 146 for (int c = 0; c < channels; ++c) { |
| 149 if (fabsf(test[i * channels + c]) > thresh) { | 147 if (fabs(test[i * channels + c]) > thresh) { |
| 150 any = true; | 148 any = true; |
| 151 break; | 149 break; |
| 152 } | 150 } |
| 153 } | 151 } |
| 154 if (any) { | 152 if (any) { |
| 178 maxdiff = diff; | 176 maxdiff = diff; |
| 179 maxAt = i; | 177 maxAt = i; |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 } | 180 } |
| 183 float meandiff = totdiff / read; | 181 float meandiff = totdiff / float(read); |
| 184 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; | 182 // cerr << "meandiff on channel " << c << ": " << meandiff << endl; |
| 185 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; | 183 // cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl; |
| 186 if (meandiff >= limit) { | 184 if (meandiff >= limit) { |
| 187 cerr << "ERROR: for audiofile " << audiofile << ": mean diff = " << meandiff << " for channel " << c << endl; | 185 cerr << "ERROR: for audiofile " << audiofile << ": mean diff = " << meandiff << " for channel " << c << endl; |
| 188 QVERIFY(meandiff < limit); | 186 QVERIFY(meandiff < limit); |
