Multiple Audio Decompressing Threads?

Hey there,

I’ve got a question about Threading. I checked out the normal Multithread Wiki post by Rama and the TaskGraph:

What do you want to achieve?

I want to be able to Decompress Audio, not one Audio file after another, but 1 to N different amounts of Audio files at the same time. I already got i working via the “How to Create Threads in UE4” Wiki entry.

But for that, I currently need to start that one thread, have a Timer listen to the Thread and then, after the Thread is finished, start the next one.

That’s why i checked out the TaskGraphSystem. While the Threads getting called, i can’t really access the Tasks.

Inside of the Decompress Function, that will be called in the Run,DoWork or what ever it’s called, function, i use a USoundWave Pointer which i use and fill with data. The USoundWave Object will get passed when creating the thread, data will be used, data will be filled and the USoundWave Object needs to get back to the original class that created the Thread.

The class is a UActorComponent Child. It loads a SoundFile from the HDD, packs the compressed Data into the USoundWave object and then starts a Thread to decompress it. And i want to load multiple at the same time.

But i can’t manage to access the Task from the TaskGraph. And if i pass the task a Pointer to the ActorComponent and let it call and pass the USoundWave Object back to the Component, it crashs.

So i can’t manage to get the USoundWave pointer back from the Task.

Can anyone guide me into the correct direction of what to use how to?

  • 1 or Multiple Threads simultaneously
  • Pass USoundWave Pointer on Creation
  • Get USoundWave Pointer back after Thread finished

That’s “all” i need.

If you need more information, please tell me (:

UE4 is already decompressing audio files asynchronously using the task graph system. Why are you trying to do it over?

On PC, there are “sound groups” that group audio assets together and allow the ability to automatically trigger real-time decompression vs “asyncronous full-decompression on load behavior”. The group definition and behaviors are defined in engine ini files.

The current default sound group fully decompresses sounds into memory on load (asynchronously) if the sound file is longer than 5 seconds. Longer sound files sound files will be real-time decompressed using the task graph system.

4.12 has some improvements to the system so that asynchronously decoded buffers will be submitted from the xaudio2 thread and new tasks will be launched from the xaudio2 thread when xaudio2 buffers are completed (OnBufferEnd). This prevents audio buffer underruns for real-time async decompression during heavy CPU usage on the main thread.

I’m loading Audio Files from the HDD and then decompressing them while the game runs. Then I use the decompressed Data to get the Frequency Spectrum via FFT.

That’s similar to the Audio Visualization Plugin that Epic has in the Engine. Despite the fact that my Plugin actually calculates the correct spectrum and can be packaged.

I didn’t know that the Engine already uses the TaskGraph System, as I’m totally new to this. For the 4.10 Version of the Plugin, I just used the FRunnable to decompress it when needed.

In which classes should I look to find code examples for this? Currently it loads .ogg files. :smiley: It’s just a hobby project. I don’t actually know what I’m doing, but I want to learn a bit more about the threading and create a better 4.11 Version of my plugin.

It would be really helpful to get a good solution for decompressing the .ogg files (and later maybe .wav files too). I tried using the “FAsyncAudioDecompressor” or what ever its called, but couldn’t get the correct sample data from it.