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.
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.
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
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?
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?
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().
@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!
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.
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