streaming and looping audio

I'm using al_load_audio_stream_f() to stream audio, and setting the play mode to ALLEGRO_PLAYMODE_LOOP for looping.

I set the stream to use 2 buffers, and 1024 samples. I noticed that with a higher number of samples, the audio doesn't loop as well since there's a more noticeable gap while looping. If I set the number of samples lower, I need more buffers to make the audio play properly. I tried at 8 buffers and 256 samples, and it loops nicely, but when I tested on a very old computer it affected performance.

My question is: What's the most efficient combination of buffers and samples I can use performance-wise, and how can I make it loop perfectly?

Arthur Kalliokoski
ph03nix said:

when I tested on a very old computer it affected performance.

Was the CPU practically maxed out in Resource Meter or whatever?


Yes it was, but it would spike instead of consistently being high


A rather simplistic hack would be to choose the amount of buffers and samples based on the speed of your rendering loop. If you have FPS to spare, then use many buffers, if not, then use less. So the old machine gets a bit of delay but not too much use of resources and the new one gets the benefits of it's performance.

Todd Cope

What exactly are you trying to do? The buffer size shouldn't affect the looping. There was a bug in the Ogg Vorbis decoder that would cause the audio to loop too soon, which caused inconsistent playback. This was fixed in the most recent version of Allegro (5.0.10).

The looping system for streamed audio shouldn't have any gaps at all. If it does, it is a bug.


I think my wording was a bit off, only the number of samples affects the looping (the higher it is the more of a gap there tends to be), but reducing the number of samples requires more buffers to play without stuttering, which seems to affect performance on my old computer. I'm trying to figure out how to get the best performance and looping from the stream.

Also forgot to mention I'm using 5.1.7

Todd Cope

Still, you shouldn't get any gaps in the audio unless the loop points are set incorrectly or the audio data itself has gaps. When the streamed audio runs out, it rewinds to the loop start point and continues to fill the buffer until it's full.

Allegro 5.1.7 doesn't have the Ogg Vorbis fix as it was implemented after that release. You can get the patch here if you don't want to pull the source from git. If you are using some other audio format, please specify what it is.


I forgot to mention it, but I am using ogg vorbis. I'd love to try the patch (sounds like it would fix my looping issue), but I'm using a built version of allegro so I don't think I can apply it.

Todd Cope

The patch won't do you any good, then. Maybe the devs will release 5.1.8 soon.


I tried out 5.0.10 and the looping problem isn't there at all, good to know the source of the issue. Just wondering, will native dialog menus be added to the stable branch eventually?

Matthew Leverton

I think the native menu dialogs need a second pass on the API before going in to the stable branch.

Peter Wang

I'm not intending to put the menus on the 5.0 branch.

Thread #612954. Printed from