spotify / pedalboard

🎛 🔊 A Python library for audio.

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plugin.process() takes 50x longer when synth produces no output. Process timeout?

petertjmills opened this issue · comments

Hi,

First off, this is an unexpectedly amazing library. Thank you.

I'm using Vital.vst3 as an ExternalPlugin on a m1 mac.
When running the above on a midi synth that produces no output (all 0s) it takes around 10s for me, vs 0.2s when it does output.

plugin(
        [Message("note_on", note=60), Message("note_off", note=60, time=4)],
        sample_rate=sample_rate,
        duration=5,
        num_channels=num_channels,
        reset=True,
    )

Is this intentional? Is ExternalPlugin waiting for sound that it's not getting?

If it is intentional and unavoidable, is there any instructions to using multithreading? I've tried using multithreading in a few ways, including in the way mentioned in #212 but it just hangs completely, with the only solution to kill the terminal session (ctrl c doesn't work), or restart the jupyter kernel. Ideally I'd like to be able to timeout a function when it's hanging due to silence.

Thanks in advance!

Hey (other) Peter! So sorry for the delay - been quite a busy time lately.

Is this intentional? Is ExternalPlugin waiting for sound that it's not getting?

Kind of, yes! This is an side effect of a trick that Pedalboard uses when loading external plugins. You can find details about this under initialization_timeout in the docs:

initialization_timeout (float) – The number of seconds that Pedalboard will spend trying to load this plugin. Some plugins load resources asynchronously in the background on startup; using larger values for this parameter can give these plugins time to load properly.

When Vital (or any plugin) fails to produce usable sound immediately after loading (or - crucially - after it's reset, which is happening when you set reset=True), Pedalboard will wait for up to 10 seconds for the plugin to load properly. You can disable this by setting initialization_timeout=0 when calling load_plugin.

Note that this might cause a race condition between the plugin's instantiation and its use (as load_plugin will probably return before Vital has actually loaded all of its assets), so you'll probably want to experiment to ensure that you are indeed getting audio out of the plugin when you expect to.