Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update()
- {
- float[] spectrum = AudioListener.GetSpectrumData(128, 0, FFTWindow.BlackmanHarris);
- float min_spec = Mathf.Min(spectrum);
- for (int idx = 0; idx < spectrum.Length; idx++)
- {
- spectrum[idx] -= min_spec;
- }
- float max_spec = Mathf.Max(spectrum);
- for (int idx = 0; idx < spectrum.Length; idx++)
- {
- spectrum[idx] /= max_spec;
- }
- float spec = 0f;
- for (int idx = 0; idx < spectrum.Length; idx++)
- {
- spec += spectrum[idx];
- }
- spec /= spectrum.Length;
- myScript.intensity = (0.5f) * spec + 0.1f;
- }
Advertisement
Add Comment
Please, Sign In to add comment