CRI ADX  Last Updated: 2024-07-17 10:48 p
以音轨为单位控制音量

示例目录

/cri/pc/samples/criatomex/control_track_volume


示例描述

Atom运行库提供将多声道音频数据 作为多重音轨的音频数据处理的机制。
例如在播放6ch的音频数据时,该音频数据在预设状态下会以5.1ch的音频数据 (各频道对应于L, R, C, LFE, Ls, Rs的数据)处理。
但是,通过使用::criAtomExPlayer_SetTrackInfo函数,可以将6ch的音频数据作为单声道6音轨的音频数据及 立体声3音轨的音频数据进行控制。
/* 定义每个音轨的频道数量 */
/* 备注)在本示例中,将8ch的音频数据作为2频道×4音轨处理。 */
const CriSint32 channels_per_track[4] = { 2, 2, 2, 2 };
/* 创建可播放8ch HCA数据的Voice池 */
voice_pool_config.player_config.max_channels = 8;
app_obj->voice_pool
= criAtomExVoicePool_AllocateHcaVoicePool(&voice_pool_config, NULL, 0);
/* 创建Player */
app_obj->player = criAtomExPlayer_Create(NULL, NULL, 0);
/* 设置要播放的音频数据的格式信息 */
/* 备注)由于要播放的数据为2频道×4音轨=8, */
/*    为criAtomExPlayer_SetNumChannels函数指定8。 */
criAtomExPlayer_SetNumChannels(app_obj->player, 8);
criAtomExPlayer_SetSamplingRate(app_obj->player, 48000);
/* 指定音频数据的音轨信息 */
/* 备注)以下代码中,指定2频道×4音轨。 */
criAtomExPlayer_SetTrackInfo(app_obj->player, NUM_TRACKS, channels_per_track);
/* 设置音频数据 */
criAtomExPlayer_SetFile(app_obj->player, NULL, PATH FILE);
/* 开始播放 */
criAtomExPlayer_Start(app_obj->player);
#define CRIATOMEX_FORMAT_HCA
Definition: cri_le_atom_ex.h:1928
void criAtomExPlayer_SetFile(CriAtomExPlayerHn player, CriFsBinderHn binder, const CriChar8 *path)
Set the sound data to play (specifying a file name)
void criAtomExPlayer_SetFormat(CriAtomExPlayerHn player, CriAtomExFormat format)
Specify the format of a sound
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback
CriAtomExPlayerHn criAtomExPlayer_Create(const CriAtomExPlayerConfig *config, void *work, CriSint32 work_size)
Create an AtomEx player
void criAtomExPlayer_SetNumChannels(CriAtomExPlayerHn player, CriSint32 num_channels)
Specify the number of channels of a sound
void criAtomExPlayer_SetSamplingRate(CriAtomExPlayerHn player, CriSint32 sampling_rate)
Specify the sampling rate of a sound
void criAtomExPlayer_SetTrackInfo(CriAtomExPlayerHn player, CriSint32 num_tracks, const CriSint32 *channels_per_track)
Set the track information
#define criAtomExVoicePool_SetDefaultConfigForHcaVoicePool(p_config)
Assign the default values to the configuration structure used to create an HCA Voice Pool
Definition: cri_le_atom_ex.h:600
CriAtomExVoicePoolHn criAtomExVoicePool_AllocateHcaVoicePool(const CriAtomExHcaVoicePoolConfig *config, void *work, CriSint32 work_size)
Create an HCA Voice Pool
执行以上设置,AtomExPlayer将8ch的音频数据作为立体声×4音轨的音频数据进行播放。
关于各音轨的音量,可以使用::criAtomExPlayer_SetTrackVolume函数单独控制。
/* 音轨2以外的声音静音 */
criAtomExPlayer_SetTrackVolume(app_obj->player, 0, 0.0f);
criAtomExPlayer_SetTrackVolume(app_obj->player, 1, 0.0f);
criAtomExPlayer_SetTrackVolume(app_obj->player, 2, 1.0f);
criAtomExPlayer_SetTrackVolume(app_obj->player, 3, 0.0f);
criAtomExPlayer_UpdateAll(app_obj->player);
void criAtomExPlayer_UpdateAll(CriAtomExPlayerHn player)
Update the playback parameters (for all sounds currently playing)
void criAtomExPlayer_SetTrackVolume(CriAtomExPlayerHn player, CriSint32 track_no, CriFloat32 volume)
Set the track volume