Emitter sound check [Solved]

M

Menik

Guest
Hi this has been a bit of a head-scratcher for me.

I'm able to get emitters and listeners to work. My problem is: when is it appropriate to free an emitter? I want to check somehow if an emitter is playing a sound, and if not then I want to free it. How do you check if a specific emitter is playing a sound? Does it put up a flag or a value that I can check? Does the emitter automatically adjust the gain when it's done, or out of range? Is there a function I'm missing that's meant to check this?

Thanks for reading.

-Menik
 

Binsk

Member
Take a look at playing a sound through an emitter, namely the last paragraph and the return.

Next take a look at this function, specifically what the index value can be. That should be all you need.

If you are playing multiple sounds through a single emitter you may need to keep track of the IDs manually so you can check them all.
 
M

Menik

Guest
Take a look at playing a sound through an emitter, namely the last paragraph and the return.

Next take a look at this function, specifically what the index value can be. That should be all you need.

If you are playing multiple sounds through a single emitter you may need to keep track of the IDs manually so you can check them all.
Thanks for the help. I just want to clarify if I got this right. With this I'm thinking I'd need to store the "sound" as a variable to later check if it's still playing? So two separate variables: One to hold the emitter, and another to hold each sound as I play it? Originally I thought the emitter itself would return that information. Didn't think to store sounds into a variable, but it kinda seems obvious now.
 

Binsk

Member
Yes, playing through the emitter should return a unique sound ID when you start the sound that you can check.

I would think that the emitter would be responsible for this as well but it looks like you have to check each individual sound yourself.
 
M

Menik

Guest
Seems I was able to get a system working where Emitters free up correctly through this method(thanks to your help Binsk), but in doing so I found my instances are sharing emitters. As when I free one, it potentially stops sounds from other instances as well.

I have just one final question. Is it better to free emitters when an instance is destroyed rather than freeing it asap? I feel like maybe I've been giving myself a headache for no reason.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Chances are an emitter doesn't need any processing power when they aren't emitting anything, only memory... and since it only has a number of playback parameters and a reference to a sound resource, it doesn't need a lot of memory. So it's probably not that bad if you have a number of inert emitters sitting around because you don't destroy them "quickly enough".

It's probably good to bring up Knuth's Axiom for cases like this: "Premature optimization is the root of all evil." Or in other words, if you optimize your code before you know whether you even have a problem, you're probably just gonna waste your time. Run your game with the Profiler every once in a while and see if you find suspicious resource hogs, but don't start optimizing code because you think it's inefficient - always test whether it is first.
 
M

Menik

Guest
Chances are an emitter doesn't need any processing power when they aren't emitting anything, only memory... and since it only has a number of playback parameters and a reference to a sound resource, it doesn't need a lot of memory. So it's probably not that bad if you have a number of inert emitters sitting around because you don't destroy them "quickly enough".

It's probably good to bring up Knuth's Axiom for cases like this: "Premature optimization is the root of all evil." Or in other words, if you optimize your code before you know whether you even have a problem, you're probably just gonna waste your time. Run your game with the Profiler every once in a while and see if you find suspicious resource hogs, but don't start optimizing code because you think it's inefficient - always test whether it is first.
Sounds like good advice. It's definitely going to clash with my perfectionism nature lol. I'm always wondering if I can make something better or easier. Thank you both for helping me out. I'm going to go ahead and mark this as completed.
 
Top