CRI ADX  Last Updated: 2024-07-17 10:48 p
通过传递工作区初始化

示例目录

/cri/pc/samples/criatomex/memory_management


示例描述

CRI Atom没有自己的内存分配功能。 将使用应用程序指定的内存分配函数,或使用从应用程序传递的工作区。
以下代码是在应用程序端分配工作区,传递给CRI Atom并执行初始化、创建句柄的示例。
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;
/* 注册错误回调函数 */
criErr_SetCallback(user_error_callback_func);
/* 初始化程序库设置参数 */
/* 计算程序库工作区内存大小 */
atomex_work_size = criAtomEx_CalculateWorkSize(&atomex_config);
/* 在应用程序端分配内存 */
atomex_work = user_alloc(NULL, atomex_work_size);
/* 从应用程序明确传递工作区并初始化 */
smputl_initialize(&atomex_config, atomex_work, atomex_work_size);
/* 读取和注册ACF文件 */
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);
/* 读取ACB文件,创建ACB句柄 */
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);
/* 创建ADX内存Voice池 */
vp_work = user_alloc(NULL, vp_work_size);
&adxvp_config, vp_work, vp_work_size);
/* 创建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


如果使用任何大小的动态内存分配,在技术上很难避免广义上的内存碎片。
通过传递工作区来初始化程序库和生成句柄,在应用程序端控制分配内存的时间和分配顺序, 可有效避免内存碎片问题。


示例使用的数据中AtomCraft项目的目录

/cri/tools/criatomex/examples/tutorial_data_for_runtime