Mixing from unity

Hello everyone,

I’d like to develop some unity scripts/components able to control the channel level of my fmod events form unity. The idea is to be able to set the volumes of the events directly from VR games in order to mix the audio from the game. We won’t use parameters because we want to control the mix and keep the volumes as set from the VR game. The idea is to control the fmod faders, not to offer to the final user the opportunity to set the volumes. I know I can do it easily for the group channel but would like to know if it is possible to control also the level of the master send level of an event (which is common for every instances of an event) ? Long story short: I’d like to do some mixing (at least set the audio volumes) from the game without having to add a group channel for every event.

Thank you for your answers

Hi,

This can easily be done using the EventIsntance.setVolume() function, explained under Studio API Reference | Event Instance.

There are a couple of ways in which you can access the EventInstance. One is a script reference to an EventEmitter in your scene

private FMODUnity.StudioEventEmitter _emitter; 

void Start()
{
	// Retrieving the Emitter object off our Unity Object 
	_emitter = GetComponent<FMODUnity.StudioEventEmitter>(); 
	
	// Debug check to make sure the Emitter was retrieved correctly 
	if (_emitter.isValid() == true)
	{
		Debug.Log("Emitter retrieved and is valid");
	}
	else
	{
		Debug.Log("Failed to retrieve emitter on Start()"); 
	}
}

// Now you have a reference to your emitter, whenever you want to set the volume do something like this
private void ChangeVolume(float value)
{
	// Setting the emitter volume value to the new value, to avoid clipping or distortion to the audio keep the value between 0 and 1. 
	_emitter.EventInstance.setVolume(value); 
	// Call this when ever you want to change the volume on the Event
}

Another option is to create the EventInstance yourself.

// This will allow us to use an Editor Window to choose the event we want to play 
public FMODUnity.EventReference _reference; 

// This will be the EventInstance we create and control 
private FMOD.Sutio.EventInstance _instance; 

// Now to create initialize our instance in our Start() function
Void Start()
{
    // Using the Reference we use the FMOD system to create our instance for us 
	_instance = FMODUnity.RuntimeManager.CreateInstance(_ref); 
	
	// Again we will want to check the instance was created successfully 
	if (_instance.isValid() = true)
	{
		Debug.Log("Created Instance successfully"); 
	}
	else 
	{
		Debug.Log("Failed to create instance");
        // You many want to stop your code here so that it doesn't continue with a broken instance
	}
	
	// A super useful FMOD debugging tool which gives insights into how functions have run
	FMOD.RESULT result; 
	
	// You will need to call start on the Instance yourself to hear the audio, how this function works in under Studio API | Event Instance, and it explains why we call .release()
	result = _instance.start(); 
	
	// Now we debug the result of the _instance call to see if there were any issues 
	if (result != FMOD.RESULT.OK)
	{
	    Debug.Log("Error starting instance with result " + result); 
	}
	else
	{
	    Debug.Log("Started instance successfully with result " + result); 
	}
	
	result = _instance.release(); 
	
	// debugging again
	if (result != FMOD.RESULT.OK)
	{
	    Debug.Log("Error releasing instance with result " + result);
	}
	else
	{
	    Debug.Log("Released instance successfully with result " + result);
	}
}

//Use the same ChangeVolume() function from above to access the volume value 
private void ChangeVolume(float value)
{
	// Setting the emitter volume value to the new value 
	_instance.setVolume(value); 
	// Call this when ever you want to change the volume on the Event
}

What each FMOD.RESULT means is explained in Core API | Common, and how .start() and .release() work is explained in Studio API | Event Instance.

Those are two ways to control an EventInstance volume.

Hope this helps!