Unity 3D line-in/mic audio analysis via Processing
After scouring the internet to find a way to get live audio analysis happening in Unity from a line in and not finding anything I took it upon myself to write a small processing and unity script to do it for me. The processing script is a simple implementation of the Minim audio libraries handy FFT, then pumps out the data through the network. The unity script runs a client to receive the data and sorts it into a float array. From there you can do what ever you like with it, use it to draw wave forms, control the scale of objects by monitoring different bands or emit particles on the beat.
The current Unity road map does specify microphone support for the 3.5 release but I am unsure weather this will provide access to the audio buffers for analysis, hopefully it will then we will have a more elegant solution.
This is unsupported code and is probably not as efficient as it could be but it works without too much overhead. If you do happen to have a play with it and find inefficiencies please let me know in the comments below. I’d love to see what people use it for and come up with so please link back if you make something you want to share.
Peace out code monkeys.
Download ***Updated – Now includes a Unity example project with an AudioTransformer Script to show the basic functionality***


2 Comments
Kirill Rybin
June 21, 2012Thank you for this solution!
Marc
August 25, 2012Hi Brad,
Thanks for this great piece of code. I downloaded the files but I don’t see the Unity exaple project. And also could further explain how to use the GetSampleFromIndex(int index)? Sorry if this is a dumb question but I’m kind of a Noob. Thanks again