Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [Audio] How to play a sound n times in A5?

This thread is locked; no one can reply to it. rss feed Print
[Audio] How to play a sound n times in A5?
xpolife
Member #12,487
January 2011

How to play a sample and/or an audio stream n times in A5?
I mean play it eg. 5 times then stop.

possible solution are:
1. listen the play complete event
2. get audio length and use a timer

the 1 solution seems not supported in A5 now.
the 2 solution works in A5.

My question is:
1. is there any better solution?
2. how can i listen the play complete event? (I need this not only for repeating but also for user callback)

someone972
Member #7,719
August 2006
avatar

Create sample instances and use the functions associated with sample instances to play it. You can then use al_get_sample_instance_playing(...) to check if it's still playing.

Manual page for your convenience: Audio Routines (Scroll down a bit for sample instance functions)

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

xpolife
Member #12,487
January 2011

Thanks for replying.

And I think the al_get_sample_instance_playing() is a polling manner,
that is i have keeps check it.

I'd prefer the event notify manner if possible.

someone972
Member #7,719
August 2006
avatar

I haven't seen anything that outputs an event when a sample stops, but I haven't really been playing sounds so I can't be sure. If you really want an event you could create a user event and send that, but you would still need to poll the sample.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

jmasterx
Member #11,410
October 2009

For streams I know there is:

Quote:

If the stream is created by al_load_audio_stream then it can also generate an ALLEGRO_EVENT_AUDIO_STREAM_FINISHED event if it reaches the end of the file and is not set to loop.

Go to: