# Sound Sync Point and callback

**URL:** <https://qa.fmod.com/t/sound-sync-point-and-callback/16662>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [January 19, 2021, 9:00am UTC](https://qa.fmod.com/t/sound-sync-point-and-callback/16662 "2021-01-19T09:00:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshechoes](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joshechoes/32/558_2.png) [@joshechoes](https://qa.fmod.com/u/joshechoes)\
**Post date:** [January 19, 2021, 9:00am UTC](https://qa.fmod.com/t/sound-sync-point-and-callback/16662/1 "2021-01-19T09:00:54Z")

</div>

I’m creating a sync point on a sound

```
// add a sync point so we get a callback before the end
unsigned int length = 0;
result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
const char *name = "sound-end";
FMOD_SYNCPOINT *syncpoint;
result = sound->addSyncPoint(length - 1, FMOD_TIMEUNIT_MS, name, &syncpoint);
if (result != FMOD_OK) {
    printf("fmod:: Error setting sound sync point because: %s\n", FMOD_ErrorString(result));
}

```

then setting a callback for the channel

```
// set the channelcontrol callback for notifications
    result = channel->setCallback(&channelControlCallback);
    if (result != FMOD_OK) {
        printf("fmod:: Error setting channel control callback because: %s - %s\n", FMOD_ErrorString(result),
             url);
    }

```

here’s the callback

```
FMOD_RESULT F_CALLBACK channelControlCallback(FMOD_CHANNELCONTROL *channelcontrol, FMOD_CHANNELCONTROL_TYPE controltype, FMOD_CHANNELCONTROL_CALLBACK_TYPE callbacktype, void *commanddata1, void *commanddata2) {

if (controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_END) {
    FMOD::Channel *channel = reinterpret_cast<FMOD::Channel *>(channelcontrol);
    echoes_sound_data *userdata;
    FMOD_RESULT result;
    result = channel->getUserData((void **)&userdata);
    if (result != FMOD_OK) {
        printf("fmod:: Error getting userdata in callback because: %s\n", FMOD_ErrorString(result));
        return FMOD_OK;
    }
    if (userdata != nullptr) {
        playerDidEnd(userdata->context);
    }
}

if (controltype == FMOD_CHANNELCONTROL_CHANNEL && callbacktype == FMOD_CHANNELCONTROL_CALLBACK_SYNCPOINT) {
    FMOD::Channel *channel = reinterpret_cast<FMOD::Channel *>(channelcontrol);
    echoes_sound_data *userdata;
    FMOD_RESULT result;
    result = channel->getUserData((void **)&userdata);
    int sync_point_index = *((int *)commanddata1);
    if (result != FMOD_OK) {
        printf("fmod:: Error getting userdata in callback because: %s\n", FMOD_ErrorString(result));
        return FMOD_OK;
    }
    if (userdata != nullptr) {
        playerDidEnd(userdata->context);
    }
}

return FMOD_OK;
}

```

The sounds plays fine, however, the callback gets called with `FMOD_CHANNELCONTROL_CALLBACK_END` _immediately_, but never at the end of the sound. The `FMOD_CHANNELCONTROL_CALLBACK_SYNCPOINT` never gets called.

I’m sure it’s something obvious I’m missing, but I can’t see it. Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [January 20, 2021, 1:25am UTC](https://qa.fmod.com/t/sound-sync-point-and-callback/16662/2 "2021-01-20T01:25:36Z")

</div>

That all seems fine to me, I pasted this into our play\_sound example with a few modifications to remove your userdata and it worked fine. Perhaps try the same on your end?

---

<div class="post-metadata">

**Author:** ![joshechoes](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joshechoes/32/558_2.png) [@joshechoes](https://qa.fmod.com/u/joshechoes)\
**Post date:** [January 20, 2021, 8:49am UTC](https://qa.fmod.com/t/sound-sync-point-and-callback/16662/3 "2021-01-20T08:49:19Z")

</div>

Oh! So I did set it up correctly… I will see if I can reproduce your `play_sound` example test. Thanks! I’ll come back if I figure it out.
