Burnner

Untitled

Mar 25th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1.     void Update()
  2.     {
  3.         float[] spectrum = AudioListener.GetSpectrumData(128, 0, FFTWindow.BlackmanHarris);
  4.  
  5.         float min_spec = Mathf.Min(spectrum);
  6.         for (int idx = 0; idx < spectrum.Length; idx++)
  7.         {
  8.             spectrum[idx] -= min_spec;
  9.         }
  10.         float max_spec = Mathf.Max(spectrum);
  11.         for (int idx = 0; idx < spectrum.Length; idx++)
  12.         {
  13.             spectrum[idx] /= max_spec;
  14.         }
  15.  
  16.         float spec = 0f;
  17.         for (int idx = 0; idx < spectrum.Length; idx++)
  18.         {
  19.             spec += spectrum[idx];
  20.         }
  21.  
  22.         spec /= spectrum.Length;
  23.  
  24.         myScript.intensity = (0.5f) * spec + 0.1f;
  25.  
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment