0
0

Helloes

I read in the FMOD documentation that one-shot sounds are deallocated automatically when they have finished, and FMOD can also choose to "reuse" the channel when it have finished.

Some things come to my mind:

How can I safely change the volume of a one-shot channel, that I have saved a FMOD::Channel pointer to, while it is playing?

Do I risk that the FMOD::Channel*, that I have to it, will be outdated and an error will occur when I dereference it?

Also, is there any chance that FMOD will reuse the Channel and that I by accident will change the volume of a different sound?

  • You must to post comments
0
0

Hi taz0k,

[quote:2cr2wp2p]Do I risk that the FMOD::Channel*, that I have to it, will be outdated and an error will occur when I dereference it? [/quote:2cr2wp2p]
Yes, but the error wont be an exception or anything nasty like that, it will be a return code. Every FMOD function returns a FMOD_RESULT value, when a channel handle is no longer valid all member functions will return FMOD_ERR_INVALID_HANDLE and there will be no effect.

[quote:2cr2wp2p]is there any chance that FMOD will reuse the Channel and that I by accident will change the volume of a different sound?
[/quote:2cr2wp2p]
No chance at all, the channel handle you have will be invalid if the underlying channel has been stolen. The only way to make a channel handle point to a different channel is if you call playSound using FMOD_CHANNEL_REUSE.

The main point here is that the instances of the FMOD::Channel class are only channel handles and do not always directly respond to real sound channels. FMOD will handle all the channel stealing behind the scenes, you can use set the priorities of channels to prevent certain channels from getting stolen.

-Pete

  • You must to post comments
0
0

Thanks! Excellent answer. Great that you mentioned FMOD_CHANNEL_REUSE I had not noticed it.

  • You must to post comments
0
0

Hm.

I tried FMOD_CHANNEL_REUSE. I thought that i would make the "previous" sound removed/stopped and the "new" sound start to play in it’s place immediately.

Instead I tried this, and it had the behavior that I desired:

[code:1l0r4dk0]
if(channel == NULL){
channel->stop();
}
system->playSound(FMOD_CHANNEL_FREE, soundInstance->fmodSound, true, &channel);[/code:1l0r4dk0]

This leads me to think either I have misunderstood FMOD_CHANNEL_REUSE or there is a bug with it. I thought that the effect of doing a

[code:1l0r4dk0]
system->playSound(FMOD_CHANNEL_REUSE, soundInstance->fmodSound, true, &channel);[/code:1l0r4dk0]

would be exactly identical, but it was not.

  • You must to post comments
0
0

[quote:1ucas3t7]if(channel == NULL){
channel->stop();
} [/quote:1ucas3t7]
I think you mean if(channel != NULL).

FMOD_CHANNEL_FREE will find a free channel, FMOD_CHANNEL_REUSE will take the existing channel handle and stop that channel and play the new sound in that channel. If the channel passed in is invalid then it will act the same as FMOD_CHANNEL_FREE.

As a side note: it’s extremely important to check the FMOD_RESULT being returned from every FMOD function call.

-Pete

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.