Google+

Wednesday, March 18, 2015

Install Scipy through pip install in mac os x

When canopy visual environment has been installed, you might find your can't install Scipy to /usr/local/lib/python2.7/ anymore, or you might encounter pip "DistributionNotFound" Error. The solution is to reinstall python like this, using the soft way. Then pip install scipy.

Python package "intonation" needs Scipy.

Plot histogram of a recording object might cause float error in mac os backend.  Try to use:

import matplotlib
matplotlib.use("Qt4Agg")

before import anything from pylab.

Tuesday, March 3, 2015

Using AcoustID in IOS

AcoustID is an audio finger print project where Chromaprint allows you to calculate finger print from audio sources, and its web service allows you to search or to submit audio information in its database by Chromaprint.

Chormaprint is the core component of AcoustID project, it is written in C and can be compiled by cmake. However to use it in IOS, one needs a toolchain file.

1. Compile Chromaprint for IOS
1) You need to download the toolchain file here: https://code.google.com/p/ios-cmake/source/browse/

2) unzip the file "iOS.cmake" to Chromaprint source files' root folder. Open it, then change IOS_PLATFORM according to what you need. The default building architecture for "OS" is armv7 and arm64, this is sufficient for nowadays IOS devises.

3) build source files into a static library

1. mkdir build.ios 
2. cd build.ios 
3. cmake -DCMAKE_TOOLCHAIN_FILE=../../../iOS.cmake -GXcode ..
4. open Xcode project, compile chromaprint_p target for "iOS Device"

4) the static library will appear in the folder src/Debug-iphoneos/libchromaprint_p.a

2. Calculate finger print
Chromaprint only receives LinearPCM as the input audio format, so one should do the conversion if his original audio file format is not LinearPCM. The conversion method can be consulted here.

Once we get the URL of the audio file, we can open it by function AudioFileOpenURL, and save the fileID to outAudioFile.

The procedure of the finger print calculation is:

1. define a finger print calculation algorithm, here we use the default one: 
int algo = CHROMAPRINT_ALGORITHM_DEFAULT.

2. declare a finger print context and start calculation:
ChromaprintContext chromaprintCtx = chromaprint_new(algo);
chromaprint_start(chromaprintCtx, samplerate, channels);

3. read data packet, feed audio buffer outBuffer into this context, this could be done in a while loop:
AudioFileReadPackets(outAudioFile, false, &outNumBytes, NULL, inStartingPacket,&ioNumPackets, outBuffer);
chromaprint_feed(chromaprintCtx, outBuffer, ioNumPackets * framesPerPackets * 2)
where ioNumPackets is the packet number of the buffer,  inStartingPacket is the starting packet of the buffer, framesPerPackets = 1 for linearPCM audio format. Notice that AcoustID web service needs only 2 minutes audio finger print for database searching.

4. finish the finger print calculation and finally get the finger print:
chromaprint_finish(chromaprintCtx)
char *fingerPrint;
chromaprint_get_fingerprint(chromaprintCtx, &fingerPrint)

Now we have the finger print, and we can use it with AcoustID API to search its database.