Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » sample instance

This thread is locked; no one can reply to it. rss feed Print
sample instance
Matheus Santos
Member #15,053
April 2013

it is possible to play a sample for a given time? using the sample instance for example?

Trent Gamblin
Member #261
April 2000
avatar

You can either loop it or set the speed so that it'll stretch to the time you want.

André Silva
Member #11,991
May 2010
avatar

If you want it to play for a shorter amount of time than what it normally lasts for, shouldn't al_init_timeout work? I have to be honest, I don't quite know what timeouts in Allegro are, and a quick read through the manual didn't help much, but I'm guessing that they're a bit like Javascript's setTimeout()?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

ph03nix
Member #15,028
April 2013
avatar

Are you using Allegro 5? There's a function called al_set_sample_instance_length. I haven't ever tried it but it seems to do what you want.
https://www.allegro.cc/manual/5/al_set_sample_instance_length

If that doesn't work you could easily just program an integer to iterate and stop the sound when it reaches a specified value, but this can become desynced if the program stops updating while the sound keeps playing (for example while switching to full screen)

Go to: