I'm trying to integrate a mechanism to calculate the BPM of the song in the iPod library(also on iphone). Searching on the web I found that the most used and reliable libraries to do this things is soundtouch.Anyone has experience with this library? It is computationally possible to make it run on the iPhone hardware?
1 Answers
I have recently been using the code from the BPMDetect class of the soundtouch library succesfully. Initially compiled it on C++, later on translated the code to C# and lately I've been using the C++ code on an Android app through JNI. I'm not really familiar with development in iOS but I'm almost certain that it is possible what you're trying to do.
The only files you should use from the soundtouch source code are the following:
C++ files
- BPMDetect.cpp
- FIFOSampleBuffer.cpp
- PeakFinder.cpp
Header files
- BPMDetect.h
- FIFOSampleBuffer.h
- FIFOSamplePipe.h
- PeakFinder.h
- soundtouch_config.h
- STTypes.h
At least these are the only ones I had to use to make it work.
The BPMDetect class recieves raw samples through its inputSamples() method, it's capable of calculating a bpm value even when the whole file is not yet loaded into its buffer. I have found that these intermediate values differ from the one obtained once the whole file is loaded, which is more accurate, in my experience.
Hope this helps.
EDIT:
It's a kind of complex process to explain in a comment so I'm going to edit the answer.
The gist of it is that you need your android app to consume native code. In order to do that, you need to compile the files listed above from the soundtouch library with the Android NDK toolset.
That will leave you with native code that will be able to process raw sound data, but you still need to get the data from the sound file, which you can do several ways, I think. The way I was doing it was using the FMOD library for Android, here's a nice example for that: FMOD for Android.
Supposing you declared a method like this in your C code:
void Java_your_package_YourClassName_cPlay(JNIEnv *env, jobject thiz)
{
sound->play();
}
On the Android app you use your native methods in the following way:
public class Sound {
// Native method declaration
private native void cPlay();
public void play()
{
cPlay();
}
}
In order to have a friendlier API to work with you can create wrappers around these function calls.
I put the native C code I was using in a gist here.
Hope this helps.

- 9,791
- 2
- 33
- 41
-
Could you kindly provide an example of how an Android app can deal with the audio input data for the soundtouch library? Thanks! – shiami May 29 '12 at 09:07
-
@juan.facorro Is there any chance of sharing your knowledge on getting the tempo on android? I can not seem to find `soundtouch_config.h`. But the main problem is actually that I am unable to find any of the FMOD classes you're using in your gist. – Sherif elKhatib Apr 05 '13 at 14:17
-
@SherifelKhatib It's been a while since I worked on this project. Here's a post that uses FMOD library on android: [FMOD for Android](http://broadcast.oreilly.com/2011/06/fmod-for-android.html). I used that post as a guide when implementing the tempo detector. I'll try to create a github project in the next few days with the code for the application. – juan.facorro Apr 08 '13 at 17:59