changeset 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 0031495aba07
children 0d943a3fcc77
files data/fileio/WavFileReader.cpp data/model/WaveFileModel.cpp system/System.h
diffstat 3 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/WavFileReader.cpp	Mon Feb 12 18:15:49 2007 +0000
+++ b/data/fileio/WavFileReader.cpp	Wed Feb 14 17:52:06 2007 +0000
@@ -151,6 +151,9 @@
     }
 
     for (size_t i = 0; i < count * m_fileInfo.channels; ++i) {
+        if (i >= m_bufsiz) {
+            std::cerr << "INTERNAL ERROR: WavFileReader::getInterleavedFrames: " << i << " >= " << m_bufsiz << std::endl;
+        }
 	results.push_back(m_buffer[i]);
     }
 
--- 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;
             }
             
--- a/system/System.h	Mon Feb 12 18:15:49 2007 +0000
+++ b/system/System.h	Wed Feb 14 17:52:06 2007 +0000
@@ -65,6 +65,9 @@
 #define MLOCK(a,b)   ::mlock((a),(b))
 #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0)
 #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
+//#define MLOCK(a,b)   1
+//#define MUNLOCK(a,b) 1
+//#define MUNLOCK_SAMPLEBLOCK(a) 1
 
 #define DLOPEN(a,b)  dlopen((a).toStdString().c_str(),(b))
 #define DLSYM(a,b)   dlsym((a),(b))