Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read raw values of 3gp / AMR-NB audio format?

In my Android application I am recording the user's voice which I save as a .3gp encoded audio file.

What I want to do is open it up, i.e. the sequence x[n] representing the audio sample, in order to perform some audio signal analysis.

Does anyone know how I could go about doing this?

like image 463
JDS Avatar asked Jan 10 '13 21:01

JDS


1 Answers

You can use the Android MediaCodec class to decode 3gp or other media files. The decoder output is standard PCM byte array. You can directly send this output to the Android AudioTrack class to play or continue with this output byte array for further processing such as DSP. To apply DSP algorithm the byte array must be transform into float/double array. There are several steps to get the byte array output. In summary it looks like as follows:

  1. Instantiate MediaCodec

    String mMime = "audio/3gpp"
    MediaCodec  mMediaCodec = MediaCodec.createDecoderByType(mMime);
    
  2. Create Media format and configure media codec

    MediaFormat mMediaFormat = new MediaFormat();
    mMediaFormat = MediaFormat.createAudioFormat(mMime,
        mMediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE),
        mMediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT));
    
    mMediaCodec.configure(mMediaFormat, null, null, 0);
    mMediaCodec.start();
    
  3. Capture output from MediaCodec ( Should process inside a thread)

    MediaCodec.BufferInfo buf_info = new MediaCodec.BufferInfo();
    int outputBufferIndex = mMediaCodec.dequeueOutputBuffer(buf_info, 0);
    byte[] pcm = new byte[buf_info.size];
    mOutputBuffers[outputBufferIndex].get(pcm, 0, buf_info.size);
    

This Google IO talk might be relevant here.

like image 102
Shamim Ahmmed Avatar answered Sep 29 '22 17:09

Shamim Ahmmed