|
Raspberry Pi - slightly delayed audio |
martinohanlon
Member #16,619
January 2017
|
This is an issue which has been discussed a couple of times in the past, https://www.allegro.cc/forums/thread/616314 https://www.raspberrypi.org/forums/viewtopic.php?f=33&t=69266 ...but I wanted to re-open to see if anyone has any new advice / recommendations / solutions. I've ported a game, mayhem https://github.com/martinohanlon/mayhem-pi, to allegro 5 on the Raspberry Pi and playing audio files are very slightly delayed, I would estimated at maybe 0.25 seconds. I have tested on version 5.2.2[1] and the problem persists. I dont see the same problem on Windows and I didnt have the problem when running on Allegro 4. Does anyone have any thoughts? |
Thomas Fjellstrom
Member #476
June 2000
|
I imagine you want to play with the sound buffers, and make sure you're not using pulseaudio if you can help it. straight alsa, and reduce the sizes of the sound buffers. -- |
martinohanlon
Member #16,619
January 2017
|
Hi Thomas, Thanks a lot for the insight. Do you have any info on how I would use sound buffers and ensure that I am only using alsa? I did a quick search of the manual and couldnt find much relevant. Martin --------------- Been doing a bit more digging.... I think I would do the following to set the driver alsa: al_set_config_value(al_get_system_config(), "audio", "driver", "alsa"); |
Elias
Member #358
May 2000
|
You're right, this is something that's missing from the documentation. If you are using pulseaudio, try this: al_set_config_value(al_get_system_config(), "pulseaudio", "buffer_size", "512") The default is 1024. Setting it too small will cause overruns so instead of delay you get ugly noise. [edit:] Make sure you call this before al_install_audio or it won't have any effect. -- |
GullRaDriel
Member #3,861
September 2003
|
That is quite the hack. Interesting enough to be noted in the manual for the audio_addon ! "Code is like shit - it only smells if it is not yours" |
Thomas Fjellstrom
Member #476
June 2000
|
You can also use the config file -- |
martinohanlon
Member #16,619
January 2017
|
Ok, so I have explicitly set the driver to alsa, with the same effect. Any other ideas? I tried using pulseaudio but I couldnt get any sound, even after starting pulseaudio, but I suspect that is a Pi setup issue as opposed to an allegro / pulseaudio issue. |
Thomas Fjellstrom
Member #476
June 2000
|
You want to look at the docs on the config file for the alsa audio driver, and tweak the buffers. -- |
Elias
Member #358
May 2000
|
The alsa driver only has a single setting "device" so there is no way to tweak anything there. -- |
Thomas Fjellstrom
Member #476
June 2000
|
Elias said: The alsa driver only has a single setting "device" so there is no way to tweak anything there. Huh. Wonder what happened to all of that stuff... -- |
martinohanlon
Member #16,619
January 2017
|
Yeah I couldn't find anything in the allegro5.cfg config about buffers and alsa. For others in the future, see the allegro5.cfg file in the source https://github.com/liballeg/allegro5/blob/master/allegro5.cfg for a description. |
Thomas Fjellstrom
Member #476
June 2000
|
I appologize for the wild goose chase. I guess I'm too far out of the loop to be that helpful. I had written the original alsa code, and it had the ability to change the alsa buffers, but i guess when it was ported, and re-ported to allegro 5, it was dumbed down. -- |
SiegeLord
Member #7,827
October 2006
|
I committed a change to allow configuring the ALSA buffer size, but the default value is so low already I'm a little skeptical it's actually at fault here. Either way, perhaps worth patching it in and trying it out. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
Where are we setting the fragment count? That also counts towards the delay from what I remember about alsa... -- |
martinohanlon
Member #16,619
January 2017
|
Thanks, Ill try the patch and report back. |
Elias
Member #358
May 2000
|
We might have to add a snd_pcm_hw_params_set_periods_near somewhere there as well. The ALSA latency is: periodsize * periods / (rate * bytes_per_frame) So it is a key parameter for low latency. -- |
SiegeLord
Member #7,827
October 2006
|
Bump. I got a Raspberry Pi myself, so once I get Allegro compiling I'll try to examine this. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
martinohanlon
Member #16,619
January 2017
|
That would be excellent. The compile of allegro on the Pi is pretty easy. I put some instructions on my blog they might be useful http://www.stuffaboutcode.com/2016/11/compile-allegro-5x-for-raspberry-pi.html |
SiegeLord
Member #7,827
October 2006
|
I played around with this a bit. Indeed, if I set the audio driver to pulseaudio and start pulse audio via `pulseaudio --start` I get the 0.25 second delay. However, if I don't start pulseaudio and just use the default driver, everything seems to work fine. For me, the default driver appears to be OpenAL of all things... I tried also using the alsa and oss drivers, but those failed to initialize, so I'll have to investigate what's up with that. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
|