diff audioio/AudioPortAudioTarget.cpp @ 106:f8e362511b2f

* Probable fix to occasional channel misalignment during playback
author Chris Cannam
date Mon, 26 Feb 2007 16:32:37 +0000
parents 0581d552481d
children 006c90387f40
line wrap: on
line diff
--- a/audioio/AudioPortAudioTarget.cpp	Mon Feb 26 14:55:08 2007 +0000
+++ b/audioio/AudioPortAudioTarget.cpp	Mon Feb 26 16:32:37 2007 +0000
@@ -202,7 +202,7 @@
 	}
     }
 	
-    m_source->getSourceSamples(nframes, tmpbuf);
+    size_t received = m_source->getSourceSamples(nframes, tmpbuf);
 
     float peakLeft = 0.0, peakRight = 0.0;
 
@@ -214,17 +214,25 @@
 
 	    // PortAudio samples are interleaved
 	    for (size_t i = 0; i < nframes; ++i) {
-		output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain;
-		float sample = fabsf(output[i * 2 + ch]);
-		if (sample > peak) peak = sample;
+                if (i < received) {
+                    output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain;
+                    float sample = fabsf(output[i * 2 + ch]);
+                    if (sample > peak) peak = sample;
+                } else {
+                    output[i * 2 + ch] = 0;
+                }
 	    }
 
 	} else if (ch == 1 && sourceChannels == 1) {
 
 	    for (size_t i = 0; i < nframes; ++i) {
-		output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain;
-		float sample = fabsf(output[i * 2 + ch]);
-		if (sample > peak) peak = sample;
+                if (i < received) {
+                    output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain;
+                    float sample = fabsf(output[i * 2 + ch]);
+                    if (sample > peak) peak = sample;
+                } else {
+                    output[i * 2 + ch] = 0;
+                }
 	    }
 
 	} else {