comparison data/model/WaveFileModel.cpp @ 1053:48e4ffa9fb48 cxx11

Minor simplification; could use more
author Chris Cannam
date Wed, 11 Mar 2015 11:52:05 +0000
parents 16dc7307d43a
children 0fd3661bcfff
comparison
equal deleted inserted replaced
1052:e603b44510c3 1053:48e4ffa9fb48
665 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); 665 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower());
666 cacheBlockSize[1] = (int((1 << m_model.m_zoomConstraint.getMinCachePower()) * 666 cacheBlockSize[1] = (int((1 << m_model.m_zoomConstraint.getMinCachePower()) *
667 sqrt(2.) + 0.01)); 667 sqrt(2.) + 0.01));
668 668
669 sv_frame_t frame = 0; 669 sv_frame_t frame = 0;
670 sv_frame_t readBlockSize = 16384; 670 const sv_frame_t readBlockSize = 16384;
671 SampleBlock block; 671 SampleBlock block;
672 672
673 if (!m_model.isOK()) return; 673 if (!m_model.isOK()) return;
674 674
675 int channels = m_model.getChannelCount(); 675 int channels = m_model.getChannelCount();
717 for (int ch = 0; ch < channels; ++ch) { 717 for (int ch = 0; ch < channels; ++ch) {
718 718
719 sv_frame_t index = channels * i + ch; 719 sv_frame_t index = channels * i + ch;
720 float sample = block[index]; 720 float sample = block[index];
721 721
722 for (int ct = 0; ct < 2; ++ct) { // cache type 722 for (int cacheType = 0; cacheType < 2; ++cacheType) { // cache type
723 723
724 sv_frame_t rangeIndex = ch * 2 + ct; 724 sv_frame_t rangeIndex = ch * 2 + cacheType;
725 725 range[rangeIndex].sample(sample);
726 if (sample > range[rangeIndex].max() || count[ct] == 0) {
727 range[rangeIndex].setMax(sample);
728 }
729 if (sample < range[rangeIndex].min() || count[ct] == 0) {
730 range[rangeIndex].setMin(sample);
731 }
732
733 means[rangeIndex] += fabsf(sample); 726 means[rangeIndex] += fabsf(sample);
734 } 727 }
735 } 728 }
736 729
737 //!!! this looks like a ludicrous way to do synchronisation 730 //!!! this looks like a ludicrous way to do synchronisation
738 QMutexLocker locker(&m_model.m_mutex); 731 QMutexLocker locker(&m_model.m_mutex);
739 732
740 for (int ct = 0; ct < 2; ++ct) { 733 for (int cacheType = 0; cacheType < 2; ++cacheType) {
741 734
742 if (++count[ct] == cacheBlockSize[ct]) { 735 if (++count[cacheType] == cacheBlockSize[cacheType]) {
743 736
744 for (int ch = 0; ch < int(channels); ++ch) { 737 for (int ch = 0; ch < int(channels); ++ch) {
745 int rangeIndex = ch * 2 + ct; 738 int rangeIndex = ch * 2 + cacheType;
746 means[rangeIndex] = means[rangeIndex] / float(count[ct]); 739 means[rangeIndex] = means[rangeIndex] / float(count[cacheType]);
747 range[rangeIndex].setAbsmean(means[rangeIndex]); 740 range[rangeIndex].setAbsmean(means[rangeIndex]);
748 m_model.m_cache[ct].push_back(range[rangeIndex]); 741 m_model.m_cache[cacheType].push_back(range[rangeIndex]);
749 range[rangeIndex] = Range(); 742 range[rangeIndex] = Range();
750 means[rangeIndex] = 0.f; 743 means[rangeIndex] = 0.f;
751 } 744 }
752 745
753 count[ct] = 0; 746 count[cacheType] = 0;
754 } 747 }
755 } 748 }
756 749
757 ++frame; 750 ++frame;
758 } 751 }
774 767
775 if (!m_model.m_exiting) { 768 if (!m_model.m_exiting) {
776 769
777 QMutexLocker locker(&m_model.m_mutex); 770 QMutexLocker locker(&m_model.m_mutex);
778 771
779 for (int ct = 0; ct < 2; ++ct) { 772 for (int cacheType = 0; cacheType < 2; ++cacheType) {
780 773
781 if (count[ct] > 0) { 774 if (count[cacheType] > 0) {
782 775
783 for (int ch = 0; ch < int(channels); ++ch) { 776 for (int ch = 0; ch < int(channels); ++ch) {
784 int rangeIndex = ch * 2 + ct; 777 int rangeIndex = ch * 2 + cacheType;
785 means[rangeIndex] = means[rangeIndex] / float(count[ct]); 778 means[rangeIndex] = means[rangeIndex] / float(count[cacheType]);
786 range[rangeIndex].setAbsmean(means[rangeIndex]); 779 range[rangeIndex].setAbsmean(means[rangeIndex]);
787 m_model.m_cache[ct].push_back(range[rangeIndex]); 780 m_model.m_cache[cacheType].push_back(range[rangeIndex]);
788 range[rangeIndex] = Range(); 781 range[rangeIndex] = Range();
789 means[rangeIndex] = 0.f; 782 means[rangeIndex] = 0.f;
790 } 783 }
791 784
792 count[ct] = 0; 785 count[cacheType] = 0;
793 } 786 }
794 787
795 const Range &rr = *m_model.m_cache[ct].begin(); 788 const Range &rr = *m_model.m_cache[cacheType].begin();
796 MUNLOCK(&rr, m_model.m_cache[ct].capacity() * sizeof(Range)); 789 MUNLOCK(&rr, m_model.m_cache[cacheType].capacity() * sizeof(Range));
797 } 790 }
798 } 791 }
799 792
800 delete[] means; 793 delete[] means;
801 delete[] range; 794 delete[] range;
802 795
803 m_fillExtent = m_frameCount; 796 m_fillExtent = m_frameCount;
804 797
805 #ifdef DEBUG_WAVE_FILE_MODEL 798 #ifdef DEBUG_WAVE_FILE_MODEL
806 for (int ct = 0; ct < 2; ++ct) { 799 for (int cacheType = 0; cacheType < 2; ++cacheType) {
807 cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; 800 cerr << "Cache type " << cacheType << " now contains " << m_model.m_cache[cacheType].size() << " ranges" << endl;
808 } 801 }
809 #endif 802 #endif
810 } 803 }
811 804
812 void 805 void