DSP Nodes showing 0 inputs and 0 outputs

I’m using the Core FMOD API within Unity, but not using the unity integration. When I create a new DSP node, it doesn’t have any input or output channels, even after calling setChannelFormat. I’ve created a minimal example that shows the problem:

using UnityEngine;

public class FMODTest : MonoBehaviour
{
    public FMOD.System FMODSystem;
    // Start is called before the first frame update
    void Start()
    {
        CheckResult(FMOD.Factory.System_Create(out FMODSystem));
        CheckResult(FMODSystem.init(
	        512,
	        FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS.PROFILE_ENABLE,
	        (System.IntPtr)null));
        Debug.Log("FMOD Core Initialized");

        FMOD.ChannelGroup nullCG = new FMOD.ChannelGroup(System.IntPtr.Zero);

		CheckResult(FMODSystem.getMasterChannelGroup(out FMOD.ChannelGroup masterCG));
        CheckResult(masterCG.getDSP(0, out FMOD.DSP masterFader));
        CheckResult(FMODSystem.createDSPByType(FMOD.DSP_TYPE.MIXER, out FMOD.DSP mixer));
        masterFader.addInput(mixer, out FMOD.DSPConnection conn);
        mixer.setActive(true);
        mixer.setChannelFormat(0, 2, FMOD.SPEAKERMODE.STEREO);
        conn.getMixMatrix(null, out int outChans, out int inChans);
        Debug.LogFormat("Got {0} input channels and {1} output channels", inChans, outChans);
        // always shows 0 inputs and 0 outputs
    }

    // Update is called once per frame
    void Update()
    {
        FMODSystem.update();
    }

	private void OnDestroy()
	{
        CheckResult(FMODSystem.release());
	}

	public static void CheckResult(FMOD.RESULT res) { 
        if(res != FMOD.RESULT.OK) {
            Debug.LogErrorFormat("FMOD Error: {0}", res);
        }
    }
}

it looks like I can get nonzero input and output channels by first calling setMixMatrix, but it doesn’t look like I can set them arbitrarily. For instance, after calling conn.setMixMatrix(new float[32], 16, 2);, I end up with 16 input and 16 output channels, instead of 16 output and 2 input, as I expected. It’s also not clear to me how setChannelFormat fits in.

My goal here is to have 8 different mix nodes, where each one takes 2 channels as input, and sends to a pair of outputs in my 16-channel audio interface.

So mixer #1 would take its stereo input and route to channels 1+2, mixer #2 would take its stereo input and route to 3+4, etc. What’s the right sequence of channel configurations to set that up?

Hi,

Here the issue is setChannelFormat is being called on the DSP while the DSPConnection is being checked for its outputs/inputs while it hasn’t been set.

This is a bit confusing, while the mix matrix is being set using the input and output you provide it has to use the greatest of those two values to create the matrix thus it returns 16,16 in this situation. This is confusing and I will make a note to improve this in our documentation. However, the mix matrix will be constructed with the values you provide.

So you were heading in the right direction using the DSPConnections and setting their mix matrices. How you set the matrix is what we will use to control where the output is going. Rather than using new float[32] when setting the matrix we will need to explicitly initialize it:

float[] matrix = {
	1,0,
	0,1,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0,
	0,0
};

Here we are closing all channels except FL and FR, you will continue this for all the other DSPConnections essentially using them to block all the audio you do not wish to pass through and passing the audio only to the desired channels.

Hope this helps!

Here the issue is setChannelFormat is being called on the DSP while the DSPConnection is being checked for its outputs/inputs while it hasn’t been set.

The inputs/outputs haven’t been set, but I thought that was what setChannelFormat is supposed to be doing. Maybe I’m misunderstanding what setChannelFormat does - I thought it would force the number of input channels for a DSP, and their format. So once I’ve called mixer.setChannelFormat(0, 0, FMOD.SPEAKERMODE.STEREO), the mixer DSP node should always have 2 input channels, right?

This is a bit confusing, while the mix matrix is being set using the input and output you provide it has to use the greatest of those two values to create the matrix thus it returns 16,16 in this situation. This is confusing and I will make a note to improve this in our documentation. However, the mix matrix will be constructed with the values you provide.

To make sure I understand here, you’re saying that getMixMatrix will always return a square matrix, even if the actual mix matrix for the connection is not square? Is there a way to find out how many input and output channels a connection actually has?

Hi,

This is for setting the channels on the FMOD Engine | Core API Reference - DSP not on the FMOD Engine | Core API Reference - DSPConnections which have different requirements for setthing them up.

Yes, I would suggest adding the FMOD Engine | Core API Reference - FMOD_INITFLAGS_PROFILE_METER_ALL which will allow you to see the channels on each DSP.

I will also suggest calling FMOD Engine | Core API Reference - System::setSoftwareFormat with the values: setSoftwareFormat(48000, 16, FMOD_SPEAKERMODE_RAW). FMOD Engine | Core API Reference - FMOD_SPEAKERMODE_RAW will allow the fmod system to accommodate the 16 channels you are looking for.

Hope this helps!