A while ago I wanted to make a rhythm game, I didn’t know how it would play, I just knew I wanted to make one where you could import your own music. And with that the biggest struggle would be to get the information from the song to use in the game.
I first made it so the song would play, and get the data in realtime, but that wouldn’t be fun to first wait 2+ minuten each time you would import a new song. So I looked for another way to get the information. I eventually found out a way to get the data from the song of which I could sample the frequences and times certain sounds would play. Using that information I could save each sound catagory and a list and It would be done in a few seconds.
After that was done I didn’t know what kind of game I wanted to make with it, but I was proud of how it worked so I ended up just making a visualization of it, and use it on my portfolio.
I begin by getting all the data from the song, the value that I get is an array of floats. The size of the array is the number of samples multiplied by the audio channels from the clip.
when I have all the samples I go trough all the nodes to see what the average level of the clip is, I use this to calculate the detect level because not every song is as loud as the other.
after this, I go through all the samples in rounds, I do this because it may freeze if there are too many samples. It takes a bit longer this way but it’s still around 1-2 seconds. In the sampling I first check if the sample is above the detect level, when it is I start to check the hertz to see in what category of the audio spectrum it is(the spectrum is showed in the image).
The visualizer begins by going through all the samples that were above the detect value. It saves the time of each note in different arrays of each category.
After this it goes trough it again en then looks if notes in the same category are too close to each other if they are. the last one is removed and the first one is given a time value.
After this is done the song starts to play and an IEnumerator that loops itself. This is used as a timer and to see when each note is spawned. When a note is spawned it checks if the sample has a time value, if it does the spawned note gets scaled to indicate this