0
0

I have this issue where sometimes this fails because the sound hasn’t started yet even though it has been called. This normally only happens when the sound loads the first time. In these cases the sound will not be moved to the correct location and will play from the start.

Subsequent times this works fine with that particular sound. So is there a callback I can use which will be called after the sound has been loaded/started for an event so the set position will work?

bool SetFMODEventSoundPosition(FMOD::Event* pEvent, int timeMilliSeconds)
{
    bool bReturnValue(false);
    if (pEvent)
    {
        FMOD::ChannelGroup* channelGroup(NULL);
        pEvent->getChannelGroup(&channelGroup);
        if (channelGroup)
        {
            int numChannels(0);
            channelGroup->getNumChannels(&numChannels);

            for (int i(0); i < numChannels; ++i)
            {
                FMOD::Channel* channel(NULL);
                channelGroup->getChannel(i, &channel);
                if (channel)
                {
                    bReturnValue = true;
                    if (FMOD_ERR_INVALID_POSITION == channel->setPosition(timeMilliSeconds, FMOD_TIMEUNIT_MS))
                    {
                        int loopCount = 0;
                        FMOD_MODE mode;
                        channel->getMode(&mode);
                        if (mode & FMOD_LOOP_OFF)
                        {
                            channel->stop(); 
                        }
                    }
                }
            }
        }
    }

    return bReturnValue;
}
  • You must to post comments
0
0

You can register a callback in your Event with Event::setCallback. SOUNDDEF_START and EVENTSTARTED might be useful to you. Just remember that those callbacks are only called on EventSystem::update, so your time resolution is relative to how often you invoke it. Sometimes it’s better not using events at all, just plain sounds and channels.

What are you trying to do? Depending on what you want to achieve we might be able to suggest other approaches.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.