Implement headphone autodetection, earpiece routing, and linear volume controls
- Fix msm8916-wcd ALSA UCM2 configs (Earpiece.conf, Speaker.conf, Headphones.conf, PrimaryMic.conf, HeadsetMic.conf) so Speaker, Earpiece, and Headphones outputs and Mic1/Headset inputs are always available and mutually exclusive without invalid mixer controls - Add event-driven wired headphone/headset jack detection and automatic audio routing in sxmo_soundmonitor.sh via evtest on the msm8916 Headset Jack input device - Make Earpiece, Speaker, and Headphones first-class routable output devices across sxmo_audio.sh, sxmo_modemaudio.sh, xdrawer, dmenu, and callscreen - Make volume controls strictly linear across all channels by keeping PipeWire software gain at unity (100%) when unmuted and linearly mapping 0-100% to hardware digital volume registers (RX3 for Speaker, RX1 for Earpiece, RX1+RX2 for Headphones, TX1+ADC for Microphone)
This commit is contained in:
1 parent
e42eb573ed
commit
370f8b085c
33 files changed
+1351
-488
No files matched your search
@@ -468,10 +468,10 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
int softkeyPending = 0;
|
||||
int64_t softkeyDeadlineMs = 0;
|
||||
|
||||
auto pctToHwVol = [](int pct, bool spk) -> long {
|
||||
auto pctToHwVol = [](int pct, bool spk, bool hp = false) -> long {
|
||||
int c = std::clamp(pct, 5, 100);
|
||||
// RX1/RX3 Digital Volume: 84 = 0 dB, 88 = +4 dB, 92 = +8 dB, 94 = +10 dB
|
||||
return spk ? (68 + (c * 26) / 100) : (68 + (c * 24) / 100);
|
||||
if (hp) return 52 + (c * 32 + 50) / 100;
|
||||
return spk ? (56 + (c * 32 + 50) / 100) : (60 + (c * 32 + 50) / 100);
|
||||
};
|
||||
|
||||
auto refreshHardwareAudioState = [&]() {
|
||||
@@ -505,7 +505,8 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
|
||||
auto setSpeakerRoute = [&](bool toSpeaker) {
|
||||
speakerOn = toSpeaker;
|
||||
long hwVol = pctToHwVol(callVolumePct, toSpeaker);
|
||||
bool jackPlugged = (readIntFile("/tmp/sxmo_jack_plugged", 0) == 1);
|
||||
long hwVol = pctToHwVol(callVolumePct, toSpeaker, !toSpeaker && jackPlugged);
|
||||
alsa.setBoolean("PRI_MI2S_RX Voice Mixer VoiceMMode1", true);
|
||||
alsa.setBoolean("VoiceMMode1 Capture Mixer TERT_MI2S_TX", !micMuted);
|
||||
alsa.setEnum("CIC1 MUX", 0);
|
||||
@@ -516,20 +517,43 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
}
|
||||
if (toSpeaker) {
|
||||
alsa.setEnum("EAR_S", 0);
|
||||
alsa.setEnum("HPHL", 0);
|
||||
alsa.setEnum("HPHR", 0);
|
||||
alsa.setEnum("RX1 MIX1 INP1", 0);
|
||||
alsa.setEnum("RX2 MIX1 INP1", 0);
|
||||
alsa.setBoolean("SPK DAC Switch", true);
|
||||
alsa.setEnum("RX3 MIX1 INP1", 3);
|
||||
alsa.setInteger("RX3 Digital Volume", hwVol);
|
||||
runAsyncCmd("sxmo_audio.sh device set Speaker >/dev/null 2>&1");
|
||||
statusNotice = "Audio routed to Speaker";
|
||||
} else if (jackPlugged) {
|
||||
alsa.setBoolean("SPK DAC Switch", false);
|
||||
alsa.setEnum("RX3 MIX1 INP1", 0);
|
||||
alsa.setInteger("RX3 Digital Volume", 0);
|
||||
alsa.setEnum("EAR_S", 0);
|
||||
alsa.setEnum("RX1 MIX1 INP1", 3);
|
||||
alsa.setEnum("RX2 MIX1 INP1", 4);
|
||||
alsa.setEnum("RDAC2 MUX", 1);
|
||||
alsa.setEnum("HPHL", 1);
|
||||
alsa.setEnum("HPHR", 1);
|
||||
alsa.setBoolean("RX1 Mute Switch", false);
|
||||
alsa.setInteger("RX1 Digital Volume", hwVol);
|
||||
alsa.setInteger("RX2 Digital Volume", hwVol);
|
||||
runAsyncCmd("sxmo_audio.sh device set Headphones >/dev/null 2>&1");
|
||||
statusNotice = "Audio routed to Headphones";
|
||||
} else {
|
||||
alsa.setBoolean("SPK DAC Switch", false);
|
||||
alsa.setEnum("RX3 MIX1 INP1", 0);
|
||||
alsa.setInteger("RX3 Digital Volume", 0);
|
||||
alsa.setEnum("HPHL", 0);
|
||||
alsa.setEnum("HPHR", 0);
|
||||
alsa.setEnum("RX2 MIX1 INP1", 0);
|
||||
alsa.setEnum("RX1 MIX1 INP1", 3);
|
||||
alsa.setEnum("RDAC2 MUX", 0);
|
||||
alsa.setEnum("EAR_S", 1);
|
||||
alsa.setBoolean("RX1 Mute Switch", false);
|
||||
alsa.setInteger("RX1 Digital Volume", hwVol);
|
||||
runAsyncCmd("sxmo_audio.sh device set Earpiece >/dev/null 2>&1");
|
||||
statusNotice = "Audio routed to Earpiece";
|
||||
}
|
||||
statusNoticeUntilMs = nowMs() + 2000;
|
||||
@@ -538,13 +562,19 @@ int callscreen_run_main(int argc, char** argv) {
|
||||
auto adjustVolume = [&](int deltaPct) {
|
||||
callVolumePct = std::clamp(callVolumePct + deltaPct, 5, 100);
|
||||
writeIntFile("/tmp/sxmo_call_vol", callVolumePct);
|
||||
alsa.setInteger("RX1 Digital Volume", pctToHwVol(callVolumePct, false));
|
||||
bool jackPlugged = (readIntFile("/tmp/sxmo_jack_plugged", 0) == 1);
|
||||
if (speakerOn) {
|
||||
alsa.setInteger("RX3 Digital Volume", pctToHwVol(callVolumePct, true));
|
||||
alsa.setInteger("RX3 Digital Volume", pctToHwVol(callVolumePct, true, false));
|
||||
} else if (jackPlugged) {
|
||||
long hw = pctToHwVol(callVolumePct, false, true);
|
||||
alsa.setInteger("RX1 Digital Volume", hw);
|
||||
alsa.setInteger("RX2 Digital Volume", hw);
|
||||
} else {
|
||||
alsa.setInteger("RX1 Digital Volume", pctToHwVol(callVolumePct, false, false));
|
||||
}
|
||||
char cmd[128];
|
||||
std::snprintf(cmd, sizeof(cmd),
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ %d%% >/dev/null 2>&1",
|
||||
"sxmo_audio.sh vol set %d >/dev/null 2>&1",
|
||||
callVolumePct);
|
||||
runAsyncCmd(cmd);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user