Event RMS Output

(Damion Sheppard) #1


I hope someone can help me out - I’m looking for the simplest way of getting the output of an FMOD event - by that I mean the actual level on the master of the event - at any given moment. RMS, or actual sample by sample, or whatever - anything will do!

I know that a few questions like this have been asked already but the answers are either super complicated or refer to the first version of the Unity integration. I’m on the latest one. There also seem to be a lot of steps (from channel groups, to DSP, to setting the metering etc), and I’m wondering whether I’m missing a simpler way. Either way, I can’t get it to work.

I’m working in Unity 5 and scripting in C#. Integration version 1.07.04.

(Nicholas Wilcox) #2

The code to enable metering and get the RMS is independent of which Unity Integration you use.

Digging into the DSP graph in the correct way to get RMS. Can you elaborate on what isn’t working, and what you’ve tried to do to fix it.

(Damion Sheppard) #3

Hi Nicholas - thanks for your help.

My bad - what I meant was that other answers are using languages other than C# and I’m not much of a programmer - I’m primarily audio - so I can’t translate too easily. I’ll try and outline how far I have got below.

The main issue seems to be with the Outputmeter - I am not a super experienced programmer and can’t quite see what has happened.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using FMOD;
using FMODUnity;

public class AudioLightFlicker : MonoBehaviour {

	// the light itself (not being used yet)
	//public Light flickeringLight;

	// UI text to display the value
	public Text flickerAudioVolText;

	// channel group and dsp
	FMOD.ChannelGroup channelGroup;
	FMOD.DSP channelDSP;

	// outputmeter

	// setting up the fmod event
	public string flickerAudio = "event:/Flickering";

	FMOD.Studio.EventInstance flickerAudioEvent;

	// Use this for initialization
	void Start () {
		// initilising the fmod event
		flickerAudioEvent = FMODUnity.RuntimeManager.CreateInstance (flickerAudio);

		// event play

		// getting the light (not being used yet)
		//flickeringLight = GetComponent<Light> ();

		// this is where things get sketchy

		// getting the channel group
		flickerAudioEvent.getChannelGroup (out channelGroup);

		// getting the head dsp (I think)
		channelGroup.getDSP (0, out channelDSP);

		// turning metering on
		channelDSP.setMeteringEnabled (false, true);

	// Update is called once per frame
	void Update () {
		// this might be where I'm going wrong - I get an error that says Outputmeter will always be null
		channelDSP.getMeteringInfo (null, Outputmeter);

		// getting the RMS level
		float outputRMS = Outputmeter.rmslevel[1];

		// displaying the value - currently just displays the default placeholder text rather than any number so not working it seems
		flickerAudioVolText.text = outputRMS.ToString();


(Nicholas Wilcox) #4

Outputmeter = new FMOD.DSP_METERING_INFO();
to your Start method. And Outputmeter.rmslevel[1] is the level for the right channel and will only be a valid number for stereo or greater channels. Use Outputmeter.rmslevel[0] for mono channels, or better still use Outputmeter.numchannels to find out how many channels there are.

(Guest) #5

thanks! but i hv a same problem here: this.flickerAudioEvent.getChannelGroup(out this.channelGroup); keeps throwing error of null argument exception. any ideas?

(Nicholas Wilcox) #6

See the documentation for EventInstance.getChannelGroup about when it returns null http://www.fmod.org/documentation/#content/generated/FMOD_Studio_EventInstance_GetChannelGroup.html

(Enrico) #7

Did you find a fix to this? I am trying to have the same result and this is the only post available (even though is still not solved)

(Andrew Scott) #8

Hi Enrico, can you start a new post and explain your situation in more detail please? Thanks.