~mixxxdevelopers/mixxx/features_rubberband

« back to all changes in this revision

Viewing changes to mixxx/src/soundsourcesndfile.cpp

  • Committer: Phillip Whelan
  • Date: 2011-01-07 04:20:46 UTC
  • mfrom: (2359.1.258 trunk)
  • Revision ID: pwhelan@mixxx.org-20110107042046-buscxz8jlsfd3nk6
Merging with Trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
*                                                                         *
15
15
***************************************************************************/
16
16
 
 
17
#include <taglib/flacfile.h>
 
18
#include <taglib/aifffile.h>
 
19
#include <taglib/rifffile.h>
 
20
#include <taglib/wavfile.h>
 
21
 
17
22
#include "trackinfoobject.h"
18
23
#include "soundsourcesndfile.h"
19
24
#include <qstring.h>
20
25
#include <QtDebug>
21
 
//Added by qt3to4:
22
 
#include <Q3ValueList>
 
26
 
23
27
/*
24
28
   Class for reading files using libsndfile
25
29
 */
51
55
{
52
56
    QByteArray qbaFilename = m_qFilename.toUtf8();
53
57
    fh = sf_open( qbaFilename.data(), SFM_READ, info );
54
 
    
55
 
    if (fh == NULL) {   // sf_format_check is only for writes                      
 
58
 
 
59
    if (fh == NULL) {   // sf_format_check is only for writes
56
60
        qWarning() << "libsndfile: Error opening file" << m_qFilename << sf_strerror(fh);
57
 
        return -1;                                                                        
58
 
    }                                                                                  
59
 
    
60
 
    if (sf_error(fh)>0) {                                                              
 
61
        return -1;
 
62
    }
 
63
 
 
64
    if (sf_error(fh)>0) {
61
65
        qWarning() << "libsndfile: Error opening file" << m_qFilename << sf_strerror(fh);
62
66
        return -1;
63
67
    }
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]
129
 
            
 
133
 
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];
146
150
 
147
151
int SoundSourceSndFile::parseHeader()
148
152
{
149
 
    QString location = this->getFilename();
150
 
    SF_INFO info;
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);     
157
 
        return ERR;                                                                    
158
 
    }                                                                                  
159
 
    
160
 
    if (sf_error(fh)>0) {                                                              
161
 
        qDebug() << "sndfile::ParseHeader: libsndfile error:" << sf_strerror(fh);
162
 
        if (fh) sf_close(fh);
163
 
        return ERR;
 
153
    QString location = getFilename();
 
154
    setType(location.section(".",-1).toLower());
 
155
 
 
156
    bool result;
 
157
    bool is_flac = location.endsWith("flac", Qt::CaseInsensitive);
 
158
    bool is_wav = location.endsWith("wav", Qt::CaseInsensitive);
 
159
 
 
160
    if (is_flac) {
 
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();
 
165
        if (id3v2) {
 
166
            processID3v2Tag(id3v2);
 
167
        }
 
168
        if (xiph) {
 
169
            processXiphComment(xiph);
 
170
        }
 
171
    } else if (is_wav) {
 
172
        TagLib::RIFF::WAV::File f(location.toUtf8().constData());
 
173
        result = processTaglibFile(f);
 
174
 
 
175
        TagLib::ID3v2::Tag* id3v2 = f.tag();
 
176
        if (id3v2) {
 
177
            processID3v2Tag(id3v2);
 
178
        }
 
179
    } else {
 
180
        // Try AIFF
 
181
        TagLib::RIFF::AIFF::File f(location.toUtf8().constData());
 
182
        result = processTaglibFile(f);
 
183
 
 
184
        TagLib::ID3v2::Tag* id3v2 = f.tag();
 
185
        if (id3v2) {
 
186
            processID3v2Tag(id3v2);
 
187
        }
164
188
    }
165
189
 
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);
171
 
 
172
 
    const char *string;
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);
184
 
 
185
 
    if (fh)
186
 
        sf_close(fh);
187
 
    
188
 
    return OK;
 
190
    if (result)
 
191
        return OK;
 
192
    return ERR;
189
193
}
190
194
 
191
195
/*
195
199
{
196
200
    return filelength;
197
201
}
198