CRI ADX  Last Updated: 2024-07-17 10:47 p
Seamless Concatenated Playback

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/seamless_playback


Sample Description

Atom library provides a feature called "seamless concatenated playback" to concatenate and play multiple wave data.
(Generally, it is also called as "gapless playback feature.")
Using seamless concatenated playback feature, you can play back wave data without loop information in loop (playing back the same wave data repeatedly) or play back wave data divided in each part in any combination.
Procedure to use seamless concatenated playback feature is as follows:

  1. Create an AtomEx player using the criAtomExPlayer_Create function.
  2. Register a data request callback function to the AtomEx player using the criAtomExPlayer_SetDataRequestCallback function.
  3. Set data to be played back first using functions such as criAtomExPlayer_SetData.
  4. Start playback using the criAtomExPlayer_Start function.
  5. Data request callback function is called when the sound data that has been set has been finished loading. Set the next data to be played back in the callback function.
Following is a code before starting playback.

:
/* Create a player */
app_obj->player = criAtomExPlayer_Create(NULL, NULL, 0);
/* Register a callback function for seamless concatenated playback */
app_obj->player, app_data_request_callback, app_obj);
/* Specify first playback data */
criAtomExPlayer_SetCueId(app_obj->player, app_obj->acb_hn, CRI_ATOMCUESHEET_SEAMLESS_A);
/* Start playback */
criAtomExPlayer_Start(app_obj->player);
:
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback.
CriAtomExPlayerHn criAtomExPlayer_Create(const CriAtomExPlayerConfig *config, void *work, CriSint32 work_size)
Create an AtomEx player.
void criAtomExPlayer_SetDataRequestCallback(CriAtomExPlayerHn player, CriAtomExPlayerDataRequestCbFunc func, void *obj)
Register the data request callback function.
void criAtomExPlayer_SetCueId(CriAtomExPlayerHn player, CriAtomExAcbHn acb_hn, CriAtomExCueId id)
Set the sound data to play (specifying a Cue ID)


Although registering callback and setting first data is done on AtomEx player, adding data in the callback must be done by calling "Atom player" API in the lower layer (Atom layer).
For example, if you want to perform concatenated playback on multiple on-memory data, first data is set to an AtomEx player using the criAtomExPlayer_SetData function, but when you set remaining data in the callback function, set data to the Atom player handle passed as an argument to the callback function using the criAtomPlayer_SetData function.
[Note]
Wave data-level concatenation is done in a Voice instead of AtomEx player.
Therefore, callback for concatenated playback is called from the Atom player internally held by a Voice instead of AtomEx player.
Note that since Atom layer does not support playing back Cue, when you want to concatenate and play back wave data in Cues, you must get AWB handles and wave data IDs from the Cues.
Procedure to play back wave data in Cues is as follows:
  1. Get information about wave data contained in the Cue using the criAtomExAcb_GetWaveformInfoById function.
  2. Use the criAtomExAcb_GetOnMemoryAwbHandle function when the wave data is an on-memory data, or use the criAtomExAcb_GetStreamingAwbHandle function when it an streaming playback data to get AWB handle.
  3. Call the criAtomPlayer_SetWaveId function using the AWB handle and waveform ID.
Specific code is as follows.

CriAtomAwbHn awb_hn;
:
/* Get information about wave data contained in the Cue to be played back */
criAtomExAcb_GetWaveformInfoById(app_obj->acb_hn, app_obj->request_id, &wave_info);
/* Check if the wave data is for streaming playback */
if (wave_info.streaming_flag == CRI_FALSE) {
/* Get AWB handle for on-memory playback from the ACB handle */
awb_hn = criAtomExAcb_GetOnMemoryAwbHandle(app_obj->acb_hn);
} else {
/* Get AWB handle for streaming playback from the ACB handle */
awb_hn = criAtomExAcb_GetStreamingAwbHandle(app_obj->acb_hn);
}
/* Set wave data to be concatenated */
/* Note) Call Atom player API instead of AtomEx player. */
criAtomPlayer_SetWaveId(player, awb_hn, wave_info.wave_id);
/* Note) When you want to play back single file or wave data */
/* loaded on memory instead of wave data in a Cue, */
/* do not perform above operation, and you may call the criAtomPlayer_SetFile function or */
/* the criAtomPlayer_SetData function directly. */
:
CriAtomAwbHn criAtomExAcb_GetOnMemoryAwbHandle(CriAtomExAcbHn acb_hn)
Get an AWB handle from an ACB handle (for in-memory playback)
CriBool criAtomExAcb_GetWaveformInfoById(CriAtomExAcbHn acb_hn, CriAtomExCueId id, CriAtomExWaveformInfo *waveform_info)
Get information about the waveform played by the Cue whose ID is given.
CriAtomAwbHn criAtomExAcb_GetStreamingAwbHandle(CriAtomExAcbHn acb_hn)
Get an AWB handle from an ACB handle (for streaming playback)
struct CriAtomAwbTag * CriAtomAwbHn
AWB handle.
Definition: cri_le_atom.h:1349
void criAtomPlayer_SetWaveId(CriAtomPlayerHn player, CriAtomAwbHn awb, CriSint32 id)
Set sound data (specify sound data ID)
Audio waveform information.
Definition: cri_le_atom_ex.h:3081
CriBool streaming_flag
Definition: cri_le_atom_ex.h:3087
CriAtomExWaveId wave_id
Definition: cri_le_atom_ex.h:3082


Attention
Seamless concatenated playback concatenates one wave data contained in a Cue.
For Cues which include multiple wave data, intended result may not be achieved since any wave data in the Cue is selected and played.
When performing seamless concatenated playback using Cues, use only Cues which do not contain multiple wave data.

Note that since wave data to be concatenated is specified by waveform ID, parameters specified for Cues such as volume of panning are not applied at all.
(Parameters for first played Cue are continued to be applied.)

Wave data used for concatenated playback must have same parameters.
Specifically, following parameters must be the same.
  • Codec
  • Number of channels
  • Sampling rate

If you attempt to concatenate waveforms with different parameters, sound data may be played back with unintended speed or error callback may occur.