I have created a forum post about this, better write it here aswell
I’ve been thinking about making a rhythm game for a long time and I want to take action. The problem is though, after all the research and reading through old posts in unity forum/reddit etc., I still don’t have a clue about how can I create what I aim for. At this point I’m not even sure if I’m approaching this the right way because I probably lack the technical knowledge.
So here’s the thing as far as I understood ;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class something : MonoBehaviour {
public AudioSource audioSource;
public float[] freqData = new float[1024];
void Start ()
{
audioSource = GetComponent<AudioSource> ();
}
void Update ()
{
audioSource.GetSpectrumData (freqData, 0, FFTWindow.BlackmanHarris);
}
}
Let’s say I have this code in place. My sampling rate is at 48000 Hz. The array size determines the frequency range of each element. So with a size of 1024, my frequency resolution is 23.4 Hz. So freqData[0] represents the freq between 0-23.4 Hz. freqData[1] represents 23.4-46.8 Hz. so on and so forth. And I want to detect, let’s say bass beats between 60Hz and 250 Hz.
How can I translate this data into “hey unity I want you to check those wiggling small numbers(relative amplitudes of frequency i think) from index 4 to 11, and if some of them is above a certain threshold(of decibel or whatever i don’t even know), I want to register them as beats.”
And everytime there is a SendMessage(“Beat Detected”) in place I can instantiate a cube to represent the beat for instance.
Even though it is an extremely complicated subject, I feel like what I want to achieve is relatively simple to accomplish yet I feel like an idiot not being able to do it.
Thanks for reading and thanks for help/tips in advance.