Sound control through channel groups

Hello, I am working with Fmod and Unity. I’m having trouble trying to add sounds to a ChannelGroup so that I can maintain control of all sounds and manipulate their parameters through the group.

Is there a way to add an EventInstance in a ChannelGroup?

I add a little toy code to better understand what I’m trying to do.

Thanks.

public class MusicManager: MonoBehaviour
{
[Header(“MUSIC Event Ref”)]
public EventReference musicEventRef;

[Header("Max Channels")]
public int maxChannels;

private FMOD.System _fmodSys;
private FMOD.ChannelGroup _chgMUSIC;
private FMOD.Studio.EventInstance _musicInstance;
private bool _mute;

private void Awake()
{
    FMOD.RESULT result = FMOD.Factory.System_Create(out _fmodSys);
    if (result != FMOD.RESULT.OK)
    {
        UnityEngine.Debug.LogError("FMOD System Create error: " + FMOD.Error.String(result));
        Application.Quit();
    }

    result = _fmodSys.init(maxChannels, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);

    if (result != FMOD.RESULT.OK)
    {
        UnityEngine.Debug.Log("FMOD System Init error: " + FMOD.Error.String(result));
        Application.Quit();
    }
}

private void Start()
{
    if (_fmodSys.createChannelGroup("SFX", out _chgMUSIC) == FMOD.RESULT.OK)
    {
        _musicInstance = FMODUnity.RuntimeManager.CreateInstance(musicEventRef.Path);
        FMODUnity.RuntimeManager.AttachInstanceToGameObject(_musicInstance, GetComponent<Transform>(), GetComponent<Rigidbody>());

        if (_musicInstance.isValid())
        {
            _musicInstance.start();
            //-> how to add instance to channel group ????
        }
    }
    _mute = false;
}

private void Update()
{
    if (Input.GetKeyDown(KeyCode.M))
    {
        _mute = !_mute;
        _chgMUSIC.setMute(_mute);
    }
}

}

Hi,

A ChannelGroup is a lower level Core API object, and an Event is a higher level Studio API object which is built on top of a Core API ChannelGroup. While it is technically possible to interact with the Core API DSP graph and route Events into your own ChannelGroup, this is isn’t recommended, as circumventing the Studio API to directly change the DSP graph can introduce obscure and difficult to diagnose bugs. That said, FMOD Studio essentially already handles this for you - Events routed into a Group Bus are effectively routed into the Buses’ underlying ChannelGroup, so I would suggest using Buses to group your Events instead of using a ChannelGroup.

However, if you want to “batch” manipulate Event parameters, you cannot do so via a ChannelGroup (ChannelGroups are Core API objects, and parameters are from the Studio API), or via Buses (Buses are functionally a simple macro control and don’t have the API function to do this). Instead, you can either:

  • Use a global parameter, which when set has the same value across all events. You can make a parameter global by setting the “Parameter Scope” to “Global” when adding or editing a parameter in Studio. Global parameter values can be set via the API with the relevant Studio::System functions, such as Studio::System::setParameterByName
  • Use standard local parameters on your events, and code a solution yourself to track your EventInstances and set the Parameter on all of them

Hope this helps!

Hello Louis,

Thank you very much for the reply. Unfortunately, I was afraid that this was the answer so I created my own “ChannelGroup” that works directly with the event instances, simulating what the real “ChannelGroup” of the Studio part does. I have lost many functionalities but for now I can continue advancing. I couldn’t figure out why Fmod’s own RunTimeManager that works with Unity allows you to create a “ChannelGroup” but doesn’t allow you to add channels to it.

Again, thank you very much.

Best regards.