1

I am working on a simple program that plays samples using pygame on a raspberry pi.

My code works fine using the built-in headphone out of the RPi (44.1kHz), but if I use a usb soundcard (Behringer U-Control, 48kHz) then my sounds play faster.

If I play the same wav files in VLC they play at regular speed. Any help would be appreciated.

I have tried lowering the sample rate when initializing the pygame mixer, and while that does correct the playback speed it is not ideal, and I'm not sure by how much exactly I need to reduce it to match the regular speed. The wav files themselves are 22050kHz

import pygame

pygame.mixer.pre_init(22050, -16, 1, 448)
pygame.mixer.init(22050, -16, 1, 448)
pygame.init()

# code that listens to button presses...

sound = pygame.mixer.Sound(path)
pygame.mixer.channel(0).play(sound)

This plays the sounds at a noticeably higher pitch and speed. With the built-in RPi DAC the same code plays at regular speed & pitch.

Louis T
  • 75
  • 8

0 Answers0