声波属性
访问音频数据
检索PCM缓冲区
您可以直接从声波中检索整个PCM缓冲区。
- 蓝图
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<float> PCMBuffer = ImportedSoundWave->GetPCMBufferCopy();
提示
如果需要将获取的 PCM 数据转换为字节,请参阅 Float Array to Bytes。
播放属性
循环播放
要创建无缝的音频循环,您可以设置循环播放,以便在播放结束后自动将声波播放时间倒回零并重新播放。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetLooping(false);
音量控制
您可以根据需要调整正在播放的声音的音量。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVolume(1.0f);
音高调整
您可以根据自己的偏好修改正在播放的声音的音高。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetPitch(1.0f);
附加功能
字幕
您可以设置字幕,即定义文本及其应显示的时间。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<FEditableSubtitleCue> Subtitles;
FEditableSubtitleCue Subtitle;
Subtitle.Text = FText::FromString("Example");
Subtitle.Time = 2.0f;
Subtitles.Add(Subtitle);
ImportedSoundWave->SetSubtitles(Subtitles);
虚拟化模式
您可以设置虚拟化模式,例如 静音时播放,该模式允许声波在静音期间继续播放。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
备注
如果您正在使用声音衰减来控制音频随距离的衰减方式,这将特别有用。
高阶立体混响
您可以将一个声波标记为高阶立体混响源,用于 3D 空间音频编码。音频引擎仅支持一阶高阶立体混响,这恰好需要 4 个声道。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetIsAmbisonics(true);
音频格式修改
手动重采样与声道混合
如果需要更改导入声音波的采样率或声道数量,可以使用相应的函数对音频数据进行重采样和混合。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->ResampleSoundWave(44100);
ImportedSoundWave->MixSoundWaveChannels(2);
注意
这将修改整个声波数据,并相应地影响来自 OnGeneratePCMData 和 OnPopulateAudioData 委托的输出。
自动格式转换
您可以自动重新采样并混合所有即将填充的音频数据,使其达到指定的期望采样率和声道数。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetInitialDesiredSampleRate(44100);
ImportedSoundWave->SetInitialDesiredNumOfChannels(2);
信息
这也会相应地影响 OnGeneratePCMData 和 OnPopulateAudioData 委托的输出。