<< Chapter < Page Chapter >> Page >

Interval generation for ten second sections

Energy computation

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

E total = 0 10 kHz FFT(Signal) 2
E target = E total 7

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.

0 I[1] FFT(Signal) 2 ± error = I[0] I[1] FFT(Signal) 2 ± error = = I[7] 10 kHz FFT(Signal) 2 ± error = E target

Each of these bands is then assigned a different game piece.

Piece selection through frequency analysis

Spectrum divided into 7 sections for each piece
The spectrum is divided into seven equal energy sections for a ten second interval

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.

Piece = argmax i Peices, I[i] I[i + 1] FFT( S section ) 2

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.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Tetris sound: using music to affect gameplay. OpenStax CNX. Dec 20, 2013 Download for free at http://cnx.org/content/col11609/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Tetris sound: using music to affect gameplay' conversation and receive update notifications?

Ask