I'm making a music player for android and I would like to get the average BPM (maybe also frequencies or tones) of a song BEFORE playing it, so I can show the user some info about the song, I know I probably have to open a stream and apply some maths to it to get the data I need, but I don't know how to act, can anyone help me?
Asked
Active
Viewed 4,697 times
3
-
Not a real answer but a step in the right direction: http://developer.android.com/reference/android/media/audiofx/Visualizer.html – Thizzer Oct 03 '12 at 11:51
-
Thanks, I've already seen that and I know that Visualizer can perform a ffT on a input, another problem is... which input? – Lucat Oct 03 '12 at 11:58
-
I've seen an example using android.media.MediaPlayer and creating the visualizer like this: new Visualizer(mediaPlayer.getAudioSessionId()); but I thinks that means you have to play the music. – Thizzer Oct 04 '12 at 07:50
-
Yes, with that method you have to, I just wonder how can I process a song without playing it, if I can achieve this maybe I could apply the fft to the song, don't know :\ – Lucat Oct 04 '12 at 13:34
-
Maybe you can use MediaPlayer#setVolume and then process the songs 1 by 1 – Thizzer Oct 05 '12 at 07:39
-
Well but then the user would have to wait lots of time, I'm looking for a way to process it in an "instant" – Lucat Oct 06 '12 at 11:03
-
Are we talking about PCM/WAV music or something compressed like MP3? To process compressed audio, you'll have to convert it to PCM. I can tell you(from painful experience) that "instant" MP3 decoding isn't possible. There are several libraries to do it(like JLayer for java, or ffmpeg for native), but none are instant. I don't have benchmarks for ffmpeg, but using JLayer, an average 3 minute VBR MP3 takes between 15-45 seconds, depending on hardware. Once you have the data, calculating BPM and doing the FFT hardly take any time at all. – Geobits Oct 19 '12 at 16:22
-
Yes, I am playing MP3 files. But if I can't process them without listening to them, how can I do? The user must completely listen to a song? Is there any trick I can do? – Lucat Nov 19 '12 at 18:14
2 Answers
3
I finally found the solution! I'm using the Minim java audio library, which can performs offline analysis on the audio buffer :) http://code.compartmental.net/tools/minim/manual-minim/

Lucat
- 2,242
- 1
- 30
- 41
2
You can use the FFT
This example may be helpful:
Android audio FFT to retrieve specific frequency magnitude using audiorecord
another one:

Community
- 1
- 1

Matias Molinas
- 2,246
- 15
- 11
-
Yes, those are useful, but I need to find a way to get all the mp3 data at once, without listening to the song :\ – Lucat Nov 19 '12 at 18:16
-
Maybe I could gather data while the song is being played and then process them at the end of the song! – Lucat Nov 19 '12 at 18:22