Get Spectrum Data Helper

Getting Started with GetSpectrumDataHelper

This asset comes with a c-sharp script called GetSpectrumDataHelper(GSDH) which is what analyzes the audio, and three example scenes, each with a different audio visualiser setup. 

There is one based on a row of cubes, one based on a  row of cylinders, and one on a row of spheres.

The  GetSpectrumDataHelper script itself can be used  in any Unity  project. However the  audio visualizers that come with the package  were  made using  the  HDRP render pipeline and require it for the  shaders to work.

The GSDH script calls the Unity native Audiosource.GetSpectrumData() method to perform an FFT transform on the audio signal to analyze the amplitude of a range of frequencies. GSDH always returns 128 values corresponding to the musical frequencies on a piano as well as an octave below and two above.

These 128 values are obtained by selecting from the return data of the GetSpectrumData() method. Therefore the accuracy of those 128 values does depend on the number of samples the GetSpectrumData() method uses, which can be set by a dropdown selection in the inspector of the GSDH script. 

Although a number such as 512 or 1024 samples may seem like plenty for an audio visualizer it actually will not give very give very good accuracy for base notes or even the third octave of the keyboard because the FFT transform divides up the range of frequencies sampled linearly, whereas the distribution of frequency in music and on a keyboard, as well the way he hear it is logarithmic. It is recommended to set the number of samples to 2048 or higher for decent to good precision with lower frequency notes. So the takeaway is that GSDH’s 128 return values help our data relate better to how we hear frequencies/music.

GSDH also returns its 128 values as decibel values (instead of voltage) which also help the data relate better to the way we perceive volume. There is a slider for the reference value (decibels always need a reference value since they are a relative measurement) which helps bring the db values out of the (correctly) negative to 0 range of the digital audio world and into the 0 to positive range so it can be used to drive an audio visualizer’s given parameters. This is done by setting the reference value to a number very close to 0. 

To get started using GSDH you can open  up any  one of the three  example scenes, replace the audio in the audio source game object with audio of your choosing and hit  play. 

For more information check out the tutorial video as well:

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