diff audio/AudioCallbackPlaySource.cpp @ 570:6f54789f3127 3.0-integration

Fix race condition in first-time recording, where adding the recording wave model would prompt the audio play source to note that its channel count had increased (from 0 to, say, 2) and thus to cause the audio device to be reopened, stopping recording. Fix is to make this only happen if channel count increases beyond that of the device, which shouldn't happen in the recording case
author Chris Cannam
date Wed, 04 Jan 2017 11:48:03 +0000
parents 36076ef960fb
children b3c35447ef31
line wrap: on
line diff
--- a/audio/AudioCallbackPlaySource.cpp	Wed Jan 04 09:57:13 2017 +0000
+++ b/audio/AudioCallbackPlaySource.cpp	Wed Jan 04 11:48:03 2017 +0000
@@ -235,6 +235,8 @@
     }
 
     if (!m_writeBuffers || (int)m_writeBuffers->size() < getTargetChannelCount()) {
+        cerr << "m_writeBuffers size = " << (m_writeBuffers ? m_writeBuffers->size() : 0) << endl;
+        cerr << "target channel count = " << (getTargetChannelCount()) << endl;
 	clearRingBuffers(true, getTargetChannelCount());
 	buffersIncreased = true;
     } else {
@@ -270,8 +272,13 @@
     m_audioGenerator->setTargetChannelCount(getTargetChannelCount());
 
     if (buffersIncreased) {
-        SVDEBUG << "AudioCallbackPlaySource::addModel: Number of buffers increased, signalling channelCountIncreased" << endl;
-        emit channelCountIncreased();
+        SVDEBUG << "AudioCallbackPlaySource::addModel: Number of buffers increased to " << getTargetChannelCount() << endl;
+        if (getTargetChannelCount() > getDeviceChannelCount()) {
+            SVDEBUG << "AudioCallbackPlaySource::addModel: This is more than the device channel count, signalling channelCountIncreased" << endl;
+            emit channelCountIncreased(getTargetChannelCount());
+        } else {
+            SVDEBUG << "AudioCallbackPlaySource::addModel: This is no more than the device channel count (" << getDeviceChannelCount() << "), so taking no action" << endl;
+        }
     }
     
     if (!m_fillThread) {