changeset 1297:5cc969b236b0 3.0-integration

Merge
author Chris Cannam
date Fri, 25 Nov 2016 11:37:06 +0000
parents 3cde25cbe7f8 (current diff) fc9cef5e988d (diff)
children a1af054d8f75 6681027ff2ff
files data/fileio/CodedAudioFileReader.cpp
diffstat 4 files changed, 27 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Fri Nov 25 10:08:52 2016 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Fri Nov 25 11:37:06 2016 +0000
@@ -305,7 +305,7 @@
 {
     QMutexLocker locker(&m_cacheMutex);
 
-    Profiler profiler("CodedAudioFileReader::finishDecodeCache", true);
+    Profiler profiler("CodedAudioFileReader::finishDecodeCache");
 
     if (!m_initialised) {
         SVDEBUG << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << endl;
--- a/data/fileio/DecodingWavFileReader.cpp	Fri Nov 25 10:08:52 2016 +0000
+++ b/data/fileio/DecodingWavFileReader.cpp	Fri Nov 25 11:37:06 2016 +0000
@@ -47,7 +47,7 @@
     m_channelCount = 0;
     m_fileRate = 0;
 
-    Profiler profiler("DecodingWavFileReader::DecodingWavFileReader", true);
+    Profiler profiler("DecodingWavFileReader::DecodingWavFileReader");
 
     m_original = new WavFileReader(m_path);
     if (!m_original->isOK()) {
--- a/data/fileio/OggVorbisFileReader.cpp	Fri Nov 25 10:08:52 2016 +0000
+++ b/data/fileio/OggVorbisFileReader.cpp	Fri Nov 25 11:37:06 2016 +0000
@@ -58,7 +58,7 @@
 
 //    SVDEBUG << "OggVorbisFileReader::OggVorbisFileReader(" << m_path << "): now have " << (++instances) << " instances" << endl;
 
-    Profiler profiler("OggVorbisFileReader::OggVorbisFileReader", true);
+    Profiler profiler("OggVorbisFileReader::OggVorbisFileReader");
 
     QFileInfo info(m_path);
     m_fileSize = info.size();
--- a/data/fileio/test/AudioFileReaderTest.h	Fri Nov 25 10:08:52 2016 +0000
+++ b/data/fileio/test/AudioFileReaderTest.h	Fri Nov 25 11:37:06 2016 +0000
@@ -123,7 +123,7 @@
         }
         if (extension == "ogg" || extension == "mp3" ||
             extension == "aac" || extension == "m4a") {
-            limit = 0.2;
+            limit = 0.1;
             edgeLimit = limit * 3;
         }
 
@@ -139,18 +139,17 @@
         }
 
         if (extension == "mp3") {
-            // while mp3s appear to vary
-            for (int i = 0; i < read; ++i) {
-                bool any = false;
-                double thresh = 0.01;
-                for (int c = 0; c < channels; ++c) {
-                    if (fabs(test[i * channels + c]) > thresh) {
-                        any = true;
-                        break;
-                    }
-                }
-                if (any) {
-                    offset = i;
+            // ...while mp3s appear to vary. What we're looking for is
+            // the first peak of the sinusoid in the first channel
+            // (since we may have only the one channel). This should
+            // appear at 0.4ms (see AudioTestData.h)
+            int expectedPeak = int(0.0004 * readRate);
+//            std::cerr << "expectedPeak = " << expectedPeak << std::endl;
+            for (int i = 1; i < read; ++i) {
+                if (test[i * channels] > 0.8 &&
+                    test[(i+1) * channels] < test[i * channels]) {
+                    offset = i - expectedPeak - 1;
+//                    std::cerr << "actual peak = " << i-1 << std::endl;
                     break;
                 }
             }
@@ -161,8 +160,18 @@
 	    float maxdiff = 0.f;
 	    int maxAt = 0;
 	    float totdiff = 0.f;
-	    for (int i = 0; i < read - offset - discard && i < refFrames; ++i) {
-		float diff = fabsf(test[(i + offset) * channels + c] -
+	    for (int i = 0; i < refFrames; ++i) {
+                int ix = i + offset;
+                if (ix >= read) {
+                    cerr << "ERROR: audiofile " << audiofile << " reads truncated (read-rate reference frames " << i << " onward are lost)" << endl;
+                    QVERIFY(ix < read);
+                }
+                if (ix + discard >= read) {
+                    // we forgive the very edge samples when
+                    // resampling (discard > 0)
+                    continue;
+                }
+		float diff = fabsf(test[(ix) * channels + c] -
 				   reference[i * channels + c]);
 		totdiff += diff;
                 // in edge areas, record this only if it exceeds edgeLimit