I'm currently reading through the documentation but I've not found an answer yet - is there a way for Allegro 5 to callback when a specific sound sample finishes playing?

I'm currently implementing a music player for my game so it would be good to know when the current track finishes so I can play the next one.

Edgar Reynaldo

I think for right now you have to poll whether the sample instance is finished playing manually. al_get_sample_instance_playing

Arthur Kalliokoski

There's also al_get_sample_instance_position(), which should have some predictive ability to know how much longer it will be until it's done.

As an aside, the old Sound Blaster DOS stuff had interrupts (events) for when the buffer was half played or at the end, so you could load the other half with data without interrupting the "active" half. Couldn't Allegro events do this?

Peter Wang

The sound card interrupts would be analogous to the audio stream events that we emit when the steam needs to be refilled. For a music player, you're more likely to be using an ALLEGRO_AUDIO_STREAM. You could check the status when you get an ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT, to save polling more than necessary. I think it should work even if you use al_load_audio_stream, which is a stream driven by an hidden thread instead of by the user.

We could also generate events for when a sample instance reaches one of the end points (to generalise it to looping samples), but we currently don't.


Yeah, I think that may be a good event to have. I can think of uses.

Thread #612628. Printed from Allegro.cc