juha-h / baresip-studio

baresip library based SIP client for Android
BSD 3-Clause "New" or "Revised" License
276 stars 70 forks source link

Low microphone volume on Google Pixel 7 Pro #493

Closed muks closed 1 month ago

muks commented 1 month ago

@juha-h I am faced with low microphone volume when using the Android app on a Google Pixel 7 Pro. The issue seems to be what many other users have reported.

I poked around a bit about this issue and found the following ticket: https://github.com/google/oboe/issues/1052

(though it is not specifically discussing OpenSLES).

https://developer.android.com/reference/android/media/MediaRecorder.AudioSource#VOICE_COMMUNICATION

I am not an Android developer, and have not even compiled the following, but could the following patch improve things in the baresip repo?

diff --git a/modules/opensles/recorder.c b/modules/opensles/recorder.c
index c70de050..c80d7ba3 100644
--- a/modules/opensles/recorder.c
+++ b/modules/opensles/recorder.c
@@ -24,6 +24,7 @@ struct ausrc_st {
        void *arg;
        struct ausrc_prm prm;

+       SLAndroidConfigurationItf recConfig;
        SLObjectItf recObject;
        SLRecordItf recRecord;
        SLAndroidSimpleBufferQueueItf recBufferQueue;
@@ -111,6 +112,26 @@ static int createAudioRecorder(struct ausrc_st *st, struct ausrc_prm *prm)
        if (SL_RESULT_SUCCESS != r)
                return ENODEV;

+       r = (*st->recObject)->GetInterface(st->recObject,
+                                          SL_IID_ANDROIDCONFIGURATION,
+                                          &st->recConfig);
+       if (SL_RESULT_SUCCESS != r)
+               return ENODEV;
+
+       SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
+       r = (*st->recConfig)->SetConfiguration(st->recConfig,
+                                              SL_ANDROID_KEY_RECORDING_PRESET,
+                                              &presetValue,
+                                              sizeof(SLuint32));
+        if (SL_RESULT_SUCCESS != r) {
+               presetValue = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
+               (*st->recConfig)->SetConfiguration
+                       (st->recConfig,
+                        SL_ANDROID_KEY_RECORDING_PRESET,
+                        &presetValue,
+                        sizeof(SLuint32));
+       }
+
        r = (*st->recObject)->GetInterface(st->recObject, SL_IID_RECORD,
                                           &st->recRecord);
        if (SL_RESULT_SUCCESS != r)
juha-h commented 1 month ago

@muks Yes, there has been reports about low mic volume, but it does not appear on all devices. I have not been able to reproduce it on my Nokia or Samsung devices.

I applied your patch to modules/opensles and build baresip app using it: https://box.tutpro.com/tmp/baresip.apk. Could you give it a try?

muks commented 1 month ago

@juha-h Thank you for preparing a build. I tried it, but unfortunately I didn't notice any difference in the mic volume between the current F-Droid package and the baresip.apk linked above.

When testing today, the regular F-Droid package appears to sound loud enough. It's not super-loud, but it's not low either. So why did it sound low when I created the bug? Perhaps when a earphone+mic is plugged in, the app continues to use the phone's mic sometimes. I've noticed this happening a few times.

juha-h commented 1 month ago

Good to know that mic vol is high enough for you. Regarding audio source, baresip does produce some debug messages to logcat when the source changes.

Can we close this now?

muks commented 1 month ago

Yes, I'll close the issue now @juha-h. Thank you for helping test it.

Thank you for this Android app. baresip is very good these days and the Android app works well with our SIP service.