diff data/model/WaveFileModel.cpp @ 232:03a24547cf3c

* Fix crash in short spectrogram paint * Fix incorrect apparent end point for waveforms
author Chris Cannam
date Wed, 14 Feb 2007 17:52:06 +0000
parents 185454896a76
children 3e6fee4e4257
line wrap: on
line diff
--- a/data/model/WaveFileModel.cpp	Mon Feb 12 18:15:49 2007 +0000
+++ b/data/model/WaveFileModel.cpp	Wed Feb 14 17:52:06 2007 +0000
@@ -300,7 +300,7 @@
 	float max = 0.0, min = 0.0, total = 0.0;
 	size_t i = 0, count = 0;
 
-	//cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", end " << end << ", power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
+	cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", end " << end << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
 
 	for (i = 0; i < endIndex - startIndex; ) {
         
@@ -327,7 +327,7 @@
 	}
     }
 
-    //cerr << "returning " << ranges.size() << " ranges" << endl;
+    cerr << "returning " << ranges.size() << " ranges" << endl;
     return;
 }
 
@@ -474,13 +474,14 @@
 
             for (size_t i = 0; i < readBlockSize; ++i) {
 		
+                if (channels * i + channels > block.size()) break;
+
                 for (size_t ch = 0; ch < size_t(channels); ++ch) {
 
                     size_t index = channels * i + ch;
-                    if (index >= block.size()) continue;
                     float sample = block[index];
                     
-                    for (size_t ct = 0; ct < 2; ++ct) {
+                    for (size_t ct = 0; ct < 2; ++ct) { // cache type
                         
                         size_t rangeIndex = ch * 2 + ct;
                         
@@ -495,14 +496,18 @@
                 }
                 
                 QMutexLocker locker(&m_model.m_mutex);
+
                 for (size_t 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;
                             range[rangeIndex].absmean /= count[ct];
                             m_model.m_cache[ct].push_back(range[rangeIndex]);
                             range[rangeIndex] = Range();
                         }
+
                         count[ct] = 0;
                     }
                 }
@@ -525,14 +530,18 @@
     if (!m_model.m_exiting) {
 
         QMutexLocker locker(&m_model.m_mutex);
+
         for (size_t 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;
                     range[rangeIndex].absmean /= count[ct];
                     m_model.m_cache[ct].push_back(range[rangeIndex]);
                     range[rangeIndex] = Range();
                 }
+
                 count[ct] = 0;
             }