- Online Community Forums » Programming Questions » [A5]

This thread is locked; no one can reply to it. rss feed Print
Member #14,522
August 2012

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
Member #8,592
May 2007

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

Arthur Kalliokoski
Second in Command
February 2005

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?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Peter Wang
Member #23
April 2000

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.

Member #1,739
December 2001

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

Go to: