Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5]

This thread is locked; no one can reply to it. rss feed Print
[A5]
Ionising
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
Major Reynaldo
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

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?

They all watch too much MSNBC... they get ideas.

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.

Trezker
Member #1,739
December 2001
avatar

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

Go to: