CRI ADX  Last Updated: 2024-07-17 10:48 p
Voice优先级

示例目录

/cri/pc/samples/criatomex/control_priority


示例描述

在CRI Atom中,执行实际发声处理的Voice与执行播放控制的Player相互独立, 如果在Voice较少的状态用多个Player执行播放处理,则会发生Player之间争夺Voice的情况。


  • 设置优先级
    如果Voice不足,请使用::criAtomExPlayer_SetVoicePriority函数设置优先使用哪个Player。

  • 设置发声控制方式(先发优先/后发优先)
    如果优先级相同,请使用::criAtomExPlayer_SetVoiceControlMethod函数, 设置优先使用先播放的Player还是稍后播放的Player。
#define SMP_PATH_LENGTH -256
CriAtomExPlayerConfig player_config;
/* 指定较少的数量以实现Voice争夺 */
pool_config.num_voices = 1;
/* 指定流播放 */
pool_config.player_config.streaming_flag = CRI_TRUE;
/* 创建Voice池 */
voice_pool = criAtomExVoicePool_AllocateAdxVoicePool(&pool_config, NULL, 0);
/* 指定保存路径所需的大小 */
player_config.max_path = SMP_PATH_LENGTH;
/* 创建Player */
player[0] = criAtomExPlayer_Create(&player_config, NULL, 0);
player[1] = criAtomExPlayer_Create(&player_config, NULL, 0);
/* 为Player设置要播放的文件 */
criAtomExPlayer_SetFile(player[0], NULL, PATH FILE1);
criAtomExPlayer_SetFile(player[1], NULL, PATH FILE2);
/* 设置优先级 */
criAtomExPlayer_SetVoicePriority(player[0], 1); /* 优先级相对较高 */
criAtomExPlayer_SetVoicePriority(player[1], 0); /* 优先级相对较低 */
/* 先发优先设置(无法为稍后播放的同一优先级的Player保证Voice) */
/* 更新信息 */
/* 开始播放 */
void criAtomExPlayer_SetFile(CriAtomExPlayerHn player, CriFsBinderHn binder, const CriChar8 *path)
Set the sound data to play (specifying a file name)
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback
void criAtomExPlayer_SetVoiceControlMethod(CriAtomExPlayerHn player, CriAtomExVoiceControlMethod method)
Specifying a voice control method
CriAtomExPlayerObj * CriAtomExPlayerHn
Player handle
Definition: cri_le_atom_ex.h:3622
void criAtomExPlayer_UpdateAll(CriAtomExPlayerHn player)
Update the playback parameters (for all sounds currently playing)
CriAtomExPlayerHn criAtomExPlayer_Create(const CriAtomExPlayerConfig *config, void *work, CriSint32 work_size)
Create an AtomEx player
void criAtomExPlayer_SetVoicePriority(CriAtomExPlayerHn player, CriSint32 priority)
Set the priority
#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
@ CRIATOMEX_PREFER_FIRST
Definition: cri_le_atom_ex.h:3685
#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
CriAtomExVoicePoolHn criAtomExVoicePool_AllocateAdxVoicePool(const CriAtomExAdxVoicePoolConfig *config, void *work, CriSint32 work_size)
Create an ADX Voice Pool
CriBool streaming_flag
Whether to perform streaming playback
Definition: cri_le_atom.h:1641
Configuration structure used when creating an ADX Voice Pool
Definition: cri_le_atom_ex.h:3277
CriSint32 num_voices
Definition: cri_le_atom_ex.h:3279
CriAtomAdxPlayerConfig player_config
Definition: cri_le_atom_ex.h:3280
Configuration structure used when creating a player
Definition: cri_le_atom_ex.h:3484
CriSint32 max_path
Maximum path length
Definition: cri_le_atom_ex.h:3565


在上述代码示例中,先播放player[1],稍后开始播放player[0], 由于只有一个Voice,但是player[0]的优先级高,因此player[1]停止播放, player[0]开始播放。


如果优先级相同,由于是先发优先,因此player[1]继续播放, 在player[1]播放结束前,player[0]不会开始播放。


Cue播放时的优先级使用工具端设置的优先级, 因此应用程序端不需要操作。(当前被设定为无法操作。)