Mercurial > hg > svapp
comparison 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 |
comparison
equal
deleted
inserted
replaced
192:2b1869fccec1 | 193:0b3aa9b702bb |
---|---|
156 #endif | 156 #endif |
157 if (m_done) return; | 157 if (m_done) return; |
158 | 158 |
159 QMutexLocker locker(&m_mutex); | 159 QMutexLocker locker(&m_mutex); |
160 | 160 |
161 if (m_source->getTargetPlayLatency() == 0) { //!!! need better test | 161 pa_usec_t latency = 0; |
162 //!!! | 162 int negative = 0; |
163 pa_usec_t latency = 0; | 163 if (!pa_stream_get_latency(m_stream, &latency, &negative)) { |
164 int negative = 0; | 164 int latframes = (latency / 1000000.f) * float(m_sampleRate); |
165 if (pa_stream_get_latency(m_stream, &latency, &negative)) { | 165 if (latframes > 0) m_source->setTargetPlayLatency(latframes); |
166 std::cerr << "AudioPulseAudioTarget::streamWrite: Failed to query latency" << std::endl; | |
167 } | |
168 // std::cerr << "Latency = " << latency << " usec" << std::endl; | |
169 int latframes = (latency / 1000000.f) * float(m_sampleRate); | |
170 // std::cerr << "that's " << latframes << " frames" << std::endl; | |
171 if (latframes > 0) { | |
172 m_source->setTargetPlayLatency(latframes); //!!! buh | |
173 } | |
174 } | 166 } |
175 | 167 |
176 static float *output = 0; | 168 static float *output = 0; |
177 static float **tmpbuf = 0; | 169 static float **tmpbuf = 0; |
178 static size_t tmpbufch = 0; | 170 static size_t tmpbufch = 0; |
322 const pa_buffer_attr *attr; | 314 const pa_buffer_attr *attr; |
323 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { | 315 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { |
324 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << std::endl; | 316 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << std::endl; |
325 m_source->setTarget(this, m_bufferSize); | 317 m_source->setTarget(this, m_bufferSize); |
326 m_source->setTargetSampleRate(m_sampleRate); | 318 m_source->setTargetSampleRate(m_sampleRate); |
327 m_source->setTargetPlayLatency(latframes); | 319 if (latframes != 0) m_source->setTargetPlayLatency(latframes); |
328 } else { | 320 } else { |
329 std::cerr << "AudioPulseAudioTarget::streamStateChanged: stream max length = " << attr->maxlength << std::endl; | 321 int targetLength = attr->tlength; |
330 int latency = attr->tlength; | 322 std::cerr << "AudioPulseAudioTarget::streamStateChanged: stream target length = " << targetLength << std::endl; |
331 std::cerr << "latency = " << latency << std::endl; | 323 m_source->setTarget(this, targetLength); |
332 m_source->setTarget(this, attr->maxlength); | |
333 m_source->setTargetSampleRate(m_sampleRate); | 324 m_source->setTargetSampleRate(m_sampleRate); |
325 if (latframes == 0) latframes = targetLength; | |
326 std::cerr << "latency = " << latframes << std::endl; | |
334 m_source->setTargetPlayLatency(latframes); | 327 m_source->setTargetPlayLatency(latframes); |
335 } | 328 } |
336 } | 329 } |
337 break; | 330 break; |
338 | 331 |