音波屬性
存取音訊資料
擷取 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);
虛擬化模式
您可以設定虛擬化模式,例如靜音時播放,這允許音波在靜音期間繼續播放。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
備註
如果您使用聲音衰減來控制音頻隨距離淡出的方式,這會特別有幫助。
環繞聲 (Ambisonics)
您可以將聲波標記為環繞聲源,用於 3D 空間音頻編碼。音頻引擎僅支援一階環繞聲 (FOA),這需要恰好 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 委派的輸出。
自動格式轉換
您可以自動重新取樣並混合所有即將填充的音訊數據,使其符合指定的目標取樣率和聲道數。
- 藍圖
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetInitialDesiredSampleRate(44100);
ImportedSoundWave->SetInitialDesiredNumOfChannels(2);
資訊
這也會相應地影響 OnGeneratePCMData 和 OnPopulateAudioData 委派的輸出。