CRI ADX  Last Updated: 2024-07-17 10:47 p
Cross-faded Playback

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/crossfade_playback


Sample Description

By attaching a "fader" to the AtomEx player, it is possible to automate time-series volume control such as fading-in, fading-out, or cross-fading.
Procedure for Fading-in
Procedure for fading-in sound (starting playback in muted state and gradually increasing the volume) is as follows:
  1. Create an AtomEx player using the criAtomExPlayer_Create function.
  2. Attach a fader to the AtomEx player using the criAtomExPlayer_AttachFader function.
  3. Specify the time to be taken by fading-in using the criAtomExPlayer_SetFadeInTime function.
  4. Set the sound data to be played back by fading-in using the criAtomExPlayer_SetCueId function.
  5. Start playback using the criAtomExPlayer_Start function.
By following the above steps, the volume of the sound played back using the criAtomExPlayer_Start function is controlled so that it increases in the time specified by the criAtomExPlayer_SetFadeInTime function.
Procedure for Fading-out
Procedure for fading-out (gradually decreasing volume and stopping playback when the sound is muted) current sound is as follows:
  1. Specify the time to be taken by fading-out using the criAtomExPlayer_SetFadeOutTime function.
  2. Stop playback using the criAtomExPlayer_Stop function.
By following the above steps, volume of the current sound is controlled so that it is muted in the time specified by the criAtomExPlayer_SetFadeOutTime function.
Procedure for Cross-fading
By calling criAtomExPlayer_Start function repeatedly while criAtomExPlayer_SetFadeInTime and criAtomExPlayer_SetFadeOutTime functions are running, the current sound fades out and the new sound fades in every time the function is called.
The following is a sample code for cross-fading.

:
/* Create a player */
app_obj->player = criAtomExPlayer_Create(NULL, NULL, 0);
/* Attach a fader */
criAtomExPlayer_AttachFader(app_obj->player, NULL, NULL, 0);
/* Initialize fading time */
/* Note: Set cross-fading time to 3 seconds. */
app_obj->fade_time_ms = 3000;
criAtomExPlayer_SetFadeInTime(app_obj->player, app_obj->fade_time_ms);
criAtomExPlayer_SetFadeOutTime(app_obj->player, app_obj->fade_time_ms);
:
:
/* Start playback */
/* Note: Previously-played sound fades-out and new sound fades-in each time you play back. */
criAtomExPlayer_Start(app_obj->player);
:
void criAtomExPlayer_AttachFader(CriAtomExPlayerHn player, const CriAtomExFaderConfig *config, void *work, CriSint32 work_size)
Attach a fader to a player.
void criAtomExPlayer_SetFadeInTime(CriAtomExPlayerHn player, CriSint32 ms)
Set the fade-in time.
void criAtomExPlayer_SetFadeOutTime(CriAtomExPlayerHn player, CriSint32 ms)
Set the fade-out time.
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback.
CriAtomExPlayerHn criAtomExPlayer_Create(const CriAtomExPlayerConfig *config, void *work, CriSint32 work_size)
Create an AtomEx player.


[Note]
By default, fade-in and fade-out start at the same time. The user can alter this timing by using criAtomExPlayer_SetFadeInStartOffset function. If the user wants to fade in a new sound after one sound has completely faded out, or if the user wants to fade out the current sound after a new sound has completed the fade-in, use this function.