Mercurial > hg > svcore
diff data/fileio/CodedAudioFileReader.cpp @ 1038:cc27f35aa75c cxx11
Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author | Chris Cannam |
---|---|
date | Tue, 03 Mar 2015 15:18:24 +0000 |
parents | d03b3d956358 |
children | a1cd5abcb38b |
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp Tue Mar 03 09:33:59 2015 +0000 +++ b/data/fileio/CodedAudioFileReader.cpp Tue Mar 03 15:18:24 2015 +0000 @@ -113,9 +113,9 @@ m_resampler = new Resampler(Resampler::FastestTolerable, m_channelCount, m_cacheWriteBufferSize); - float ratio = float(m_sampleRate) / float(m_fileRate); + double ratio = double(m_sampleRate) / double(m_fileRate); m_resampleBuffer = new float - [lrintf(ceilf(m_cacheWriteBufferSize * m_channelCount * ratio + 1))]; + [lrint(ceil(double(m_cacheWriteBufferSize) * m_channelCount * ratio + 1))]; } m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount]; @@ -176,13 +176,13 @@ } void -CodedAudioFileReader::addSamplesToDecodeCache(float **samples, int nframes) +CodedAudioFileReader::addSamplesToDecodeCache(float **samples, sv_frame_t nframes) { QMutexLocker locker(&m_cacheMutex); if (!m_initialised) return; - for (int i = 0; i < nframes; ++i) { + for (sv_frame_t i = 0; i < nframes; ++i) { for (int c = 0; c < m_channelCount; ++c) { @@ -206,13 +206,13 @@ } void -CodedAudioFileReader::addSamplesToDecodeCache(float *samples, int nframes) +CodedAudioFileReader::addSamplesToDecodeCache(float *samples, sv_frame_t nframes) { QMutexLocker locker(&m_cacheMutex); if (!m_initialised) return; - for (int i = 0; i < nframes; ++i) { + for (sv_frame_t i = 0; i < nframes; ++i) { for (int c = 0; c < m_channelCount; ++c) { @@ -242,9 +242,7 @@ if (!m_initialised) return; - for (int i = 0; i < (int)samples.size(); ++i) { - - float sample = samples[i]; + for (float sample: samples) { m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample; @@ -295,7 +293,7 @@ } void -CodedAudioFileReader::pushBuffer(float *buffer, int sz, bool final) +CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final) { m_fileFrameCount += sz; @@ -312,13 +310,13 @@ } void -CodedAudioFileReader::pushBufferNonResampling(float *buffer, int sz) +CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz) { float clip = 1.0; - int count = sz * m_channelCount; + sv_frame_t count = sz * m_channelCount; if (m_normalised) { - for (int i = 0; i < count; ++i) { + for (sv_frame_t i = 0; i < count; ++i) { float v = fabsf(buffer[i]); if (v > m_max) { m_max = v; @@ -326,10 +324,10 @@ } } } else { - for (int i = 0; i < count; ++i) { + for (sv_frame_t i = 0; i < count; ++i) { if (buffer[i] > clip) buffer[i] = clip; } - for (int i = 0; i < count; ++i) { + for (sv_frame_t i = 0; i < count; ++i) { if (buffer[i] < -clip) buffer[i] = -clip; } } @@ -339,7 +337,7 @@ switch (m_cacheMode) { case CacheInTemporaryFile: - if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < (int)sz) { + if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) { sf_close(m_cacheFileWritePtr); m_cacheFileWritePtr = 0; throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath()); @@ -348,7 +346,7 @@ case CacheInMemory: m_dataLock.lockForWrite(); - for (int s = 0; s < count; ++s) { + for (sv_frame_t s = 0; s < count; ++s) { m_data.push_back(buffer[s]); } MUNLOCK_SAMPLEBLOCK(m_data); @@ -358,14 +356,14 @@ } void -CodedAudioFileReader::pushBufferResampling(float *buffer, int sz, - float ratio, bool final) +CodedAudioFileReader::pushBufferResampling(float *buffer, sv_frame_t sz, + double ratio, bool final) { SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl; if (sz > 0) { - int out = m_resampler->resampleInterleaved + sv_frame_t out = m_resampler->resampleInterleaved (buffer, m_resampleBuffer, sz, @@ -377,27 +375,27 @@ if (final) { - int padFrames = 1; - if (m_frameCount / ratio < m_fileFrameCount) { - padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1; + sv_frame_t padFrames = 1; + if (double(m_frameCount) / ratio < double(m_fileFrameCount)) { + padFrames = m_fileFrameCount - sv_frame_t(double(m_frameCount) / ratio) + 1; } - int padSamples = padFrames * m_channelCount; + sv_frame_t padSamples = padFrames * m_channelCount; - SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl; + SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << double(m_frameCount) / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl; float *padding = new float[padSamples]; - for (int i = 0; i < padSamples; ++i) padding[i] = 0.f; + for (sv_frame_t i = 0; i < padSamples; ++i) padding[i] = 0.f; - int out = m_resampler->resampleInterleaved + sv_frame_t out = m_resampler->resampleInterleaved (padding, m_resampleBuffer, padFrames, ratio, true); - if (int(m_frameCount + out) > int(m_fileFrameCount * ratio)) { - out = int(m_fileFrameCount * ratio) - int(m_frameCount); + if (m_frameCount + out > sv_frame_t(double(m_fileFrameCount) * ratio)) { + out = sv_frame_t(double(m_fileFrameCount) * ratio) - m_frameCount; } pushBufferNonResampling(m_resampleBuffer, out); @@ -406,7 +404,7 @@ } void -CodedAudioFileReader::getInterleavedFrames(int start, int count, +CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count, SampleBlock &frames) const { // Lock is only required in CacheInMemory mode (the cache file @@ -433,11 +431,11 @@ if (count == 0) return; frames.reserve(count * m_channelCount); - int idx = start * m_channelCount; - int i = 0; + sv_frame_t idx = start * m_channelCount; + sv_frame_t i = 0; m_dataLock.lockForRead(); - while (i < count * m_channelCount && idx < (int)m_data.size()) { + while (i < count * m_channelCount && idx < (sv_frame_t)m_data.size()) { frames.push_back(m_data[idx]); ++idx; } @@ -446,7 +444,7 @@ } if (m_normalised) { - for (int i = 0; i < (int)(count * m_channelCount); ++i) { + for (sv_frame_t i = 0; i < (sv_frame_t)(count * m_channelCount); ++i) { frames[i] *= m_gain; } }