comparison data/fileio/AudioFileReaderFactory.cpp @ 1583:c8fad3c14a2b bqaudiostream

Start wiring in BQAudioStream stuff
author Chris Cannam
date Thu, 06 Dec 2018 12:50:28 +0000
parents 1c9bbbb6116a
children f8e3dcbafb4d
comparison
equal deleted inserted replaced
1578:07f23b90701a 1583:c8fad3c14a2b
15 15
16 #include "AudioFileReaderFactory.h" 16 #include "AudioFileReaderFactory.h"
17 17
18 #include "WavFileReader.h" 18 #include "WavFileReader.h"
19 #include "DecodingWavFileReader.h" 19 #include "DecodingWavFileReader.h"
20 #include "OggVorbisFileReader.h"
21 #include "MP3FileReader.h" 20 #include "MP3FileReader.h"
22 #include "CoreAudioFileReader.h" 21 #include "BQAFileReader.h"
23 #include "AudioFileSizeEstimator.h" 22 #include "AudioFileSizeEstimator.h"
24 23
25 #include "base/StorageAdviser.h" 24 #include "base/StorageAdviser.h"
26 25
27 #include <QString> 26 #include <QString>
28 #include <QFileInfo> 27 #include <QFileInfo>
29 #include <iostream> 28 #include <iostream>
30 29
30 using namespace std;
31
31 QString 32 QString
32 AudioFileReaderFactory::getKnownExtensions() 33 AudioFileReaderFactory::getKnownExtensions()
33 { 34 {
34 std::set<QString> extensions; 35 set<QString> extensions;
35 36
36 WavFileReader::getSupportedExtensions(extensions); 37 WavFileReader::getSupportedExtensions(extensions);
37 #ifdef HAVE_MAD 38 #ifdef HAVE_MAD
38 MP3FileReader::getSupportedExtensions(extensions); 39 MP3FileReader::getSupportedExtensions(extensions);
39 #endif 40 #endif
40 #ifdef HAVE_OGGZ 41 BQAFileReader::getSupportedExtensions(extensions);
41 #ifdef HAVE_FISHSOUND
42 OggVorbisFileReader::getSupportedExtensions(extensions);
43 #endif
44 #endif
45 #ifdef HAVE_COREAUDIO
46 CoreAudioFileReader::getSupportedExtensions(extensions);
47 #endif
48 42
49 QString rv; 43 QString rv;
50 for (std::set<QString>::const_iterator i = extensions.begin(); 44 for (set<QString>::const_iterator i = extensions.begin();
51 i != extensions.end(); ++i) { 45 i != extensions.end(); ++i) {
52 if (i != extensions.begin()) rv += " "; 46 if (i != extensions.begin()) rv += " ";
53 rv += "*." + *i; 47 rv += "*." + *i;
54 } 48 }
55 49
124 SVDEBUG << "AudioFileReaderFactory: Checking whether any reader officially handles this source" << endl; 118 SVDEBUG << "AudioFileReaderFactory: Checking whether any reader officially handles this source" << endl;
125 } else { 119 } else {
126 SVDEBUG << "AudioFileReaderFactory: Source not officially handled by any reader, trying again with each reader in turn" 120 SVDEBUG << "AudioFileReaderFactory: Source not officially handled by any reader, trying again with each reader in turn"
127 << endl; 121 << endl;
128 } 122 }
129
130 #ifdef HAVE_OGGZ
131 #ifdef HAVE_FISHSOUND
132 // If we have the "real" Ogg reader, use that first. Otherwise
133 // the WavFileReader will likely accept Ogg files (as
134 // libsndfile supports them) but it has no ability to return
135 // file metadata, so we get a slightly less useful result.
136 if (anyReader || OggVorbisFileReader::supports(source)) {
137 123
138 reader = new OggVorbisFileReader 124 #ifdef HAVE_MAD
139 (source, decodeMode, cacheMode, targetRate, normalised, reporter); 125 if (anyReader || MP3FileReader::supports(source)) {
126
127 MP3FileReader::GaplessMode gapless =
128 params.gaplessMode == GaplessMode::Gapless ?
129 MP3FileReader::GaplessMode::Gapless :
130 MP3FileReader::GaplessMode::Gappy;
131
132 reader = new MP3FileReader
133 (source, decodeMode, cacheMode, gapless,
134 targetRate, normalised, reporter);
140 135
141 if (reader->isOK()) { 136 if (reader->isOK()) {
142 SVDEBUG << "AudioFileReaderFactory: Ogg file reader is OK, returning it" << endl; 137 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl;
143 return reader; 138 return reader;
144 } else { 139 } else {
145 delete reader; 140 delete reader;
146 } 141 }
147 } 142 }
148 #endif 143 #endif
149 #endif 144
145 if (anyReader || BQAFileReader::supports(source)) {
146
147 reader = new BQAFileReader
148 (source, decodeMode, cacheMode,
149 targetRate, normalised, reporter);
150
151 if (reader->isOK()) {
152 SVDEBUG << "AudioFileReaderFactory: BQA reader is OK, returning it" << endl;
153 return reader;
154 } else {
155 delete reader;
156 }
157 }
150 158
151 if (anyReader || WavFileReader::supports(source)) { 159 if (anyReader || WavFileReader::supports(source)) {
152 160
153 reader = new WavFileReader(source); 161 reader = new WavFileReader(source);
154 162
176 return reader; 184 return reader;
177 } else { 185 } else {
178 delete reader; 186 delete reader;
179 } 187 }
180 } 188 }
181
182 #ifdef HAVE_MAD
183 if (anyReader || MP3FileReader::supports(source)) {
184
185 MP3FileReader::GaplessMode gapless =
186 params.gaplessMode == GaplessMode::Gapless ?
187 MP3FileReader::GaplessMode::Gapless :
188 MP3FileReader::GaplessMode::Gappy;
189
190 reader = new MP3FileReader
191 (source, decodeMode, cacheMode, gapless,
192 targetRate, normalised, reporter);
193
194 if (reader->isOK()) {
195 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl;
196 return reader;
197 } else {
198 delete reader;
199 }
200 }
201 #endif
202
203 #ifdef HAVE_COREAUDIO
204 if (anyReader || CoreAudioFileReader::supports(source)) {
205
206 reader = new CoreAudioFileReader
207 (source, decodeMode, cacheMode, targetRate, normalised, reporter);
208
209 if (reader->isOK()) {
210 SVDEBUG << "AudioFileReaderFactory: CoreAudio reader is OK, returning it" << endl;
211 return reader;
212 } else {
213 delete reader;
214 }
215 }
216 #endif
217
218 } 189 }
219 190
220 SVCERR << "AudioFileReaderFactory::Failed to create a reader for " 191 SVCERR << "AudioFileReaderFactory::Failed to create a reader for "
221 << "url \"" << source.getLocation() 192 << "url \"" << source.getLocation()
222 << "\" (local filename \"" << source.getLocalFilename() 193 << "\" (local filename \"" << source.getLocalFilename()