Audiolistener & frequencies

Is there a way to make the audiolistener tell me what frequencies are being played within my level? Im trying to make a script that gives feedback based on a certain frequency but i dont know a whole lot about audio in unity…
Thanks in advance!

Yes.

        float[] samples = new float[1024];
        AudioListener.GetSpectrumData(samples,0,FFTWindow.Hanning);

        for(int i = 0; i<samples.Length-1; i++)
        {
            Vector3 start = new Vector3(i*.1f, samples[i]*100, 0);
            Vector3 end = new Vector3((i+1)*.1f, samples[i+1]*100, 0);

            Debug.DrawLine(start,end);
        }

This gets a spectrum of the audio that’s currently playing and draws it.

1 Like