CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
Getting the playback time synchronized with audio
The playback time available via CriWare.CriAtomSource::time corresponds to the elapsed time since initiating the playback.
Therefore, if the supply of audio data is temporarily interrupted, there will be a discrepancy between the time returned and the actual playback time.

If your application requires a tight synchronization with the sound being played (for example for rhythm games), it is recommended to get the playback time via the audio-synchronized timer by the calling CriWare.CriAtomExPlayback::GetTimeSyncedWithAudio function.

  • When using CriAtomExPlayer directly
    To activate the audio-synchronized timer, it is necessary to create a dedicated CriWare.CriAtomExPlayer.
    The code below demonstrates how to create a CriWare.CriAtomExPlayer , then play the Cues and finally get the actual audio playback time.

    /* Create a player with the enableAudioSyncedTimer flag enabled */
    CriAtomExPlayer player = new CriAtomExPlayer(true);
    /* Set the names of the Cue Sheet and Cue to be played to the player */
    player.SetCue(CriAtom.GetAcb("<CueSheetName>"), "<CueName>");
    /* Start playback */
    CriAtomExPlayback playback = player.Start();
    ...
    /* Get the playback time synchronized with audio */
    long playTime = playback.GetTimeSyncedWithAudio();


  • When using CriAtomSource
    By defining an application-specific class that derives from CriWare.CriAtomSource , it is possible to get the audio-synchronized playback time by using the function of the component.
    Please override the initialization method and create a dedicated CriWare.CriAtomExPlayer as shown below.

    using System.Collections;
    public class MyAtomSource : CriAtomSource {
    protected override void InternalInitialize()
    {
    CriAtomPlugin.InitializeLibrary();
    /* Create a player with the enableAudioSyncedTimer flag enabled */
    this.player = new CriAtomExPlayer(true);
    this.source = new CriAtomEx3dSource();
    }
    }