B and B week 6/1- 6/8
This week I focused on getting the frequency from my music to be able to place down platforms later. These platforms are going to be placed based on the frequency of certain parts of a song. I already have the concept of peaks from last week up and running, so now I can use these peaks as points of interest I can use to generate platforms. These will be used as the points where the frequency of all the notes will be analyzed in order to find the best one for placing a platform
My first approach to this was flawed. I tried comparing the frequency of every bin in the peak’s array to the next frames frequencies by taking the difference. I though as the current frames frequencies would be guarantied to have some higher values in amplitude these would be good points of comparison. This however in practice would be very inconsistent and most of the time would yield no results, and I gained no info from this.
I went back to the drawing board and thought about what makes a melody a melody, and a good rule of thumb is the frequency range of the note that is being played. This note is usually being played from a range of 350 hz to 1200 hz. This corresponds to around middle F on the keyboard to not the next F but the F right after. This gives the range of frequencies I test to be around 2 octaves. An octave is an interval from one note to the next highest version of that note, so in this case it would be FGABDEF.
The range of notes I am currently using to determine melody
With this new range in mind, I now am going to a peak and going through this range of the frequency bins and asking, am I the largest value in this range? If so, make this the new important note to be used as a platform. And I log the index multiplied by the frequency range per bin in order to get what frequency I am currently using. I am logging these as 2 new variables inside of my spectralFluxInfo class, to keep all the important information about each frame in one place.
int minFrequencyRange = 20; int maxFrequencyRange = 50; for (int i = minFrequencyRange; i < maxFrequencyRange; ++i) { if(spectralFluxSamples[spectralFluxIndex].ThisSpectrum[i] > spectralFluxSamples[spectralFluxIndex].peakFrequency) { spectralFluxSamples[spectralFluxIndex].peakFrequency = spectralFluxSamples[spectralFluxIndex].ThisSpectrum[i]; spectralFluxSamples[spectralFluxIndex].peakFrequencyHz = i * hzPerBin; } }
Displaying the current hz values being analyzed as best fit for platform placement
Now that I have the frequency of the notes for platforms, I need to analyze the whole song at once. To pre load in the info in another scene so when I go to the game scene, it has all the info it needs. Once this is finished, I will begin implementing my platform generation algorithm.