androidaudioechocancellation

Android echo cancellation


I'm trying to develop an Audio Capture application using the AudioRecord class from Android API. Setting the audio source as MediaRecorder.AudioSource.MIC the application works, but when I try to use the echo cancellation setting by using MediaRecorder.AudioSource.VOICE_COMMUNICATION as audio source, I get an IllegalArgumentException when creating the AudioRecorder, but I don't know why.

My code is:

private static final int SAMPLE_RATE = 16000;
private static final int BIT_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
private static final int CHANNEL_CONFIGURATION = AudioFormat.CHANNEL_CONFIGURATION_MONO;

private int m_i32BufferSize;

private AudioRecord m_AudioRecorder;

public caudioCapture ()
{
    super ();

    m_i32BufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_CONFIGURATION, BIT_ENCODING);

    //Create audio recorder object 
    try
    {
        m_AudioRecorder = new AudioRecord (MediaRecorder.AudioSource.VOICE_COMMUNICATION,SAMPLE_RATE,CHANNEL_CONFIGURATION,BIT_ENCODING,m_i32BufferSize);

    }
    catch (IllegalArgumentException e)
    {
        throw new IllegalArgumentException("Bad arguments on AudioRecorder creation", e);
    }

In my android manifest I have:

uses-permission android:name="android.permission.RECORD_AUDIO"

Maybe it is because I'm using a Samsung galaxy tab p1000 running with Android 2.2? Any ideas?

Thanks a lot!


Solution

  • Yes that is correct. The problem is that you are using Android 2.2. The new VOICE_COMMUNICATION got introduced in Android 3.0. When run on older versions you will get the DEFAULT source instead.