Multi-threading audio processes? or, what's the right way to do this?

Hi all,

I’m trying to wrap my head around how to best run a third-party audio-generating process within UE4, namely the STK (Synthesis Toolkit) C++ codebase running RtAudio as a backend. Any wisdoms would be much appreciated.

To date, I’ve compiled the STK as a Windows 64bit .dll, which I can call from a simple cmd line app. In this hacktastic test setup, I initialize my STK instance in a separate thread ( e.g. std::thread InitThread(initSTK, <parameters>) ) then call noteOn, noteOff style methods to generate glorious bowed strings. Crude, but effective.

Seeing that one can load a DLL within Unreal, I created a BlueprintFunctionLibrary to load my dll (following A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums).

Blueprints show up as one would expect, but UE will hang when I call my initSTK method… as expected, assuming STK is just trying to run on the main thread and never exits.

While I have many questions, to limit scope here, perhaps just a few:

  1. Would it be possible/advisable to pursue this direction, calling my initSTK method on its own thread (e.g. as a background task via ->StartBackgroundTask, with FNonAbandonableTask)

  2. Is there a better way, such as aiming to roll the STK into a Plugin?

I’m still exploring everything around these code-bases so any suggestions could be helpful at this point.

Thanks in advance,

rob


rob hamilton
assistant professor of music and media
rensselaer polytechnic institute
http://robhamilton.io
h
ttp://coretet.io