15
15
***************************************************************************/
17
#include <taglib/flacfile.h>
18
#include <taglib/aifffile.h>
19
#include <taglib/rifffile.h>
20
#include <taglib/wavfile.h>
17
22
#include "trackinfoobject.h"
18
23
#include "soundsourcesndfile.h"
19
24
#include <qstring.h>
22
#include <Q3ValueList>
24
28
Class for reading files using libsndfile
52
56
QByteArray qbaFilename = m_qFilename.toUtf8();
53
57
fh = sf_open( qbaFilename.data(), SFM_READ, info );
55
if (fh == NULL) { // sf_format_check is only for writes
59
if (fh == NULL) { // sf_format_check is only for writes
56
60
qWarning() << "libsndfile: Error opening file" << m_qFilename << sf_strerror(fh);
61
65
qWarning() << "libsndfile: Error opening file" << m_qFilename << sf_strerror(fh);
126
130
// i = 10-1 = 9, so dest[9*2] and dest[9*2+1],
127
131
// so the first iteration touches the very ends of destination
128
132
// on the last iteration, dest[0] and dest[1] are assigned to dest[0]
130
134
for(int i=(readNo-1); i>=0; i--) {
131
135
dest[i*2] = dest[i];
132
136
dest[(i*2)+1] = dest[i];
147
151
int SoundSourceSndFile::parseHeader()
149
QString location = this->getFilename();
151
info.format = 0; // Must be set to 0 per the API for reading (non-RAW files)
152
QByteArray qbaLocation = location.toUtf8();
153
SNDFILE * fh = sf_open(qbaLocation.data() ,SFM_READ, &info);
154
//const char* err = sf_strerror(0);
155
if (fh == NULL) { // sf_format_check is only for writes
156
qDebug() << "sndfile::ParseHeader: libsndfile error:" << sf_strerror(fh);
160
if (sf_error(fh)>0) {
161
qDebug() << "sndfile::ParseHeader: libsndfile error:" << sf_strerror(fh);
162
if (fh) sf_close(fh);
153
QString location = getFilename();
154
setType(location.section(".",-1).toLower());
157
bool is_flac = location.endsWith("flac", Qt::CaseInsensitive);
158
bool is_wav = location.endsWith("wav", Qt::CaseInsensitive);
161
TagLib::FLAC::File f(location.toUtf8().constData());
162
result = processTaglibFile(f);
163
TagLib::ID3v2::Tag* id3v2 = f.ID3v2Tag();
164
TagLib::Ogg::XiphComment* xiph = f.xiphComment();
166
processID3v2Tag(id3v2);
169
processXiphComment(xiph);
172
TagLib::RIFF::WAV::File f(location.toUtf8().constData());
173
result = processTaglibFile(f);
175
TagLib::ID3v2::Tag* id3v2 = f.tag();
177
processID3v2Tag(id3v2);
181
TagLib::RIFF::AIFF::File f(location.toUtf8().constData());
182
result = processTaglibFile(f);
184
TagLib::ID3v2::Tag* id3v2 = f.tag();
186
processID3v2Tag(id3v2);
166
this->setType(location.section(".",-1).toLower());
167
this->setBitrate((int)(info.samplerate*32./1000.));
168
this->setDuration(info.frames/info.samplerate);
169
this->setSampleRate(info.samplerate);
170
this->setChannels(info.channels);
173
string = sf_get_string(fh, SF_STR_ARTIST);
174
// qDebug() << location << "SF_STR_ARTIST" << string;
175
if(string && strlen(string))
176
this->setArtist(string);
177
string = sf_get_string(fh, SF_STR_TITLE);
178
if(string && strlen(string))
179
this->setTitle(string);
180
// qDebug() << location << "SF_STR_TITLE" << string;
181
string = sf_get_string(fh, SF_STR_DATE);
182
if (string && strlen(string))
183
this->setYear(string);