CRI ADX  Last Updated: 2024-07-17 10:47 p
Initialization by Passing Work Area

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/memory_management


Sample Description

CRI Atom does not have its own memory allocation mechanism.
It uses memory allocator specified by application or uses work area passed by application.

The following code is an example of allocating work area in application and passing it to CRI Atom to create handle.

CriAtomExPlayerConfig player_config;
CriAtomExConfig atomex_config;
CriSint32 atomex_work_size;
void *atomex_work;
CriSint32 acf_work_size;
void *acf_work;
CriSint32 acb_work_size;
void *acb_work;
CriSint32 vp_work_size;
void *vp_work;
CriSint32 player_work_size;
void *player_work;
/* Register error callback function */
criErr_SetCallback(user_error_callback_func);
/* Initialize library setting parameters */
/* Calculate library work size */
atomex_work_size = criAtomEx_CalculateWorkSize(&atomex_config);
/* Allocate memory in the application */
atomex_work = user_alloc(NULL, atomex_work_size);
/* Initialize library by explicitly passing work area from the application */
smputl_initialize(&atomex_config, atomex_work, atomex_work_size);
/* Read and register ACF file */
acf_work_size = criAtomEx_CalculateWorkSizeForRegisterAcfFile(NULL, PATH ACF_FILE);
acf_work = user_alloc(NULL, acf_work_size);
criAtomEx_RegisterAcfFile(NULL, PATH ACF_FILE, acf_work, acf_work_size);
/* Load an ACB file and create an ACB handle */
acb_work_size = criAtomExAcb_CalculateWorkSizeForLoadAcbFile(NULL, PATH ACB_FILE, NULL, PATH AWB_FILE);
acb_work = user_alloc(NULL, acb_work_size);
NULL, PATH ACB_FILE, NULL, PATH AWB_FILE, acb_work, acb_work_size);
/* Create ADX on-memory Voice Pool */
vp_work = user_alloc(NULL, vp_work_size);
&adxvp_config, vp_work, vp_work_size);
/* Create a player */
player_work_size = criAtomExPlayer_CalculateWorkSize(&player_config);
player_work = user_alloc(NULL, player_work_size);
&player_config, player_work, player_work_size);
CriAtomExAcbObj * CriAtomExAcbHn
ACB handle.
Definition: cri_le_atom_ex.h:3033
CriAtomExAcbHn criAtomExAcb_LoadAcbFile(CriFsBinderHn acb_binder, const CriChar8 *acb_path, CriFsBinderHn awb_binder, const CriChar8 *awb_path, void *work, CriSint32 work_size)
Load an ACB file.
CriSint32 criAtomExAcb_CalculateWorkSizeForLoadAcbFile(CriFsBinderHn acb_binder, const CriChar8 *acb_path, CriFsBinderHn awb_binder, const CriChar8 *awb_path)
Calculate the size of the work buffer required to load an ACB file.
CriSint32 criAtomEx_CalculateWorkSize(const CriAtomExConfig *config)
Calculate the size of the work buffer required to initialize the library.
CriSint32 criAtomEx_CalculateWorkSizeForRegisterAcfFile(CriFsBinderHn binder, const CriChar8 *path)
Calculate the size of the work buffer required to register an ACF file.
#define criAtomEx_SetDefaultConfig(p_config)
Assign the default values to the configuration structure used for the library's initialization.
Definition: cri_le_atom_ex.h:322
CriBool criAtomEx_RegisterAcfFile(CriFsBinderHn binder, const CriChar8 *path, void *work, CriSint32 work_size)
Register an ACF file.
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.
CriSint32 criAtomExPlayer_CalculateWorkSize(const CriAtomExPlayerConfig *config)
Calculate the size of the work buffer required to create an AtomEx player.
#define criAtomExPlayer_SetDefaultConfig(p_config)
Assign the default values to the configuration structure used to create an AtomeEx Player.
Definition: cri_le_atom_ex.h:710
#define criAtomExVoicePool_SetDefaultConfigForAdxVoicePool(p_config)
Assign the default values to the configuration structure used to create an ADX Voice Pool.
Definition: cri_le_atom_ex.h:582
CriSint32 criAtomExVoicePool_CalculateWorkSizeForAdxVoicePool(const CriAtomExAdxVoicePoolConfig *config)
Calculate the size of the work buffer required to create an ADX Voice Pool.
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.
void criErr_SetCallback(CriErrCbFunc cbf)
Register error callback function.
Configuration structure used when creating an ADX Voice Pool.
Definition: cri_le_atom_ex.h:3277
Configuration structure used to initialize the Atom libraryThis structure is used to specify the beha...
Definition: cri_le_atom_ex.h:1461
Configuration structure used when creating a player.
Definition: cri_le_atom_ex.h:3484


If the user uses a dynamic memory allocation in an arbitrary size, it technically makes it difficult to avoid a memory fragmentation in a broad sense.
By initializing the library and creating handle by passing work area, application can control the timing and order of memory allocation, which helps avoiding the problem of memory fragmentation.