Answered
0
0

I’m trying to figure out why my file handles to .fsb sound streams aren’t being closed. Below is a minimal example of the usage. Every time I call [PlayStream], it’s opening a file handle to the file specified, which is what I expect. HOWEVER, when I release the sound and stop the channel, the file handle still remains open. So if I were to call [PlayStream] 150 times, there would be 150 OS file handles open and I would also incur the ever-increasing memory usage associated with this as well. Main question: What is a way to properly close the .fsb file handle using the FMOD Low Level API? Do I have to close the file myself even though FMOD opens it for me?

FMOD_RESULT F_CALLBACK FMODMusicChannelCallback(FMOD_CHANNELCONTROL *pChanControl, 
                                                FMOD_CHANNELCONTROL_TYPE controlType, 
                                                FMOD_CHANNELCONTROL_CALLBACK_TYPE callbackType, 
                                                void *commandData1, void *commandData2) {
    switch(controlType) {
    case FMOD_CHANNELCONTROL_CHANNEL:
        {
            if(callbackType == FMOD_CHANNELCONTROL_CALLBACK_END) {
                FMOD::Channel *pChannel = reinterpret_cast<FMOD::Channel*>(pChanControl);
                FMOD::Sound *pSound;
                pChannel->stop();
                pChannel->getCurrentSound(&pSound);
                pSound->release();
            }
        }
    }
}

void FrameUpdate() {
    mpFMODSystem->Update();
}

void PlayStream(unsigned int subsoundID) {

    FMOD::Sound *pBaseSound, *pSubSound;
    FMOD::Channel *pChannel;

    mpFMODSystem->createStream("soundbankwithsubsounds.fsb", FMOD_LOOP_OFF|FMOD_2D, NULL, &pBaseSound);
    pBaseSound->getSubSound(subsoundID, &pSubSound);
    mpFMODSystem->playSound(pSubSound, NULL, false, &pChannel);
    pChannel->setCallback(FMODMusicChannelCallback);
}
  • You must to post comments
Best Answer
0
0

Woah there stop the presses!! I figured it out.

When streaming from a bank using a subSound, you’ve got to call [release()] on the parent sound that was initially created from [createStream()]. If you don’t call [release()] on the parent, then the handle stays open since the parent FMOD::Sound isn’t released at all. You can retrieve the parent (or check if there is a parent) by using [FMOD::Sound::getSubSoundParent]. If the value retrieved is NULL, then I’m assuming you most likely have a parent already.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.