Disable HTC Noise Cancellation
Asked Answered
L

1

6

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;
        }
    }
Lasagne answered 3/5, 2012 at 2:3 Comment(0)
C
5

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.
Conventionality answered 24/10, 2012 at 23:1 Comment(2)
I haven't had a chance to try what you suggest. I'm going to award you part of the bounty as your solution seems reasonable, but would require potentially significant refactoring and testing.Lasagne
It definitely requires some code gymnastics to get a solid audio solution that works across all devices. I know the pain.Conventionality

© 2022 - 2024 — McMap. All rights reserved.