Runtime Audio Importing

Recently, I’ve been trying to import audio at runtime, and I’ve come across the great Runtime Audio Importer plugin, which has been super helpful.

Unfortunately, the plugin doesn’t work particularly well in UE5, due to a couple of issues, like SetSoundAssetCompressionType only working in the editor, and SoundWaveProcedural having no obvious way of stopping audio from playing, despite having access to the duration and looping properties.

If a procedural sound reaches the duration, regardless of whether it’s looping or not, the Parse method continues to be called, and AudioComponents playing that sound never change status to “Stopped”.
Even if you stop and destroy the AudioComponent directly, the procedural sound is never cleaned from memory, despite the fact that it shouldn’t be referenced anywhere else.
Talking of being unable to reference it anywhere else, you can only play a procedural sound from one Audio Component, which is quite wasteful in this particular case.

In regards to the SoundWave SoundAssetCompressionType property, without the ability to set this, there is no real option for importing audio at runtime without some kind of dummy SoundWave, since a default SoundWave is built with the compression type “BinkAudio”, meaning that without a decoder set, the engine will throw a null exception.
I can set any of the buffers in a SoundWave, but, I can’t set the compression type? This seems like very strange logic to me.

Can there not be a “RuntimeSoundWave” class, where we can generate sounds during gameplay, and then have them treated like a regular SoundWave? Sounds with a beginning, an end (Audio Components stopped when they reach the end), and cleaned up by the garbage collector when no longer needed?

I managed to get most of the Runtime Audio’s USoundWave functionality working, but we’ve still not discerned why a USoundWaveProcedural with a finite duration will never lead to an UAudioComponent to evaluate itself as no longer playing audio.

Even if we destroy the component, the USoundWaveProcedural will live on indefinitely, never getting cleaned up until the engine is shut down, unless it’s expressly destroyed.

Did you, by any chance, managed to hook up runtime sound wave to a Metasound source?

I’ve never done anything with any of the meta projects, but if they accept a normal USoundWave, then you can just generate a USoundWave at runtime, which is something that I was doing, since the procedural sound functionality was a bit weird to deal with.

You can find my fork here, I’ve not done anything on it in a while, since I’m not really sure I need this functionality now, but it should be vaguely helpful in making runtime USoundWaves.

The problem is that it’s apparently impossible to generate USoundWave at runtime now. In UE4 you could populate its compressed data directly and it would work. Now it’s inaccessible and when you try to get a reference to compressed data, UE first tires to load it from DDC and then tires to cook the data from raw wave data, if running in the editor, and fails otherwise in cooked build.

Try looking at this USoundWave branch, there were a couple of options for exporting USoundWaves, as I recall, I think two of them would work, but one crashed it immediately… which I THINK was the method you’re using?

I seem to recall that decompressing the buffer had positive results, but if you poke around in there, you’ll get all the answers I have, at least.

Sorry, it’s been a long time since I’ve messed with this!