FMOD Mixer in Unreal Engine 4

In this tutorial we will learn how to change the volumes of FMOD Busses and VCA’s in Unreal Engine 4 by using Blueprint nodes and writing C++ code.

Controlling the FMOD Mixer using Blueprints

We can use two nodes, namely Bus Set Volume and VCA Set Volume to control the volume of specific Busses and VCA’s. But first let’s create a function that converts a decibel value to a linear value. Since both volumes are represented in a linear (amplitude) scale that ranges between 0 and 1, it feels more natural to work with a logarithmic scale as dB.

Converting a decibel value to a linear scale

Create two float variables called dB and linear. We will create a function with one float input and one float output that will convert our dB value to a linear scale:

dBToLinear Function in Unreal Engine 4
dBToLinear Function in Unreal Engine 4

Bus volume control

In the blueprint, we can use this function to set the volume of a bus by using the dB scale. The FMOD node to set the bus volume is called Bus Set Volume:

FMOD Set Bus Volume node in Unreal Engine 4
FMOD Set Bus Volume node in Unreal Engine 4

VCA volume control

For VCA’s the procedure is the same. We can use the VCASet Volume node to set the volume of a VCA:

FMOD VCA Set Volume node in Unreal Engine 4
FMOD VCA Set Volume node in Unreal Engine 4

Controlling the FMOD Mixer using C++

In C++ we can use both the Blueprint functions and the FMOD Studio API to change the volume of VCA’s and Busses. Here you can find an overview of the methods to achieve the same behaviour as the Blueprints in code.

Bus volume control with UFMODBus

Let’s declare an UFMODBus, a float variable to hold the desired volume and a function that will convert the volume value from a dB scale into a linear scale:

UPROPERTY(EditAnywhere, Category = "FMOD")
        class UFMODBus* Bus;

UPROPERTY(EditAnywhere, Category = "FMOD", meta = (ClampMin = "-80", ClampMax = "10"))
         float BusVolume;

float dBToLinear(float dB);

Let’s implement the dBtoAmplitude function first:

float ATutorialCharacter::dBToLinear(float dB)
{
	return pow(10.0f, dB / 20.0f);
}

To set the volume of the bus, we can use the BusSetVolume function of UFMODBlueprintStatics by passing the UFMODBus and the converted volume value:

UFMODBlueprintStatics::BusSetVolume(Bus, dBToLinear(BusVolume));

In the Details tab of our character, we will find the selectable FMODBus reference and the Bus Volume float slider:

FMOD Bus in the Details tab in Unreal Engine 4
FMOD Bus in the Details tab in Unreal Engine 4

Bus volume control using FMOD’s Studio API

If we want do directly use the Studio API, we can declare a bus in the header file:

FMOD::Studio::Bus* Bus;

In the character class we check if FMOD Studio System is available and if that is the case, get the Bus and assign it to the Bus we declared:

if (IFMODStudioModule::IsAvailable())
	{
		FMOD::Studio::System* StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
		if (StudioSystem)
		{
	StudioSystem->getBus(TCHAR_TO_UTF8(*FName("bus:/Bus").ToString()), &Bus);
		}
	}

Now we can just call the setVolume function and pass the volume as the argument:

Bus->setVolume(dBToAmplitude(BusVolume));

VCA volume control with UFMODVCA

Setting the volume of a VCA is very similar to the previous steps. We declare a UFMODVCA and a float variable for the actual volume. We also visually clamp the variable to a value between -80 and 10.

UPROPERTY(EditAnywhere, Category = "FMOD")
class UFMODVCA* Vca;

UPROPERTY(EditAnywhere, Category = "Variables", meta = (ClampMin = "-80", ClampMax = "10"))
float VcaVolume;

After that, we can set the volume of the VCA like we did with the Bus by calling VCASetVolume:

UFMODBlueprintStatics::VCASetVolume(Vca, dBToAmplitude(VcaVolume));

VCA volume control using FMOD’s Studio API

Setting the volume of a VCA with the Studio API also behaves the same. Declare an VCA and a float variable that we will use to change the volume value:

FMOD::Studio::VCA* Vca;

UPROPERTY(EditAnywhere, Category = "FMOD", meta = (ClampMin = "-80", ClampMax = "10"))
float VcaVolume;

Then we check if StudioSystem is available and get the VCA:

if (IFMODStudioModule::IsAvailable())
	{
		FMOD::Studio::System* StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
		if (StudioSystem)
		{
	StudioSystem->getVCA(TCHAR_TO_UTF8(*FName("vca:/Music").ToString()), &Vca);
		}
	}

Finally we can use the setVolume function to set the volume of the VCA to our desired value:

Vca->setVolume(dBToAmplitude(VcaVolume));

Congratulations! You learned how to change the volumes of FMOD Groups and VCA’s in Unreal Engine 4.

↑ To the Top