Skip to content

omamobile-modem-sit 0.3.45: switch call audio between loudspeaker and earpiece (9a) - #626

Draft
den-kloot wants to merge 5 commits into
derekross:mainfrom
den-kloot:modem-sit-call-audio-output
Draft

den-kloot wants to merge 5 commits into
derekross:mainfrom
den-kloot:modem-sit-call-audio-output

Conversation

@den-kloot

Copy link
Copy Markdown
Contributor

What and why

On the Pixel 9a (tegu) the TAS2572 call route always ran as speakerphone, and sitd's {"action":"audio","what":"speaker"} command was a stub ("Speakerphone routing is not configured yet"). So the shell's Speaker toggle (omatel SetRoute → callaudiod EnableSpeaker) had nothing to act on: a call could not be moved off the loudspeaker.

This implements the switch in the one place that actually routes this hardware — sitd's voice_audio.

  • VoiceAudio.set_output("speaker"|"earpiece"): the top amplifier is the earpiece and the bottom the loudspeaker (the module's own docstring). earpiece mutes the bottom's Speaker Digital Volume; speaker runs both at the conservative gain. The Incall sink is muted across the gain change, and the pre-call gains return from saved when the call ends — so a switch is a plain, reversible volume change that never touches the PCM or modem state.
  • service.py: wires the audio/speaker command to set_output, starts a call on [audio] output (default speaker, so behaviour is unchanged until asked), and reports the live output (speaker) and whether switching is available (speaker_available, true on the tegu route) in the status.

Switching on the 7 Pro's CS35L41 earpiece-mode route is left as it is; set_output is refused there for now (tegu only).

Device and build

  • Phone: Pixel 9a (tegu), AoC card google,tegu-aoc-snd-card, kernel 7.3.0-rc6-omamobile-push1-gcbb1a7eb0a78.
  • Package: omamobile-modem-sit 0.3.33 → 0.3.34.

Tested

  • On the phone, live call: the exact mixer sequence set_output performs (Bottom Speaker Digital Volume 0 for earpiece vs 180 for speaker, around an Incall-sink mute) was applied during an active VoLTE call on the 9a. The audio moved from the loudspeaker (top+bottom) to the earpiece (top amplifier only, localised to the top of the phone and quieter at the ear) and back, confirmed by ear, switched several times.
  • Unit tests: set_output (switch + restore), a configured earpiece start, the reported status fields and the speaker command. packages/omamobile-modem-sit/test/all passes bar one pre-existing failure unrelated to this change (test_attach_bearer, which reads the live phone's data configuration when run on the device; it fails identically on main without this change).
  • Not yet exercised: set_output running inside sitd during a call, rather than the identical mixer sequence applied by hand — that needs a fresh CP (a reboot) to load the new module. The code paths are covered by the unit tests; only the in-situ run is pending.

Notes

  • The shell already has the Speaker/Mute buttons and omatel already forwards them to org.mobian_project.CallAudio, but callaudiod isn't present on these phones and the AoC voice path isn't UCM-routable, so the button currently no-ops. This PR gives the daemon side the capability; wiring omatel/the button to sitd (or a small callaudiod stand-in) is a follow-up for the maintainer to decide.
  • Headphone/USB-C and Bluetooth (HFP) outputs are out of scope here.

🤖 Generated with Claude Code

@den-kloot
den-kloot marked this pull request as draft November 10, 2026 16:43
@derekross

Copy link
Copy Markdown
Owner

Thanks for this. It's the right place for the switch (sitd's voice_audio
is the only thing that routes that hardware), it's small, and the call ends
with the gains it started with. I ran the unit tests on a merge with today's
main and they pass. Since it's a draft, here is what I'd want before it's
ready, most important first.

  1. The status is wrong on every phone but the 9a. speaker used to be
    "this is the tegu route"; it is now output == 'speaker', and output
    defaults to speaker everywhere. On my 7 Pro a call plays in the
    earpiece (the CS35L41 earpiece mode) and would now report
    speaker: true. Please keep it a tegu fact, something like
    tegu and output == 'speaker', and add a test with a non-tegu audio
    object; the current test only flips tegu to check speaker_available.
  2. 0.3.34 is taken (omamobile-device-tegu 0.2.12: start the Pixel 9a's modem and phone service at boot, opt-in #372 landed it today). Because your version file
    and main's hold the same line it merges with no bump at all. The next
    free number is 0.3.35 as things stand; please also put the version in the
    title, which becomes the commit subject.
  3. Unmute only after a read-back. The tegu route's rule is that the call
    sink is unmuted once both gains read back what was written. set_output
    writes them and unmutes in a finally, also when a write failed. With
    the bottom write made to fail in your fixture I get the error and then
    Incall Sink Mute 0 with the old gains. Nothing above 180 can come out
    of it today, but I'd like this path to follow the same rule: read both
    gains back, and on a mismatch or a failed write leave the sink muted and
    raise.
  4. [audio] output = earpiece starts on the loudspeaker. tegu_enter
    unmutes at 180/180 and then calls set_output, so the first moment of
    the call is on the loudspeaker. Could the start write the configured
    output's gains, read those back, and only then unmute?
  5. A run of the code itself. You were clear that only the mixer sequence
    was tried by hand, thank you for saying so. Before this leaves draft I'd
    like one call on the 9a on the built package, switched both ways through
    the command, with sitd's log lines and uname -r. An
    omamobile-sit speaker on|off next to mute would make that one
    command, and I'd use it too.

Smaller: [audio] output isn't in etc/omamobile/modem-sit.conf, where the
other audio keys are explained (please mark it Pixel 9a only);
TEGU_SPEAKER_DIGITAL repeats TEGU_GAINS; and the module docstring still
describes the 9a as speakerphone only.

Two things I need to decide, and your view helps:

  • The earpiece level. omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374 (a draft from the 9a's other owner) also adds
    an earpiece on the tegu route, with the top amplifier at index 160, 10 dB
    below the speakerphone's 180, and with the handset echo-cancellation
    tuning. Yours keeps 180 and the speakerphone tuning. Could you read omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374
    and say how 180 sounded at the ear at normal speech levels, and whether
    the far end heard an echo? I don't want two answers to what the 9a's
    earpiece is.
  • The button. You're right that the Phone app's Speaker button has
    nothing to talk to on these phones. I'll decide how it reaches sitd; until
    then speaker_available: true has no user, which is fine for a first
    step.

Since service.py and voice_audio.py are every phone's sitd, I'll make
one call on my 7 Pro on your branch before merging: the earpiece as today,
the status reading speaker: false, the speaker command refused with the
call going on, and media back on both speakers afterwards.

@W4HO-ham

Copy link
Copy Markdown
Contributor

Derek asked on #374 that the two of us compare this with #374's earpiece route and tell him which design should carry on. I have the other 9a here (the palmtop), so here is my reading, and what I'd like to try with your branch.

The two side by side:

  • omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374's earpiece is a setting read when sitd starts (tegu_route = earpiece): the top amplifier at digital volume index 160, the bottom at 0, and it refuses unless the handset AEC tuning is on. There is no switch during a call.
  • Yours switches during a call: top and bottom at 180 for the loudspeaker, 180 and 0 for the earpiece, the sink muted across the change, the output in the status and the speaker command wired.

I think yours is the design to carry on. A switch during the call is what the Phone app's Speaker button needs, and #374's route can't give it. It is also smaller and leaves the PCMs and the modem alone.

Two things from my side that bear on it:

  1. omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374's rule that the earpiece needs the AEC tuning should go. This morning I read the AoC's own log through calls on the palmtop (results 6 to 8 in omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374's CALL-AUDIO-TUNING): stock's tuning doesn't cancel the echo on our route, and with it on the echo comes back louder than with it off. So an earpiece that works without the tuning is the part that helps the far end today.
  2. Levels. I chose 160 for the earpiece as a first-test level and never had it at my ear; you've had 180 at yours. How was 180 in a quiet room, and did the far end say anything about hearing themselves in either output?

What I'll do, unless you'd rather I didn't: run your branch as it is on the palmtop and post here the echo the far end gets in each output. I can measure that with nobody listening (a call to a talking clock, with the uplink's samples from the AoC's log; device/tegu/bringup/call-audio-watch.py and call-levels.py on #374's branch). I'd also try the switch inside sitd during a call, which your description lists as not yet exercised. Has that run since?

If the numbers agree with your ears, I'll tell Derek this one carries the earpiece, and I'll take the earpiece route out of #374 so the two don't collide.

@derekross

Copy link
Copy Markdown
Owner

Thank you both. @W4HO-ham, thank you for reading this next to your own #374 and saying plainly that you'd carry this design on; a switch during the call is what the Speaker button needs, and your AoC-log results are a good reason to drop the "earpiece needs the tuning" rule. I agree with the direction: one earpiece for the 9a, this one, with #374 giving up its route once this is ready.

@den-kloot, the branch hasn't changed since my comment of 11 November, so the five points there are all still open, and so are my two questions: how did 180 sound at your ear in a quiet room, and did the far end hear itself in either output? Are you still on this? If you'd rather hand it over, say so and W4HO can open a pull request that keeps your commit and adds the fixes; if I don't hear from you in a few days I'll ask him to do that.

One more point I found on this read:

  1. An unknown [audio] output value silences calls on every phone. VoiceAudio.__init__ raises ValueError for a value it doesn't know, and sitd's start turns that into "the call goes on without audio". So a typo in a key that is meant for the 9a only would take call audio away on a Pixel 7 Pro, where today the key is ignored. Please check the value only on the 9a's route, and for an unknown value log a warning and use speaker. A test with a non-9a audio object and a bad value would pin it.

W4HO, yes to trying it on your 9a, with these conditions:

  • Build it on today's main, not the branch as it is. The branch says 0.3.34 and is older than what main ships, and your phone runs 0.3.37 from your chain, so as it is you would be going back to an older sitd. Merging it onto main conflicts only in version; give your build a number above what's installed.
  • Reboot after installing; don't restart the phone service. Stop the modem first (systemctl stop omamobile-modem), then systemctl reboot.
  • You at the phone, on the charger, as for your other calls. The talking clock is fine as the far end.
  • Away from your ear to begin with. Two of my open points are in what you'd run: a failed gain write still unmutes, and an earpiece start still opens on the loudspeaker for a moment. Nothing above 180 can come out, but 180 is the speakerphone's level on the earpiece, and neither 160 nor 180 has been tried at an ear and measured.
  • The switch is a socket request for now, {"action":"audio","what":"speaker","value":"on"} or "off". Please post sitd's log lines for each switch, the two Speaker Digital Volume values and Incall Sink Mute read back after each, your echo numbers for both outputs, and uname -r.

That run would also be point 5 of my list (the code itself on a call), so it's worth having whoever finishes the branch.

The version is mine to set at merge; 0.3.35 has shipped, and 0.3.36 and 0.3.37 are spoken for. Before this merges I'll still make the call on my 7 Pro that I promised: the earpiece as today, the status reading speaker: false, the speaker command refused with the call going on, and media back on both speakers afterwards.

@den-kloot

Copy link
Copy Markdown
Contributor Author

Thanks @derekross, and sorry for the silence. I'll be honest about what I can still add here: not much.

What I can report is only what my 9a does as it is set up now (omamobile-modem-sit 0.3.35 from the repository, not this branch, [audio] output not set):

  • On a call I hear the other person normally, though the quality could be better.
  • With Speaker on, the person calling me hears themselves (an echo at the far end).

I can't answer your two questions properly: I don't have a build of this branch on the phone, and I can't judge earpiece levels like 180 well enough for it to count as a measurement.

So yes, please hand it over. @W4HO-ham, it's yours if you want it: keep my commit or rewrite it, whatever works with your #374 results and Derek's six points. I'm glad to run a build on my 9a and tell you what I hear, and what the other person hears.

It would also help if other 9a owners could try it and say how calls sound at the ear and on speaker, and whether the far end hears an echo. My ears shouldn't be the only data point.

den-kloot and others added 5 commits November 17, 2026 08:26
… earpiece

On the Pixel 9a (tegu) the TAS2572 call route always ran as speakerphone and
the audio "speaker" command was unimplemented ("not configured yet"), so the
shell's speaker toggle could not move a call off the loudspeaker.

Add VoiceAudio.set_output("speaker"|"earpiece"): the top amplifier is the
earpiece and the bottom the loudspeaker (this module's docstring), so earpiece
mutes the bottom's Speaker Digital Volume and speaker runs both at the
conservative gain. The Incall sink is muted across the gain change, and the
pre-call gains return from `saved` when the call ends, so a switch is a plain,
reversible volume change that never touches the PCM or modem state. Wire the
{"action":"audio","what":"speaker","value":"on"|"off"} command to it, start a
call on [audio] output (default "speaker", so unchanged behaviour), and report
the live output and whether switching is available (tegu) in the status.

Switching on other routes (the 7 Pro's CS35L41 earpiece mode) is left as is;
set_output is refused there for now.

Tested on a Pixel 9a during a live call: the exact mixer sequence set_output
performs (Bottom Speaker Digital Volume 0 for earpiece vs 180 for speaker)
moved the audio between the earpiece (top amplifier only) and the loudspeaker,
confirmed by ear, and back. Unit tests cover set_output, the configured
earpiece start, the reported status fields and the speaker command; the
package's test/all passes bar one pre-existing failure unrelated to this
change (test_attach_bearer, which reads the live phone's data configuration).
Not yet exercised: set_output running inside sitd during a call rather than
the identical sequence by hand (needs a fresh CP, i.e. a reboot, to load).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@den-kloot
den-kloot force-pushed the modem-sit-call-audio-output branch from 0a573c5 to df2bb83 Compare November 17, 2026 07:30
@den-kloot

Copy link
Copy Markdown
Contributor Author

@W4HO-ham, @derekross: so you don't start from zero, I've pushed what I had locally, and I've now measured the echo question from Derek's review instead of guessing.

The branch

Rebuilt on today's main (c4623572), as Derek asked. Version 0.3.45 (main is at 0.3.43, and #759/#754/#837 hold 0.3.42 to 0.3.44; Derek sets the number at merge anyway). Head df2bb836, 5 commits:

  • Point 1: the status speaker is a tegu fact again (tegu and output == 'speaker'), with a test on a non-tegu audio object.
  • Point 2: version.
  • Point 3: set_output reads both gains back and unmutes only if they match. A failed write or a mismatch leaves the sink muted and raises.
  • Point 4: with [audio] output = earpiece, the call starts by writing and reading back the earpiece gains, and only then unmutes.
  • Point 6: [audio] output is only checked on the tegu route. An unknown value logs a warning and uses speaker, so it can't take call audio away on a 7 Pro. There's a test with a non-9a audio object and a bad value.
  • Smaller: [audio] output is explained in etc/omamobile/modem-sit.conf (marked Pixel 9a only), the duplicate TEGU_SPEAKER_DIGITAL is gone, the module docstring no longer calls the 9a speakerphone only, and omamobile-sit speaker on|off sits next to mute.

All 299 unit tests and packages/omamobile-modem-sit/test/all pass on the rebased branch.

Does the far end hear itself? (measured, 2026-11-17)

An automated call instead of my ears: the 9a calls a landline whose SIP account a PC answers (baresip, G.711 A-law). For each phase the PC plays German test speech (Piper, 6.8 s) into the call at three levels, and records what the phone sends back while only the PC talks. Anything correlated with the PC's speech is echo. The phone lay flat on a table in a quiet room.

  • Kernel 7.3.0-rc6-omamobile-push1-gcbb1a7eb0a78, package 0.3.35 with this branch's voice_audio.py and its service.py speaker handling installed (same set_output and status lines as df2bb836).
  • Phases were switched with omamobile-sit speaker on|off. 160 and 140 were set on the top amplifier by hand with amixer, since the branch has only 180. sitd logged AoC tegu call audio switched to the loudspeaker / … to the earpiece with no refusals.
phase gains top/bottom floor back at -36 / -26 / -16 dBFS sent echo return loss at -16 verdict
speaker 180 / 180 -55.9 -59.9 / -57.6 / -49.0 33 dB echo (7 dB over the floor, correlation 0.71, ~600 ms)
earpiece 180 / 0 -72.6 -62.5 / -70.8 / -66.9 51 dB clean; a faint trace at -16 (6 dB over the floor, correlation 0.47, same ~600 ms delay)
earpiece 160 / 0 -71.7 -71.7 / -72.2 / -71.3 55 dB clean, at the floor
earpiece 140 / 0 -71.2 -71.6 / -63.6 / -72.7 57 dB clean
muted (control) 140 / 0 -72.3 -72.3 / -72.3 / -72.3 nothing back, as expected

"floor" is what the phone sends during 4 s of silence from the PC. "back" is the level of the return while the PC talks, aligned to the speech.

What I read from it:

  • On the loudspeaker the far end hears itself when it talks loudly. That matches what my callers told me.
  • The earpiece removes it. At 180 a trace is still there at the loudest level, and at 160 none. So 160, omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374's value, is the better earpiece level from the echo side too.
  • This doesn't say how loud 160 is at the ear. I can't judge that well, so someone holding a 9a to their ear should say whether 160 is loud enough.

The noise floor on the loudspeaker is 16 dB higher than on the earpiece. That's probably the AoC's processing for speakerphone, but I haven't checked.

The test is a script pair (phone + PC), about 4 minutes per run. I can run it again on any build, for example W4HO's with 160 and the handset tuning.

Still open

@den-kloot den-kloot changed the title omamobile-modem-sit: switch call audio between loudspeaker and earpiece (9a) omamobile-modem-sit 0.3.45: switch call audio between loudspeaker and earpiece (9a) Nov 17, 2026
@derekross

Copy link
Copy Markdown
Owner

Thank you, @den-kloot, both for saying plainly where you stand and for not leaving it at that: the rebuilt branch answers all six points, and the echo measurement is better evidence than anyone's ears. I read the new code: the status is a 9a fact again, a switch unmutes only after both gains read back, a configured earpiece starts on the earpiece, and a mistyped output can't cost another phone its call audio. CI is green on df2bb83.

Yes to the hand-over. @W4HO-ham, it's yours if you'll take it: open a pull request that keeps den-kloot's commits and adds what's below, and I'll close this one in its favour. #374 then gives up its earpiece route, as you offered.

Before it leaves draft:

  1. A mixer command that hangs. mixer() runs amixer with a 10 s timeout, and subprocess.TimeoutExpired isn't among the exceptions the request handler turns into an error reply, so a hung amixer during a switch would end sitd's loop, and with it the call. mute on main has the same gap; the switch makes several mixer calls per press, so please close it for both: a timeout becomes a refusal, the sink stays muted, and a test with a mixer that times out.
  2. The level. Your table says the earpiece at 160 is clean and at 180 leaves a trace, which is omamobile-modem-sit: opt-in 9a call tuning upload and earpiece audio #374's value. Please make the earpiece 160, and I'd like one of you to hold a 9a to an ear on a normal call at 160 and say whether it is loud enough before I call it settled.
  3. One call from the built package, since the measured run had two files copied over 0.3.35: install with the modem stopped, reboot, switch both ways with omamobile-sit speaker on|off, and post sitd's lines, the two Speaker Digital Volume values and Incall Sink Mute after each switch, uname -r and the package version.

One question, den-kloot: after copying the two files, did you reboot, or restart the phone service? On the 9a it should be a reboot.

The measurement scripts would be welcome under device/tegu/bringup/. The version is mine to set at merge, and my own call on the 7 Pro with this code still comes before that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants