[Qt-interest] Buffer underrun problems with QtMultimedia 4.7
kurt.korbatits at nokia.com
kurt.korbatits at nokia.com
Thu Jun 24 23:47:46 CEST 2010
If your output is supposed to be a tone then you must be talking about the click.
If you open the file with something like audacity you should be able to see were your problem is.
Somethings to note:
-periodSize() and bufferSize() are in bytes but not all things work in this unit some may work in samples.
-you are still not checking your write() return value.
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 3:05 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Buffer underrun problems with QtMultimedia 4.7
Thank you. However, now I get the following sound, both on a free running loop and a 20ms timer:
http://idisk.mac.com/pietro10-Public/gtchunked.wav
Here is the new code, in the free running loop:
void SoundOutput::run()
{
uint16_t *k;
uint16_t *FMbuf[2];
uint16_t *PSGbuf;
int chunks, ps;
FMbuf[0] = new uint16_t[speaker->bufferSize()];
FMbuf[1] = new uint16_t[speaker->bufferSize()];
PSGbuf = new uint16_t[speaker->bufferSize()];
k = new uint16_t[speaker->bufferSize()];
while (!dead) {
soundAccess.lock();
ps = speaker->periodSize();
chunks = speaker->bytesFree() / ps;
while (chunks) {
// YM2612UpdateOne(0, (void **) FMbuf, ps);
SN76496Update_16(0, PSGbuf, ps);
for (int i = 0; i < ps; i++)
k[i] = PSGbuf[i] ;//+ ((FMbuf[0][i] + FMbuf[1][i]) );//^ 0x8000);
speakerOut->write((char *) k, ps);
chunks--;
}
soundAccess.unlock();
}
delete[] FMbuf[0];
delete[] FMbuf[1];
delete[] PSGbuf;
delete[] k;
}
What am I doing wrong this time? Thanks.
On Jun 23, 2010, at 11:45 PM, kurt.korbatits at nokia.com<mailto:kurt.korbatits at nokia.com> wrote:
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> [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<mailto: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/42a7a98a/attachment.html
More information about the Qt-interest-old
mailing list