-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetSpectrumDataExample.cs
27 lines (24 loc) · 1.01 KB
/
GetSpectrumDataExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using System.Collections;
public class GetSpectrumDataExample : MonoBehaviour
{
AudioSource audio;
float[] spectrum = new float[256];
void Start()
{
audio = GetComponent<AudioSource>();
}
void Update()
{
audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
int i = 1;
while (i < spectrum.Length - 1)
{
Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.yellow);
i++;
}
}
}