Sound wave properties
Accessing Audio Data
Retrieving PCM Buffer
You can retrieve the entire PCM buffer from a sound wave directly.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<float> PCMBuffer = ImportedSoundWave->GetPCMBufferCopy();
If you need to convert the obtained PCM data to bytes, see Float Array to Bytes.
Playback Properties
Looping
To create a seamless audio loop, you can set looping to automatically rewind the sound wave playback time to zero and play after playback ends.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetLooping(false);
Volume Control
You can adjust the volume of the sound being played to suit your needs.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVolume(1.0f);
Pitch Adjustment
You can modify the pitch of the sound being played to your preference.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetPitch(1.0f);
Additional Features
Subtitles
You can set subtitles, namely, define the text and the time at which they should be displayed.
- 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);
Virtualization Mode
You can set the virtualization mode, such as Play When Silent, which allows the sound wave to continue playback even during silence.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
This is particularly helpful if you're using sound attenuation to control how audio fades with distance.
Audio Format Modifications
Manual Resampling and Channel Mixing
If you need to change the sample rate or number of channels in the imported sound wave, you can use the appropriate functions to resample and mix the audio data.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->ResampleSoundWave(44100);
ImportedSoundWave->MixSoundWaveChannels(2);
This will modify the entire sound wave data and affect the output from the OnGeneratePCMData
and OnPopulateAudioData
delegates accordingly.
Automatic Format Conversion
You can automatically resample and mix all the upcoming audio data to be populated to the specified desired sample rate and number of channels.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetInitialDesiredSampleRate(44100);
ImportedSoundWave->SetInitialDesiredNumOfChannels(2);
This will also affect the output from the OnGeneratePCMData
and OnPopulateAudioData
delegates accordingly.