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

**URL:** <https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486>\
**Category:** Unity\
**Created:** [July 27, 2021, 6:10pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486 "2021-07-27T18:10:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [July 27, 2021, 6:10pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/1 "2021-07-27T18:10:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [August 2, 2021, 1:50am UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/2 "2021-08-02T01:50:42Z")

</div>

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_setmeteringenabled)

[https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp\_getmeteringinfo](https://fmod.com/resources/documentation-api?version=2.00&page=core-api-dsp.html#dsp_getmeteringinfo)

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 2, 2021, 10:15pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/3 "2021-08-02T22:15:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [August 3, 2021, 3:41am UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/4 "2021-08-03T03:41:11Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 3, 2021, 1:32pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/5 "2021-08-03T13:32:15Z")

</div>

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:

```auto

        //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);

```

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 3, 2021, 1:41pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/6 "2021-08-03T13:41:13Z")

</div>

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

```auto
channelGroup.setVolume(0);

```

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 3, 2021, 5:51pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/7 "2021-08-03T17:51:44Z")

</div>

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?

```auto
      //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);

```

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 3, 2021, 6:10pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/8 "2021-08-03T18:10:50Z")

</div>

I tried initilizing the CoreSystem without FMOD.INITFLAGS.VOL0\_BECOMES\_VIRTUAL like this:

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

```

instead of this:

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

```

didn’t help

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [August 6, 2021, 2:25am UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/9 "2021-08-06T02:25:28Z")

</div>

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](https://fmod.com/resources/documentation-unity?version=2.02&page=examples-callback-handler.html)

---

<div class="post-metadata">

**Author:** ![Danielkotzer](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Danielkotzer](https://qa.fmod.com/u/Danielkotzer)\
**Post date:** [August 7, 2021, 8:49pm UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/10 "2021-08-07T20:49:48Z")

</div>

I followed the instructions, here is my code:

```auto
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.

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [August 11, 2021, 12:21am UTC](https://qa.fmod.com/t/can-i-detect-the-volume-of-the-sound-being-recorded-in-real-time/17486/11 "2021-08-11T00:21:53Z")

</div>

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:

```cs
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);
}

```
