How to Adjust Microphone Sensitivity While Recording Audio in Android

How to adjust microphone sensitivity while recording audio in android

As I understand you don't want any automatic adjustments, only manual from the UI. There is no built-in functionality for this in Android, instead you have to modify your data manually.

Suppose you use read (short[] audioData, int offsetInShorts, int sizeInShorts) for reading the stream. So you should just do something like this:

float gain = getGain(); // taken from the UI control, perhaps in range from 0.0 to 2.0
int numRead = read(audioData, 0, SIZE);
if (numRead > 0) {
for (int i = 0; i < numRead; ++i) {
audioData[i] = (short)Math.min((int)(audioData[i] * gain), (int)Short.MAX_VALUE);
}
}

Math.min is used to prevent overflow if gain is greater than 1.

Adjusting the mic sensitivity while recording audio in android

Not really. It's usually possible to get at least two different "sensitivities" (acoustic tunings used by the platform) implicitly by using different AudioSources.
There should at least be one tuning for handset recording and one for far-field recording. On some devices you might also have different far-field tunings, e.g. one for recording audio a few decimeters away and one for recording audio a few meters away.


The problem is that you can't really know which AudioSource corresponds to which tuning, as there's no standard for it. CAMCORDER typically means far-field, and VOICE_RECOGNITION often means handset mode, but there's no guarantee for it. You should also keep in mind that vendors typically apply automatic gain control, noise reduction, etc that you as a user / app developer can't disable, in order to meet acoustic requirements for their products.

Your best bet would probably be to use a single AudioSource and then do attenuation of the signal in your app to simulate a lower mic sensitivity. You could do amplification as well, but that would be akin to using digital zoom in the camera app (it works, but doesn't look all that good because you're just scaling the existing data).

How to increase Microphone volume level in Android PJSIP?

Problem is Microphone volume level is too low when our application access through microphone. When you got low volume, you need to check multiple things.

One of them is MODE OF THE AUDIO MANAGER when microphone is used.

Getting MODE of the Android Audio manager::

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
long mode = am.getMode();
Log.e(TAG,"audio mode "+mode);

Setting MODE of the Android Audio manager::

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setMode(3);

You can access the mode of audio manager through this above code for your app.
There are

1.MODE_NORMAL

2.MODE_RINGTONE

3.MODE_IN_CALL

4.MODE_IN_COMMUNICATION

P.S. : Whenever you change the mode of the AudioManager, please change into MODE_NORMAL after using microphone otherwise it won't work once you restart the mobile.



Related Topics



Leave a reply



Submit