comparison data/fileio/MP3FileReader.cpp @ 1599:ce185d4dd408 bqaudiostream

Merge from default branch
author Chris Cannam
date Wed, 23 Jan 2019 14:43:43 +0000
parents 70e172e6cc59
children 14747f24ad04
comparison
equal deleted inserted replaced
1598:d2555df635ec 1599:ce185d4dd408
56 CodedAudioFileReader(mode, targetRate, normalised), 56 CodedAudioFileReader(mode, targetRate, normalised),
57 m_source(source), 57 m_source(source),
58 m_path(source.getLocalFilename()), 58 m_path(source.getLocalFilename()),
59 m_gaplessMode(gaplessMode), 59 m_gaplessMode(gaplessMode),
60 m_decodeErrorShown(false), 60 m_decodeErrorShown(false),
61 m_decodeThread(0) 61 m_decodeThread(nullptr)
62 { 62 {
63 SVDEBUG << "MP3FileReader: local path: \"" << m_path 63 SVDEBUG << "MP3FileReader: local path: \"" << m_path
64 << "\", decode mode: " << decodeMode << " (" 64 << "\", decode mode: " << decodeMode << " ("
65 << (decodeMode == DecodeAtOnce ? "DecodeAtOnce" : "DecodeThreaded") 65 << (decodeMode == DecodeAtOnce ? "DecodeAtOnce" : "DecodeThreaded")
66 << ")" << endl; 66 << ")" << endl;
80 CodedAudioFileReader::setFramesToTrim(DEFAULT_DECODER_DELAY, 0); 80 CodedAudioFileReader::setFramesToTrim(DEFAULT_DECODER_DELAY, 0);
81 } 81 }
82 82
83 m_fileSize = 0; 83 m_fileSize = 0;
84 84
85 m_fileBuffer = 0; 85 m_fileBuffer = nullptr;
86 m_fileBufferSize = 0; 86 m_fileBufferSize = 0;
87 87
88 m_sampleBuffer = 0; 88 m_sampleBuffer = nullptr;
89 m_sampleBufferSize = 0; 89 m_sampleBufferSize = 0;
90 90
91 QFile qfile(m_path); 91 QFile qfile(m_path);
92 if (!qfile.open(QIODevice::ReadOnly)) { 92 if (!qfile.open(QIODevice::ReadOnly)) {
93 m_error = QString("Failed to open file %1 for reading.").arg(m_path); 93 m_error = QString("Failed to open file %1 for reading.").arg(m_path);
140 if (m_sampleBuffer) { 140 if (m_sampleBuffer) {
141 for (int c = 0; c < m_channelCount; ++c) { 141 for (int c = 0; c < m_channelCount; ++c) {
142 delete[] m_sampleBuffer[c]; 142 delete[] m_sampleBuffer[c];
143 } 143 }
144 delete[] m_sampleBuffer; 144 delete[] m_sampleBuffer;
145 m_sampleBuffer = 0; 145 m_sampleBuffer = nullptr;
146 } 146 }
147 147
148 delete[] m_fileBuffer; 148 delete[] m_fileBuffer;
149 m_fileBuffer = 0; 149 m_fileBuffer = nullptr;
150 150
151 if (isDecodeCacheInitialised()) finishDecodeCache(); 151 if (isDecodeCacheInitialised()) finishDecodeCache();
152 endSerialised(); 152 endSerialised();
153 153
154 } else { 154 } else {
290 if (!m_reader->decode(m_reader->m_fileBuffer, m_reader->m_fileBufferSize)) { 290 if (!m_reader->decode(m_reader->m_fileBuffer, m_reader->m_fileBufferSize)) {
291 m_reader->m_error = QString("Failed to decode file %1.").arg(m_reader->m_path); 291 m_reader->m_error = QString("Failed to decode file %1.").arg(m_reader->m_path);
292 } 292 }
293 293
294 delete[] m_reader->m_fileBuffer; 294 delete[] m_reader->m_fileBuffer;
295 m_reader->m_fileBuffer = 0; 295 m_reader->m_fileBuffer = nullptr;
296 296
297 if (m_reader->m_sampleBuffer) { 297 if (m_reader->m_sampleBuffer) {
298 for (int c = 0; c < m_reader->m_channelCount; ++c) { 298 for (int c = 0; c < m_reader->m_channelCount; ++c) {
299 delete[] m_reader->m_sampleBuffer[c]; 299 delete[] m_reader->m_sampleBuffer[c];
300 } 300 }
301 delete[] m_reader->m_sampleBuffer; 301 delete[] m_reader->m_sampleBuffer;
302 m_reader->m_sampleBuffer = 0; 302 m_reader->m_sampleBuffer = nullptr;
303 } 303 }
304 304
305 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); 305 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache();
306 306
307 m_reader->m_done = true; 307 m_reader->m_done = true;
322 data.reader = this; 322 data.reader = this;
323 323
324 mad_decoder_init(&decoder, // decoder to initialise 324 mad_decoder_init(&decoder, // decoder to initialise
325 &data, // our own data block for callbacks 325 &data, // our own data block for callbacks
326 input_callback, // provides (entire) input to mad 326 input_callback, // provides (entire) input to mad
327 0, // checks header 327 nullptr, // checks header
328 filter_callback, // filters frame before decoding 328 filter_callback, // filters frame before decoding
329 output_callback, // receives decoded output 329 output_callback, // receives decoded output
330 error_callback, // handles decode errors 330 error_callback, // handles decode errors
331 0); // "message_func" 331 nullptr); // "message_func"
332 332
333 mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC); 333 mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
334 mad_decoder_finish(&decoder); 334 mad_decoder_finish(&decoder);
335 335
336 SVDEBUG << "MP3FileReader: Decoding complete, decoded " << m_mp3FrameCount 336 SVDEBUG << "MP3FileReader: Decoding complete, decoded " << m_mp3FrameCount
538 538
539 if (m_sampleBufferSize < size_t(frames)) { 539 if (m_sampleBufferSize < size_t(frames)) {
540 if (!m_sampleBuffer) { 540 if (!m_sampleBuffer) {
541 m_sampleBuffer = new float *[channels]; 541 m_sampleBuffer = new float *[channels];
542 for (int c = 0; c < channels; ++c) { 542 for (int c = 0; c < channels; ++c) {
543 m_sampleBuffer[c] = 0; 543 m_sampleBuffer[c] = nullptr;
544 } 544 }
545 } 545 }
546 for (int c = 0; c < channels; ++c) { 546 for (int c = 0; c < channels; ++c) {
547 delete[] m_sampleBuffer[c]; 547 delete[] m_sampleBuffer[c];
548 m_sampleBuffer[c] = new float[frames]; 548 m_sampleBuffer[c] = new float[frames];