Mercurial > hg > svapp
comparison audioio/AudioPulseAudioTarget.cpp @ 232:025065fd5b49
Merge from debug-output branch
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 14:49:22 +0100 |
parents | 8c13e8219903 |
children | 8aace2d9f1c2 |
comparison
equal
deleted
inserted
replaced
219:85e59c901de9 | 232:025065fd5b49 |
---|---|
94 #endif | 94 #endif |
95 } | 95 } |
96 | 96 |
97 AudioPulseAudioTarget::~AudioPulseAudioTarget() | 97 AudioPulseAudioTarget::~AudioPulseAudioTarget() |
98 { | 98 { |
99 std::cerr << "AudioPulseAudioTarget::~AudioPulseAudioTarget()" << std::endl; | 99 DEBUG << "AudioPulseAudioTarget::~AudioPulseAudioTarget()" << endl; |
100 | 100 |
101 if (m_source) { | 101 if (m_source) { |
102 m_source->setTarget(0, m_bufferSize); | 102 m_source->setTarget(0, m_bufferSize); |
103 } | 103 } |
104 | 104 |
117 | 117 |
118 m_stream = 0; | 118 m_stream = 0; |
119 m_context = 0; | 119 m_context = 0; |
120 m_loop = 0; | 120 m_loop = 0; |
121 | 121 |
122 std::cerr << "AudioPulseAudioTarget::~AudioPulseAudioTarget() done" << std::endl; | 122 DEBUG << "AudioPulseAudioTarget::~AudioPulseAudioTarget() done" << endl; |
123 } | 123 } |
124 | 124 |
125 void | 125 void |
126 AudioPulseAudioTarget::shutdown() | 126 AudioPulseAudioTarget::shutdown() |
127 { | 127 { |
273 if (ch == 0) peakLeft = peak; | 273 if (ch == 0) peakLeft = peak; |
274 if (ch > 0 || sourceChannels == 1) peakRight = peak; | 274 if (ch > 0 || sourceChannels == 1) peakRight = peak; |
275 } | 275 } |
276 | 276 |
277 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY | 277 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET_PLAY |
278 std::cerr << "calling pa_stream_write with " | 278 DEBUG << "calling pa_stream_write with " |
279 << nframes * tmpbufch * sizeof(float) << " bytes" << std::endl; | 279 << nframes * tmpbufch * sizeof(float) << " bytes" << endl; |
280 #endif | 280 #endif |
281 | 281 |
282 pa_stream_write(m_stream, output, nframes * tmpbufch * sizeof(float), | 282 pa_stream_write(m_stream, output, nframes * tmpbufch * sizeof(float), |
283 0, 0, PA_SEEK_RELATIVE); | 283 0, 0, PA_SEEK_RELATIVE); |
284 | 284 |
300 | 300 |
301 void | 301 void |
302 AudioPulseAudioTarget::streamStateChanged() | 302 AudioPulseAudioTarget::streamStateChanged() |
303 { | 303 { |
304 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET | 304 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET |
305 std::cerr << "AudioPulseAudioTarget::streamStateChanged" << std::endl; | 305 DEBUG << "AudioPulseAudioTarget::streamStateChanged" << endl; |
306 #endif | 306 #endif |
307 QMutexLocker locker(&m_mutex); | 307 QMutexLocker locker(&m_mutex); |
308 | 308 |
309 switch (pa_stream_get_state(m_stream)) { | 309 switch (pa_stream_get_state(m_stream)) { |
310 | 310 |
312 case PA_STREAM_TERMINATED: | 312 case PA_STREAM_TERMINATED: |
313 break; | 313 break; |
314 | 314 |
315 case PA_STREAM_READY: | 315 case PA_STREAM_READY: |
316 { | 316 { |
317 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Ready" << std::endl; | 317 DEBUG << "AudioPulseAudioTarget::streamStateChanged: Ready" << endl; |
318 | 318 |
319 pa_usec_t latency = 0; | 319 pa_usec_t latency = 0; |
320 int negative = 0; | 320 int negative = 0; |
321 if (pa_stream_get_latency(m_stream, &latency, &negative)) { | 321 if (pa_stream_get_latency(m_stream, &latency, &negative)) { |
322 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Failed to query latency" << std::endl; | 322 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Failed to query latency" << std::endl; |
325 int latframes = (latency / 1000000.f) * float(m_sampleRate); | 325 int latframes = (latency / 1000000.f) * float(m_sampleRate); |
326 std::cerr << "that's " << latframes << " frames" << std::endl; | 326 std::cerr << "that's " << latframes << " frames" << std::endl; |
327 | 327 |
328 const pa_buffer_attr *attr; | 328 const pa_buffer_attr *attr; |
329 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { | 329 if (!(attr = pa_stream_get_buffer_attr(m_stream))) { |
330 std::cerr << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << std::endl; | 330 DEBUG << "AudioPulseAudioTarget::streamStateChanged: Cannot query stream buffer attributes" << endl; |
331 m_source->setTarget(this, m_bufferSize); | 331 m_source->setTarget(this, m_bufferSize); |
332 m_source->setTargetSampleRate(m_sampleRate); | 332 m_source->setTargetSampleRate(m_sampleRate); |
333 if (latframes != 0) m_source->setTargetPlayLatency(latframes); | 333 if (latframes != 0) m_source->setTargetPlayLatency(latframes); |
334 } else { | 334 } else { |
335 int targetLength = attr->tlength; | 335 int targetLength = attr->tlength; |
336 std::cerr << "AudioPulseAudioTarget::streamStateChanged: stream target length = " << targetLength << std::endl; | 336 DEBUG << "AudioPulseAudioTarget::streamStateChanged: stream target length = " << targetLength << endl; |
337 m_source->setTarget(this, targetLength); | 337 m_source->setTarget(this, targetLength); |
338 m_source->setTargetSampleRate(m_sampleRate); | 338 m_source->setTargetSampleRate(m_sampleRate); |
339 if (latframes == 0) latframes = targetLength; | 339 if (latframes == 0) latframes = targetLength; |
340 std::cerr << "latency = " << latframes << std::endl; | 340 std::cerr << "latency = " << latframes << std::endl; |
341 m_source->setTargetPlayLatency(latframes); | 341 m_source->setTargetPlayLatency(latframes); |
365 | 365 |
366 void | 366 void |
367 AudioPulseAudioTarget::contextStateChanged() | 367 AudioPulseAudioTarget::contextStateChanged() |
368 { | 368 { |
369 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET | 369 #ifdef DEBUG_AUDIO_PULSE_AUDIO_TARGET |
370 std::cerr << "AudioPulseAudioTarget::contextStateChanged" << std::endl; | 370 DEBUG << "AudioPulseAudioTarget::contextStateChanged" << endl; |
371 #endif | 371 #endif |
372 QMutexLocker locker(&m_mutex); | 372 QMutexLocker locker(&m_mutex); |
373 | 373 |
374 switch (pa_context_get_state(m_context)) { | 374 switch (pa_context_get_state(m_context)) { |
375 | 375 |
377 case PA_CONTEXT_AUTHORIZING: | 377 case PA_CONTEXT_AUTHORIZING: |
378 case PA_CONTEXT_SETTING_NAME: | 378 case PA_CONTEXT_SETTING_NAME: |
379 break; | 379 break; |
380 | 380 |
381 case PA_CONTEXT_READY: | 381 case PA_CONTEXT_READY: |
382 std::cerr << "AudioPulseAudioTarget::contextStateChanged: Ready" | 382 DEBUG << "AudioPulseAudioTarget::contextStateChanged: Ready" |
383 << std::endl; | 383 << endl; |
384 | 384 |
385 m_stream = pa_stream_new(m_context, "stream", &m_spec, 0); | 385 m_stream = pa_stream_new(m_context, "stream", &m_spec, 0); |
386 assert(m_stream); //!!! | 386 assert(m_stream); //!!! |
387 | 387 |
388 pa_stream_set_state_callback(m_stream, streamStateChangedStatic, this); | 388 pa_stream_set_state_callback(m_stream, streamStateChangedStatic, this); |
398 } | 398 } |
399 | 399 |
400 break; | 400 break; |
401 | 401 |
402 case PA_CONTEXT_TERMINATED: | 402 case PA_CONTEXT_TERMINATED: |
403 std::cerr << "AudioPulseAudioTarget::contextStateChanged: Terminated" << std::endl; | 403 DEBUG << "AudioPulseAudioTarget::contextStateChanged: Terminated" << endl; |
404 //!!! do something... | 404 //!!! do something... |
405 break; | 405 break; |
406 | 406 |
407 case PA_CONTEXT_FAILED: | 407 case PA_CONTEXT_FAILED: |
408 default: | 408 default: |
414 } | 414 } |
415 | 415 |
416 void | 416 void |
417 AudioPulseAudioTarget::streamOverflowStatic(pa_stream *, void *) | 417 AudioPulseAudioTarget::streamOverflowStatic(pa_stream *, void *) |
418 { | 418 { |
419 std::cerr << "AudioPulseAudioTarget::streamOverflowStatic: Overflow!" << std::endl; | 419 DEBUG << "AudioPulseAudioTarget::streamOverflowStatic: Overflow!" << endl; |
420 } | 420 } |
421 | 421 |
422 void | 422 void |
423 AudioPulseAudioTarget::streamUnderflowStatic(pa_stream *, void *data) | 423 AudioPulseAudioTarget::streamUnderflowStatic(pa_stream *, void *data) |
424 { | 424 { |
425 std::cerr << "AudioPulseAudioTarget::streamUnderflowStatic: Underflow!" << std::endl; | 425 DEBUG << "AudioPulseAudioTarget::streamUnderflowStatic: Underflow!" << endl; |
426 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; | 426 AudioPulseAudioTarget *target = (AudioPulseAudioTarget *)data; |
427 if (target && target->m_source) { | 427 if (target && target->m_source) { |
428 target->m_source->audioProcessingOverload(); | 428 target->m_source->audioProcessingOverload(); |
429 } | 429 } |
430 } | 430 } |