comparison data/fileio/AudioFileReaderFactory.cpp @ 1592:f8e3dcbafb4d bqaudiostream

Implement title/maker in wav readers; extra handling of supported-ness for file types
author Chris Cannam
date Mon, 21 Jan 2019 13:16:17 +0000
parents c8fad3c14a2b
children ce185d4dd408
comparison
equal deleted inserted replaced
1591:6e68bd92ee21 1592:f8e3dcbafb4d
46 if (i != extensions.begin()) rv += " "; 46 if (i != extensions.begin()) rv += " ";
47 rv += "*." + *i; 47 rv += "*." + *i;
48 } 48 }
49 49
50 return rv; 50 return rv;
51 }
52
53 bool
54 AudioFileReaderFactory::isSupported(FileSource source)
55 {
56 #ifdef HAVE_MAD
57 if (MP3FileReader::supports(source)) {
58 return true;
59 }
60 #endif
61 if (WavFileReader::supports(source)) {
62 return true;
63 }
64 if (BQAFileReader::supports(source)) {
65 return true;
66 }
67 return false;
51 } 68 }
52 69
53 AudioFileReader * 70 AudioFileReader *
54 AudioFileReaderFactory::createReader(FileSource source, 71 AudioFileReaderFactory::createReader(FileSource source,
55 Parameters params, 72 Parameters params,
120 SVDEBUG << "AudioFileReaderFactory: Source not officially handled by any reader, trying again with each reader in turn" 137 SVDEBUG << "AudioFileReaderFactory: Source not officially handled by any reader, trying again with each reader in turn"
121 << endl; 138 << endl;
122 } 139 }
123 140
124 #ifdef HAVE_MAD 141 #ifdef HAVE_MAD
125 if (anyReader || MP3FileReader::supports(source)) { 142 // Having said we'll try any reader on the second pass, we
126 143 // actually don't want to try the mp3 reader for anything not
127 MP3FileReader::GaplessMode gapless = 144 // identified as an mp3 - it can't identify files by header,
128 params.gaplessMode == GaplessMode::Gapless ? 145 // it'll try to read any data and then fail with
129 MP3FileReader::GaplessMode::Gapless : 146 // synchronisation errors - causing misleading and potentially
130 MP3FileReader::GaplessMode::Gappy; 147 // alarming warning messages at the least
148 if (!anyReader) {
149 if (MP3FileReader::supports(source)) {
150
151 MP3FileReader::GaplessMode gapless =
152 params.gaplessMode == GaplessMode::Gapless ?
153 MP3FileReader::GaplessMode::Gapless :
154 MP3FileReader::GaplessMode::Gappy;
131 155
132 reader = new MP3FileReader 156 reader = new MP3FileReader
133 (source, decodeMode, cacheMode, gapless, 157 (source, decodeMode, cacheMode, gapless,
134 targetRate, normalised, reporter); 158 targetRate, normalised, reporter);
135 159
136 if (reader->isOK()) { 160 if (reader->isOK()) {
137 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl; 161 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl;
138 return reader; 162 return reader;
139 } else { 163 } else {
140 delete reader; 164 delete reader;
165 }
141 } 166 }
142 } 167 }
143 #endif 168 #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 }
158 169
159 if (anyReader || WavFileReader::supports(source)) { 170 if (anyReader || WavFileReader::supports(source)) {
160 171
161 reader = new WavFileReader(source); 172 reader = new WavFileReader(source);
162 173
184 return reader; 195 return reader;
185 } else { 196 } else {
186 delete reader; 197 delete reader;
187 } 198 }
188 } 199 }
200
201 if (anyReader || BQAFileReader::supports(source)) {
202
203 reader = new BQAFileReader
204 (source, decodeMode, cacheMode,
205 targetRate, normalised, reporter);
206
207 if (reader->isOK()) {
208 SVDEBUG << "AudioFileReaderFactory: BQA reader is OK, returning it" << endl;
209 return reader;
210 } else {
211 delete reader;
212 }
213 }
189 } 214 }
190 215
191 SVCERR << "AudioFileReaderFactory::Failed to create a reader for " 216 SVCERR << "AudioFileReaderFactory::Failed to create a reader for "
192 << "url \"" << source.getLocation() 217 << "url \"" << source.getLocation()
193 << "\" (local filename \"" << source.getLocalFilename() 218 << "\" (local filename \"" << source.getLocalFilename()