How to work with Imported Sound Wave

Mar, 17 2021— #docs

The Runtime Audio Importer plugin imports the sound wave not as a standard USoundWave, but as a UImportedSoundWave, which has its own methods and described here.

To begin with, the most important thing for playing ImportedSoundWave is the "Start Time" value in the function for playing the sound wave must be "0" (this can be any function such as "Play Sound 2D" or "Play" from Audio Component).

An example of different methods for playing audio, where

An example of different methods for playing audio, where "Start Time" = 0

Due to the use of a procedural sound wave, to rewind the playing time, you need to use the "Rewind Playback Time" method, which rewinds the sound wave for the required specified time.  You can call this method even before the sound is played, so that the sound starts playing at a specific time.

An example of rewinding playback of a sound wave for 32 seconds

An example of rewinding playback of a sound wave for 32 seconds

You can also get the current playing time of the sound wave in seconds or as a percentage using the "Get Playback Time" and "Get Playback Percentage" methods.

GetPlaybackTime and GetPlaybackPercentage nodes

GetPlaybackTime and GetPlaybackPercentage nodes

To check if the audio playback is finished, use the "Is Playback Finished" method

Is Playback Finished node

Is Playback Finished node

To track the end of audio playback, bind to the "On Audio Playback Finished" delegate

An example of binding to the

An example of binding to the "On Audio Playback Finished" delegate

If you no longer need Imported Sound Wave, you need to clear the data in memory for optimization. To do this, use the "Release Memory" method. Even though the importer sound wave can be destroyed automatically, during garbage collection on "Begin Destroy", for the sake of optimization, it is advised to clear the memory manually.

Release Memory node

Release Memory node

Important! If you want to stop playing a sound wave and clear its data, before clearing the data through Release Memory, you should process a small Delay for about half a second. This is necessary due to the fact that after stopping the playback of the sound wave, the engine can use the residual data of the audio buffer or request a new one, and therefore a Memory Access Violation error is possible due to the fact that the data has been cleared by Release Memory.  

By Georgy Treshchev

Unreal Engine Developer. Contact for any questions. Telegram chat, e-mail, Github.