2026-10-19 23:34:06 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2026-10-25 18:15:36 +02:00
|
|
|
export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH"
|
|
|
|
|
|
2026-10-19 23:34:06 +03:00
|
|
|
# shellcheck source=scripts/core/sxmo_common.sh
|
|
|
|
|
. sxmo_common.sh
|
|
|
|
|
|
2026-10-29 20:42:26 +02:00
|
|
|
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo"
|
|
|
|
|
|
2026-10-19 23:34:06 +03:00
|
|
|
enable_call_audio_mode() {
|
2026-10-29 20:42:26 +02:00
|
|
|
printf "1\n" > /tmp/sxmo_in_call 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
# If wired headphones are plugged in or currently routed, keep call audio on Headphones;
|
|
|
|
|
# otherwise route voice call audio to Earpiece by default.
|
|
|
|
|
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
|
|
|
|
|
jack_plugged=0
|
|
|
|
|
if [ -r /tmp/sxmo_jack_plugged ]; then
|
|
|
|
|
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then
|
|
|
|
|
target_out="Headphones"
|
|
|
|
|
else
|
|
|
|
|
target_out="Earpiece"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
|
|
|
|
|
|
2026-10-25 11:31:41 +02:00
|
|
|
if command -v amixer >/dev/null 2>&1; then
|
2026-10-25 20:23:17 +02:00
|
|
|
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true
|
|
|
|
|
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
|
|
|
|
|
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
|
|
|
|
|
amixer -c 0 cset "name='RX1 Mute Switch'" 0 >/dev/null 2>&1 || true
|
2026-10-25 11:31:41 +02:00
|
|
|
fi
|
2026-10-29 20:42:26 +02:00
|
|
|
|
|
|
|
|
sxmo_log "Enabled ALSA voice call audio mode ($target_out)."
|
2026-10-25 11:31:41 +02:00
|
|
|
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
|
|
|
|
return 0
|
2026-10-19 23:34:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disable_call_audio_mode() {
|
2026-10-29 20:42:26 +02:00
|
|
|
rm -f /tmp/sxmo_in_call /tmp/sxmo_call_vol 2>/dev/null || true
|
2026-10-25 18:15:36 +02:00
|
|
|
|
2026-10-29 20:42:26 +02:00
|
|
|
jack_plugged=0
|
|
|
|
|
if [ -r /tmp/sxmo_jack_plugged ]; then
|
|
|
|
|
read -r jack_plugged < /tmp/sxmo_jack_plugged 2>/dev/null || jack_plugged=0
|
2026-10-25 18:15:36 +02:00
|
|
|
fi
|
2026-10-29 20:42:26 +02:00
|
|
|
|
|
|
|
|
if [ "$jack_plugged" = "1" ]; then
|
|
|
|
|
target_out="Headphones"
|
|
|
|
|
else
|
|
|
|
|
target_out="Speaker"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-10-25 11:31:41 +02:00
|
|
|
if command -v amixer >/dev/null 2>&1; then
|
2026-10-25 20:23:17 +02:00
|
|
|
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
|
|
|
|
|
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
|
|
|
|
|
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
|
2026-10-25 11:31:41 +02:00
|
|
|
fi
|
2026-10-29 20:42:26 +02:00
|
|
|
|
|
|
|
|
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
|
|
|
|
|
sxmo_log "Disabled ALSA voice call audio mode ($target_out)."
|
2026-10-25 11:31:41 +02:00
|
|
|
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
|
|
|
|
return 0
|
2026-10-19 23:34:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup_audio() {
|
2026-10-25 11:31:41 +02:00
|
|
|
enable_call_audio_mode
|
|
|
|
|
return 0
|
2026-10-19 23:34:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset_audio() {
|
2026-10-25 11:31:41 +02:00
|
|
|
disable_call_audio_mode
|
|
|
|
|
return 0
|
2026-10-19 23:34:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"$@"
|