Version

menu_open
Warning: you were redirected to the latest documentation corresponding to your major release ( 2022.1.17.8543 ). Should you wish to access your specific version's documentation, please download the offline documentation from the Audiokinetic Launcher and check the Offline Documentation option in Wwise Authoring.
Wwise SDK 2022.1.17
Integration Details - Music Callbacks

Introduction

When creating the interactive music for your game, you may need information about the music's beat. You can request this information from the sound engine using music notifications. The beat is determined by the main music segment currently playing. Since segments can have different time signatures, the beat will change based on the music currently playing. When no music is playing, there will be no notifications.

There are two types of music callbacks:

  • Music Notifications: inform the callee of current music playback properties.
  • Music Playlist Selection: allows the callee to force the selection of a music playlist's next item.

How to Use Music Notifications

If you want to receive marker notifications about your music, there are specific things you need to be aware of when designing your application:

  • When posting a play event that contains music with the beat you want to follow, you can add one or more of the following flags:

If you also want to receive a notification at the end of an event, you should use AK_EndOfEvent | AK_MusicSyncBeat since the flags are bitwise exclusive.

  • Your callback function must have the following form:
  • When your callback function is called, you first need to check what type of notification is passed. For example, if you only want to process AK_MusicSyncBar notifications, you should return when any other event type is received.
  • Based on the type of notification, you can typecast in_pCallbackInfo into the appropriate information structure type. For music notifications, it is AkMusicSyncCallbackInfo.
Note
When requesting multiple music notifications, they will be sent additionally. That means that if you register for both AK_MusicSyncBeat and AK_MusicSyncBar in a 4/4 time signature, you will receive 4 beat notifications per bar + one notification for the bar itself. Time "0" also counts for a beat and a bar and in most cases so does the AK_MusicSyncEntry. This means that if you register for bars, beats and entry points, you will receive three callbacks back to back when the music starts.
The tempo can be calculated by using the following formula: Tempo (in BPM) = 60.0 / fBeatDuration
The upper value of the time signature can be calculated by using the following formula: Upper value = fBarDuration / fBeatDuration. This tells you how many beats per bar there are.
The notification AK_MusicSyncExit will only be sent if the end of the body of the current segment is reached. If the music switches to another segment before finishing the current one, the AK_MusicSyncExit nofification will not be sent.
See also
Quick Start Sample Integration - Events

How to Use Music Playlist Callbacks

The callback function described above may also be used to manually manage a music playlist's next item selection. This is done by adding the following flag.

Upon reception of this type of event, the callback function must typecast the parameter in_pCallbackInfo to type AkMusicPlaylistCallbackInfo.

The active playlist node is indicated by the member playlistID. The sound engine selects the next item in the playlist node to play prior to the callback function call. The selection is contained in the members uPlaylistSelection and uPlaylistItemDone. If uPlaylistItemDone is set to 0 then uPlaylistSelection determines the next item to play in the playlist node. If uPlaylistItemDone is not set to 0 then the current playlist node is to end (the parent node will then become the active node). Both members uPlaylistSelection and uPlaylistItemDone may be changed by the callback function.

Notification Latency

Currently, notification is sent when the buffer is passed down to the hardware. This means that there is a certain constant delay between when the notification is sent and the moment it actually gets played. This gives your application enough time to gather the information on the marker and process it before the sound associated with that marker is really played.

Note that this delay is platform-dependent.

Callback Thread

The callbacks are done from the sound engine's main thread. This means that your application should gather all the information it needs from the notification and return immediately. If any processing needs to be done, it should be performed in a separate thread after the relevant information has been copied from the notification.

If the application holds the thread for too long, the sound engine might fall into an underrun state and the output might stop playing.

See also
Integration Details - Events
@ AK_MusicSyncEntry
Enable notifications on Music Entry Cue. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:63
@ AK_MusicSyncBar
Enable notifications on Music Bar. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:62
AkUInt32 uPlaylistSelection
Selection: set by sound engine, modified by callback function (if not in range 0 <= uPlaylistSelectio...
Definition: AkCallback.h:209
AkUInt64 AkGameObjectID
Game object ID.
Definition: AkTypes.h:128
@ AK_MusicSyncAll
Use this flag if you want to receive all notifications concerning AK_MusicSync registration.
Definition: AkCallback.h:68
AkCallbackType
Type of callback. Used as a bitfield in methods AK::SoundEngine::PostEvent() and AK::SoundEngine::Dyn...
Definition: AkCallback.h:48
#define NULL
Definition: AkTypes.h:46
float AkReal32
32-bit floating point
AkCallbackType musicSyncType
Would be either AK_MusicSyncEntry, AK_MusicSyncBeat, AK_MusicSyncBar, AK_MusicSyncExit,...
Definition: AkCallback.h:238
AkUInt32 AkUniqueID
Unique 32-bit ID.
Definition: AkTypes.h:120
AkPlayingID playingID
Playing ID of Event, returned by PostEvent()
Definition: AkCallback.h:236
@ AK_MusicSyncGrid
Enable notifications on Music Grid. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:65
void(* AkCallbackFunc)(AkCallbackType in_eType, AkCallbackInfo *in_pCallbackInfo)
Definition: AkCallback.h:266
AkUInt32 uPlaylistItemDone
Playlist node done: set by sound engine, modified by callback function (if set to anything but 0 then...
Definition: AkCallback.h:210
AkUniqueID playlistID
ID of playlist node.
Definition: AkCallback.h:207
@ AK_MusicPlaylistSelect
Callback triggered when music playlist container must select the next item to play....
Definition: AkCallback.h:58
@ AK_MusicSyncExit
Enable notifications on Music Exit Cue. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:64
@ AK_MusicSyncBeat
Enable notifications on Music Beat. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:61
uint32_t AkUInt32
Unsigned 32-bit integer.
@ AK_MusicSyncPoint
Enable notifications on Music switch transition synchronization point. AkCallbackInfo can be cast to ...
Definition: AkCallback.h:67
AkUInt32 uNumPlaylistItems
Number of items in playlist node (may be segments or other playlists)
Definition: AkCallback.h:208
AKSOUNDENGINE_API AkPlayingID PostEvent(AkUniqueID in_eventID, AkGameObjectID in_gameObjectID, AkUInt32 in_uFlags=0, AkCallbackFunc in_pfnCallback=NULL, void *in_pCookie=NULL, AkUInt32 in_cExternals=0, AkExternalSourceInfo *in_pExternalSources=NULL, AkPlayingID in_PlayingID=AK_INVALID_PLAYING_ID)
AkUInt32 AkPlayingID
Playing ID.
Definition: AkTypes.h:123
@ AK_MusicSyncUserCue
Enable notifications on Music Custom Cue. AkCallbackInfo can be cast to AkMusicSyncCallbackInfo.
Definition: AkCallback.h:66

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise