2

Chromaprint is an open-source software library for calculating an AcoustID audio fingerprint of an audio file.

I'm trying to generate this audio fingerprint from a local file on iOS.

The library can be built on Windows, Linux and OS X, where it creates a dynamic library as well as a standalone program (fpcalc) that accepts an audio file, decodes the audio and passes it to the chromaprint library to calculate the fingerprint. It doesn't really work on iOS for the following reasons:

  1. The standalone fpcalc program can't be run on iOS because you can't run an executable from an app
  2. The source code to the fpcalc program uses chromaprint and ffmpeg. From what I've read, ffmpeg is difficult to compile on iOS. The chromaprint docs state that the Accelerate framework can be used in OS X/iOS, but there is no example code to do this and I have no idea where to start.

I've been having a bit of trouble actually building the library for iOS (CMake hates me), but I feel like the above problems are more relevant because even with the library compiled, it wouldn't just work out of the box.

I'm trying to avoid this being a "write my code for me" question, but I am very much stuck on essentially every aspect of generating a chromaprint fingerprint for iOS.

My goal, I think, is to recreate the functionality of the fpcalc program on iOS - to decode an audio file (stored on the device, of any audio type) and pass it to the chromaprint library to generate the fingerprint.

I found this question about acoustic fingerprinting on iOS but it wasn't relevant to chromaprint/AcoustID and the answers were less than helpful. Echoprint Codegen is interesting, but I need a chromaprint fingerprint.

1 Answer 1

1

Disclaimer: This works, but I have no idea what I'm doing. There are definitely better ways of doing this.

Build problems: In the beginning, nothing worked with CMake. I found and used this toolchain file from the ios-cmake project, and most things worked. As stated on their wiki, you must use the latest version of the file from the source code rather than the Downloads section. CMake complained about Boost, and Xcode complained about Boost, but both of those things magically fixed themselves many hours later.

Building the fpcalc functionality (fingerprint generation) was the tricky part, because it uses ffmpeg and I wasn't ready to try and build that with my app on iOS. Fortunately, Apple's Audio File Services (part of AudioToolbox) has the same sort of low-level audio functions.

I started out looking at this code that plays an MP3 file from NSData. The Audio Queue Services Programming Guide also has really useful information for opening and reading audio files and their properties. However, using an mp3 file (or any compressed format), the frames that you read from the data are not the raw PCM data that chromaprint needs.

Fortunately, this sample project from Apple converts an audio file to another format. Although it took some fiddling to get the project to compile in my app (lots of weird C++/Objective-C mixing), this is what I needed - it includes a DoConvertFile method.

Basically, my final code uses both of these methods. First it converts whatever input file to Linear PCM format using DoConvertFile, and then uses AudioFileOpenURL and AudioFileReadPackets to read the contents of the converted file. AudioFileGetProperty gives us the values that we need to pass to chromaprint_new. We then receive the same frame-by-frame audio data that can be passed to chromaprint_feed, and once you're at the end of the file, that's it! chromaprint_finish and chromaprint_get_fingerprint work perfectly. Delete the converted file and do whatever you want to do with the fingerprint.

4
  • I'm glad you got it working. It seems to me that it would be easier to use Extended Audio File Services rather than converting the file to PCM, saving it on the storage and then deleting it. Plus, you normally only use the initial X seconds of audio from the file, so you don't need to convert the whole file. Sep 30, 2014 at 17:28
  • Ah, sorry, I just checked the code and it actually uses that library. In that case you should be able to figure out how to get the fingerprint without saving the converted file. Sep 30, 2014 at 17:30
  • @LukášLalinský Yes, definitely. You could use the code from Apple's DoConvertFile function that just reads the input file and do all of the fingerprint work there. For me, after my hours of trial and error (mostly error), I was satisfied with just converting the whole file. I'll work on optimising it another day. ;)
    – ttarik
    Sep 30, 2014 at 17:37
  • @ev0lution Can you share some mote details to achieve this ?
    – jnix
    Sep 29, 2015 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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