Get Spectrum Data Helper

Get Spectrum Data Helper is a Unity script that helps the user leverage unity’s AudioListener.GetSpectrumData() function.

The main script is GetSpectrumDataHelper.cs. It takes an audio source and returns an array of 128 values corresponding to the amplitude of frequencies on a classical piano (and a few notes above and below that range). This makes it such that you can have musical frequency values of any audio file drive anything you can connect to it through scripts in unity.

It uses unity’s native function AudioListener.GetSpectrumData. That function returns 4096 values, our helper function selects 128 of those values matching frequencies that align with musical notation and how we hear, and then converts the values from signal/voltage to decibels. Finally it uses an equal loudness contour graph to massage the values a little more to account for how our ears have different sensitivities to different frequency ranges.

The project also contains an audio visualizer example and an audio file for testing, as well as a debug mode that shows equalizer bars in the editor.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s