2
\$\begingroup\$

I'm trying to load a level from a music file (mp3, midi, etc, I'm not picky) for a rhythm-based game. I must be searching in all the wrong places because I can't seem to find any help on this topic.

(I am using Eclipse Luna, AndEngine, Android SDK Tools 20.0.5 and ADT 23.0.4)

My plan was to stream the music file at run-time and create objects when certain pitches, etc are reached, but I have no idea how to do this in Java? Are there any libraries, etc I should be using or is this just not possible?

\$\endgroup\$

closed as off-topic by Kromster, Anko, FxIII, Josh Dec 3 '14 at 18:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Kromster, Anko, FxIII, Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

3
\$\begingroup\$

It seems to me that you will need to perform some sort of Frequency analysis on the audio file in question. You could either pre-process the file on level load (using the data to queue up your level actions), or perform the analysis in real-time.

Either way, you'll want to divide your audio waveform into sections, each comprised of N samples, and then perform a Fourier Transform on those N samples. This will give you frequency data for that section of time in your audio, from which you can decide what to do in your game (e.g. drop a bomb on a bass kick).

If you instead perform a transform on the whole song, you will get the frequency data for the whole song. Which you probably don't want, as you will no longer know at what points in time the frequencies occur. However, you could use this information to theme your level (e.g. lots of bass = some sort of underground level or somesuch).

In order to do that in a reasonable amount of time (pre-processing or real-time), you'll want to implement a Fast Fourier Transform algorithm. The Cooley-Tukey algorithm is apparently pretty commonly used. If you don't want to try to implement such an algorithm yourself, JTransforms is a multi-threaded FFT library for Java, and Kiss FFT, while in C, has a BSD license (and you may be able to find a java wrapper for it).

Addendum: You will also probably want to take a look into whether or not applying a Windowing Function affects your output in a significant way. In the above, taking N samples, a Rectangular Window Function is applied automatically.

From Information I have found, it appears that most people don't worry too much about dealing with a Window Function for the FFT.

\$\endgroup\$
  • \$\begingroup\$ Also, I don't know if Kiss FFT or JTransforms applies a windowing function, or if the effects of not applying a windowing function would be noticeable enough to matter. Either way, it's something additional to look into. \$\endgroup\$ – XNargaHuntress Dec 1 '14 at 14:23
0
\$\begingroup\$

This is definitely possible. I would look into this book or ebook online and it teaches you how to write effective sound classes so that you can use them in the future, with situations like you are speaking of.

You can iterate through samples in any sound file and throw flags on high/low pitches, amplitudes, frequencies, etc..

Here is the book:

http://www.amazon.com/Introduction-Computing-Programming-Java-Multimedia/dp/0131496980

Once you have the sound class down, you can store the samples into an obj, then use that obj on the fly. Instead of trying to iterate through the sound file as it is playing.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.