[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Problems with sound lag



Luke Paireepinart wrote:

However, a side-effect of this is that it takes longer for sounds
to fill the buffer, and therefore, longer to start playing.
After a certain point, the delay in filling the buffer becomes noticeable.
Perhaps the author of whichever game you're playing needed to increase
the buffer size to get sound playback to work correctly?
> I'm sure Aaron Maupin (the Natto-Cat guy) will be interested
> to talk to you about this.

Well, I'm no expert.  John, check near the line pygame.init() for either
pygame.mixer.init() or pygame.mixer.pre_init().

If using 22050 samples per second, a good buffer size is 1024:

pygame.mixer.pre_init(22050, -16, 2, 1024)

You can double it for 44100 Hz:

pygame.mixer.pre_init(44100, -16, 2, 2048)

This is what I use on Natto-Cat, and what causes pops and crackles on my
new laptop.  :(  Doubling the buffer values (the docs say the buffer
should be a power of 2, though mixer seems to take any value) causes the
strange cadence mentioned in my previous message.  Lowering the buffer
causes sound dropouts for me on Windows, but you may be able to get away
with more on Linux...