[Qt-interest] Buffer underrun problems with QtMultimedia 4.7

Pietro Gagliardi pietro10 at mac.com
Thu Jun 24 07:05:21 CEST 2010


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 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 
> ] 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 playback.h Thanks.
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100624/754d6825/attachment.html 


More information about the Qt-interest-old mailing list