Mercurial > hg > svcore
diff data/fileio/AudioFileReaderFactory.cpp @ 297:c022976d18e8
* Merge from sv-match-alignment branch (excluding alignment-specific document).
- add aggregate wave model (not yet complete enough to be added as a true
model in a layer, but there's potential)
- add play solo mode
- add alignment model -- unused in plain SV
- fix two plugin leaks
- add m3u playlist support (opens all files at once, potentially hazardous)
- fix retrieval of pre-encoded URLs
- add ability to resample audio files on import, so as to match rates with
other files previously loaded; add preference for same
- add preliminary support in transform code for range and rate of transform
input
- reorganise preferences dialog, move dark-background option to preferences,
add option for temporary directory location
author | Chris Cannam |
---|---|
date | Fri, 28 Sep 2007 13:56:38 +0000 |
parents | 92e8dbde73cd |
children | 14e0f60435b8 |
line wrap: on
line diff
--- a/data/fileio/AudioFileReaderFactory.cpp Fri Sep 21 09:13:11 2007 +0000 +++ b/data/fileio/AudioFileReaderFactory.cpp Fri Sep 28 13:56:38 2007 +0000 @@ -16,6 +16,7 @@ #include "AudioFileReaderFactory.h" #include "WavFileReader.h" +#include "ResamplingWavFileReader.h" #include "OggVorbisFileReader.h" #include "MP3FileReader.h" #include "QuickTimeFileReader.h" @@ -53,10 +54,12 @@ } AudioFileReader * -AudioFileReaderFactory::createReader(QString path) +AudioFileReaderFactory::createReader(QString path, size_t targetRate) { QString err; + std::cerr << "AudioFileReaderFactory::createReader(\"" << path.toStdString() << "\"): Requested rate: " << targetRate << std::endl; + AudioFileReader *reader = 0; // First try to construct a preferred reader based on the @@ -69,6 +72,20 @@ WavFileReader::getSupportedExtensions(extensions); if (extensions.find(ext) != extensions.end()) { reader = new WavFileReader(path); + + if (targetRate != 0 && + reader->isOK() && + reader->getSampleRate() != targetRate) { + + std::cerr << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", creating resampling reader" << std::endl; + + delete reader; + reader = new ResamplingWavFileReader + (path, + ResamplingWavFileReader::ResampleThreaded, + ResamplingWavFileReader::CacheInTemporaryFile, + targetRate); + } } #ifdef HAVE_OGGZ @@ -80,7 +97,8 @@ reader = new OggVorbisFileReader (path, OggVorbisFileReader::DecodeThreaded, - OggVorbisFileReader::CacheInTemporaryFile); + OggVorbisFileReader::CacheInTemporaryFile, + targetRate); } } #endif @@ -94,7 +112,8 @@ reader = new MP3FileReader (path, MP3FileReader::DecodeThreaded, - MP3FileReader::CacheInTemporaryFile); + MP3FileReader::CacheInTemporaryFile, + targetRate); } } #endif @@ -107,7 +126,8 @@ reader = new QuickTimeFileReader (path, QuickTimeFileReader::DecodeThreaded, - QuickTimeFileReader::CacheInTemporaryFile); + QuickTimeFileReader::CacheInTemporaryFile, + targetRate); } } #endif @@ -128,7 +148,21 @@ } reader = new WavFileReader(path); + + if (targetRate != 0 && + reader->isOK() && + reader->getSampleRate() != targetRate) { + + delete reader; + reader = new ResamplingWavFileReader + (path, + ResamplingWavFileReader::ResampleThreaded, + ResamplingWavFileReader::CacheInTemporaryFile, + targetRate); + } + if (reader->isOK()) return reader; + if (reader->getError() != "") { std::cerr << "AudioFileReaderFactory: WAV file reader error: \"" << reader->getError().toStdString() << "\"" << std::endl;