Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
begonia: rootdir: Fix in-call volumes
Browse files Browse the repository at this point in the history
* Add shell daemon for correcting volumes using tinymix (don't forget add this tool to build)
* Kang idea by phhusson/treble_experimentations#1908

* Refactored code
* Also adapt channels and sh path for A12

Signed-off-by: 7Soldier <reg.fm4@gmail.com>
  • Loading branch information
TTTT555 authored and 7Soldier committed Jul 13, 2022
1 parent e50b886 commit db2fd4e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
5 changes: 4 additions & 1 deletion device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ PRODUCT_PACKAGES += \
libtinycompress \
libtinycompress.vendor \
libaudiofoundation \
libaudiofoundation.vendor
libaudiofoundation.vendor \
tinymix

PRODUCT_COPY_FILES += \
$(call find-copy-subdir-files,*,$(LOCAL_PATH)/configs/audio/,$(TARGET_COPY_OUT_VENDOR)/etc)
Expand Down Expand Up @@ -264,12 +265,14 @@ PRODUCT_COPY_FILES += \
# Ramdisk
PRODUCT_PACKAGES += \
partition_permission.sh \
setup_MTK_In-Call_volume_adjust.sh \
throttle.sh \
init.connectivity.rc \
init.modem.rc \
init.mt6785.rc \
init.mt6785.power.rc \
init.mt6785.usb.rc \
init.mtkincalladj.rc \
init.project.rc \
init.sensor_1_0.rc \
init.ttl.rc \
Expand Down
16 changes: 16 additions & 0 deletions rootdir/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ LOCAL_SRC_FILES := etc/init.mt6785.usb.rc
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := setup_MTK_In-Call_volume_adjust.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_SRC_FILES := bin/setup_MTK_In-Call_volume_adjust.sh
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := init.project.rc
LOCAL_MODULE_TAGS := optional
Expand Down Expand Up @@ -83,6 +91,14 @@ LOCAL_SRC_FILES := etc/fstab.mt6785
LOCAL_MODULE_PATH := $(TARGET_RAMDISK_OUT)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := init.mtkincalladj.rc
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_SRC_FILES := etc/init.mtkincalladj.rc
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := ueventd.mt6785.rc
LOCAL_MODULE_STEM := ueventd.rc
Expand Down
61 changes: 61 additions & 0 deletions rootdir/bin/setup_MTK_In-Call_volume_adjust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/vendor/bin/sh
### Begonia In-call volume fix by TTTT555 ###
while [ "$(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done
sleep 10

# Channel current volume (to find all params use "tinymix" command)
chcurrent=$(/system/bin/tinymix "ADDA_DL_GAIN" --v)
# Used gain = chcurrent + our offset < max value by tinymix "ADDA_DL_GAIN"
chused=65535
# Start value need less than $callmin
callcurrentold=0

# Logging
/system/bin/log -t MTKInCallDirtyFix "Starting Service"
/system/bin/log -t MTKInCallDirtyFix "Hardware Current Gain: $chcurrent"
/system/bin/log -t MTKInCallDirtyFix "Hardware Used Gain: $chused"

# Loop every 2 seconds
while true
do
# Check call status
callstatus=$(/system/bin/tinymix "Speech_SCP_CALL_STATE" --v)

if [ "$callstatus" = 1 ]
then
# Check call min volume in decimal FIXME: write HEX to DEX in one line
callmin=$(/system/bin/service call audio 18 i32 0 | /system/bin/awk -F ' ' '{print $3}' | sed 's/0*//')
callmin=$(echo $((16#$callmin)))
# Check call max volume in decimal FIXME: write HEX to DEX in one line
callmax=$(/system/bin/service call audio 19 i32 0 | /system/bin/awk -F ' ' '{print $3}' | sed 's/0*//')
callmax=$(echo $((16#$callmax)))
# Calculate interval for using via parabolic function
interval=$(/system/bin/expr $chused / $callmax / $callmax)

# Enable deep buffer for fix crackling
/system/bin/tinymix "deep_buffer_irq_cnt" 2048
/system/bin/tinymix "deep_buffer_scenario" 1

while [ "$callstatus" = 1 ]
do
# Check choosen volume level FIXME: write HEX to DEX in one line
callcurrent=$(/system/bin/service call audio 17 i32 0 | /system/bin/awk -F ' ' '{print $3}' | sed 's/0*//')
callcurrent=$(echo $((16#$callcurrent)))
if [ "$callcurrentold" != "$callcurrent" ]
then
# Calculate and write the new channel volume via parabolic function & rewrite max Db for small speaker
newchvol=$(/system/bin/expr $callcurrent \* $callcurrent \* $interval)
/system/bin/tinymix "ADDA_DL_GAIN" $newchvol
/system/bin/tinymix "Handset_PGA_GAIN" 8Db
/system/bin/log -t MTKInCallDirtyFix "Hardware In-Call Volume: $newchvol"
callcurrentold=$callcurrent
fi
callstatus=$(/system/bin/tinymix "Speech_SCP_CALL_STATE" --v)
done
# Restore $callcurrentold and chcurrent
/system/bin/tinymix "ADDA_DL_GAIN" $chcurrent
callcurrentold=0
fi
sleep 2

done
1 change: 1 addition & 0 deletions rootdir/etc/init.mt6785.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import /vendor/etc/init/hw/init.connectivity.rc
import /vendor/etc/init/hw/init.mt6785.power.rc
import /vendor/etc/init/hw/init.mt6785.usb.rc
import /vendor/etc/init/hw/init.mtkincalladj.rc
import /vendor/etc/init/hw/init.project.rc
import /vendor/etc/init/hw/init.sensor_1_0.rc
import /vendor/etc/init/hw/init.ttl.rc
Expand Down
9 changes: 9 additions & 0 deletions rootdir/etc/init.mtkincalladj.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on boot
start incalladj

# Start in-call volume adjusting for headset
service incalladj /vendor/bin/setup_MTK_In-Call_volume_adjust.sh
class main
user root
seclabel u:r:su:s0
oneshot

0 comments on commit db2fd4e

Please sign in to comment.