声波属性
访问音频数据
获取PCM缓冲区
您可以直接从声波中检索整个PCM缓冲区。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<float> PCMBuffer = ImportedSoundWave->GetPCMBufferCopy();
:::小贴士 如需将获取的PCM数据转换为字节,请参阅浮点数组转字节。 :::
播放属性
循环播放
要创建无缝音频循环,可以设置循环属性,使音波播放结束后自动将播放时间重置为零并继续播放。
- 蓝图
- 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);
虚拟化模式
您可以设置虚拟化模式,例如静音时播放(Play When Silent),该模式允许声波在静音期间继续播放。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
备注
这对于使用声音衰减控制音频随距离淡出特别有帮助。
音频格式修改
手动重采样与声道混合
如果需要更改导入声音波的采样率或声道数量,可以使用相应函数对音频数据进行重采样和混合处理。
- 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
委托的输出。