Get Volume db of an instance


I’ve seen a post that asked something similar but I can’t find the way. I simply want to know the volume in db of any track. Through a bus or the instance itself with getVolume it only returns a float that gives either 0 or 1 (I don’t understand why it asks for a float either)

I hope someone can help me,

Thank you very much.

You definitely can get the decibels of an instance, there are a few API calls you’ll have to make to get the right information.

  1. Get the FMOD.ChannelGroup from your bus using Bus.getChannelGroup
  2. Get the ChannelGroup’s underlying DSP object using ChannelGroup.getDSP
  3. Enable DSP metering using DSP.setMeteringEnabled
  4. Repeatedly query DSP.getMeteringInfo to get the RMS level (average volume) or Peak level (maximum transient volume)

When you want the dB levels use this math’s function to return usable dB numbers

private float lin2dB(float linear) 
    return Mathf.Clamp(Mathf.Log10(linear) * 20.0f, -80.0f, 0.0f); 

Inserting DSP_METERING_INFO.rmslevel[x] into the function parameter.
Note retrieving the ChannelGroup will all need to happen on a playing EventInstance to ensure the ChannelGroup exists. FMOD.Result is a useful tool to debug the code and can be used on most FMOD functions.

Hope this helps!

1 Like

Thanks a lot! There are no words to thank you for this!! :))

If it’s not too much to ask, two doubts have arisen.

1 - When I do getDPS it asks me for an int to tell it which channel to get. What exactly does that number refer to? To the tracks that are within that channel? And is it just a list?

2 - Then when I get the value of rmslevel, it’s a list of floats. Taking the first value of that list works, but what do the 32 numbers in that list refer to? Why with the first number I can already extract the volume?

Thank you very much again, it’s perfect for what I needed!!!

1 Like


Really happy to hear that helped!

1 - The “index” will decide where FMOD will sample the sound from within the buffer. Recommended that you use FMOD_CHENNELCONTROL_DPS_INDEX to make sure you use a valid int.

2 - It is a list of output channels coming from FMOD, with a maximum of 32 explained under Plugin API Reference DSP. FMOD’s default output configuration is Stero outputting to channels 1 and 2. That is why only the first two indexes of meteringInfo.rmslevel[x] have values. If you explicitly tell FMOD to change its output configuration it will populate another index in the array correlating to the new configuration.

Hope this explains things!