diff data/fileio/AudioFileReaderFactory.cpp @ 823:f0558e69a074

Rename Resampling- to DecodingWavFileReader, and use it whenever we have an audio file that is not quickly seekable using libsndfile. Avoids very slow performance when analysing ogg files.
author Chris Cannam
date Wed, 17 Jul 2013 15:40:01 +0100
parents babed5be1ae7
children e802e550a1f2
line wrap: on
line diff
--- a/data/fileio/AudioFileReaderFactory.cpp	Mon Jul 08 14:49:28 2013 +0100
+++ b/data/fileio/AudioFileReaderFactory.cpp	Wed Jul 17 15:40:01 2013 +0100
@@ -16,7 +16,7 @@
 #include "AudioFileReaderFactory.h"
 
 #include "WavFileReader.h"
-#include "ResamplingWavFileReader.h"
+#include "DecodingWavFileReader.h"
 #include "OggVorbisFileReader.h"
 #include "MP3FileReader.h"
 #include "QuickTimeFileReader.h"
@@ -98,20 +98,22 @@
 
         reader = new WavFileReader(source);
 
-        if (targetRate != 0 &&
-            reader->isOK() &&
-            reader->getSampleRate() != targetRate) {
+        int fileRate = reader->getSampleRate();
 
-            SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", creating resampling reader" << endl;
+        if (reader->isOK() &&
+            (!reader->isQuicklySeekable() ||
+             (targetRate != 0 && fileRate != targetRate))) {
+
+            SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl;
 
             delete reader;
-            reader = new ResamplingWavFileReader
+            reader = new DecodingWavFileReader
                 (source,
                  threading ?
-                 ResamplingWavFileReader::ResampleThreaded :
-                 ResamplingWavFileReader::ResampleAtOnce,
-                 ResamplingWavFileReader::CacheInTemporaryFile,
-                 targetRate,
+                 DecodingWavFileReader::ResampleThreaded :
+                 DecodingWavFileReader::ResampleAtOnce,
+                 DecodingWavFileReader::CacheInTemporaryFile,
+                 targetRate ? targetRate : fileRate,
                  reporter);
             if (!reader->isOK()) {
                 delete reader;
@@ -209,20 +211,22 @@
 
         reader = new WavFileReader(source);
 
-        if (targetRate != 0 &&
-            reader->isOK() &&
-            reader->getSampleRate() != targetRate) {
+        int fileRate = reader->getSampleRate();
 
-            SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", creating resampling reader" << endl;
+        if (reader->isOK() &&
+            (!reader->isQuicklySeekable() ||
+             (targetRate != 0 && fileRate != targetRate))) {
+
+            SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl;
 
             delete reader;
-            reader = new ResamplingWavFileReader
+            reader = new DecodingWavFileReader
                 (source,
                  threading ?
-                 ResamplingWavFileReader::ResampleThreaded :
-                 ResamplingWavFileReader::ResampleAtOnce,
-                 ResamplingWavFileReader::CacheInTemporaryFile,
-                 targetRate,
+                 DecodingWavFileReader::ResampleThreaded :
+                 DecodingWavFileReader::ResampleAtOnce,
+                 DecodingWavFileReader::CacheInTemporaryFile,
+                 targetRate ? targetRate : fileRate,
                  reporter);
         }