Getting Audio Data in Unity 5

Hi,

I am trying to create a Unity audio visualization. There are a few threads on this but most are a few years old and use now obsolete methods so I thought I would bring it up again.

What is the best way to extract audio data (such as decibel levels of different frequency bands). Most of the audio analyzing functions in the scripting api are now obsolete (such as GetSpectrumData) so I am unsure as were to start.

Ideally I would like to get data as the audio is playing, e.g so I can stick my visualization in the Update function but it’s possible there is another way of doing it.

Thanks in advance

GetSpectrumData should do what you want, but according to the docs you should use this one, where you give it a pre allocated array.

GetSpectrumData(samples: float[ ], channel: int, window: FFTWindow)

So for example:

float[] spectrum = new float[1024];

audioSource.GetSpectrumData(spectrum, 0, FFTWindow.Hanning)