comparison 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
comparison
equal deleted inserted replaced
296:2b6c99b607f1 297:c022976d18e8
14 */ 14 */
15 15
16 #include "AudioFileReaderFactory.h" 16 #include "AudioFileReaderFactory.h"
17 17
18 #include "WavFileReader.h" 18 #include "WavFileReader.h"
19 #include "ResamplingWavFileReader.h"
19 #include "OggVorbisFileReader.h" 20 #include "OggVorbisFileReader.h"
20 #include "MP3FileReader.h" 21 #include "MP3FileReader.h"
21 #include "QuickTimeFileReader.h" 22 #include "QuickTimeFileReader.h"
22 23
23 #include <QString> 24 #include <QString>
51 52
52 return rv; 53 return rv;
53 } 54 }
54 55
55 AudioFileReader * 56 AudioFileReader *
56 AudioFileReaderFactory::createReader(QString path) 57 AudioFileReaderFactory::createReader(QString path, size_t targetRate)
57 { 58 {
58 QString err; 59 QString err;
60
61 std::cerr << "AudioFileReaderFactory::createReader(\"" << path.toStdString() << "\"): Requested rate: " << targetRate << std::endl;
59 62
60 AudioFileReader *reader = 0; 63 AudioFileReader *reader = 0;
61 64
62 // First try to construct a preferred reader based on the 65 // First try to construct a preferred reader based on the
63 // extension. If we can't identify one or it fails to load the 66 // extension. If we can't identify one or it fails to load the
67 std::set<QString> extensions; 70 std::set<QString> extensions;
68 71
69 WavFileReader::getSupportedExtensions(extensions); 72 WavFileReader::getSupportedExtensions(extensions);
70 if (extensions.find(ext) != extensions.end()) { 73 if (extensions.find(ext) != extensions.end()) {
71 reader = new WavFileReader(path); 74 reader = new WavFileReader(path);
75
76 if (targetRate != 0 &&
77 reader->isOK() &&
78 reader->getSampleRate() != targetRate) {
79
80 std::cerr << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", creating resampling reader" << std::endl;
81
82 delete reader;
83 reader = new ResamplingWavFileReader
84 (path,
85 ResamplingWavFileReader::ResampleThreaded,
86 ResamplingWavFileReader::CacheInTemporaryFile,
87 targetRate);
88 }
72 } 89 }
73 90
74 #ifdef HAVE_OGGZ 91 #ifdef HAVE_OGGZ
75 #ifdef HAVE_FISHSOUND 92 #ifdef HAVE_FISHSOUND
76 if (!reader) { 93 if (!reader) {
78 OggVorbisFileReader::getSupportedExtensions(extensions); 95 OggVorbisFileReader::getSupportedExtensions(extensions);
79 if (extensions.find(ext) != extensions.end()) { 96 if (extensions.find(ext) != extensions.end()) {
80 reader = new OggVorbisFileReader 97 reader = new OggVorbisFileReader
81 (path, 98 (path,
82 OggVorbisFileReader::DecodeThreaded, 99 OggVorbisFileReader::DecodeThreaded,
83 OggVorbisFileReader::CacheInTemporaryFile); 100 OggVorbisFileReader::CacheInTemporaryFile,
101 targetRate);
84 } 102 }
85 } 103 }
86 #endif 104 #endif
87 #endif 105 #endif
88 106
92 MP3FileReader::getSupportedExtensions(extensions); 110 MP3FileReader::getSupportedExtensions(extensions);
93 if (extensions.find(ext) != extensions.end()) { 111 if (extensions.find(ext) != extensions.end()) {
94 reader = new MP3FileReader 112 reader = new MP3FileReader
95 (path, 113 (path,
96 MP3FileReader::DecodeThreaded, 114 MP3FileReader::DecodeThreaded,
97 MP3FileReader::CacheInTemporaryFile); 115 MP3FileReader::CacheInTemporaryFile,
116 targetRate);
98 } 117 }
99 } 118 }
100 #endif 119 #endif
101 120
102 #ifdef HAVE_QUICKTIME 121 #ifdef HAVE_QUICKTIME
105 QuickTimeFileReader::getSupportedExtensions(extensions); 124 QuickTimeFileReader::getSupportedExtensions(extensions);
106 if (extensions.find(ext) != extensions.end()) { 125 if (extensions.find(ext) != extensions.end()) {
107 reader = new QuickTimeFileReader 126 reader = new QuickTimeFileReader
108 (path, 127 (path,
109 QuickTimeFileReader::DecodeThreaded, 128 QuickTimeFileReader::DecodeThreaded,
110 QuickTimeFileReader::CacheInTemporaryFile); 129 QuickTimeFileReader::CacheInTemporaryFile,
130 targetRate);
111 } 131 }
112 } 132 }
113 #endif 133 #endif
114 134
115 if (reader) { 135 if (reader) {
126 delete reader; 146 delete reader;
127 reader = 0; 147 reader = 0;
128 } 148 }
129 149
130 reader = new WavFileReader(path); 150 reader = new WavFileReader(path);
131 if (reader->isOK()) return reader; 151
152 if (targetRate != 0 &&
153 reader->isOK() &&
154 reader->getSampleRate() != targetRate) {
155
156 delete reader;
157 reader = new ResamplingWavFileReader
158 (path,
159 ResamplingWavFileReader::ResampleThreaded,
160 ResamplingWavFileReader::CacheInTemporaryFile,
161 targetRate);
162 }
163
164 if (reader->isOK()) return reader;
165
132 if (reader->getError() != "") { 166 if (reader->getError() != "") {
133 std::cerr << "AudioFileReaderFactory: WAV file reader error: \"" 167 std::cerr << "AudioFileReaderFactory: WAV file reader error: \""
134 << reader->getError().toStdString() << "\"" << std::endl; 168 << reader->getError().toStdString() << "\"" << std::endl;
135 } else { 169 } else {
136 std::cerr << "AudioFileReaderFactory: WAV file reader failed" 170 std::cerr << "AudioFileReaderFactory: WAV file reader failed"