How to use programmer instruments inside a multi instrument?

Hi everyone,

I’m a developer who’s still quite new to FMOD, and I’ve recently run into a problem that I hope someone can help me understand.

According to the FMOD documentation,

“A multi instrument’s playlist can contain nearly any kind of instrument, including single instruments, event instruments, programmer instruments, command instruments, silence instruments, and other multi instruments.”

So I tried to create a multi instrument in FMOD Studio and added several programmer instruments to its playlist.

However, when I play the multi instrument, there’s no sound output.

Then I realized that programmer instruments rely on an event instance callback (e.g., FMOD_STUDIO_EVENT_CALLBACK_CREATE_PROGRAMMER_SOUND) to load the sound at runtime.
So I created several events that each contain a programmer instrument, and then referenced those events inside the multi instrument.

But now I’m facing a new problem — I can’t find a way to set the callback or user data for the programmer instruments that are triggered through the multi instrument.

Sorry if my description is a bit long — I just wanted to make sure I’m explaining the context clearly.

I don’t know if the usage method I described above is correct.

In summary:
I’d like to know how to properly use the random/playlist functionality of multi instruments together with programmer instruments, so that I can dynamically assign different sounds at runtime. **what’s the proper workflow for designing audio in FMOD Studio while implementing the logic in code?**Currently, my programmer instrument setup follows the same logic as shown in the official FMOD examples.

Thanks a lot for your time and help!

My working environment:

FMOD Studio Version: 2.02.22
FMOD Studio API Version: 2.02.22
Platform: Windows
Language: C++

Hi, sorry for the delayed response!

Can you elaborate on what specific audio behavior you’re trying to implement using programmer instruments with multi instruments? For example, is this a case where you have vocal grunts that you want to play randomly, but the vocal grunts have localized variations?

In this case, in which you have multiple programmer instruments in a playlist, you don’t need to have each programmer instrument inside its own referenced event - simply having the programmer instrument as is in the playlist is fine. Each of them will trigger a CREATE_PROGRAMMER_SOUND callback via the instance that is playing them when they’re about to be played.

Hi, thanks for your reply!

Here is my goal:

I want NPC dialogues to play randomly (so I use a Multi Instrument), and I also need to support multiple languages without creating separate assets in FMOD Studio.
So I planned to use Programmer Instruments and switch the key at runtime based on the current language.

My questions are:

  1. If a Multi Instrument contains several Programmer Instruments, how can I know which Programmer Instrument triggered the CREATE_PROGRAMMER_SOUND callback? Can this be identified through the properties parameter or some other way?

  2. For my use case (random dialogue + runtime language switching), what is the recommended way to use Programmer Instruments?
    Should I use only one Programmer Instrument and handle random selection + language switching entirely in code?

If you have a better suggestion for this workflow, I would be glad to hear it.
Thanks again!

Thanks for the more detailed explanation.

Unfortunately, at the moment it’s not possible to accomplish what you want with programmer + multi-instruments, as it’s not possible to populate all of the programmer instruments in a multi-instrument’s playlist using the API.

For your use case, I would recommend what you noted in 2 and handle randomizing the asset played at runtime using code. For example, you could use audio tables to associate all your localized audio with specific keys, and then randomly pick a key to play in the CREATE_PROGRAMMER_SOUND callback. If you want to replicate multi-instrument’s “shuffle” playlist mode (randomization without repetition), you can track the previously played key to avoid playing it again.

I can definitely see that this particular behavior would be a lot easier to implement in just Studio, without using code, so I’ve added it to our feature tracker.

1 Like

Thank you very much for the detailed explanation and the clear guidance.
I’ll follow your recommendation and handle the randomization logic in code, using audio tables and selecting keys at runtime as you suggested. This approach should work for my current needs.

I appreciate your consideration in adding the feature to the tracker, and I’m looking forward to seeing possible support for this in future versions of FMOD.

Thanks again for your help!

1 Like