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

Re: [pygame] Pygame causes ALSA underrun



The docs for pygame.mixer.init() have this info, which seems relevant:

> The buffer argument controls the number of internal samples used in the sound mixer. The default value should work for most cases. It can be lowered to reduce latency, but sound dropout may occur. It can be raised to larger values to ensure playback never skips, but it will impose latency on sound playback. The buffer size must be a power of two (if not it is rounded up to the next nearest power of 2).

http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init

This is the argument you're setting to 512 (also the default). If I've understood correctly, it needs to prepare new data every 512 / 22050 seconds, or about 40 times per second.

Thomas

On Thu, 26 Aug 2021 at 08:21, David Scheele <david.scheele2@xxxxxxxxxxxxxx> 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