Good Morning
Is anyone able to advise please?
I'm just reserving samples in my code.
At present I've done:
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:
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
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.
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).
what's the best way to know when to delete sample instances after they've finished playing?
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.
I really wanted to have "instance finished" events. I wonder if that's a thing that can happen.
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.