Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_reserve_samples

This thread is locked; no one can reply to it. rss feed Print
al_reserve_samples
StanEd
Member #16,038
August 2015

Good Morning :)

Is anyone able to advise please?

I'm just reserving samples in my code.

At present I've done:

al_reserve_samples(5);

But actually I'm probably going to need more than that, but the actual number is unclear now I thought I could simply be greedy and reserve all the samples I could get:

#SelectExpand
1int reservedSamples = 0; 2int i = 100; 3bool success = false; 4 5do 6{ 7 success = al_reserve_samples(i); 8 i -= 1; 9}while(success == false || i > 0); 10 11if(!success) 12 printf("Sorry, can't play any sounds today!");

But I suspect there a many credible reasons not to do this.

Alternatively, can you call al_reserve_samples(n) multiple successful times? If so does it reserve n additional samples, or does it simply adjust the reserved sample count?

What do you think is the best way to go?

Thanks

Stan

beoran
Member #12,636
March 2011

This function sets the amount of samples connected to a default mixer available. The amount of samples, in essence determines how many sounds you will be able to play on top of each other. Unless you're making a very aurally intensive game, something like 8 to 16 samples for 8 to 16 sounds in parallel will be enough. There's not much sense to loop around it to be greedy, having too many samples may possibly lower performance.

Elias
Member #358
May 2000

If you need more control, don't use al_reserve_samples at all and just create the required sample instances yourself - that way you can limit the amount of concurrent sounds based on the sample (e.g. if you have 500 bullet sounds, don't make that drown out everything else).

--
"Either help out or stop whining" - Evert

roger levy
Member #2,513
July 2002

what's the best way to know when to delete sample instances after they've finished playing?

beoran
Member #12,636
March 2011

If it's a one shot sound , then just check al_get_sample_instance_playing, say, once every second or so using a timer, and delete the instance if it isn't playing anymore.

Thomas Fjellstrom
Member #476
June 2000
avatar

I really wanted to have "instance finished" events. :( I wonder if that's a thing that can happen.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

StanEd
Member #16,038
August 2015

Hi guys,

Apologies for being awol.Thank you for your posts and advice.

Roger, I'd suggest creating a SampleManager class (this is pretty much what I've ended up doing) that manages all your sample instances, you could give it a update function which checks each sample instance and destroys them once they are done. You guess you could either poll update, or do it on a timer... You may even be able to run it in a separate thread, but I imagine there are all sorts of complexities with destroying objects from a separate thread.

Just thoughts :)

Thanks again for everyone's advice.

Go to: