I’m having problems managing the lifetime of non-looping, virtual fmod channels right now. This is what I currently do in my engine:
- create a channel with FMOD_System_PlaySound
- create custom bookkeeping for that sound
- poll the channel with FMOD_Channel_IsPlaying every frame. If the return value is not FMOD_OK or isPlaying is false, I consider the channel to have finished playback (because to my understanding these are the symptoms of FMOD cleaning the channel up, which only happens after it has finished playback)
- if I consider a channel to have finished playback, I free my custom bookkeeping and call FMOD_Channel_Stop on it.
I have a debug-mode that delays the cleanup of custom bookkeeping and the FMOD_Channel_Stop call, so I can look at state in an ingame UI. I can then at some point let the deletions and FMOD_Channel_Stop-calls catch up. If I delay too many deletions, some channels will start to go virtual, and on catch- up, they won’t ever be cleaned up. On further inspection, this is because they are still playing and still non-paused, even after they should have finished (virtual) playback.
The basic goal I want to achieve with this is to know when a channel has finished playback, regardless whether it is virtual or not. Right now, the failure to tell if a virtual sound has finished playback leads to my engine keeping the bookkeeping around after debugging, and it starts piling up. I haven’t encountered this in normal gameplay yet, but believe this might happen there aswell if too many channels play at the same time, and that would be bad news and a resource-leak.
What am I doing wrong? How can I tell if a non-looping virtual channel has finished playback?