Mercurial > hg > svcore
diff data/model/WaveFileModel.cpp @ 935:f960d67ce842 tonioni
Merge from branch warnfix_no_size_t
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 13:42:01 +0100 |
parents | d03b3d956358 |
children | 6d2ece0fe356 |
line wrap: on
line diff
--- a/data/model/WaveFileModel.cpp Mon Jun 16 11:28:45 2014 +0100 +++ b/data/model/WaveFileModel.cpp Wed Jun 18 13:42:01 2014 +0100 @@ -37,7 +37,7 @@ PowerOfSqrtTwoZoomConstraint WaveFileModel::m_zoomConstraint; -WaveFileModel::WaveFileModel(FileSource source, size_t targetRate) : +WaveFileModel::WaveFileModel(FileSource source, int targetRate) : m_source(source), m_path(source.getLocation()), m_myReader(true), @@ -129,32 +129,32 @@ return model; } -size_t +int WaveFileModel::getFrameCount() const { if (!m_reader) return 0; return m_reader->getFrameCount(); } -size_t +int WaveFileModel::getChannelCount() const { if (!m_reader) return 0; return m_reader->getChannelCount(); } -size_t +int WaveFileModel::getSampleRate() const { if (!m_reader) return 0; return m_reader->getSampleRate(); } -size_t +int WaveFileModel::getNativeRate() const { if (!m_reader) return 0; - size_t rate = m_reader->getNativeRate(); + int rate = m_reader->getNativeRate(); if (rate == 0) rate = getSampleRate(); return rate; } @@ -182,8 +182,8 @@ return ""; } -size_t -WaveFileModel::getData(int channel, size_t start, size_t count, +int +WaveFileModel::getData(int channel, int start, int count, float *buffer) const { // Always read these directly from the file. @@ -197,7 +197,7 @@ if (start >= m_startFrame) { start -= m_startFrame; } else { - for (size_t i = 0; i < count; ++i) buffer[i] = 0.f; + for (int i = 0; i < count; ++i) buffer[i] = 0.f; if (count <= m_startFrame - start) { return 0; } else { @@ -207,7 +207,7 @@ } if (!m_reader || !m_reader->isOK() || count == 0) { - for (size_t i = 0; i < count; ++i) buffer[i] = 0.f; + for (int i = 0; i < count; ++i) buffer[i] = 0.f; return 0; } @@ -221,7 +221,7 @@ SampleBlock frames(count * channels); m_reader->getInterleavedFrames(start, count, frames); - size_t i = 0; + int i = 0; int ch0 = channel, ch1 = channel; if (channel == -1) { @@ -235,8 +235,8 @@ for (int ch = ch0; ch <= ch1; ++ch) { - size_t index = i * channels + ch; - if (index >= frames.size()) break; + int index = i * channels + ch; + if (index >= (int)frames.size()) break; float sample = frames[index]; buffer[i] += sample; @@ -248,8 +248,8 @@ return i; } -size_t -WaveFileModel::getData(int channel, size_t start, size_t count, +int +WaveFileModel::getData(int channel, int start, int count, double *buffer) const { #ifdef DEBUG_WAVE_FILE_MODEL @@ -259,7 +259,7 @@ if (start > m_startFrame) { start -= m_startFrame; } else { - for (size_t i = 0; i < count; ++i) buffer[i] = 0.0; + for (int i = 0; i < count; ++i) buffer[i] = 0.0; if (count <= m_startFrame - start) { return 0; } else { @@ -269,7 +269,7 @@ } if (!m_reader || !m_reader->isOK() || count == 0) { - for (size_t i = 0; i < count; ++i) buffer[i] = 0.0; + for (int i = 0; i < count; ++i) buffer[i] = 0.0; return 0; } @@ -278,7 +278,7 @@ SampleBlock frames(count * channels); m_reader->getInterleavedFrames(start, count, frames); - size_t i = 0; + int i = 0; int ch0 = channel, ch1 = channel; if (channel == -1) { @@ -292,8 +292,8 @@ for (int ch = ch0; ch <= ch1; ++ch) { - size_t index = i * channels + ch; - if (index >= frames.size()) break; + int index = i * channels + ch; + if (index >= (int)frames.size()) break; float sample = frames[index]; buffer[i] += sample; @@ -305,16 +305,16 @@ return i; } -size_t -WaveFileModel::getData(size_t fromchannel, size_t tochannel, - size_t start, size_t count, +int +WaveFileModel::getData(int fromchannel, int tochannel, + int start, int count, float **buffer) const { #ifdef DEBUG_WAVE_FILE_MODEL cout << "WaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << ", " << buffer << endl; #endif - size_t channels = getChannelCount(); + int channels = getChannelCount(); if (fromchannel > tochannel) { cerr << "ERROR: WaveFileModel::getData: fromchannel (" @@ -334,7 +334,7 @@ return getData(fromchannel, start, count, buffer[0]); } - size_t reqchannels = (tochannel - fromchannel) + 1; + int reqchannels = (tochannel - fromchannel) + 1; // Always read these directly from the file. // This is used for e.g. audio playback. @@ -343,8 +343,8 @@ if (start >= m_startFrame) { start -= m_startFrame; } else { - for (size_t c = 0; c < reqchannels; ++c) { - for (size_t i = 0; i < count; ++i) buffer[c][i] = 0.f; + for (int c = 0; c < reqchannels; ++c) { + for (int i = 0; i < count; ++i) buffer[c][i] = 0.f; } if (count <= m_startFrame - start) { return 0; @@ -355,8 +355,8 @@ } if (!m_reader || !m_reader->isOK() || count == 0) { - for (size_t c = 0; c < reqchannels; ++c) { - for (size_t i = 0; i < count; ++i) buffer[c][i] = 0.f; + for (int c = 0; c < reqchannels; ++c) { + for (int i = 0; i < count; ++i) buffer[c][i] = 0.f; } return 0; } @@ -364,19 +364,17 @@ SampleBlock frames(count * channels); m_reader->getInterleavedFrames(start, count, frames); - size_t i = 0; + int i = 0; - int ch0 = fromchannel, ch1 = tochannel; - - size_t index = 0, available = frames.size(); + int index = 0, available = frames.size(); while (i < count) { if (index >= available) break; - size_t destc = 0; + int destc = 0; - for (size_t c = 0; c < channels; ++c) { + for (int c = 0; c < channels; ++c) { if (c >= fromchannel && c <= tochannel) { buffer[destc][i] = frames[index]; @@ -392,12 +390,12 @@ return i; } -size_t -WaveFileModel::getSummaryBlockSize(size_t desired) const +int +WaveFileModel::getSummaryBlockSize(int desired) const { int cacheType = 0; int power = m_zoomConstraint.getMinCachePower(); - size_t roundedBlockSize = m_zoomConstraint.getNearestBlockSize + int roundedBlockSize = m_zoomConstraint.getNearestBlockSize (desired, cacheType, power, ZoomConstraint::RoundDown); if (cacheType != 0 && cacheType != 1) { // We will be reading directly from file, so can satisfy any @@ -409,8 +407,8 @@ } void -WaveFileModel::getSummaries(size_t channel, size_t start, size_t count, - RangeBlock &ranges, size_t &blockSize) const +WaveFileModel::getSummaries(int channel, int start, int count, + RangeBlock &ranges, int &blockSize) const { ranges.clear(); if (!isOK()) return; @@ -425,10 +423,10 @@ int cacheType = 0; int power = m_zoomConstraint.getMinCachePower(); - size_t roundedBlockSize = m_zoomConstraint.getNearestBlockSize + int roundedBlockSize = m_zoomConstraint.getNearestBlockSize (blockSize, cacheType, power, ZoomConstraint::RoundDown); - size_t channels = getChannelCount(); + int channels = getChannelCount(); if (cacheType != 0 && cacheType != 1) { @@ -452,12 +450,12 @@ } float max = 0.0, min = 0.0, total = 0.0; - size_t i = 0, got = 0; + int i = 0, got = 0; while (i < count) { - size_t index = i * channels + channel; - if (index >= m_directRead.size()) break; + int index = i * channels + channel; + if (index >= (int)m_directRead.size()) break; float sample = m_directRead[index]; if (sample > max || got == 0) max = sample; @@ -490,7 +488,7 @@ blockSize = roundedBlockSize; - size_t cacheBlock, div; + int cacheBlock, div; if (cacheType == 0) { cacheBlock = (1 << m_zoomConstraint.getMinCachePower()); @@ -500,11 +498,11 @@ div = ((unsigned int)((1 << power) * sqrt(2.) + 0.01)) / cacheBlock; } - size_t startIndex = start / cacheBlock; - size_t endIndex = (start + count) / cacheBlock; + int startIndex = start / cacheBlock; + int endIndex = (start + count) / cacheBlock; float max = 0.0, min = 0.0, total = 0.0; - size_t i = 0, got = 0; + int i = 0, got = 0; #ifdef DEBUG_WAVE_FILE_MODEL cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; @@ -512,8 +510,8 @@ for (i = 0; i <= endIndex - startIndex; ) { - size_t index = (i + startIndex) * channels + channel; - if (index >= cache.size()) break; + int index = (i + startIndex) * channels + channel; + if (index >= (int)cache.size()) break; const Range &range = cache[index]; if (range.max() > max || got == 0) max = range.max(); @@ -542,7 +540,7 @@ } WaveFileModel::Range -WaveFileModel::getSummary(size_t channel, size_t start, size_t count) const +WaveFileModel::getSummary(int channel, int start, int count) const { Range range; if (!isOK()) return range; @@ -554,21 +552,21 @@ start = 0; } - size_t blockSize; + int blockSize; for (blockSize = 1; blockSize <= count; blockSize *= 2); if (blockSize > 1) blockSize /= 2; bool first = false; - size_t blockStart = (start / blockSize) * blockSize; - size_t blockEnd = ((start + count) / blockSize) * blockSize; + int blockStart = (start / blockSize) * blockSize; + int blockEnd = ((start + count) / blockSize) * blockSize; if (blockStart < start) blockStart += blockSize; if (blockEnd > blockStart) { RangeBlock ranges; getSummaries(channel, blockStart, blockEnd - blockStart, ranges, blockSize); - for (size_t i = 0; i < ranges.size(); ++i) { + for (int i = 0; i < (int)ranges.size(); ++i) { if (first || ranges[i].min() < range.min()) range.setMin(ranges[i].min()); if (first || ranges[i].max() > range.max()) range.setMax(ranges[i].max()); if (first || ranges[i].absmean() < range.absmean()) range.setAbsmean(ranges[i].absmean()); @@ -617,12 +615,12 @@ WaveFileModel::fillTimerTimedOut() { if (m_fillThread) { - size_t fillExtent = m_fillThread->getFillExtent(); + int fillExtent = m_fillThread->getFillExtent(); #ifdef DEBUG_WAVE_FILE_MODEL SVDEBUG << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; #endif if (fillExtent > m_lastFillExtent) { - emit modelChanged(m_lastFillExtent, fillExtent); + emit modelChangedWithin(m_lastFillExtent, fillExtent); m_lastFillExtent = fillExtent; } } else { @@ -643,7 +641,7 @@ m_updateTimer = 0; m_mutex.unlock(); if (getEndFrame() > m_lastFillExtent) { - emit modelChanged(m_lastFillExtent, getEndFrame()); + emit modelChangedWithin(m_lastFillExtent, getEndFrame()); } emit modelChanged(); emit ready(); @@ -655,18 +653,18 @@ void WaveFileModel::RangeCacheFillThread::run() { - size_t cacheBlockSize[2]; + int cacheBlockSize[2]; cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01)); - size_t frame = 0; + int frame = 0; int readBlockSize = 16384; SampleBlock block; if (!m_model.isOK()) return; - size_t channels = m_model.getChannelCount(); + int channels = m_model.getChannelCount(); bool updating = m_model.m_reader->isUpdating(); if (updating) { @@ -679,7 +677,7 @@ Range *range = new Range[2 * channels]; float *means = new float[2 * channels]; - size_t count[2]; + int count[2]; count[0] = count[1] = 0; for (int i = 0; i < 2 * channels; ++i) { means[i] = 0.f; @@ -706,7 +704,7 @@ for (int i = 0; i < readBlockSize; ++i) { - if (channels * i + channels > block.size()) break; + if (channels * i + channels > (int)block.size()) break; for (int ch = 0; ch < channels; ++ch) { @@ -730,12 +728,12 @@ QMutexLocker locker(&m_model.m_mutex); - for (size_t ct = 0; ct < 2; ++ct) { + for (int ct = 0; ct < 2; ++ct) { if (++count[ct] == cacheBlockSize[ct]) { - for (size_t ch = 0; ch < size_t(channels); ++ch) { - size_t rangeIndex = ch * 2 + ct; + for (int ch = 0; ch < int(channels); ++ch) { + int rangeIndex = ch * 2 + ct; means[rangeIndex] /= count[ct]; range[rangeIndex].setAbsmean(means[rangeIndex]); m_model.m_cache[ct].push_back(range[rangeIndex]); @@ -769,12 +767,12 @@ QMutexLocker locker(&m_model.m_mutex); - for (size_t ct = 0; ct < 2; ++ct) { + for (int ct = 0; ct < 2; ++ct) { if (count[ct] > 0) { - for (size_t ch = 0; ch < size_t(channels); ++ch) { - size_t rangeIndex = ch * 2 + ct; + for (int ch = 0; ch < int(channels); ++ch) { + int rangeIndex = ch * 2 + ct; means[rangeIndex] /= count[ct]; range[rangeIndex].setAbsmean(means[rangeIndex]); m_model.m_cache[ct].push_back(range[rangeIndex]); @@ -796,7 +794,7 @@ m_fillExtent = m_frameCount; #ifdef DEBUG_WAVE_FILE_MODEL - for (size_t ct = 0; ct < 2; ++ct) { + for (int ct = 0; ct < 2; ++ct) { cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; } #endif