Can I detect the volume of the sound being recorded in real time?

Can I record a sound by the device’s mic and in real time know the volume of the sound being recorded?

Yes you can, you will need to setMeteringEnabled() on the DSP of the ChannelGroup you are recording into. Then you can grab the volume data from getMeteringInfo().

https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp_setmeteringenabled

https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp_getmeteringinfo

Thanks for your reply I have found a way to do it, on a visualization tutorial, I took the sound from the channel that receives it from RuntimeManager.CoreSystem.playSound after it is recorded, but now I don’t want to hear the sound, and if I do channel.setVolume(0); I don’t get any data from channel.getChannelGroup(out channelGroup); what sould I do?

You need to have the ChannelGroup (B) you are detecting volume on routed into another “parent” ChannelGroup (A). This is the ChannelGroup that you need to mute.

ChannelGroupA (muted)
|----> ChannelGroupB (detecting volume)

Either it doesn’t work, or I don’t know how to do it, here is my code, let me know if I did something wrong:


        //Step 5: Start recording through our chosen device into our Sound object.

        RuntimeManager.CoreSystem.recordStart(RecordingDeviceIndex, sound, true);

        //Step 5: Create a higher level group that will controll the sound volume.

        RuntimeManager.CoreSystem.createChannelGroup("muteLevel", out channelGroupB);

        // Step 6: Start a Corutine that will tell our Sound object to play after a ceratin amount of time.

        RuntimeManager.CoreSystem.playSound(sound, channelGroup, true, out channel);

        channelGroupB.addGroup(channelGroup);
        channelGroupB.setVolume(0);

even if I mute the first channelGroup nothing happens, I can still hear the sound:

channelGroup.setVolume(0);

only if I mute the channel itself the actual playing is muted:

channel.setVolume(0);

but then there is no signal going to the ChannelGroup which I use to visualize the sound.
What about the listener attached to the camera, can I mute the Fmod listener, because the Unity listener can be muted, but I took it out to use Fmod listener on the cammera, so how can I mute it? The listener is like the upper level channel.

this is working, I found my mistake, I had to create the first channelGroup only then add it to the second one, here is the code that is working, but there is still a problem, when I make the volume of the second channelGroup 0 the sound is again not active, I guess this is because in volume 0 it becomes a virtual sound, how can I change this so a sound with volume 0 will not become virtual?

      //Step 5: Start recording through our chosen device into our Sound object.

        RuntimeManager.CoreSystem.recordStart(RecordingDeviceIndex, sound, true);

        //Step 5: Create a higher level group that will controll the sound volume.

        RuntimeManager.CoreSystem.createChannelGroup("playLevel", out channelGroupA);
        RuntimeManager.CoreSystem.createChannelGroup("muteLevel", out channelGroupB);
        channelGroupB.addGroup(channelGroupA);
        channelGroupB.setVolume(0.01f);
      

        // Step 6: Start a Corutine that will tell our Sound object to play after a ceratin amount of time.

        RuntimeManager.CoreSystem.playSound(sound, channelGroupA, true, out channel);

I tried initilizing the CoreSystem without FMOD.INITFLAGS.VOL0_BECOMES_VIRTUAL like this:

RuntimeManager.CoreSystem.init(1000, FMOD.INITFLAGS.NORMAL, System.IntPtr.Zero);

instead of this:

RuntimeManager.CoreSystem.init(1000, FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS.VOL0_BECOMES_VIRTUAL, System.IntPtr.Zero);

didn’t help

When using Unity, you need to utilize a PlatformCallbackHandler in order to manipulate the init flags of the FMOD systems. Please see our docs for more info:

https://fmod.com/resources/documentation-unity?version=2.02&page=examples-callback-handler.html

I followed the instructions, here is my code:

using System;
using UnityEngine;

[CreateAssetMenu( menuName = "My FMOD Callback Handler")]
public class MyFMODCallbackHandler : FMODUnity.PlatformCallbackHandler
{
    public override void PreInitialize(FMOD.Studio.System studioSystem, Action<FMOD.RESULT, string> reportResult)
    {
        FMOD.RESULT result;

        FMOD.System coreSystem;
        result = studioSystem.getCoreSystem(out coreSystem);
        reportResult(result, "studioSystem.getCoreSystem");

        // Set up studioSystem and coreSystem as desired

// added this line only, but I'm supposed to do the setup here as it says in the previous line
        FMODUnity.RuntimeManager.CoreSystem.init(32, FMOD.INITFLAGS.NORMAL, System.IntPtr.Zero);

    }
}

got an error message in Unity: “SystemNotInitializedException: [FMOD] Initialization failed : Studio::System::initialize : ERR_INITIALIZED : Cannot call this command after System::init.”

Probobly did something wrong, but don’t know what it is, help would be appriciated.

Sorry, my mistake - I’ve just found out that it isn’t possible to change the init flags of the Unity integration.

Instead, you can adjust the priority of the Channels of the ChannelGroup in order to prevent virtualization. You can do something like this:

int numOfChannels;
channelGroupA.getNumChannels(out numOfChannels);
for (int i = 0; i < numOfChannels; i++) 
{
  FMOD.Channel channel;
  channelGroupA.getChannel(i, out channel);
  channel.setPriority(0);
}

channelGroupB.getNumChannels(out numOfChannels);
for (int i = 0; i < numOfChannels; i++) 
{
  FMOD.Channel channel;
  channelGroupB.getChannel(i, out channel);
  channel.setPriority(0);
}