diff audioio/AudioCallbackPlaySource.cpp @ 212:fe83e6e68683

* Fix crash on document deletion (new session, or application exit) after loading session with alignments
author Chris Cannam
date Sun, 24 Oct 2010 22:09:42 +0200
parents 5ee9e6bc21eb
children 8c13e8219903
line wrap: on
line diff
--- a/audioio/AudioCallbackPlaySource.cpp	Sun Oct 24 17:39:00 2010 +0200
+++ b/audioio/AudioCallbackPlaySource.cpp	Sun Oct 24 22:09:42 2010 +0200
@@ -106,7 +106,10 @@
     m_exiting = true;
 
     if (m_fillThread) {
-	m_condition.wakeAll();
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource dtor: awakening thread" << std::endl;
+#endif
+        m_condition.wakeAll();
 	m_fillThread->wait();
 	delete m_fillThread;
     }
@@ -252,6 +255,10 @@
     connect(model, SIGNAL(modelChanged(size_t, size_t)),
             this, SLOT(modelChanged(size_t, size_t)));
 
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource::addModel: awakening thread" << std::endl;
+#endif
+
     m_condition.wakeAll();
 }
 
@@ -304,10 +311,10 @@
     }
     m_lastModelEndFrame = lastEnd;
 
+    m_audioGenerator->removeModel(model);
+
     m_mutex.unlock();
 
-    m_audioGenerator->removeModel(model);
-
     clearRingBuffers();
 }
 
@@ -441,6 +448,11 @@
     m_lastRetrievalTimestamp = 0;
     m_lastCurrentFrame = 0;
     m_playing = true;
+
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource::play: awakening thread" << std::endl;
+#endif
+
     m_condition.wakeAll();
     if (changed) {
         emit playStatusChanged(m_playing);
@@ -453,8 +465,16 @@
 void
 AudioCallbackPlaySource::stop()
 {
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cerr << "AudioCallbackPlaySource::stop()" << std::endl;
+#endif
     bool changed = m_playing;
     m_playing = false;
+
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource::stop: awakening thread" << std::endl;
+#endif
+
     m_condition.wakeAll();
     m_lastRetrievalTimestamp = 0;
     if (changed) {
@@ -1058,6 +1078,10 @@
 	return 0;
     }
 
+#ifdef DEBUG_AUDIO_PLAY_SOURCE_PLAYING
+    std::cerr << "AudioCallbackPlaySource::getSourceSamples: Playing" << std::endl;
+#endif
+
     // Ensure that all buffers have at least the amount of data we
     // need -- else reduce the size of our requests correspondingly
 
@@ -1151,6 +1175,10 @@
 
         applyAuditioningEffect(count, buffer);
 
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource::getSamples: awakening thread" << std::endl;
+#endif
+
         m_condition.wakeAll();
 
 	return got;
@@ -1239,6 +1267,10 @@
 
     applyAuditioningEffect(count, buffer);
 
+#ifdef DEBUG_AUDIO_PLAY_SOURCE
+    std::cout << "AudioCallbackPlaySource::getSamples [stretched]: awakening thread" << std::endl;
+#endif
+
     m_condition.wakeAll();
 
     return count;