bydariogamer / beatgame

This game was born as an entry for the II Pygame Community Server Game Jam. It uses procedural generation of levels... based on music! Feel free to include your own songs at the assets/songs and try to your custom level.
GNU General Public License v3.0
3 stars 2 forks source link

Map generation: bandpass filters or fourier analysis #8

Open Sogolumbo opened 3 years ago

Sogolumbo commented 3 years ago

Some songs are heavily compressed. Hence the volume is a bad metric to get interesting maps. Instead the volume of specific (randomly chosen?) frequency bands might be better at representing the rhythm.

bydariogamer commented 3 years ago

I am not sure about that... I am using sndarray to get the array of the song samples... And it is in the format I gave in the mixer module initializer (I leave it defaut so I guess it will be 22KHz but who knows). All formats of the same sound will return the exact same array. The only variation would be the number of channels (mono or stereo sound) but it doesn't change the intensity. I am not an expert in pygame however so maybe I am wrong... I am not sure about how to implement the FFT needed, although I could just 'translate' the algorithm from beat-feet I guess. The problem is FFT is more expensive that this intensities algorithm, although you can try to implement it and compare pros and cons.

Sogolumbo commented 3 years ago

What I've seen in the array is just a normal stereo audio signal. You can mathematically treat it just like any other function.

We can use a bandpass filter to get the signal in a specific frequency range. If we change the filter during the song the player might e.g. need to jump over the rhythm of the melody first and the rhythm of the drums after that.

I am sure there are suitable implementations of fft in python out there, only a quick search away.

bydariogamer commented 3 years ago

Seems fair to me. We can implement the new algorithm then. I will merge the current state of development to main (I will review your PR first and if they don't introduce any bug they will become the 1.4.2 release) and start adding new things to main...