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

Re: [pygame] Pygame causes ALSA underrun



I had the same results with the Rpi architecture. They need to fix the kernel and/or audio driver.

The underrun happens when you  push the CPU too hard, and the audio device (seems to) expect there is audio data but there is none in the audio buffer. I imagine it's a race condition that occurs when the system is too busy, and the CPU can't keep the puny audio buffer fed.

The only thing you can do is throttle the CPU so that it never overwhelms the system for long periods.

What is long? Maybe 1-3 seconds. But I had no way of testing it, so I gave up on my Rpi game projects.

On 8/26/2021 12:21 AM, David Scheele wrote:
Hi there, new to the mailing list.
I'm currently misusing pygame and its mixer to create a raspberry pi script that can switch between different music playlists and play sfx on command, all without any graphics. So far it worked perfectly but now, in reach of the finish line, I came across errors like this:

ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred

I'm not even sure what this means. But it really hurts the audio playback. I play my music over pygame.mixer.Channel(0) and (1). I know that's not the usual way to do it but I have my reasons for using it.

I init my mixer with
pygame.mixer.pre_init(22050, -16, 2, 512)

I would like to put everything I can into getting the audio right as it is literally the only thing that matters in this project. Does anyone have any pointers what steps I could try?

Thanks!
David