# Playing sound specific range

**URL:** <https://qa.fmod.com/t/playing-sound-specific-range/18497>\
**Category:** FMOD Engine\
**Created:** [March 9, 2022, 7:13pm UTC](https://qa.fmod.com/t/playing-sound-specific-range/18497 "2022-03-09T19:13:16Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [August 9, 2022, 11:46pm UTC](https://qa.fmod.com/t/playing-sound-specific-range/18497/9 "2022-08-09T23:46:55Z")

</div>

Sample accurate playback is achieved with [`ChannelControl::setPosition`](https://fmod.com/docs/2.02/api/core-api-channel.html#channel_setposition) to set the start time and [`ChannelControl::setDelay`](https://fmod.com/docs/2.02/api/core-api-channelcontrol.html#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`](https://fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_getdspclock).

```cpp
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?

```cs
[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
){}

```

---

_[View the full topic](https://qa.fmod.com/t/playing-sound-specific-range/18497)._
