I have created a Python program to play a song when a button is pressed. I am using a USB sound card and pygame.mixer
to load songs and play them randomly when the button is pressed. The songs are 16-bit little-endian signed WAV files at 44100 Hz (but I don't think this matters).
OS: Raspbian (Debian 8 (Jessie))
Hardware: Raspberry Pi Zero
When I initialize the mixer at 44100 Hz like so:
pygame.mixer.init(44100,-16,2,2048)
I get the following error printed many times when I run my program:
ALSA lib pcm.c:7843:(snd_pcm_recover) underrun occurred
I get this before I even play any songs.
However, if I initialize at 48000 Hz, I do not get the underrun occurred
message. But my files play back at 48000 Hz! So they are faster and at higher frequency.
Any clues as to why this happens and how I can fix it? I will accept workarounds using other packages to play the files.