I am creating a rhythm based music game in which you should (theoretically) choose whatever song you want. This is created in Unity (5.4.1) with C #.
In real time, the step of the song, which he discovered and showed to the user through visualizers.
The problem I ran into is creating a visualizer, but it barely shows higher notes. I am afraid that this is due to the fact that (like in most musical works) several pitches are played immediately (for testing, I used Darude Sandstorm, waiting for a sound guy to give me music). In the end, I want this definition of pitch to show the user whether to hit a high, medium, or low note.
I tried using GetComponent<FFT>().PitchValue;
as well AudioListener.GetSpectrumData(2048, 0, FFTWindow.Hamming);
I suppose the fear is that it simply cannot be done on songs with several games that play immediately (i.e., a basic high-pitched overlay).
I would like to hear any advice or find out if anyone has overcome a similar problem.
This is an example of what I'm working with right now, I tried several different online solutions (some of the information is actually related to a tutorial related in the code that has been commented out), which I intend to fully reference if I continue to follow this path (I have been working on this hour for a couple of weeks). It makes a pretty visualizer, but I can not use it fully. This works well as a visualizer without if else instructions, this is exactly where I am doing the trial version and the error at the moment. I follow this tutorial
using UnityEngine;
using System.Collections;
public class soundspectrume : MonoBehaviour {
public GameObject prefab;
public int numberOfObjects = 25;
public float radius = 5f;
public GameObject[] cubes;
public float PitchValue;
public Color mycolour;
void Start()
{
PitchValue = GameObject.Find("Main Camera").GetComponent<FFT>().PitchValue;
for (int i = 0; i < numberOfObjects; i++)
{
float angle = i * Mathf.PI * 2 / numberOfObjects;
Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
Instantiate(prefab, pos, Quaternion.identity);
}
cubes = GameObject.FindGameObjectsWithTag("cube");
}
void Update () {
PitchValue = GameObject.Find("Main Camera").GetComponent<FFT>().PitchValue;
print(PitchValue);
float[] spectrum = AudioListener.GetSpectrumData(2048, 0, FFTWindow.Hamming);
for (int i = 0; i < numberOfObjects; i++)
{
if (PitchValue <= 200)
{
Vector3 previousscale = cubes[i].transform.localScale;
previousscale.y = spectrum[i] * 500;
cubes[i].transform.localScale = previousscale;
}
else if (PitchValue >= 201)
{
Vector3 previousscale = cubes[i].transform.localScale;
previousscale.y = spectrum[i] * 1;
cubes[i].transform.localScale = previousscale;
}
else if (PitchValue >= 500)
{
Vector3 previousscale = cubes[i].transform.localScale;
previousscale.y = spectrum[i] * 100;
cubes[i].transform.localScale = previousscale;
}
}
}
}
, ,