Disable HTC Noise Cancellation

android, htc-android, microphone

Solution

It is settable to a very small degree.

Using the audio source `MediaRecorder.AudioSource.VOICE_RECOGNITION` instead of `MediaRecorder.AudioSource.MIC` will turn off audio filters for that input. In general it's kind of the wild west in terms of the filtering you see from device to device. Even using `VOICE_RECOGNITION` isn't perfect since having filters off was only adopted into the Ice Cream Sandwich compatibility definition. HTC was using it before Ice Cream Sandwich though so for your case it will probably be the right choice.

From section 5.3 of the Android 4.0 Compatibility Definition Document:

In addition to the above recording specifications, 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.

Problem

I have an app that reads the microphone. Specifically I'm detecting blowing into the microphone ;) It doesn't work on a lot of HTC devices. I've picked up an HTC Droid Eris as well as an HTC Droid Incredible. In addition to those I have reports from many friends that have HTC devices also experiencing this problem to include the relatively new HTC Thunderbolt. So, debugging the app has shown that ambient room noise registers from 4000-11000 in a Starbucks. As soon as I blow into the mic the input volume drops to the 4000s: every time, all the time. Anyone know if this can be programmatically disabled? Here's how I'm reading the input ... ``` int minBufferSize = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize); short[] buffer = new short[minBufferSize]; audioRecord.startRecording(); audioRecord.read(buffer, 0, minBufferSize); int i = 0; for (short sample : buffer) { inputVolume = Math.abs(sample); maxVolumeIn = (inputVolume > maxVolumeIn) ? inputVolume : maxVolumeIn; if (inputVolume >= micSensitivity) { Log.d(TAG, "Blowing Detected. Volume Level: " + inputVolume); break; } } ```

Original source