diff audioio/AudioCallbackPlaySource.cpp @ 436:72c662fe7ea3 cxx11

Further dedicated-types fixes
author Chris Cannam
date Tue, 10 Mar 2015 17:02:52 +0000
parents 618d5816b04d
children aa6fb3516e28
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp	Tue Mar 10 13:22:10 2015 +0000
+++ b/audioio/AudioCallbackPlaySource.cpp	Tue Mar 10 17:02:52 2015 +0000
@@ -306,7 +306,7 @@
 	m_sourceSampleRate = 0;
     }
 
-    int lastEnd = 0;
+    sv_frame_t lastEnd = 0;
     for (std::set<Model *>::const_iterator i = m_models.begin();
 	 i != m_models.end(); ++i) {
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
@@ -367,7 +367,7 @@
     rebuildRangeLists();
 
     if (count == 0) {
-	if (m_writeBuffers) count = m_writeBuffers->size();
+	if (m_writeBuffers) count = int(m_writeBuffers->size());
     }
 
     cerr << "current playing frame = " << getCurrentPlayingFrame() << endl;
@@ -593,7 +593,7 @@
 AudioCallbackPlaySource::getTargetBlockSize() const
 {
 //    cout << "AudioCallbackPlaySource::getTargetBlockSize() -> " << m_blockSize << endl;
-    return m_blockSize;
+    return int(m_blockSize);
 }
 
 void
@@ -614,8 +614,8 @@
     // This method attempts to estimate which audio sample frame is
     // "currently coming through the speakers".
 
-    int targetRate = getTargetSampleRate();
-    int latency = m_playLatency; // at target rate
+    sv_samplerate_t targetRate = getTargetSampleRate();
+    sv_frame_t latency = m_playLatency; // at target rate
     RealTime latency_t = RealTime::zeroTime;
 
     if (targetRate != 0) {
@@ -655,8 +655,8 @@
 	}
     }
 
-    int readBufferFill = m_readBufferFill;
-    int lastRetrievedBlockSize = m_lastRetrievedBlockSize;
+    sv_frame_t readBufferFill = m_readBufferFill;
+    sv_frame_t lastRetrievedBlockSize = m_lastRetrievedBlockSize;
     double lastRetrievalTimestamp = m_lastRetrievalTimestamp;
     double currentTime = 0.0;
     if (m_target) currentTime = m_target->getCurrentTime();
@@ -665,7 +665,7 @@
 
     RealTime inbuffer_t = RealTime::frame2RealTime(inbuffer, targetRate);
 
-    int stretchlat = 0;
+    sv_frame_t stretchlat = 0;
     double timeRatio = 1.0;
 
     if (m_timeStretcher) {
@@ -755,7 +755,9 @@
         ++index;
     }
 
-    if (inRange >= (int)m_rangeStarts.size()) inRange = m_rangeStarts.size()-1;
+    if (inRange >= int(m_rangeStarts.size())) {
+        inRange = int(m_rangeStarts.size())-1;
+    }
 
     RealTime playing_t = bufferedto_t;
 
@@ -806,7 +808,7 @@
 
         if (inRange == 0) {
             if (looping) {
-                inRange = m_rangeStarts.size() - 1;
+                inRange = int(m_rangeStarts.size()) - 1;
             } else {
                 break;
             }
@@ -854,7 +856,7 @@
     m_rangeStarts.clear();
     m_rangeDurations.clear();
 
-    int sourceRate = getSourceSampleRate();
+    sv_samplerate_t sourceRate = getSourceSampleRate();
     if (sourceRate == 0) return;
 
     RealTime end = RealTime::frame2RealTime(m_lastModelEndFrame, sourceRate);
@@ -1060,28 +1062,28 @@
 }
 
 void
-AudioCallbackPlaySource::setTimeStretch(float factor)
+AudioCallbackPlaySource::setTimeStretch(double factor)
 {
     m_stretchRatio = factor;
 
     if (!getTargetSampleRate()) return; // have to make our stretcher later
 
-    if (m_timeStretcher || (factor == 1.f)) {
+    if (m_timeStretcher || (factor == 1.0)) {
         // stretch ratio will be set in next process call if appropriate
     } else {
         m_stretcherInputCount = getTargetChannelCount();
         RubberBandStretcher *stretcher = new RubberBandStretcher
-            (getTargetSampleRate(),
+            (int(getTargetSampleRate()),
              m_stretcherInputCount,
              RubberBandStretcher::OptionProcessRealTime,
              factor);
         RubberBandStretcher *monoStretcher = new RubberBandStretcher
-            (getTargetSampleRate(),
+            (int(getTargetSampleRate()),
              1,
              RubberBandStretcher::OptionProcessRealTime,
              factor);
         m_stretcherInputs = new float *[m_stretcherInputCount];
-        m_stretcherInputSizes = new int[m_stretcherInputCount];
+        m_stretcherInputSizes = new sv_frame_t[m_stretcherInputCount];
         for (int c = 0; c < m_stretcherInputCount; ++c) {
             m_stretcherInputSizes[c] = 16384;
             m_stretcherInputs[c] = new float[m_stretcherInputSizes[c]];
@@ -1146,12 +1148,12 @@
     RubberBandStretcher *ts = m_timeStretcher;
     RubberBandStretcher *ms = m_monoStretcher;
 
-    float ratio = ts ? ts->getTimeRatio() : 1.f;
+    double ratio = ts ? ts->getTimeRatio() : 1.0;
 
     if (ratio != m_stretchRatio) {
         if (!ts) {
             cerr << "WARNING: AudioCallbackPlaySource::getSourceSamples: Time ratio change to " << m_stretchRatio << " is pending, but no stretcher is set" << endl;
-            m_stretchRatio = 1.f;
+            m_stretchRatio = 1.0;
         } else {
             ts->setTimeRatio(m_stretchRatio);
             if (ms) ms->setTimeRatio(m_stretchRatio);
@@ -1186,10 +1188,10 @@
 
 		// this is marginally more likely to leave our channels in
 		// sync after a processing failure than just passing "count":
-		int request = count;
+		sv_frame_t request = count;
 		if (ch > 0) request = got;
 
-		got = rb->read(buffer[ch], request);
+		got = rb->read(buffer[ch], int(request));
 	    
 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING
 		cout << "AudioCallbackPlaySource::getSamples: got " << got << " (of " << count << ") samples on channel " << ch << ", signalling for more (possibly)" << endl;
@@ -1215,20 +1217,20 @@
     }
 
     int channels = getTargetChannelCount();
-    int available;
+    sv_frame_t available;
+    sv_frame_t fedToStretcher = 0;
     int warned = 0;
-    int fedToStretcher = 0;
 
     // The input block for a given output is approx output / ratio,
     // but we can't predict it exactly, for an adaptive timestretcher.
 
     while ((available = ts->available()) < count) {
 
-        int reqd = lrintf((count - available) / ratio);
-        reqd = std::max(reqd, (int)ts->getSamplesRequired());
+        sv_frame_t reqd = lrint(double(count - available) / ratio);
+        reqd = std::max(reqd, sv_frame_t(ts->getSamplesRequired()));
         if (reqd == 0) reqd = 1;
                 
-        int got = reqd;
+        sv_frame_t got = reqd;
 
 #ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING
         cerr << "reqd = " <<reqd << ", channels = " << channels << ", ic = " << m_stretcherInputCount << endl;
@@ -1250,11 +1252,11 @@
             if (c >= m_stretcherInputCount) continue;
             RingBuffer<float> *rb = getReadRingBuffer(c);
             if (rb) {
-                int gotHere;
+                sv_frame_t gotHere;
                 if (stretchChannels == 1 && c > 0) {
-                    gotHere = rb->readAdding(m_stretcherInputs[0], got);
+                    gotHere = rb->readAdding(m_stretcherInputs[0], int(got));
                 } else {
-                    gotHere = rb->read(m_stretcherInputs[c], got);
+                    gotHere = rb->read(m_stretcherInputs[c], int(got));
                 }
                 if (gotHere < got) got = gotHere;
                 
@@ -1341,7 +1343,7 @@
         }
     }
 
-    plugin->run(Vamp::RealTime::zeroTime, count);
+    plugin->run(Vamp::RealTime::zeroTime, int(count));
     
     for (int c = 0; c < getTargetChannelCount(); ++c) {
         for (int i = 0; i < count; ++i) {
@@ -1355,7 +1357,7 @@
 AudioCallbackPlaySource::fillBuffers()
 {
     static float *tmp = 0;
-    static int tmpSize = 0;
+    static sv_frame_t tmpSize = 0;
 
     sv_frame_t space = 0;
     for (int c = 0; c < getTargetChannelCount(); ++c) {
@@ -1408,7 +1410,7 @@
 	bufferPtrCount = channels;
     }
 
-    int generatorBlockSize = m_audioGenerator->getBlockSize();
+    sv_frame_t generatorBlockSize = m_audioGenerator->getBlockSize();
 
     if (resample && !m_converter) {
 	static bool warned = false;
@@ -1422,13 +1424,13 @@
 
 	double ratio =
 	    double(getTargetSampleRate()) / double(getSourceSampleRate());
-	orig = int(orig / ratio + 0.1);
+	orig = sv_frame_t(double(orig) / ratio + 0.1);
 
 	// orig must be a multiple of generatorBlockSize
 	orig = (orig / generatorBlockSize) * generatorBlockSize;
 	if (orig == 0) return false;
 
-	int work = std::max(orig, space);
+	sv_frame_t work = std::max(orig, space);
 
 	// We only allocate one buffer, but we use it in two halves.
 	// We place the non-interleaved values in the second half of
@@ -1490,7 +1492,7 @@
             err = src_process(m_converter, &data);
         }
 
-	int toCopy = int(got * ratio + 0.1);
+	sv_frame_t toCopy = sv_frame_t(double(got) * ratio + 0.1);
 
 	if (err) {
 	    cerr
@@ -1510,7 +1512,7 @@
 		tmp[i] = srcout[channels * i + c];
 	    }
 	    RingBuffer<float> *wb = getWriteRingBuffer(c);
-	    if (wb) wb->write(tmp, toCopy);
+	    if (wb) wb->write(tmp, int(toCopy));
 	}
 
 	m_writeBufferFill = f;
@@ -1519,7 +1521,7 @@
     } else {
 
 	// space must be a multiple of generatorBlockSize
-        int reqSpace = space;
+        sv_frame_t reqSpace = space;
 	space = (reqSpace / generatorBlockSize) * generatorBlockSize;
 	if (space == 0) {
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
@@ -1545,13 +1547,13 @@
 	    }
 	}
 
-	int got = mixModels(f, space, bufferPtrs); // also modifies f
+	sv_frame_t got = mixModels(f, space, bufferPtrs); // also modifies f
 
 	for (int c = 0; c < channels; ++c) {
 
 	    RingBuffer<float> *wb = getWriteRingBuffer(c);
 	    if (wb) {
-                int actual = wb->write(bufferPtrs[c], got);
+                int actual = wb->write(bufferPtrs[c], int(got));
 #ifdef DEBUG_AUDIO_PLAY_SOURCE
 		cout << "Wrote " << actual << " samples for ch " << c << ", now "
 			  << wb->getReadSpace() << " to read" 
@@ -1759,7 +1761,7 @@
 	}
     }
 
-    int rf = m_readBufferFill;
+    sv_frame_t rf = m_readBufferFill;
     RingBuffer<float> *rb = getReadRingBuffer(0);
     if (rb) {
 	int rs = rb->getReadSpace();
@@ -1773,8 +1775,8 @@
     SVDEBUG << "AudioCallbackPlaySource::unifyRingBuffers: m_readBufferFill = " << m_readBufferFill << ", rf = " << rf << ", m_writeBufferFill = " << m_writeBufferFill << endl;
 #endif
 
-    int wf = m_writeBufferFill;
-    int skip = 0;
+    sv_frame_t wf = m_writeBufferFill;
+    sv_frame_t skip = 0;
     for (int c = 0; c < getTargetChannelCount(); ++c) {
 	RingBuffer<float> *wb = getWriteRingBuffer(c);
 	if (wb) {
@@ -1792,7 +1794,7 @@
 	    }
 
 //	    cout << "skipping " << skip << endl;
-	    wb->skip(skip);
+	    wb->skip(int(skip));
 	}
     }
 		    
@@ -1835,10 +1837,9 @@
 
 	} else {
 	    
-	    float ms = 100;
+	    double ms = 100;
 	    if (s.getSourceSampleRate() > 0) {
-		ms = float(s.m_ringBufferSize) /
-                    float(s.getSourceSampleRate()) * 1000.0;
+		ms = double(s.m_ringBufferSize) / s.getSourceSampleRate() * 1000.0;
 	    }
 	    
 	    if (s.m_playing) ms /= 10;