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.
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
FMOD.DSP_METERING_INFO Outputmeter;
// setting up the fmod event
[FMODUnity.EventRef]
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
flickerAudioEvent.start();
// 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();
}
}
Add
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.
thanks! but i hv a same problem here: this.flickerAudioEvent.getChannelGroup(out this.channelGroup); keeps throwing error of null argument exception. any ideas?