Here is my scenario:
First I call playSound, this creates a ‘Channel* chan’ object.
Let’s say after a few seconds, I want to modify something on ‘chan’ ( modify frequency, fade out, stop … ).
My concern is that if the sound has already finished playing it seems FMOD will automatically delete the ‘chan’ object. And all my calls on ‘chan’ will return error with ‘FMOD_ERR_INVALID_HANDLE’.
When I use my invalid ‘chan’ handle. Does FMOD means:
“I know this is a channel handle that has stopped, so I won’t modify it”
“I don’t know what ‘chan’ is, it musn’t be used in the API anymore”.
in other words, is it illegal to use an invalid ‘chan’ ( like using a deleted object in C++ ) ?
If it’s illegal, what’s the easiest way to track if my ‘chan’ is still valid, I need a way to set it to ‘nullptr’ when FMOD deletes it internally.
I’m relatively new to FMOD too and found this confusing as well.
I mention here about using ChannelControl::setCallBack() to get a callback when the sound ends so maybe that works for you. As I mentioned, I am still trying to figure out why it is not firing when iOS is in background mode.
Thanks for the reply -
yes I had the idea of adding callback for each sounds I wanted to track. but that feel a bit over-engineered. I hope there is something simpler
I will link to our white papers that outline our handle system: FMOD API | White Papers - Handle System. In summary, it is closest to your first answer but not exactly. As it says in our docs “If a Channel is stopped with ChannelControl::stopor ends naturally, the Channel handle will become invalid and return
FMOD_ERR_INVALID_HANDLE” so it will be safe to still interact with it however, it will just return an invalid handle. A way to check if a channel is still valid is using the channel in an FMOD function and checking the result for
Hope this clears it up a bit.
Thanks for the detail.
So my understanding is that on my app side, I don’t need to track the life time of all my channel handles. There is no risk of undefined behavior when using an invalid one.
That makes my developer life easier.
Correct, if a stopped channel is used in an FMOD function it will return the
Thanks for the confirmation