[Qt-interest] Buffer underrun problems with QtMultimedia 4.7
kurt.korbatits at nokia.com
kurt.korbatits at nokia.com
Thu Jun 24 05:45:04 CEST 2010
When you write data you get the best performance on playback writes in periodSize() chunks and don't write more data then bufferSize()
for example: (from examples/multimedia/audiooutput/audiooutput.cpp)
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;
}
Then make sure you are called again before the buffer is empty so you can fill it up again.
so, first time around write as many periodSize() chunks into buffer to fill it up (bufferSize()).
then next time your called check bytesFree() and write as many periodSize() chunks in to fill it again.
as long as you are called to fill it up before the buffer is empty everything is fine.
I would recommend 20-40ms timer.
When you try and write more than what can be written it will only write what it can returning the bytes that were actually written
(if you checked your return from the write you will see that only a part of the data was actually written out the rest was lost)
Kurt Korbatits
Software Engineer
Nokia - Qt Development Frameworks
________________________________
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of ext Pietro Gagliardi
Sent: Thursday, June 24, 2010 1:21 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Buffer underrun problems with QtMultimedia 4.7
Okay, so I upgraded to 4.7 and my GUI problems went away; they seemed to be caused by the Carbon core, as 4.6.3 on Windows seems to works fine until the application is quit. Now I have a new problem that I can't seem to get rid of:
If you listen to the following recording of my tracker at work, you'll notice occasional skipping: http://idisk.mac.com/pietro10-Public/gtaudiosnip.wav (The code below reduced the speed of the skips.) I found that this is due to a buffer underrun that happens every so often in the code. I have the buffer set to as large as it could be without the sound processor taking forever, so I wonder if any of you know what else is going on. I have tried chunking as in the Audio Output example and using bytesFree(), periodSize(), and bufferSize(), but these just increase the number of underruns; switching to a timer yields the same result. playback.cpp<http://idisk.mac.com/pietro10-Public/underrun/playback.cpp> playback.h<http://idisk.mac.com/pietro10-Public/underrun/playback.h> Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100624/879073e9/attachment.html
More information about the Qt-interest-old
mailing list