Search Unity

Get Output Data for Audio Mixer?

Discussion in 'Audio & Video' started by JeffForKing, Sep 23, 2016.

  1. JeffForKing

    JeffForKing

    Joined:
    Apr 8, 2014
    Posts:
    25
    Hi, I am surprised this question seems to not have been asked before- spent a lot of time googling.

    Is there a way to get or expose the current output level of an audio mixer group, similar to the GetOutputData() function available for Audio Sources?

    Not the volume, the current level of the mixer's output during playback.

    Thanks so much
     
  2. marcdhall

    marcdhall

    Joined:
    Oct 5, 2016
    Posts:
    6
    Seems like asking for that at game loop frequency would give you nonsense results. This is one of the key hurdles with audio: the game loop is refreshing extremely slowly compared to audio.

    I was wondering if writing a native audio processor plug would bridge the gap. There are audio plugins that render stuff to the editor. It seems plausible to write a plugin that can do metering and relay a smooth property back to Unity.
     
  3. mangoone

    mangoone

    Joined:
    Oct 11, 2016
    Posts:
    3
    Hi @JeffForKing,
    did you find a solution? I am trying to analyse my input captured by the microphone in realtime. I want to manipulate gameobjects depending on the input - e.g. if a db value > ... appears a cube should move or be spawned. I tried the method getspectrumdata for the audiosource but i was just able to manipulate objects with a recorded clip (record wth microphone - stop recording - playing and objects move depending on the recorded input), not in realtime. Furthermore in the actual unity manual is written that the method getspectrumdata is obsolete (also the method audiosource.getdata) - i am pretty new to unity - so does anyone out there know what this means? and whats the new alternative if this is obsolete.
     
  4. JeffForKing

    JeffForKing

    Joined:
    Apr 8, 2014
    Posts:
    25
    No answer to my initial question.
    Re: mic FFT, definitely still possible, as I did it for a project fairly recently, but I'm legally not allowed to post that code. Wish I could!! Check all the information in this thread as it should be most of what you need: http://answers.unity3d.com/questions/1113690/microphone-input-in-unity-5x.html

    If you're still stuck, post your code and can try to help you from there
     
  5. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
  6. kloot

    kloot

    Joined:
    Mar 14, 2018
    Posts:
    78
    It's bananas, but I can't seem to figure out how to read runtime data from the AudioMixer (or more preferably an AudioGroup). Does anyone have any idea?
     
  7. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    421
    The AudioMixer does not offer something similar to OnAudioFilterRead, or any other callback that would allow you to simply read its state or data.

    In regards to the initial question on that thread, I think using an exposed parameter on "Level" would do the thing.
     
  8. kloot

    kloot

    Joined:
    Mar 14, 2018
    Posts:
    78
    Note that the original poster is asking not for the volume, but for the current level of the mixer's output during playback (which is exactly what I need too). From what I understand, audioMixer.GetFloat() only returns the volume, not the output. Are you saying that there's a way to read the output based on an exposed parameter?

    If so, that would solve everyone's problems
     
  9. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    421
    *facepalm* :eek:

    You're right... there is no simple way to do that actually...The "simplest" would be to have a custom native plugin that would calculate this value when audio buffers would pass through, and expose a function returning that info.

    For the same kind of information using an AudioSource, you would have to do the same calculation on buffers returned by GetOutputData().
     
    Gasimo likes this.
  10. unity_Ynx_5e9OD0Ry8Q

    unity_Ynx_5e9OD0Ry8Q

    Joined:
    May 13, 2020
    Posts:
    1
    @SeventhString can you explain how to expose a function and access it from a c# script.
    I've been using Juce to create a small plugin, I learned how to expose plugin parameters and expose them in the audio mixer and feed them from a c# script.
    But I could not expose a function to then access it from a c# script.

    I also need to read the audio buffer from the mixer groups!
     
  11. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    421
    So if I understand correctly you interface a JUCE plugin as a Unity native audio plugin right? If that's the case, then you already have all you need. In your process callback where you compute the levels of the audio buffers, set a "Level" parameter that would be the one you expose in the AudioMixer, and them from a C# script, use AudioMixer.GetFloat("Level") to retrieve its current value.
     
  12. bencekovacs

    bencekovacs

    Joined:
    Oct 24, 2017
    Posts:
    1
    Hey,
    I previously wrote an article on how to interface with JUCE native audio plugins in a Unity application using P/Invoke.
    I find the official Unity API for accessing parameters tedious to use as it can only be done after exposing the parameter manually in the mixer GUI.
    Instead you could add some native method in your plugin code for retrieving parameter data and call that from managed code.
    This post should get you started on how to interface with your JUCE plugin from gameplay code:
    https://playfultones.com/interfacing-with-juce-synth-plugins-in-unity.html

    I hope this helps!