From 3b2d9d0644a57ac377a7bcbfd40f8bd6da32cd1f Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:41:18 +0000 Subject: Cleaned up implementation of audio output example Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 04e1923..0c44b4f 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -257,23 +257,16 @@ void AudioTest::status() void AudioTest::writeMore() { - if (!m_audioOutput) - return; - - if (m_audioOutput->state() == QAudio::StoppedState) - return; - - int l; - int out; - - int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); - while(chunks) { - l = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); - if (l > 0) - out = m_output->write(m_buffer.data(), l); - if (l != m_audioOutput->periodSize()) - break; - chunks--; + if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) { + int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); + while (chunks) { + const qint64 len = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); + if (len) + m_output->write(m_buffer.data(), len); + if (len != m_audioOutput->periodSize()) + break; + --chunks; + } } } -- cgit v0.12