Chris@235
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@235
|
2
|
Chris@235
|
3 /*
|
Chris@235
|
4 Sonic Visualiser
|
Chris@235
|
5 An audio file viewer and annotation editor.
|
Chris@235
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@235
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@235
|
8
|
Chris@235
|
9 This program is free software; you can redistribute it and/or
|
Chris@235
|
10 modify it under the terms of the GNU General Public License as
|
Chris@235
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@235
|
12 License, or (at your option) any later version. See the file
|
Chris@235
|
13 COPYING included with this distribution for more information.
|
Chris@235
|
14 */
|
Chris@235
|
15
|
Chris@235
|
16 #include "AudioFileReaderFactory.h"
|
Chris@235
|
17
|
Chris@235
|
18 #include "WavFileReader.h"
|
Chris@297
|
19 #include "ResamplingWavFileReader.h"
|
Chris@235
|
20 #include "OggVorbisFileReader.h"
|
Chris@235
|
21 #include "MP3FileReader.h"
|
Chris@281
|
22 #include "QuickTimeFileReader.h"
|
Chris@235
|
23
|
Chris@235
|
24 #include <QString>
|
Chris@241
|
25 #include <QFileInfo>
|
Chris@235
|
26 #include <iostream>
|
Chris@235
|
27
|
Chris@290
|
28 QString
|
Chris@235
|
29 AudioFileReaderFactory::getKnownExtensions()
|
Chris@235
|
30 {
|
Chris@290
|
31 std::set<QString> extensions;
|
Chris@235
|
32
|
Chris@235
|
33 WavFileReader::getSupportedExtensions(extensions);
|
Chris@235
|
34 #ifdef HAVE_MAD
|
Chris@235
|
35 MP3FileReader::getSupportedExtensions(extensions);
|
Chris@235
|
36 #endif
|
Chris@235
|
37 #ifdef HAVE_OGGZ
|
Chris@235
|
38 #ifdef HAVE_FISHSOUND
|
Chris@235
|
39 OggVorbisFileReader::getSupportedExtensions(extensions);
|
Chris@235
|
40 #endif
|
Chris@235
|
41 #endif
|
Chris@281
|
42 #ifdef HAVE_QUICKTIME
|
Chris@281
|
43 QuickTimeFileReader::getSupportedExtensions(extensions);
|
Chris@281
|
44 #endif
|
Chris@235
|
45
|
Chris@290
|
46 QString rv;
|
Chris@290
|
47 for (std::set<QString>::const_iterator i = extensions.begin();
|
Chris@235
|
48 i != extensions.end(); ++i) {
|
Chris@235
|
49 if (i != extensions.begin()) rv += " ";
|
Chris@235
|
50 rv += "*." + *i;
|
Chris@235
|
51 }
|
Chris@235
|
52
|
Chris@235
|
53 return rv;
|
Chris@235
|
54 }
|
Chris@235
|
55
|
Chris@235
|
56 AudioFileReader *
|
Chris@317
|
57 AudioFileReaderFactory::createReader(FileSource source, size_t targetRate)
|
Chris@235
|
58 {
|
Chris@290
|
59 QString err;
|
Chris@235
|
60
|
Chris@316
|
61 std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\"): Requested rate: " << targetRate << std::endl;
|
Chris@316
|
62
|
Chris@316
|
63 if (!source.isOK() || !source.isAvailable()) {
|
Chris@316
|
64 std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\": Source unavailable" << std::endl;
|
Chris@316
|
65 return 0;
|
Chris@316
|
66 }
|
Chris@297
|
67
|
Chris@235
|
68 AudioFileReader *reader = 0;
|
Chris@235
|
69
|
Chris@316
|
70 // Try to construct a preferred reader based on the extension or
|
Chris@316
|
71 // MIME type.
|
Chris@241
|
72
|
Chris@316
|
73 if (WavFileReader::supports(source)) {
|
Chris@241
|
74
|
Chris@316
|
75 reader = new WavFileReader(source);
|
Chris@297
|
76
|
Chris@297
|
77 if (targetRate != 0 &&
|
Chris@297
|
78 reader->isOK() &&
|
Chris@297
|
79 reader->getSampleRate() != targetRate) {
|
Chris@297
|
80
|
Chris@297
|
81 std::cerr << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", creating resampling reader" << std::endl;
|
Chris@297
|
82
|
Chris@297
|
83 delete reader;
|
Chris@297
|
84 reader = new ResamplingWavFileReader
|
Chris@316
|
85 (source,
|
Chris@297
|
86 ResamplingWavFileReader::ResampleThreaded,
|
Chris@297
|
87 ResamplingWavFileReader::CacheInTemporaryFile,
|
Chris@297
|
88 targetRate);
|
Chris@297
|
89 }
|
Chris@241
|
90 }
|
Chris@241
|
91
|
Chris@241
|
92 #ifdef HAVE_OGGZ
|
Chris@241
|
93 #ifdef HAVE_FISHSOUND
|
Chris@241
|
94 if (!reader) {
|
Chris@316
|
95 if (OggVorbisFileReader::supports(source)) {
|
Chris@241
|
96 reader = new OggVorbisFileReader
|
Chris@316
|
97 (source,
|
Chris@265
|
98 OggVorbisFileReader::DecodeThreaded,
|
Chris@297
|
99 OggVorbisFileReader::CacheInTemporaryFile,
|
Chris@297
|
100 targetRate);
|
Chris@241
|
101 }
|
Chris@241
|
102 }
|
Chris@241
|
103 #endif
|
Chris@241
|
104 #endif
|
Chris@241
|
105
|
Chris@281
|
106 #ifdef HAVE_MAD
|
Chris@281
|
107 if (!reader) {
|
Chris@316
|
108 if (MP3FileReader::supports(source)) {
|
Chris@281
|
109 reader = new MP3FileReader
|
Chris@316
|
110 (source,
|
Chris@281
|
111 MP3FileReader::DecodeThreaded,
|
Chris@297
|
112 MP3FileReader::CacheInTemporaryFile,
|
Chris@297
|
113 targetRate);
|
Chris@281
|
114 }
|
Chris@281
|
115 }
|
Chris@281
|
116 #endif
|
Chris@281
|
117
|
Chris@281
|
118 #ifdef HAVE_QUICKTIME
|
Chris@281
|
119 if (!reader) {
|
Chris@316
|
120 if (QuickTimeFileReader::supports(source)) {
|
Chris@281
|
121 reader = new QuickTimeFileReader
|
Chris@316
|
122 (source,
|
Chris@281
|
123 QuickTimeFileReader::DecodeThreaded,
|
Chris@297
|
124 QuickTimeFileReader::CacheInTemporaryFile,
|
Chris@297
|
125 targetRate);
|
Chris@281
|
126 }
|
Chris@281
|
127 }
|
Chris@281
|
128 #endif
|
Chris@281
|
129
|
Chris@241
|
130 if (reader) {
|
Chris@316
|
131 if (reader->isOK()) {
|
Chris@316
|
132 std::cerr << "AudioFileReaderFactory: Reader is OK" << std::endl;
|
Chris@316
|
133 return reader;
|
Chris@316
|
134 }
|
Chris@316
|
135 std::cerr << "AudioFileReaderFactory: Preferred reader for "
|
Chris@316
|
136 << "url \"" << source.getLocation().toStdString()
|
Chris@316
|
137 << "\" (content type \""
|
Chris@316
|
138 << source.getContentType().toStdString() << "\") failed";
|
Chris@316
|
139
|
Chris@241
|
140 if (reader->getError() != "") {
|
Chris@316
|
141 std::cerr << ": \"" << reader->getError().toStdString() << "\"";
|
Chris@316
|
142 }
|
Chris@316
|
143 std::cerr << std::endl;
|
Chris@241
|
144 delete reader;
|
Chris@241
|
145 reader = 0;
|
Chris@241
|
146 }
|
Chris@241
|
147
|
Chris@316
|
148 std::cerr << "AudioFileReaderFactory: No reader" << std::endl;
|
Chris@308
|
149 return reader;
|
Chris@235
|
150 }
|
Chris@235
|
151
|