- Online Community Forums » Programming Questions » Sound Delay

This thread is locked; no one can reply to it. rss feed Print
Sound Delay
Member #16,781
December 2017


Raspberry Pi3, Allegro 5.

I have delays when playing wav sounds.

I used pulseaudio (very bad, 5+ seconds).
With pulseaudio disabled and alsa, about 500ms.

I tried al_load_sample/al_play_sample and also al_create_sample_instance/al_play_sample_instance.

The wav file is short, about 1-2 seconds.

With command aplay is ok.

I have read
and other threads but I can't solve.

Mark Oates
Member #1,146
March 2001

Are you loading your samples right at play time or are you preloading them all first before using al_play_sample.

Chris Katko
Member #1,881
January 2002

Looks like others had it happen... both with Allegro ... and SDL.

See last post here:


Okay, so I think I have the high latency issue resolved. It would seem to be an issue with the Raspberry Pi's sound hardware, or at least that's the perhaps simplistic conclusion I draw from getting low latency audio playback using USB headphones. I have heard the Raspberry Pi's audio is a little flaky and that external USB audio adapters have been handy with the RPi. Here's what I found works...

1) Disable the Raspberry Pi's on-board sound hardware.
2) Connect USB headphones to the RPi.
3) Reboot.
4) Specify to use PulseAudio before I initialize audio in my program.
5) Start PulseAudio.
6) Run my program.

Not sure if it's related to your case or not. But I've definitely seem multiple threads about RPi and delay.

“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Member #7,827
October 2006

Please try the attached patch, it helped significantly on my RPI.

It adds a new configuration option under the alsa section called buffer_frames. Try reducing it if you still see a delay, or increasing it if the sound appears choppy. If this works, there'll be a slightly more advanced version of this change committed soon.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Member #16,781
December 2017

Yes, that is.

I leave value (2048) unchanged in your patch.
Sounds starts ok now.

Many thanks SiegeLord.

Go to: