CRI ADX  Last Updated: 2024-07-17 10:47 p
On-memory Playback

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/playback_memory


Sample Description

You can play back the sound data loaded on memory by specifying its memory address and size.
This method of playing back the sound data on memory is called on-memory playback.

Since on-memory playback does not need streaming playback, sound break due to the stoppage of data supply does not occur.
In addition, since all the data is already loaded, playback starting latency can be very small.

Following is a code for on-memory playback.

CriFsStdioHn fp;
CriSint64 filesize;
CriSint32 mem_file;
/* Open file */
fp = criFsStdio_OpenFile(NULL, PATH FILE, "r");
/* Get file size */
filesize = criFsStdio_GetFileSize(fp);
/* Allocate memory large enough for the file size */
mem_file = user_alloc(NULL, (CriSint32)filesize);
/* Load the data to be played back */
criFsStdio_ReadFile(fp, filesize, mem_file, filesize);
/* Close the file */
criFsStdio_CloseFile(fp);
/* Create Voice Pool */
voice_pool = criAtomExVoicePool_AllocateAdxVoicePool(NULL, NULL, 0);
/* Create a player */
player = criAtomExPlayer_Create(NULL, NULL, 0);
/* Set the address and the size of the memory where the data to be played back was loaded */
criAtomExPlayer_SetData(player, mem_file, (CriSint32)filesize);
/* Start playback */
void criAtomExPlayer_SetData(CriAtomExPlayerHn player, void *buffer, CriSint32 size)
Set the sound data to play (specifying in-memory data)
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback.
CriAtomExPlayerObj * CriAtomExPlayerHn
Player handle.
Definition: cri_le_atom_ex.h:3622
CriAtomExPlayerHn criAtomExPlayer_Create(const CriAtomExPlayerConfig *config, void *work, CriSint32 work_size)
Create an AtomEx player.
struct CriAtomExVoicePoolTag * CriAtomExVoicePoolHn
Voice Pool handle.
Definition: cri_le_atom_ex.h:3220
CriAtomExVoicePoolHn criAtomExVoicePool_AllocateAdxVoicePool(const CriAtomExAdxVoicePoolConfig *config, void *work, CriSint32 work_size)
Create an ADX Voice Pool.


Procedure for on-memory playback is as follows:

  1. Load sound data (*.adx or *.hca file) onto the memory.
  2. Using the criAtomExPlayer_SetFile function, set the address and the size of the sound data to the player.
  3. Use the criAtomExPlayer_Start function to start playback.