comparison data/model/ReadOnlyWaveFileModel.cpp @ 1152:d73b4bac2dc4 3.0-integration

Fix one-block rounding error when zoomed a long way out, visible as an offset toward the end of very long audio files
author Chris Cannam
date Fri, 22 Jan 2016 12:46:19 +0000
parents def42cbba8bc
children 6b847a59d908
comparison
equal deleted inserted replaced
1151:def42cbba8bc 1152:d73b4bac2dc4
401 const RangeBlock &cache = m_cache[cacheType]; 401 const RangeBlock &cache = m_cache[cacheType];
402 402
403 blockSize = roundedBlockSize; 403 blockSize = roundedBlockSize;
404 404
405 sv_frame_t cacheBlock, div; 405 sv_frame_t cacheBlock, div;
406 406
407 if (cacheType == 0) { 407 cacheBlock = (sv_frame_t(1) << m_zoomConstraint.getMinCachePower());
408 cacheBlock = (1 << m_zoomConstraint.getMinCachePower()); 408 if (cacheType == 1) {
409 div = (1 << power) / cacheBlock; 409 cacheBlock = sv_frame_t(double(cacheBlock) * sqrt(2.) + 0.01);
410 } else {
411 cacheBlock = sv_frame_t((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01);
412 div = sv_frame_t(((1 << power) * sqrt(2.) + 0.01) / double(cacheBlock));
413 } 410 }
411 div = blockSize / cacheBlock;
414 412
415 sv_frame_t startIndex = start / cacheBlock; 413 sv_frame_t startIndex = start / cacheBlock;
416 sv_frame_t endIndex = (start + count) / cacheBlock; 414 sv_frame_t endIndex = (start + count) / cacheBlock;
417 415
418 float max = 0.0, min = 0.0, total = 0.0; 416 float max = 0.0, min = 0.0, total = 0.0;
423 #endif 421 #endif
424 422
425 for (i = 0; i <= endIndex - startIndex; ) { 423 for (i = 0; i <= endIndex - startIndex; ) {
426 424
427 sv_frame_t index = (i + startIndex) * channels + channel; 425 sv_frame_t index = (i + startIndex) * channels + channel;
428 if (index >= (sv_frame_t)cache.size()) break; 426 if (!in_range_for(cache, index)) break;
429 427
430 const Range &range = cache[index]; 428 const Range &range = cache[index];
431 if (range.max() > max || got == 0) max = range.max(); 429 if (range.max() > max || got == 0) max = range.max();
432 if (range.min() < min || got == 0) min = range.min(); 430 if (range.min() < min || got == 0) min = range.min();
433 total += range.absmean(); 431 total += range.absmean();