Change Convolution Reverb's IR via script

I feel kinda stupid asking this question, but: How do I launch an FMOD Script at runtime, from within FMOD or, even better, from Unity?
I’d like to change Impulse Responses on my single instance of convolution reverb using ConvolutionReverb.setIRFromFilePath(filePath) - there will be due loading time and silence between rooms.

I’m thinking of a script called ChangeIR.js or so. Whenever Unity calls this script it passes a variable that holds the room index (about 20 rooms) and the script will do something like (syntax omitted):

if RoomIndex = 2

Is this going to work or am I on an entirely wrong path?


Let me refine this:

How do I, in general, launch a script at runtime without hitting ‘Scripts/Reload’ or from some type of console, but from within the Game?

Would it be possible to “attach” a js script (which lives in my project’s ‘/Scripts’ folder) to a mixer snapshot, i.e. have the snapshot launch the script as soon as it’s playing? I did dump() all info on the snapshot in the terminal but most of the parameters aren’t covered in the documentation, I spent a day taking guesses and experimenting (to no success) and there’s virtually not a single tutorial out there.

Halp anyone?

Alternatively, is there a way to have a script launch at startup and loop in the background? When I put a while loop in my script, have it count to 100, log the current number and wait 100ms every iteration, FMOD (on Mac) will give me the beach ball for 10 seconds (that’s how long the script takes) and only then log 100 lines at once. Accordingly, it will just beach ball and crash if I put an infinite loop. Looks to me like the script is happening in the main thread - could that be the problem?

It’s funny how nobody seems to be using scripts in FMOD that much, or am I missing something?

FMOD Studio scripts are only effective within the FMOD Studio application, and cannot be used in-game. (Well, not without using live update, but I assume you don’t want the FMOD Studio GUI running in the background whenever your game is running.) This is because the scripting feature is designed to allow you to simplify your workflow by replacing time-intensive multi-step procedures with keyboard shortcuts and menu commands. It is not designed to allow you to trigger and control the content of your project, as the FMOD Studio API already exists for that purpose.

For the same reason, it is not possible to trigger an FMOD Studio script from an event or snapshot, as such a trigger would be meaningless in-game.

In addition, it is not possible to replace the impulse response used by a convolution reverb effect as your game runs. This is because the impulse response file is built into your project’s master bank as part of the bank building process. A better option is to create multiple different convolution effects on different return buses, and use snapshots to determine which of those buses receives audible input.

1 Like

I am curious: what is the CPU cost of using multiple convolution reverbs (for diferent IRs to simulate different spaces) vs having 1 regular algorithmic where you only need to change parameters?

Convolution reverb is very expensive, the less you can have active at a time the better.

Interestingly, while you are running the game and connected to Studio via Live Link, you can actually upload new impulses into a Convolution Reverb and you can hear the change in real time. Live Link only updates user data not audio assets - but the Convolution Reverb impulse is actually user data. The XML file becomes huuuuuuuge if it contains a Convolution Reverb with a long impulse.

However, there is a way…

You can “hack” your game to have multiple Convolution impulse presets by containing them into Events instead of the Mixer.

Here’s the basic idea:

  • The Reverb return in your mixer contains a Transceiver to sends to a channel (followed by a mute, so the signal gets ‘redirected’). Let’s say channel 23.
  • The “Convolution Events” contain a Transceiver that receive that channel 23, and follow it with a Convolution Reverb with an impulse in it (and output to another bus)
  • You can then switch reverb presets by starting and stopping their respective FMOD events. If you add AHDSR to the master gain of these events, there’s a fade from one reverb to another, during which two Convolution Reverbs will be active simultaneously, but then you can have any number of different presets while only having max 2 of them active.
  • You will need to manage these reverbs carefully, ie make sure the other reverbs get a stop command when a new one is activated, so you won’t have multiple reverbs playing simultaneously.

Note that this approach will cause a bit of latency (since signal is going from events to a mixer, then back to another event and from there to the mixer), but with reverb this is not a big deal since it’s supposed to be delayed anyway.

1 Like