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
@@ -256,33 +256,30 @@ std::string getConfigDirPath() {
|
||||
}
|
||||
|
||||
int readSavedSpeakerVol() {
|
||||
std::ifstream ifs(getConfigDirPath() + "/speaker_vol");
|
||||
int v = 85;
|
||||
std::string outDev = "Speaker";
|
||||
{
|
||||
std::ifstream dfs("/tmp/sxmo_audio_out_device");
|
||||
if (dfs) std::getline(dfs, outDev);
|
||||
}
|
||||
std::string vfile = "/speaker_vol";
|
||||
int defv = 85;
|
||||
if (outDev.find("Headphone") != std::string::npos || outDev.find("Headset") != std::string::npos) {
|
||||
vfile = "/headphones_vol";
|
||||
defv = 80;
|
||||
} else if (outDev.find("Earpiece") != std::string::npos) {
|
||||
vfile = "/earpiece_vol";
|
||||
}
|
||||
std::ifstream ifs(getConfigDirPath() + vfile);
|
||||
int v = defv;
|
||||
if (ifs && (ifs >> v)) {
|
||||
return std::clamp((v / 5) * 5, 0, 100);
|
||||
}
|
||||
return 85;
|
||||
return defv;
|
||||
}
|
||||
|
||||
void applySystemSpeakerVol(int pct) {
|
||||
pct = std::clamp((pct / 5) * 5, 0, 100);
|
||||
std::string cfgDir = getConfigDirPath();
|
||||
::mkdir(cfgDir.c_str(), 0755);
|
||||
{
|
||||
std::ofstream ofs(cfgDir + "/speaker_vol", std::ios::trunc);
|
||||
if (ofs) ofs << pct << "\n";
|
||||
}
|
||||
int rx3 = (pct <= 0) ? 0 : (54 + (pct * 38) / 100);
|
||||
runAsyncCmd("amixer -c 0 cset \"name='SPK DAC Switch'\" " +
|
||||
std::string(pct > 0 ? "1" : "0") + " >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
|
||||
std::to_string(rx3) + " >/dev/null 2>&1; "
|
||||
"wpctl set-mute @DEFAULT_AUDIO_SINK@ " +
|
||||
std::string(pct == 0 ? "1" : "0") + " >/dev/null 2>&1; "
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ " +
|
||||
std::to_string(pct) + "% >/dev/null 2>&1; "
|
||||
"sxmo_hook_statusbar.sh audio >/dev/null 2>&1");
|
||||
runAsyncCmd("sxmo_audio.sh vol set " + std::to_string(pct) + " >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
int runMusicApp(int argc, char** argv) {
|
||||
|
||||
Reference in new issue
Block a user