0

I am trying to do a music identification application like shazam. This is an android app. First i have captured an audio signal through the MIC. Next I have implemented the hanning window function and FFT to the audio signal as shown as following code :

private class RecordAudio extends AsyncTask<Void, double[], Void> {
    @Override
    protected Void doInBackground(Void... params) {
        started = true;
        try {
            DataOutputStream dos = new DataOutputStream(
                    new BufferedOutputStream(new FileOutputStream(
                            recordingFile)));
            int bufferSize = AudioRecord.getMinBufferSize(frequency,
                    channelConfiguration, audioEncoding);
            audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                    frequency, channelConfiguration, audioEncoding,
                    bufferSize);

            short[] buffer = new short[blockSize];
            double[] toTransform = new double[blockSize];
            long t = System.currentTimeMillis();
            long end = t + 15000;
            audioRecord.startRecording();

            while (started) {
                //System.currentTimeMillis() < end
                int bufferReadResult = audioRecord.read(buffer, 0,
                        blockSize);
                for (int i = 0; i < blockSize && i < bufferReadResult; i++) {
                    toTransform[i] = (double) buffer[i] / 32768.0;
                    dos.writeShort(buffer[i]);
                }
                toTransform = hann(toTransform);
                transformer.ft(toTransform);
                publishProgress(toTransform);
            } 
            audioRecord.stop();
            dos.close();
        } catch (Throwable t) {
            Log.e("AudioRecord", "Recording Failed");
        }
        return null;
    }

Now my question is how do I need to apply high pass filter to my audio signal. Is there any API for this ?? Please some one help me to do this function.

Code modification part

private class RecordAudio extends AsyncTask<Void, double[], Void> {
    @Override
    protected Void doInBackground(Void... params) {
        started = true;
        try {
            DataOutputStream dos = new DataOutputStream(
                    new BufferedOutputStream(new FileOutputStream(
                            recordingFile)));
            int bufferSize = AudioRecord.getMinBufferSize(sampleRate,
                    channelConfiguration, audioEncoding);
            audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                    sampleRate, channelConfiguration, audioEncoding,
                    bufferSize);

            short[] buffer = new short[blockSize];
            double[] toTransform = new double[blockSize];
            long t = System.currentTimeMillis();
            long end = t + 15000;
            audioRecord.startRecording();

            while (started) {
                //System.currentTimeMillis() < end
                int bufferReadResult = audioRecord.read(buffer, 0,
                        blockSize);
                for (int i = 0; i < blockSize && i < bufferReadResult; i++) {
                    toTransform[i] = (double) buffer[i] / 32768.0;
                    dos.writeShort(buffer[i]);
                }
                toTransform = hann(toTransform);
                transformer.ft(toTransform);
                publishProgress(toTransform);
                //new part
                //sample rate = 8000
                highPassFilter(toTransform, sampleRate);
            } 
            audioRecord.stop();
            dos.close();
        } catch (Throwable t) {
            Log.e("AudioRecord", "Recording Failed");
        }
        return null;
    }

Here is my high pass filter method:

public void highPassFilter(double []frequency, int samplerate){
    double [] f = new double[frequency.length];
    for (int n=1; n<frequency.length; n++){
    f[n] = (double)frequency[n]/samplerate;
    double x = (double)Math.exp(-2 * Math.PI * f[n]);
    double []a = new double[] { (1+x)/2, -(1+x)/2 };
    double []b = new double[] { x };
    }   
}

Thanks !!

Hash_S
  • 79
  • 4
  • 18

1 Answers1

0

I think the signal processing could be done in the native level(C,C++) libs only You may try

this (TarsosDSP)

If the above doesn't help then try this SO Answer.

Community
  • 1
  • 1
  • @ Vigneshearan.m thanks for the answer...I have tried some code for my program according to your first link. There was a class called HighPass under the src folder (TarsosDSP/src/be/tarsos/dsp/filters/).But I am not sure my code is correct or not. Can you please check it?? Check my code modification part in the above. – Hash_S Feb 01 '15 at 05:29