First, for a period of ten seconds the frequency spectrum is broken into bands of equal energy. The FFT of the signal is computed for the entire ten seconds and then bandlimited to the lower 10 KHz. The total energy across all frequencies is calculated. Because tetris has seven pieces, we will need seven frequency bands. By dividing the total energy by seven, we know have a target energy for each sections
Interval selection
A binary search algorithm is implemented to find the bounds of each frequency band such that the energy of each section will equal the target energy within a reasonable error. Ideally, we could compute exactly equal energies but we are limited by the number of samples in our seconds interval.
Each of these bands is then assigned a different game piece.
Piece selection for half second sections
Once the frequency bands are computed for the section of the song, we compute the pieces. We take the FFT of a half-second samples and calculate the energy across each frequency band and find the maximum energy. The next piece is assigned accordingly.
This process is repeated for each half second of the song. In theory, sections of the song with vocals will see more instances of the higher frequency pieces, while areas with bass guitar solos will be dominated by pieces from the lower frequencies.