Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 410:9c7ebf2cd956
* Halve space requirements for range (waveform peak) caches
author | Chris Cannam |
---|---|
date | Fri, 16 May 2008 13:27:07 +0000 |
parents | 183ee2a55fc7 |
children | 52303ec15cd2 |
comparison
equal
deleted
inserted
replaced
409:6075c90744d4 | 410:9c7ebf2cd956 |
---|---|
500 | 500 |
501 size_t index = (i + startIndex) * channels + channel; | 501 size_t index = (i + startIndex) * channels + channel; |
502 if (index >= cache.size()) break; | 502 if (index >= cache.size()) break; |
503 | 503 |
504 const Range &range = cache[index]; | 504 const Range &range = cache[index]; |
505 if (range.max > max || got == 0) max = range.max; | 505 if (range.max() > max || got == 0) max = range.max(); |
506 if (range.min < min || got == 0) min = range.min; | 506 if (range.min() < min || got == 0) min = range.min(); |
507 total += range.absmean; | 507 total += range.absmean(); |
508 | 508 |
509 ++i; | 509 ++i; |
510 ++got; | 510 ++got; |
511 | 511 |
512 if (got == div) { | 512 if (got == div) { |
553 | 553 |
554 if (blockEnd > blockStart) { | 554 if (blockEnd > blockStart) { |
555 RangeBlock ranges; | 555 RangeBlock ranges; |
556 getSummaries(channel, blockStart, blockEnd - blockStart, ranges, blockSize); | 556 getSummaries(channel, blockStart, blockEnd - blockStart, ranges, blockSize); |
557 for (size_t i = 0; i < ranges.size(); ++i) { | 557 for (size_t i = 0; i < ranges.size(); ++i) { |
558 if (first || ranges[i].min < range.min) range.min = ranges[i].min; | 558 if (first || ranges[i].min() < range.min()) range.setMin(ranges[i].min()); |
559 if (first || ranges[i].max > range.max) range.max = ranges[i].max; | 559 if (first || ranges[i].max() > range.max()) range.setMax(ranges[i].max()); |
560 if (first || ranges[i].absmean < range.absmean) range.absmean = ranges[i].absmean; | 560 if (first || ranges[i].absmean() < range.absmean()) range.setAbsmean(ranges[i].absmean()); |
561 first = false; | 561 first = false; |
562 } | 562 } |
563 } | 563 } |
564 | 564 |
565 if (blockStart > start) { | 565 if (blockStart > start) { |
566 Range startRange = getSummary(channel, start, blockStart - start); | 566 Range startRange = getSummary(channel, start, blockStart - start); |
567 range.min = std::min(range.min, startRange.min); | 567 range.setMin(std::min(range.min(), startRange.min())); |
568 range.max = std::max(range.max, startRange.max); | 568 range.setMax(std::max(range.max(), startRange.max())); |
569 range.absmean = std::min(range.absmean, startRange.absmean); | 569 range.setAbsmean(std::min(range.absmean(), startRange.absmean())); |
570 } | 570 } |
571 | 571 |
572 if (blockEnd < start + count) { | 572 if (blockEnd < start + count) { |
573 Range endRange = getSummary(channel, blockEnd, start + count - blockEnd); | 573 Range endRange = getSummary(channel, blockEnd, start + count - blockEnd); |
574 range.min = std::min(range.min, endRange.min); | 574 range.setMin(std::min(range.min(), endRange.min())); |
575 range.max = std::max(range.max, endRange.max); | 575 range.setMax(std::max(range.max(), endRange.max())); |
576 range.absmean = std::min(range.absmean, endRange.absmean); | 576 range.setAbsmean(std::min(range.absmean(), endRange.absmean())); |
577 } | 577 } |
578 | 578 |
579 return range; | 579 return range; |
580 } | 580 } |
581 | 581 |
661 channels = m_model.getChannelCount(); | 661 channels = m_model.getChannelCount(); |
662 } | 662 } |
663 } | 663 } |
664 | 664 |
665 Range *range = new Range[2 * channels]; | 665 Range *range = new Range[2 * channels]; |
666 float *means = new float[2 * channels]; | |
666 size_t count[2]; | 667 size_t count[2]; |
667 count[0] = count[1] = 0; | 668 count[0] = count[1] = 0; |
668 | 669 |
669 bool first = true; | 670 bool first = true; |
670 | 671 |
696 | 697 |
697 for (size_t ct = 0; ct < 2; ++ct) { // cache type | 698 for (size_t ct = 0; ct < 2; ++ct) { // cache type |
698 | 699 |
699 size_t rangeIndex = ch * 2 + ct; | 700 size_t rangeIndex = ch * 2 + ct; |
700 | 701 |
701 if (sample > range[rangeIndex].max || count[ct] == 0) { | 702 if (sample > range[rangeIndex].max() || count[ct] == 0) { |
702 range[rangeIndex].max = sample; | 703 range[rangeIndex].setMax(sample); |
703 } | 704 } |
704 if (sample < range[rangeIndex].min || count[ct] == 0) { | 705 if (sample < range[rangeIndex].min() || count[ct] == 0) { |
705 range[rangeIndex].min = sample; | 706 range[rangeIndex].setMin(sample); |
706 } | 707 } |
707 range[rangeIndex].absmean += fabsf(sample); | 708 |
709 means[rangeIndex] += fabsf(sample); | |
708 } | 710 } |
709 } | 711 } |
710 | 712 |
711 QMutexLocker locker(&m_model.m_mutex); | 713 QMutexLocker locker(&m_model.m_mutex); |
712 | 714 |
713 for (size_t ct = 0; ct < 2; ++ct) { | 715 for (size_t ct = 0; ct < 2; ++ct) { |
714 | 716 |
715 if (++count[ct] == cacheBlockSize[ct]) { | 717 if (++count[ct] == cacheBlockSize[ct]) { |
716 | 718 |
717 for (size_t ch = 0; ch < size_t(channels); ++ch) { | 719 for (size_t ch = 0; ch < size_t(channels); ++ch) { |
718 size_t rangeIndex = ch * 2 + ct; | 720 size_t rangeIndex = ch * 2 + ct; |
719 range[rangeIndex].absmean /= count[ct]; | 721 means[rangeIndex] /= count[ct]; |
722 range[rangeIndex].setAbsmean(means[rangeIndex]); | |
720 m_model.m_cache[ct].push_back(range[rangeIndex]); | 723 m_model.m_cache[ct].push_back(range[rangeIndex]); |
721 range[rangeIndex] = Range(); | 724 range[rangeIndex] = Range(); |
722 } | 725 } |
723 | 726 |
724 count[ct] = 0; | 727 count[ct] = 0; |
751 | 754 |
752 if (count[ct] > 0) { | 755 if (count[ct] > 0) { |
753 | 756 |
754 for (size_t ch = 0; ch < size_t(channels); ++ch) { | 757 for (size_t ch = 0; ch < size_t(channels); ++ch) { |
755 size_t rangeIndex = ch * 2 + ct; | 758 size_t rangeIndex = ch * 2 + ct; |
756 range[rangeIndex].absmean /= count[ct]; | 759 means[rangeIndex] /= count[ct]; |
760 range[rangeIndex].setAbsmean(means[rangeIndex]); | |
757 m_model.m_cache[ct].push_back(range[rangeIndex]); | 761 m_model.m_cache[ct].push_back(range[rangeIndex]); |
758 range[rangeIndex] = Range(); | 762 range[rangeIndex] = Range(); |
759 } | 763 } |
760 | 764 |
761 count[ct] = 0; | 765 count[ct] = 0; |
764 const Range &rr = *m_model.m_cache[ct].begin(); | 768 const Range &rr = *m_model.m_cache[ct].begin(); |
765 MUNLOCK(&rr, m_model.m_cache[ct].capacity() * sizeof(Range)); | 769 MUNLOCK(&rr, m_model.m_cache[ct].capacity() * sizeof(Range)); |
766 } | 770 } |
767 } | 771 } |
768 | 772 |
773 delete[] means; | |
769 delete[] range; | 774 delete[] range; |
770 | 775 |
771 m_fillExtent = m_frameCount; | 776 m_fillExtent = m_frameCount; |
772 | 777 |
773 #ifdef DEBUG_WAVE_FILE_MODEL | 778 #ifdef DEBUG_WAVE_FILE_MODEL |