Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 883
Puckl Avatar asked Oct 02 '12 15:10

Puckl


2 Answers

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.
like image 116
Douglas Jones Avatar answered Sep 27 '22 18:09

Douglas Jones


I think that the artifact shown is side effect of a digital filter that is being used to process recorded audio. Every digital filter has a certain delay. For example, if filter has N coefficients, it's delay is N/2. Essentially, that means that filter is going to start behaving normal after first N/2 samples of audio signal have passed through it. This should be the reason for the artifact you are having. Hope this helps.

like image 23
Pijetren Avatar answered Sep 27 '22 17:09

Pijetren