5

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.

slezadav
  • 6,104
  • 7
  • 40
  • 61
Puckl
  • 731
  • 5
  • 19
  • we need to see your code ??? but u can read this maybe help u [prev. answer][1] [1]: http://stackoverflow.com/questions/4707994/android-audiorecord-questions – Omarj Oct 08 '12 at 13:04
  • This question belongs on SO since it is a developer question. Programming questions are off topic on Android.SE: http://android.stackexchange.com/faq#what-about-other-android-related-questions – Bryan Denny Oct 09 '12 at 15:17
  • @eldarerathis whoops, that's what I get for skimming :) – Bryan Denny Oct 09 '12 at 15:52

2 Answers2

6

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.
Douglas Jones
  • 2,522
  • 1
  • 23
  • 27
2

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.

Pijetren
  • 159
  • 1
  • 9