rosemary: 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
This commit is contained in:
telepathine
2022-08-15 13:41:12 +02:00
committed by Matsvei Niaverau
parent ced33fe9d4
commit 61471b2338

View File

@@ -1,15 +1,20 @@
package org.lineageos.mediatek.incallservice; package org.lineageos.mediatek.incallservice;
import android.os.SystemProperties;
import android.media.AudioSystem; import android.media.AudioSystem;
import android.util.Log; import android.util.Log;
public class GainUtils { public class GainUtils {
public static final String LOG_TAG = "MediatekInCallService"; public static final String LOG_TAG = "MediatekInCallService";
public static void setGainLevel(int audioDevice, int gainIndex, int streamType) { 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", 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); Log.d(LOG_TAG, "Setting audio parameters to: " + parameters);
AudioSystem.setParameters(parameters); AudioSystem.setParameters(parameters);
} }