Audiosurf style audio analysis (unity 3.5)

I want to be able to analyze music before actually playing it similarly to what the game Audiosurf does. This is necessary in order to build levels and such based on the music data. To my knowledge this makes AudioScource.GetOutputData() and AudioSource.GetSpectrumData() useless as it provides up to 1024 audio samples as the music is playing.

Now, it seems as of Unity3.5(correct me if I’m wrong), we have AudioClip.GetData() which gives 44100(or whatever the sample rate is) samples per second; the entire song’s sample data. Now to my understanding these samples provided by GetData() coincide with the ones provided by GetOutputData(), as in they are the songs amplitudes.

But it seems like GetSpectrumData() does not have a sister function to provide the entire song’s samples (which in GetSpectrumData’s case appear to be the frequencies?). Won’t I need the frequencies for Fast Fourier Transform analysis (which I believe Audiosurf does)?

I realize I’m a bit in over my head here but I know I’m not the only one looking for this info in Unity and any information that could be provided here would be most appreciated.

I don’t have Unity 3.5, but if there’s a way to get all the samples from an audio clip, you could use some FFT implementation to transform the data to frequency domain and analyze it.

Hi,
Maybe this plugin can help:

I’m late to the game here, but I had the exact same question about a month ago. It took a lot of searching around and a lot of testing, but I landed on a pretty solid solution.

Using GetData, I retrieved the interleaved stereo samples of a clip and then averaged each pair of stereo samples together to get something similar to GetOutputData’s Channel 0.

For the FFT it took some minor conversion but I used DSPLib (DSPLib - FFT / DFT Fourier Transform Library for .NET 4 - CodeProject).

I explain in detail in this blog series:

After you get the initial context, you’re probably most interested in the “Preprocessed Audio Analysis” post. I also include a link in the Outro to a public Github repo with the working source.

Hope this helps you (6 years later) and anyone else that stumbles upon this post looking for a way to do preprocessed audio analysis in Unity!