# Getting Current Event Waveform information/volume

**URL:** https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771
**Category:** Unity
**Created:** [May 17, 2022, 9:46pm UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771 "2022-05-17T21:46:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![regularfriend](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@regularfriend](https://qa.fmod.com/u/regularfriend)
#### Post date: [May 17, 2022, 9:46pm UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/1 "2022-05-17T21:46:36Z")

</div>

Hey,

In previous Unity projects, I’ve sampled an audio source’s current waveform volume (the amplitude of the waveform at the time its currently playing essentially, post effects/ect) and piped it into a simple ‘talker’ script that basically passes that value (multiplied by a constant) to an animation to get the actor to ‘talk’ by opening its mouth when the volume is loud and closing it when its quiet.

Is there a way to access this data easily in Fmod? I dont see anything obvious in the API so i figured I’d ask here.

```auto
				sampleTime = Mathf.Min (audioSource.timeSamples + sampleOffset, audioSource.clip.samples - sampleDataLength);
                currentUpdateTime = 0f;
				audioSource.clip.GetData(clipSampleData, sampleTime); //I read 1024 samples, which is about 80 ms on a 44khz stereo clip, beginning at the current sample position of the clip.
                clipLoudness = 0f;
                i = 0;
				for (i = 0; i < clipSampleData.Length; i++)
                {
                    clipLoudness += Mathf.Abs(clipSampleData[i]);
                }

		clipLoudness /= sampleDataLength; //clipLoudness is what you are looking for

```

is roughly the code we use for unity audio sources if that helps clarify what type of data i’m trying to access.

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [May 23, 2022, 12:16am UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/2 "2022-05-23T00:16:10Z")

</div>

You can access peak (loudest sample in a given audio buffer) and rms (root mean squared, average sample value) volume data by enabling metering on any of the channel’s DSPs with [`DSP::setMeteringEnabled`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-dsp.html#dsp_setmeteringenabled), and retrieve its [`FMOD_DSP_METERING_INFO`](https://fmod.com/resources/documentation-api?version=2.02&page=plugin-api-dsp.html#fmod_dsp_metering_info) using [`DSP::getMeteringInfo`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-dsp.html#dsp_getmeteringinfo).  
Here is a simple example of how to retrieve the left and right volumes of a playing event instance.

> **DisplayEventSound.cs**
>
> ```cs
> using System.Collections;
> using UnityEngine;
> 
> public class DisplayEventSound : MonoBehaviour
> {
> public FMODUnity.EventReference eventReference;
> 
> public float leftVolume;
> public float rightVolume;
> 
> FMOD.DSP_METERING_INFO inputInfo, outputInfo;
> 
> FMOD.Studio.PLAYBACK_STATE playbackState;
> FMOD.DSP dsp;
> 
> void Start()
> {
> StartCoroutine(PlayEventAsync());
> }
> 
> IEnumerator PlayEventAsync()
> {
> FMODUnity.RuntimeManager.StudioSystem.getEvent(eventReference.Path, out FMOD.Studio.EventDescription eventDescription);
> eventDescription.createInstance(out FMOD.Studio.EventInstance eventInstance);
> eventInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
> eventInstance.start();
> 
> // Need to wait for event instance to play before getting channel group
> do
> {
> eventInstance.getPlaybackState(out playbackState);
> yield return null;
> }
> while (playbackState != FMOD.Studio.PLAYBACK_STATE.PLAYING);
> 
> FMOD.ChannelGroup channelGroup;
> eventInstance.getChannelGroup(out channelGroup);
> 
> channelGroup.getDSP(FMOD.CHANNELCONTROL_DSP_INDEX.FADER, out dsp);
> dsp.setMeteringEnabled(true, true);
> }
> 
> // Update is called once per frame
> void Update()
> {
> if(playbackState == FMOD.Studio.PLAYBACK_STATE.PLAYING)
> {
> dsp.getMeteringInfo(out inputInfo, out outputInfo);
> leftVolume = outputInfo.rmslevel[0];
> rightVolume = outputInfo.rmslevel[1];
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![mrd777](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrd777](https://qa.fmod.com/u/mrd777)
#### Post date: [April 30, 2023, 8:17pm UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/3 "2023-04-30T20:17:51Z")

</div>

@jeff_fmod what if I trigger a whole series of dialogue by doing a PlayOneShot?

I won’t have a event instance because the way I did this is by using Command instruments that will command other events to fire off.

I have the player say one line of dialogue, then a command instrument at the end of that dialogue is triggered and another person speaks.

So I am simply starting the whole chain of dialogue by playing a OneShot.

How does one get volume info in this kind of situation?

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [May 2, 2023, 4:21am UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/4 "2023-05-02T04:21:04Z")

</div>

If you need to do sophisticated things with your `EventInstances`, such as checking their volume in realtime, then `PlayOneShot` is probably not the best way to be playing event. Perhaps you could try creating your events with [`RuntimeManager.CreateInstance`](https://fmod.com/docs/2.02/unity/api-runtimemanager.html#createinstance), and `start` / `release` them yourself.

If you are using Command Instruments then you can set an [Event Callback](https://fmod.com/docs/2.02/api/studio-guide.html#event-callbacks) on [`FMOD_STUDIO_EVENT_CALLBACK_START_EVENT_COMMAND`](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_event_callback_type), which will give you access to the newly created `EventInstance` in the [parameters](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_event_callback) argument. You can then access the `ChannelGroup` and get the `DSP` metering as suggested above. For an example of how to assign a callback to an `EventDescription` you can refer to the [Programmer Sounds](https://fmod.com/docs/2.02/unity/examples-programmer-sounds.html) scripting example.

---

<div class="post-metadata">

### Author: ![mrd777](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrd777](https://qa.fmod.com/u/mrd777)
#### Post date: [May 2, 2023, 6:30pm UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/5 "2023-05-02T18:30:25Z")

</div>

I figured out a work around. I basically just did what you said and created instances, and had a list of events that chain off one another within my game. Ie, the dialogue is not chained in FMOD anymore.

This allowed me to get the volume from the event instances and animate character mouth movements.

Thanks!

---

<div class="post-metadata">

### Author: ![graycloud](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@graycloud](https://qa.fmod.com/u/graycloud)
#### Post date: [October 31, 2023, 2:01am UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/6 "2023-10-31T02:01:31Z")

</div>

Is there a way to do this for Unreal?

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [October 31, 2023, 11:11pm UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/7 "2023-10-31T23:11:56Z")

</div>

Unfortunately, there’s no way to do this using Blueprints in Unreal. However, you can still accomplish this by interacting directly with the FMOD API using C++ code. In this case, you’ll want to access your event instance’s underlying channelgroup with [`Studio::EventInstance::getChannelGroup`](https://www.fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_getchannelgroup), retrieve a DSP from the channelgroup with [`ChannelControl::getDSP`](https://www.fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_getdsp), and then follow the steps that Jeff outlined to get the metering info from the DSP. Jeff’s example is in C#, but it should still serve as a decent example of how you might go about doing this.

Please see our Unreal docs on [Programming Support](https://www.fmod.com/docs/2.02/unreal/user-guide.html#programming-support) for more information on directly interacting with the FMOD C++ API.

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [November 9, 2023, 12:04am UTC](https://qa.fmod.com/t/getting-current-event-waveform-information-volume/18771/8 "2023-11-09T00:04:58Z")

</div>

@graycloud just following up on this - was my response and Jeff’s C# example sufficient to point you in the right direction? If not, was there anything you were unclear about?
