diff audioio/AudioPulseAudioTarget.cpp @ 193:0b3aa9b702bb

* Fix problems playing back when the target block size is close to, or greater than, the default ring-buffer size
author Chris Cannam
date Tue, 22 Jun 2010 13:48:00 +0000
parents 2b1869fccec1
children d9c21e7bff21
line wrap: on
line diff
--- a/audioio/AudioPulseAudioTarget.cpp	Tue Jun 22 09:45:19 2010 +0000
+++ b/audioio/AudioPulseAudioTarget.cpp	Tue Jun 22 13:48:00 2010 +0000
@@ -158,19 +158,11 @@
 
     QMutexLocker locker(&m_mutex);
 
-    if (m_source->getTargetPlayLatency() == 0) { //!!! need better test
-            //!!!
-            pa_usec_t latency = 0;
-            int negative = 0;
-            if (pa_stream_get_latency(m_stream, &latency, &negative)) {
-                std::cerr << "AudioPulseAudioTarget::streamWrite: Failed to query latency" << std::endl;
-            }
-//            std::cerr << "Latency = " << latency << " usec" << std::endl;
-            int latframes = (latency / 1000000.f) * float(m_sampleRate);
-//            std::cerr << "that's " << latframes << " frames" << std::endl;
-            if (latframes > 0) {
-                m_source->setTargetPlayLatency(latframes); //!!! buh
-            }
+    pa_usec_t latency = 0;
+    int negative = 0;
+    if (!pa_stream_get_latency(m_stream, &latency, &negative)) {
+        int latframes = (latency / 1000000.f) * float(m_sampleRate);
+        if (latframes > 0) m_source->setTargetPlayLatency(latframes);
     }
 
     static float *output = 0;
@@ -324,13 +316,14 @@
                 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << std::endl;
                 m_source->setTarget(this, m_bufferSize);
                 m_source->setTargetSampleRate(m_sampleRate);
-                m_source->setTargetPlayLatency(latframes);
+                if (latframes != 0) m_source->setTargetPlayLatency(latframes);
             } else {
-                std::cerr << "AudioPulseAudioTarget::streamStateChanged: stream max length = " << attr->maxlength << std::endl;
-                int latency = attr->tlength;
-                std::cerr << "latency = " << latency << std::endl;
-                m_source->setTarget(this, attr->maxlength);
+                int targetLength = attr->tlength;
+                std::cerr << "AudioPulseAudioTarget::streamStateChanged: stream target length = " << targetLength << std::endl;
+                m_source->setTarget(this, targetLength);
                 m_source->setTargetSampleRate(m_sampleRate);
+                if (latframes == 0) latframes = targetLength;
+                std::cerr << "latency = " << latframes << std::endl;
                 m_source->setTargetPlayLatency(latframes);
             }
         }