音波属性
您可以直接从音波中检索整个PCM缓冲区。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<float> PCMBuffer = ImportedSoundWave->GetPCMBufferCopy();
为了创建一个无缝的音频循环,您可以设置循环,使得在播放结束后自动将声波播放时间倒回到零并重新播放。
- 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);
您可以设置虚拟化模式,例如Play When Silent,这允许声波在静音期间继续播放。如果您使用声音衰减,这将特别有帮助。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
如果你需要更改导入声音波形的采样率或通道数量,可以使用适当的函数来重新采样和混合音频数据。这将修改整个声音波形数据,并相应地影响 OnGeneratePCMData
和 OnPopulateAudioData
委托的输出。
- 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);