B and B week 5/25 - 6/1

This week I focused on capturing the audio of a song in Unity and analyzing the beat of the song, and producing an output of useful information for the platform generation to use later. I read all over the internet for a while about how the best and brightest minds figured out how to mathematically find this information. I mean a beat is very subjective, and music is an artistic medium, but there have been some ways to turn this art into data. These systems are not without limitations however, and even the state of the art beat detection algorithms found online are not without fault.

The most glaringly obvious problem I found was that of tempo, which is the measurement of how fast a song is. This is displayed as a bpm, or beats per minute. If this if a song has a change in tempo in it, any algorithm will fail and have to recalibrate. During the recalibration time however there would have to be backtracking to apply the newly changed tempo. This could work in theory, but the more complicated a song gets, the less accurate theses algorithms become.

There is also a difficulty of having a strange time signature or a less defined beat, like more classical music would. A time signature is basically how music is structured. Most music you would know is in 4/4, meaning there is 4 beats before the next collection of notes. However, if there is a stranger time signature like 5/8 changing into 3/8 back and forth, the beat detection would have no way to tell how the song goes. There also must be a well defined beat, meaning the song is rigidly structured and the percussion is very rigid as well.

This isn’t what will be the best for the algorithm

Therefore the best music to put into this algorithm is a song that doesn’t change tempos with a well defined and rigid beat, most likely in 4/4 or 3/4. In the future I may have a feature where the player can tap out their own beat before the song plays for them to use if they find that the automatic one is inaccurate. So what is this algorithm?

First I get the data every frame of how much amplitude each frequency of sound is playing in an array of floats. This done using the GetSpectrumData() method from the AudioSource GameObject. This does a Fast Fourier Transform (FFT) on the AudioSource to seperate all the frequencies for me to use for any purpose. For this week, this data will be used for detecting when specific frequencies are being changed. If a frequency is changed in amplitude positively fast enough, it is labeled as a Spectral Flux. This flux is then compared to the previous and next amplitude. If it is higher than both of these, and above the threshold, then it is considered a peak, and it is logged in a list of peaks to be used for calculating the bpm of the song.

These “peaks” are representative of important notes in a song, which always land on the beat of the song, or a subdivision of the beat. These peaks are then used to calculate the BPM of the song.


Previous
Previous

Beats and Blocks

Next
Next

Hermea