Sample accurate playback is achieved with ChannelControl::setPosition
to set the start time and ChannelControl::setDelay
to set a duration. The duration of ChannelControl::setDelay
needs to be offset by the current dsp clock time, which you can get through ChannelControl::getDSPClock
.
void SetChannelRange(FMOD::ChannelGroup *channel, int start, int end)
{
int duration = stop - start;
int sampleRate;
unsigned long long time;
result = system->getSoftwareFormat(&sampleRate, 0, 0);
ERRCHECK(result);
result = channel->getDSPClock(0, &time);
ERRCHECK(result);
result = channel->setPosition(start * sampleRate, FMOD_TIMEUNIT_PCM);
ERRCHECK(result);
result = channel->setDelay(0, time + duration * sampleRate);
ERRCHECK(result);
}
As for the callback, I can see you are using C#, does your callback signature look like this?
[AOT.MonoPInvokeCallback(typeof(FMOD.CHANNELCONTROL_CALLBACK))]
static FMOD.RESULT ChannelControlCallbackFunc(
IntPtr channelcontrol,
FMOD.CHANNELCONTROL_TYPE controltype,
FMOD.CHANNELCONTROL_CALLBACK_TYPE callbacktype,
IntPtr commanddata1,
IntPtr commanddata2
){}