From 35966292e83dd4e3dfa493138de8e3f6c2bedc25 Mon Sep 17 00:00:00 2001 From: telepathine <36798666+telepathine@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:41:12 +0200 Subject: [PATCH] LG8n: InCallService: Map AOSP gain step range to MTK one MTK has 15 volume steps, we have whatever is set in vc_call_vol_steps. Mapping our range to theirs allows reaching higher volume levels. A log curve is used to make gain transitions less abrupt at higher volumes. Change-Id: I5f0e6467ba9fd0779d7e4abbf9f258b0b42224e4 Signed-off-by: fjrXTR Signed-off-by: xyzuniverse Signed-off-by: fjrXTR Signed-off-by: Shirayuki39 --- .../org/lineageos/mediatek/incallservice/GainUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/InCallService/src/org/lineageos/mediatek/incallservice/GainUtils.java b/app/InCallService/src/org/lineageos/mediatek/incallservice/GainUtils.java index 2588c79..b62558a 100644 --- a/app/InCallService/src/org/lineageos/mediatek/incallservice/GainUtils.java +++ b/app/InCallService/src/org/lineageos/mediatek/incallservice/GainUtils.java @@ -1,15 +1,20 @@ package org.lineageos.mediatek.incallservice; +import android.os.SystemProperties; import android.media.AudioSystem; - import android.util.Log; public class GainUtils { public static final String LOG_TAG = "MediatekInCallService"; public static void setGainLevel(int audioDevice, int gainIndex, int streamType) { + int maxStep = SystemProperties.getInt("ro.config.vc_call_vol_steps", 7); String parameters = String.format("volumeDevice=%d;volumeIndex=%d;volumeStreamType=%d", - audioDevice, Math.min(7, gainIndex), streamType); + audioDevice, + Math.round( + (15.0 / Math.log(maxStep + 1.0)) + * Math.log(Math.min(maxStep, gainIndex) + 1.0)), + streamType); Log.d(LOG_TAG, "Setting audio parameters to: " + parameters); AudioSystem.setParameters(parameters); }