spotify / pedalboard

🎛 🔊 A Python library for audio.

Home Page:https://spotify.github.io/pedalboard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is threading supported for `VST3Plugin` instances?

csteinmetz1 opened this issue · comments

I followed the example in #212 to use ThreadPoolExecutor but I find that this does not work for me when using VST3 plugin objects. It does work using the internal Pedalboard effects such as Reverb() in your example. When I call the below example it will hang indefinitely. Is there a limitation with using VST3Plugin instances here? I couldn't find a mention in the docs.

Here is a minimal example:

from concurrent.futures import ThreadPoolExecutor

audio_segment = np.random.randn(2, 524288)
sample_rate = 48000

futures = []  
with ThreadPoolExecutor(max_workers=16) as executor:
   futures.append(
    executor.submit(
        pedalboard.load_plugin("MyPlugin.vst3").process,
        audio_segment,
        sample_rate,
    )
  )   
   for future in futures:
    print(future.result())

Hey Christian! Great question - I have a feeling this might be related to #268, which I haven't had time to dig into yet. VSTs certainly support pumping the audio callback from multiple threads (as that's what DAWs do) but we might not be properly handling a lock somewhere. I'll do a bit of digging.

Hey @csteinmetz1 - after a hectic couple months away, I've just merged a fix that should allow you to run VST3Plugin instances in background threads. Note that this is fairly experimental and may break for some plugins; the VST3 spec doesn't allow us to call some methods (like prepareToPlay) from threads other than the main thread, but Pedalboard does anyways. It's worked for every VST3 I've tried, but there will definitely be exceptions.

This change is part of v0.8.8, which has just entered CI and should be live on PyPI within a couple of hours.