I’ve been using the GetSpectrumData method to try and “listen” for a couple beats that trigger at a specific time. So far I’m able to get the Unity project to react to notes but when I try and separate it and have only certain notes get picked up by GetSpectrumData I run into issues.
void Update () {
musicTrack.GetSpectrumData(this.samples,0,FFTWindow.BlackmanHarris);
for(int i=0; i<samples.Length;i++)
{
Debug.Log(samples*);*
if(samples == spectrumData1)
{
Debug.Log(“spectrum match”);
foreach (GameObject thing in things) {
thing.SendMessage(“DoThat”);
}
break;
}
if(samples == spectrumData2)
{
Debug.Log(“spectrum match”);
foreach (GameObject thing in things) {
thing.SendMessage(“DoThat”);
}
break;
}
if(samples == spectrumData3)
{
Debug.Log(“spectrum match”);
foreach (GameObject thing in things) {
thing.SendMessage(“DoThat”);
}
break;
}
}
Even though the music track is just a couple beats I see wildly varying results when I print out the array of spectrum data. I was hoping that since it is just three notes that are three different frequencies that I could examine the spectrum data to see what the three “spectrums” I should have the program wait for but the numbers never show any kind of pattern.
Any help would be greatly appreciated!