Is it somehow possible to access an AudioMixer’s output level via Script?
1. In editor
Call this method by reflection:
// UnityEditor.Audio.AudioMixerController
internal sealed class AudioMixerController : AudioMixer
{
public int GetGroupVUInfo(GUID group, bool fader, float[] vuLevel, float[] vuPeak);
}
vuLevel and vuPeak are 9-element arrays which get these values
- one element per channel
2. At runtime by OnAudioFilterRead
Works only on the level of AudioListener (all sounds) or AudioSource (single sound), no support for mixers or groups
This is better method than 3., because it’s called directly from Audio thread and gives you data at appropriate time
public class AudioFilterMeasureVolume : MonoBehaviour
{
private void OnAudioFilterRead(float[] data, int channels)
{
// Process data
}
}
Process the data like this:
https://answers.unity.com/questions/165729/editing-height-relative-to-audio-levels.html
3. At runtime by AudioListener
Works only for master output data, cannot get data for individual mixers or groups
Call AudioListener.GetOutputData and process the data like this:
https://answers.unity.com/questions/165729/editing-height-relative-to-audio-levels.html
4. At runtime by Native Audio Plugin SDK
It’s possible to write native audio plugin, which will extract this information:
https://docs.unity3d.com/Manual/AudioMixerNativeAudioPlugin.html