Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 1069:32ab6c48efaa
Merge from branch tonioni
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:11:34 +0100 |
parents | a1cd5abcb38b |
children | 52d088c24c5c |
comparison
equal
deleted
inserted
replaced
1036:682d64f05e72 | 1069:32ab6c48efaa |
---|---|
35 //#define DEBUG_ID3TAG 1 | 35 //#define DEBUG_ID3TAG 1 |
36 | 36 |
37 #include <QFileInfo> | 37 #include <QFileInfo> |
38 | 38 |
39 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode, | 39 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode, |
40 CacheMode mode, int targetRate, | 40 CacheMode mode, sv_samplerate_t targetRate, |
41 bool normalised, | 41 bool normalised, |
42 ProgressReporter *reporter) : | 42 ProgressReporter *reporter) : |
43 CodedAudioFileReader(mode, targetRate, normalised), | 43 CodedAudioFileReader(mode, targetRate, normalised), |
44 m_source(source), | 44 m_source(source), |
45 m_path(source.getLocalFilename()), | 45 m_path(source.getLocalFilename()), |
84 ::close(fd); | 84 ::close(fd); |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 ssize_t sz = 0; | 88 ssize_t sz = 0; |
89 int offset = 0; | 89 ssize_t offset = 0; |
90 while (offset < m_fileSize) { | 90 while (offset < m_fileSize) { |
91 sz = ::read(fd, m_filebuffer + offset, m_fileSize - offset); | 91 sz = ::read(fd, m_filebuffer + offset, m_fileSize - offset); |
92 if (sz < 0) { | 92 if (sz < 0) { |
93 m_error = QString("Read error for file %1 (after %2 bytes)") | 93 m_error = QString("Read error for file %1 (after %2 bytes)") |
94 .arg(m_path).arg(offset); | 94 .arg(m_path).arg(offset); |
289 | 289 |
290 m_reader->endSerialised(); | 290 m_reader->endSerialised(); |
291 } | 291 } |
292 | 292 |
293 bool | 293 bool |
294 MP3FileReader::decode(void *mm, int sz) | 294 MP3FileReader::decode(void *mm, sv_frame_t sz) |
295 { | 295 { |
296 DecoderData data; | 296 DecoderData data; |
297 struct mad_decoder decoder; | 297 struct mad_decoder decoder; |
298 | 298 |
299 data.start = (unsigned char const *)mm; | 299 data.start = (unsigned char const *)mm; |
318 unsigned char const *start = data->start; | 318 unsigned char const *start = data->start; |
319 unsigned long length = data->length; | 319 unsigned long length = data->length; |
320 | 320 |
321 #ifdef HAVE_ID3TAG | 321 #ifdef HAVE_ID3TAG |
322 if (length > ID3_TAG_QUERYSIZE) { | 322 if (length > ID3_TAG_QUERYSIZE) { |
323 int taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE); | 323 ssize_t taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE); |
324 if (taglen > 0) { | 324 if (taglen > 0) { |
325 // cerr << "ID3 tag length to skip: " << taglen << endl; | 325 // cerr << "ID3 tag length to skip: " << taglen << endl; |
326 start += taglen; | 326 start += taglen; |
327 length -= taglen; | 327 length -= taglen; |
328 } | 328 } |
350 { | 350 { |
351 int channels = pcm->channels; | 351 int channels = pcm->channels; |
352 int frames = pcm->length; | 352 int frames = pcm->length; |
353 | 353 |
354 if (header) { | 354 if (header) { |
355 m_bitrateNum += header->bitrate; | 355 m_bitrateNum = m_bitrateNum + double(header->bitrate); |
356 m_bitrateDenom ++; | 356 m_bitrateDenom ++; |
357 } | 357 } |
358 | 358 |
359 if (frames < 1) return MAD_FLOW_CONTINUE; | 359 if (frames < 1) return MAD_FLOW_CONTINUE; |
360 | 360 |