Mercurial > hg > svcore
comparison data/fileio/AudioFileReaderFactory.cpp @ 1097:abc309f507ae simple-fft-model
Tidy
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 12:38:50 +0100 |
parents | a1cd5abcb38b |
children | 329ddaf7415d |
comparison
equal
deleted
inserted
replaced
1096:4d9816ba0ebe | 1097:abc309f507ae |
---|---|
96 return 0; | 96 return 0; |
97 } | 97 } |
98 | 98 |
99 AudioFileReader *reader = 0; | 99 AudioFileReader *reader = 0; |
100 | 100 |
101 CodedAudioFileReader::CacheMode cacheMode = | |
102 CodedAudioFileReader::CacheInTemporaryFile; | |
103 | |
104 CodedAudioFileReader::DecodeMode decodeMode = | |
105 (threading ? | |
106 CodedAudioFileReader::DecodeThreaded : | |
107 CodedAudioFileReader::DecodeAtOnce); | |
108 | |
101 // Try to construct a preferred reader based on the extension or | 109 // Try to construct a preferred reader based on the extension or |
102 // MIME type. | 110 // MIME type. |
111 | |
112 #define CHECK(reader) if (!reader->isOK()) { delete reader; reader = 0; } | |
103 | 113 |
104 if (WavFileReader::supports(source)) { | 114 if (WavFileReader::supports(source)) { |
105 | 115 |
106 reader = new WavFileReader(source); | 116 reader = new WavFileReader(source); |
107 | 117 |
115 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl; | 125 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl; |
116 | 126 |
117 delete reader; | 127 delete reader; |
118 reader = new DecodingWavFileReader | 128 reader = new DecodingWavFileReader |
119 (source, | 129 (source, |
120 threading ? | 130 decodeMode, cacheMode, |
121 DecodingWavFileReader::ResampleThreaded : | |
122 DecodingWavFileReader::ResampleAtOnce, | |
123 DecodingWavFileReader::CacheInTemporaryFile, | |
124 targetRate ? targetRate : fileRate, | 131 targetRate ? targetRate : fileRate, |
125 normalised, | 132 normalised, |
126 reporter); | 133 reporter); |
127 if (!reader->isOK()) { | 134 CHECK(reader); |
128 delete reader; | |
129 reader = 0; | |
130 } | |
131 } | 135 } |
132 } | 136 } |
133 | 137 |
134 #ifdef HAVE_OGGZ | 138 #ifdef HAVE_OGGZ |
135 #ifdef HAVE_FISHSOUND | 139 #ifdef HAVE_FISHSOUND |
136 if (!reader) { | 140 if (!reader && OggVorbisFileReader::supports(source)) { |
137 if (OggVorbisFileReader::supports(source)) { | 141 reader = new OggVorbisFileReader |
138 reader = new OggVorbisFileReader | 142 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
139 (source, | 143 CHECK(reader); |
140 threading ? | |
141 OggVorbisFileReader::DecodeThreaded : | |
142 OggVorbisFileReader::DecodeAtOnce, | |
143 OggVorbisFileReader::CacheInTemporaryFile, | |
144 targetRate, | |
145 normalised, | |
146 reporter); | |
147 if (!reader->isOK()) { | |
148 delete reader; | |
149 reader = 0; | |
150 } | |
151 } | |
152 } | 144 } |
153 #endif | 145 #endif |
154 #endif | 146 #endif |
155 | 147 |
156 #ifdef HAVE_MAD | 148 #ifdef HAVE_MAD |
157 if (!reader) { | 149 if (!reader && MP3FileReader::supports(source)) { |
158 if (MP3FileReader::supports(source)) { | 150 reader = new MP3FileReader |
159 reader = new MP3FileReader | 151 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
160 (source, | 152 CHECK(reader); |
161 threading ? | |
162 MP3FileReader::DecodeThreaded : | |
163 MP3FileReader::DecodeAtOnce, | |
164 MP3FileReader::CacheInTemporaryFile, | |
165 targetRate, | |
166 normalised, | |
167 reporter); | |
168 if (!reader->isOK()) { | |
169 delete reader; | |
170 reader = 0; | |
171 } | |
172 } | |
173 } | 153 } |
174 #endif | 154 #endif |
175 | 155 |
176 #ifdef HAVE_QUICKTIME | 156 #ifdef HAVE_QUICKTIME |
177 if (!reader) { | 157 if (!reader && QuickTimeFileReader::supports(source)) { |
178 if (QuickTimeFileReader::supports(source)) { | 158 reader = new QuickTimeFileReader |
179 reader = new QuickTimeFileReader | 159 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
180 (source, | 160 CHECK(reader); |
181 threading ? | |
182 QuickTimeFileReader::DecodeThreaded : | |
183 QuickTimeFileReader::DecodeAtOnce, | |
184 QuickTimeFileReader::CacheInTemporaryFile, | |
185 targetRate, | |
186 normalised, | |
187 reporter); | |
188 if (!reader->isOK()) { | |
189 delete reader; | |
190 reader = 0; | |
191 } | |
192 } | |
193 } | 161 } |
194 #endif | 162 #endif |
195 | 163 |
196 #ifdef HAVE_COREAUDIO | 164 #ifdef HAVE_COREAUDIO |
197 if (!reader) { | 165 if (!reader && CoreAudioFileReader::supports(source)) { |
198 if (CoreAudioFileReader::supports(source)) { | 166 reader = new CoreAudioFileReader |
199 reader = new CoreAudioFileReader | 167 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
200 (source, | 168 CHECK(reader); |
201 threading ? | 169 } |
202 CoreAudioFileReader::DecodeThreaded : | 170 #endif |
203 CoreAudioFileReader::DecodeAtOnce, | 171 |
204 CoreAudioFileReader::CacheInTemporaryFile, | 172 if (reader) { |
205 targetRate, | 173 // The happy case: a reader recognised the file extension & |
206 normalised, | 174 // succeeded in opening the file |
207 reporter); | 175 return reader; |
208 if (!reader->isOK()) { | 176 } |
209 delete reader; | 177 |
210 reader = 0; | |
211 } | |
212 } | |
213 } | |
214 #endif | |
215 | |
216 | |
217 // If none of the readers claimed to support this file extension, | 178 // If none of the readers claimed to support this file extension, |
218 // perhaps the extension is missing or misleading. Try again, | 179 // perhaps the extension is missing or misleading. Try again, |
219 // ignoring it. We have to be confident that the reader won't | 180 // ignoring it. We have to be confident that the reader won't |
220 // open just any old text file or whatever and pretend it's | 181 // open just any old text file or whatever and pretend it's |
221 // succeeded | 182 // succeeded |
222 | 183 |
223 if (!reader) { | 184 reader = new WavFileReader(source); |
224 | 185 |
225 reader = new WavFileReader(source); | 186 sv_samplerate_t fileRate = reader->getSampleRate(); |
226 | 187 |
227 sv_samplerate_t fileRate = reader->getSampleRate(); | 188 if (reader->isOK() && |
228 | 189 (!reader->isQuicklySeekable() || |
229 if (reader->isOK() && | 190 normalised || |
230 (!reader->isQuicklySeekable() || | 191 (targetRate != 0 && fileRate != targetRate))) { |
231 normalised || | 192 |
232 (targetRate != 0 && fileRate != targetRate))) { | 193 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl; |
233 | 194 |
234 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", creating decoding reader" << endl; | 195 delete reader; |
235 | 196 reader = new DecodingWavFileReader |
236 delete reader; | 197 (source, |
237 reader = new DecodingWavFileReader | 198 decodeMode, cacheMode, |
238 (source, | 199 targetRate ? targetRate : fileRate, |
239 threading ? | 200 normalised, |
240 DecodingWavFileReader::ResampleThreaded : | 201 reporter); |
241 DecodingWavFileReader::ResampleAtOnce, | 202 } |
242 DecodingWavFileReader::CacheInTemporaryFile, | 203 |
243 targetRate ? targetRate : fileRate, | 204 CHECK(reader); |
244 normalised, | |
245 reporter); | |
246 } | |
247 | |
248 if (!reader->isOK()) { | |
249 delete reader; | |
250 reader = 0; | |
251 } | |
252 } | |
253 | 205 |
254 #ifdef HAVE_OGGZ | 206 #ifdef HAVE_OGGZ |
255 #ifdef HAVE_FISHSOUND | 207 #ifdef HAVE_FISHSOUND |
256 if (!reader) { | 208 if (!reader) { |
257 reader = new OggVorbisFileReader | 209 reader = new OggVorbisFileReader |
258 (source, | 210 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
259 threading ? | 211 CHECK(reader); |
260 OggVorbisFileReader::DecodeThreaded : | |
261 OggVorbisFileReader::DecodeAtOnce, | |
262 OggVorbisFileReader::CacheInTemporaryFile, | |
263 targetRate, | |
264 reporter); | |
265 | |
266 if (!reader->isOK()) { | |
267 delete reader; | |
268 reader = 0; | |
269 } | |
270 } | 212 } |
271 #endif | 213 #endif |
272 #endif | 214 #endif |
273 | 215 |
274 #ifdef HAVE_MAD | 216 #ifdef HAVE_MAD |
275 if (!reader) { | 217 if (!reader) { |
276 reader = new MP3FileReader | 218 reader = new MP3FileReader |
277 (source, | 219 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
278 threading ? | 220 CHECK(reader); |
279 MP3FileReader::DecodeThreaded : | |
280 MP3FileReader::DecodeAtOnce, | |
281 MP3FileReader::CacheInTemporaryFile, | |
282 targetRate, | |
283 reporter); | |
284 | |
285 if (!reader->isOK()) { | |
286 delete reader; | |
287 reader = 0; | |
288 } | |
289 } | 221 } |
290 #endif | 222 #endif |
291 | 223 |
292 #ifdef HAVE_QUICKTIME | 224 #ifdef HAVE_QUICKTIME |
293 if (!reader) { | 225 if (!reader) { |
294 reader = new QuickTimeFileReader | 226 reader = new QuickTimeFileReader |
295 (source, | 227 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
296 threading ? | 228 CHECK(reader); |
297 QuickTimeFileReader::DecodeThreaded : | |
298 QuickTimeFileReader::DecodeAtOnce, | |
299 QuickTimeFileReader::CacheInTemporaryFile, | |
300 targetRate, | |
301 reporter); | |
302 | |
303 if (!reader->isOK()) { | |
304 delete reader; | |
305 reader = 0; | |
306 } | |
307 } | 229 } |
308 #endif | 230 #endif |
309 | 231 |
310 #ifdef HAVE_COREAUDIO | 232 #ifdef HAVE_COREAUDIO |
311 if (!reader) { | 233 if (!reader) { |
312 reader = new CoreAudioFileReader | 234 reader = new CoreAudioFileReader |
313 (source, | 235 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
314 threading ? | 236 CHECK(reader); |
315 CoreAudioFileReader::DecodeThreaded : | 237 } |
316 CoreAudioFileReader::DecodeAtOnce, | 238 #endif |
317 CoreAudioFileReader::CacheInTemporaryFile, | 239 |
318 targetRate, | 240 if (!reader) { |
319 reporter); | 241 cerr << "AudioFileReaderFactory::Failed to create a reader for " |
320 | 242 << "url \"" << source.getLocation() |
321 if (!reader->isOK()) { | 243 << "\" (content type \"" |
322 delete reader; | 244 << source.getContentType() << "\")" << endl; |
323 reader = 0; | 245 return nullptr; |
324 } | 246 } |
325 } | 247 |
326 #endif | |
327 | |
328 if (reader) { | |
329 if (reader->isOK()) { | |
330 SVDEBUG << "AudioFileReaderFactory: Reader is OK" << endl; | |
331 return reader; | |
332 } | |
333 cerr << "AudioFileReaderFactory: Preferred reader for " | |
334 << "url \"" << source.getLocation() | |
335 << "\" (content type \"" | |
336 << source.getContentType() << "\") failed"; | |
337 | |
338 if (reader->getError() != "") { | |
339 cerr << ": \"" << reader->getError() << "\""; | |
340 } | |
341 cerr << endl; | |
342 delete reader; | |
343 reader = 0; | |
344 } | |
345 | |
346 cerr << "AudioFileReaderFactory: No reader" << endl; | |
347 return reader; | 248 return reader; |
348 } | 249 } |
349 | 250 |