# HG changeset patch # User Chris Cannam # Date 1453466779 0 # Node ID d73b4bac2dc4bd403f97e57d2eeeeaa46176d10e # Parent def42cbba8bc92641b57aa4cf35ebb76f4740301 Fix one-block rounding error when zoomed a long way out, visible as an offset toward the end of very long audio files diff -r def42cbba8bc -r d73b4bac2dc4 data/model/ReadOnlyWaveFileModel.cpp --- a/data/model/ReadOnlyWaveFileModel.cpp Fri Jan 22 09:52:30 2016 +0000 +++ b/data/model/ReadOnlyWaveFileModel.cpp Fri Jan 22 12:46:19 2016 +0000 @@ -403,14 +403,12 @@ blockSize = roundedBlockSize; sv_frame_t cacheBlock, div; - - if (cacheType == 0) { - cacheBlock = (1 << m_zoomConstraint.getMinCachePower()); - div = (1 << power) / cacheBlock; - } else { - cacheBlock = sv_frame_t((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01); - div = sv_frame_t(((1 << power) * sqrt(2.) + 0.01) / double(cacheBlock)); + + cacheBlock = (sv_frame_t(1) << m_zoomConstraint.getMinCachePower()); + if (cacheType == 1) { + cacheBlock = sv_frame_t(double(cacheBlock) * sqrt(2.) + 0.01); } + div = blockSize / cacheBlock; sv_frame_t startIndex = start / cacheBlock; sv_frame_t endIndex = (start + count) / cacheBlock; @@ -425,7 +423,7 @@ for (i = 0; i <= endIndex - startIndex; ) { sv_frame_t index = (i + startIndex) * channels + channel; - if (index >= (sv_frame_t)cache.size()) break; + if (!in_range_for(cache, index)) break; const Range &range = cache[index]; if (range.max() > max || got == 0) max = range.max();