Search code examples
javaandroidaudioaudio-recordingandroid-audiorecord

Android AudioRecord artifact


When I use Androids AudioRecord to record from the microphone, I get this annoying artifact

enter image description here

Is there a way to avoid or remove this? What is it? Or do I get that because I did something wrong in the configuration (but everything else works fine).

Here is my AudioRecord configuration:

    sampleRateInHz = 44100;
    channelConfigRec = AudioFormat.CHANNEL_IN_MONO;
    audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    bufferSizeInBytesRec = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfigRec, audioFormat);
    audioSource = AudioSource.MIC;

I am pretty sure that my code is right, because I can record everything fine, but there is this click at the beginning.


Solution

  • Try setting your audioSource to AudioSource.VOICE_RECOGNITION. On some devices, particularly HTC devices, I have found that there is less filtering going on with that source. And with ICS and after that's the official way things are supposed to be.In the Android 4.0 device compatibility document this is formalized:

    When an application has started recording an audio stream using the android.media.MediaRecorder.AudioSource.VOICE_RECOGNITION audio source:

    • Noise reduction processing, if present, MUST be disabled.
    • Automatic gain control, if present, MUST be disabled.