How do I get the output level of a sound?

I want to get the output level (how loud the sound is in dB or any value) of the dialogue I’m playing. I thought this would be a really simple thing but I can’t find any help on it anywhere. I’m playing the sound as an event instance, and I need the level of just that instance, but I guess I could assign the sound a group or VCA and get the level of that. I’m just clueless. :man_shrugging:t2:

OK. As always I’ve worked it out just after posting my question. I did it using this code (which seems like a very long way to do a simple thing).

        FMOD.ChannelGroup playerGroup;
        playerAudio.getChannelGroup(out playerGroup);            
        FMOD.DSP playerdsp;
        playerGroup.getDSP(0, out playerdsp);
        playerdsp.setMeteringEnabled(true, true);
        FMOD.DSP_METERING_INFO playerLevel;
        playerdsp.getMeteringInfo(new IntPtr(), out playerLevel);
        float playerOutput = playerLevel.peaklevel[0] + playerLevel.peaklevel[1];
        Player.talkAmount = playerOutput * 3;

However. The problem I have now is that I’m using this for an animation on my character. I want the user to be able to mute the dialogue if they want and still get this animation, but if I turn the sound down I don’t get the output levels. Is there any way I can mute the sound, but still get the metering info of the sound as if it was playing at full volume???

Anyone?

You should be able to get the volume/metering from the Channel the FMOD::Sound is being played through and muting the ChannelGroup it is routed into.

Thanks! I have tried this path before, as well as trying to get the metering of a child bus and muting the parent. I can’t get any of it to work and I suspect it because of my code. I’ve spent a really long time trying to find the right code to do this but can’t find it anywhere.

I hate to be that guy who needs his hand held, but I really need my hand held on this.

How do I access the channel that the sound is being played through and get the metering of it with C# code in Unity?

Or

How do I get the metering info of a child bus that isn’t effected by turning down the volume of its parent bus?

We set our dialogue volume with code similar to this.

FMOD.Studio.Bus bus = RuntimeManager.GetBus("bus:/Dialog");
bus.setVolume(volume);

There is also a getVolume:

float volume = 0.0f;
bus.getVolume(out volume);

This assumes all your dialogue is on this bus.

You can get the volume of an event instance like this:

FMOD.Studio.EventInstance eventInstance = new FMOD.Studio.EventInstance();
eventInstance = RuntimeManager.CreateInstance(eventPath);
float volume = 0.0f;
float finalVolume = 0.0f;
eventInstance.getVolume(out volume, out finalVolume);
eventInstance.setVolume(volume);

Volume is a normalized value between 0.0 and 1.0.

You can use ChannelGroup::getNumChannels to get the number of channels routed into the ChannelGroup and then get all the necessary information with ChannelGroup::getChannel.

https://www.fmod.com/resources/documentation-api?version=2.1&page=core-api-channelgroup.html#channelgroup_getnumchannels

https://www.fmod.com/resources/documentation-api?version=2.1&page=core-api-channelgroup.html#channelgroup_getchannel

I can’t get that to work even with the sound turned up. Here’s my code.

            FMOD.Studio.Bus playerBus = FMODUnity.RuntimeManager.GetBus("bus:/Master/Dialogue");
            FMOD.ChannelGroup playerGroup;
            //playerBus.lockChannelGroup();
            playerBus.getChannelGroup(out playerGroup);
            FMOD.Channel playerChannel;
            int playernumChan;
            playerGroup.getNumChannels(out playernumChan);
            playerGroup.getChannel(playernumChan, out playerChannel);
            FMOD.DSP playerdsp;
            playerChannel.getDSP(0, out playerdsp);
            playerdsp.setMeteringEnabled(true, true);
            FMOD.DSP_METERING_INFO playerLevel;
            playerdsp.getMeteringInfo(out playerLevel, new IntPtr());
            float playerOutput = playerLevel.peaklevel[0] + playerLevel.peaklevel[1];
            Player.talkAmount = playerOutput * 3;

The number of channels it returns is always 0. Same if I use the channel group of the event rather than the bus. Surely that should be at least 1.

Hi MiddleMan82,

I am wondering how you have this routed? It might be if you have a channel group routed into the bus’ channel group. In this case, you would see that the channel group has other channel groups, but not channels.

You may also not see the channel while the sound is not playing.