diff data/model/WaveFileModel.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 36f79bc5c3d7
children a1cd5abcb38b
line wrap: on
line diff
--- a/data/model/WaveFileModel.cpp	Tue Mar 03 09:33:59 2015 +0000
+++ b/data/model/WaveFileModel.cpp	Tue Mar 03 15:18:24 2015 +0000
@@ -131,7 +131,7 @@
     return model;
 }
 
-int
+sv_frame_t
 WaveFileModel::getFrameCount() const
 {
     if (!m_reader) return 0;
@@ -191,8 +191,8 @@
     return "";
 }
     
-int
-WaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                        float *buffer) const
 {
     // Always read these directly from the file. 
@@ -206,7 +206,7 @@
     if (start >= m_startFrame) {
         start -= m_startFrame;
     } else {
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             buffer[i] = 0.f;
         }
         if (count <= m_startFrame - start) {
@@ -218,7 +218,7 @@
     }
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.f;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.f;
         return 0;
     }
 
@@ -232,7 +232,7 @@
     SampleBlock frames(count * channels);
     m_reader->getInterleavedFrames(start, count, frames);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
     int ch0 = channel, ch1 = channel;
     if (channel == -1) {
@@ -246,8 +246,8 @@
 
 	for (int ch = ch0; ch <= ch1; ++ch) {
 
-	    int index = i * channels + ch;
-	    if (index >= (int)frames.size()) break;
+	    sv_frame_t index = i * channels + ch;
+	    if (index >= (sv_frame_t)frames.size()) break;
             
 	    float sample = frames[index];
 	    buffer[i] += sample;
@@ -259,8 +259,8 @@
     return i;
 }
 
-int
-WaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                        double *buffer) const
 {
 #ifdef DEBUG_WAVE_FILE_MODEL
@@ -270,7 +270,7 @@
     if (start > m_startFrame) {
         start -= m_startFrame;
     } else {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.0;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0;
         if (count <= m_startFrame - start) {
             return 0;
         } else {
@@ -280,7 +280,7 @@
     }
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.0;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0;
         return 0;
     }
 
@@ -289,7 +289,7 @@
     SampleBlock frames(count * channels);
     m_reader->getInterleavedFrames(start, count, frames);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
     int ch0 = channel, ch1 = channel;
     if (channel == -1) {
@@ -303,8 +303,8 @@
 
 	for (int ch = ch0; ch <= ch1; ++ch) {
 
-	    int index = i * channels + ch;
-	    if (index >= (int)frames.size()) break;
+	    sv_frame_t index = i * channels + ch;
+	    if (index >= (sv_frame_t)frames.size()) break;
             
 	    float sample = frames[index];
 	    buffer[i] += sample;
@@ -316,9 +316,9 @@
     return i;
 }
 
-int
+sv_frame_t
 WaveFileModel::getData(int fromchannel, int tochannel,
-                       int start, int count,
+                       sv_frame_t start, sv_frame_t count,
                        float **buffer) const
 {
 #ifdef DEBUG_WAVE_FILE_MODEL
@@ -355,7 +355,7 @@
         start -= m_startFrame;
     } else {
         for (int c = 0; c < reqchannels; ++c) {
-            for (int i = 0; i < count; ++i) buffer[c][i] = 0.f;
+            for (sv_frame_t i = 0; i < count; ++i) buffer[c][i] = 0.f;
         }
         if (count <= m_startFrame - start) {
             return 0;
@@ -367,7 +367,7 @@
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
         for (int c = 0; c < reqchannels; ++c) {
-            for (int i = 0; i < count; ++i) buffer[c][i] = 0.f;
+            for (sv_frame_t i = 0; i < count; ++i) buffer[c][i] = 0.f;
         }
         return 0;
     }
@@ -375,9 +375,9 @@
     SampleBlock frames(count * channels);
     m_reader->getInterleavedFrames(start, count, frames);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
-    int index = 0, available = frames.size();
+    sv_frame_t index = 0, available = frames.size();
 
     while (i < count) {
 
@@ -418,7 +418,7 @@
 }    
 
 void
-WaveFileModel::getSummaries(int channel, int start, int count,
+WaveFileModel::getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                             RangeBlock &ranges, int &blockSize) const
 {
     ranges.clear();
@@ -461,12 +461,12 @@
         }
 
 	float max = 0.0, min = 0.0, total = 0.0;
-	int i = 0, got = 0;
+	sv_frame_t i = 0, got = 0;
 
 	while (i < count) {
 
-	    int index = i * channels + channel;
-	    if (index >= (int)m_directRead.size()) break;
+	    sv_frame_t index = i * channels + channel;
+	    if (index >= (sv_frame_t)m_directRead.size()) break;
             
 	    float sample = m_directRead[index];
             if (sample > max || got == 0) max = sample;
@@ -477,7 +477,7 @@
             ++got;
             
             if (got == blockSize) {
-                ranges.push_back(Range(min, max, total / got));
+                ranges.push_back(Range(min, max, total / float(got)));
                 min = max = total = 0.0f;
                 got = 0;
 	    }
@@ -486,7 +486,7 @@
         m_directReadMutex.unlock();
 
 	if (got > 0) {
-            ranges.push_back(Range(min, max, total / got));
+            ranges.push_back(Range(min, max, total / float(got)));
 	}
 
 	return;
@@ -499,21 +499,21 @@
 
         blockSize = roundedBlockSize;
 
-	int cacheBlock, div;
+	sv_frame_t cacheBlock, div;
         
 	if (cacheType == 0) {
 	    cacheBlock = (1 << m_zoomConstraint.getMinCachePower());
             div = (1 << power) / cacheBlock;
 	} else {
-	    cacheBlock = ((unsigned int)((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01));
-            div = ((unsigned int)((1 << power) * sqrt(2.) + 0.01)) / cacheBlock;
+	    cacheBlock = sv_frame_t((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01);
+            div = sv_frame_t(((1 << power) * sqrt(2.) + 0.01) / double(cacheBlock));
 	}
 
-	int startIndex = start / cacheBlock;
-	int endIndex = (start + count) / cacheBlock;
+	sv_frame_t startIndex = start / cacheBlock;
+	sv_frame_t endIndex = (start + count) / cacheBlock;
 
 	float max = 0.0, min = 0.0, total = 0.0;
-	int i = 0, got = 0;
+	sv_frame_t i = 0, got = 0;
 
 #ifdef DEBUG_WAVE_FILE_MODEL
 	cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
@@ -521,8 +521,8 @@
 
 	for (i = 0; i <= endIndex - startIndex; ) {
         
-	    int index = (i + startIndex) * channels + channel;
-	    if (index >= (int)cache.size()) break;
+	    sv_frame_t index = (i + startIndex) * channels + channel;
+	    if (index >= (sv_frame_t)cache.size()) break;
             
             const Range &range = cache[index];
             if (range.max() > max || got == 0) max = range.max();
@@ -533,14 +533,14 @@
             ++got;
             
 	    if (got == div) {
-		ranges.push_back(Range(min, max, total / got));
+		ranges.push_back(Range(min, max, total / float(got)));
                 min = max = total = 0.0f;
                 got = 0;
 	    }
 	}
 		
 	if (got > 0) {
-            ranges.push_back(Range(min, max, total / got));
+            ranges.push_back(Range(min, max, total / float(got)));
 	}
     }
 
@@ -551,7 +551,7 @@
 }
 
 WaveFileModel::Range
-WaveFileModel::getSummary(int channel, int start, int count) const
+WaveFileModel::getSummary(int channel, sv_frame_t start, sv_frame_t count) const
 {
     Range range;
     if (!isOK()) return range;
@@ -569,8 +569,8 @@
 
     bool first = false;
 
-    int blockStart = (start / blockSize) * blockSize;
-    int blockEnd = ((start + count) / blockSize) * blockSize;
+    sv_frame_t blockStart = (start / blockSize) * blockSize;
+    sv_frame_t blockEnd = ((start + count) / blockSize) * blockSize;
 
     if (blockStart < start) blockStart += blockSize;
         
@@ -626,7 +626,7 @@
 WaveFileModel::fillTimerTimedOut()
 {
     if (m_fillThread) {
-	int fillExtent = m_fillThread->getFillExtent();
+	sv_frame_t fillExtent = m_fillThread->getFillExtent();
 #ifdef DEBUG_WAVE_FILE_MODEL
         SVDEBUG << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl;
 #endif
@@ -666,11 +666,11 @@
 {
     int cacheBlockSize[2];
     cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower());
-    cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) *
+    cacheBlockSize[1] = (int((1 << m_model.m_zoomConstraint.getMinCachePower()) *
                                         sqrt(2.) + 0.01));
     
-    int frame = 0;
-    int readBlockSize = 16384;
+    sv_frame_t frame = 0;
+    sv_frame_t readBlockSize = 16384;
     SampleBlock block;
 
     if (!m_model.isOK()) return;
@@ -713,18 +713,18 @@
 
 //            cerr << "block is " << block.size() << endl;
 
-            for (int i = 0; i < readBlockSize; ++i) {
+            for (sv_frame_t i = 0; i < readBlockSize; ++i) {
 		
                 if (channels * i + channels > (int)block.size()) break;
 
                 for (int ch = 0; ch < channels; ++ch) {
 
-                    int index = channels * i + ch;
+                    sv_frame_t index = channels * i + ch;
                     float sample = block[index];
                     
                     for (int ct = 0; ct < 2; ++ct) { // cache type
                         
-                        int rangeIndex = ch * 2 + ct;
+                        sv_frame_t rangeIndex = ch * 2 + ct;
                         
                         if (sample > range[rangeIndex].max() || count[ct] == 0) {
                             range[rangeIndex].setMax(sample);
@@ -745,7 +745,7 @@
                         
                         for (int ch = 0; ch < int(channels); ++ch) {
                             int rangeIndex = ch * 2 + ct;
-                            means[rangeIndex] /= count[ct];
+                            means[rangeIndex] = means[rangeIndex] / float(count[ct]);
                             range[rangeIndex].setAbsmean(means[rangeIndex]);
                             m_model.m_cache[ct].push_back(range[rangeIndex]);
                             range[rangeIndex] = Range();
@@ -784,7 +784,7 @@
 
                 for (int ch = 0; ch < int(channels); ++ch) {
                     int rangeIndex = ch * 2 + ct;
-                    means[rangeIndex] /= count[ct];
+                    means[rangeIndex] = means[rangeIndex] / float(count[ct]);
                     range[rangeIndex].setAbsmean(means[rangeIndex]);
                     m_model.m_cache[ct].push_back(range[rangeIndex]);
                     range[rangeIndex] = Range();