Skip to content
Open
22 changes: 20 additions & 2 deletions crates/chatd/src/adapters/tiny/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,10 @@ fn hear_busy(ctx: &Context, seat: &mut Seat, frame: &Value) {
clear_direct(seat, direct_id);
}

/// A direct call encodes like a seat in a default room: the voice-quality ladder over the
/// server's room default, since a direct has no room row of its own to ask.
const DIRECT_CALL_KBPS: u32 = protocol::TINY_BITRATE_DEFAULT;

/// Joins an accepted direct. Media is `d:{ring_id}`. The shell keeps the direct message's id.
#[allow(clippy::too_many_arguments)]
fn join_direct(
Expand Down Expand Up @@ -2848,11 +2852,15 @@ fn join_direct(
}
let direct_id = direct.direct_id.clone();
if live.seats_only() {
let intent = direct.intent.unwrap();
if let Some(direct) = seat.direct.as_mut() {
direct.joining = true;
}
seat.wanted = Some(direct_id.clone());
return ask_direct_join(wire, pending, refs, direct_id, None, direct.intent.unwrap(), timing);
let sent =
ask_direct_join(wire, pending, refs, direct_id.clone(), None, intent, timing);
ctx.tiny_room(&direct_id, DIRECT_CALL_KBPS, false);
return sent;
}
match offer_direct(ctx, saved, seat) {
Ok(sdp) => {
Expand All @@ -2864,7 +2872,17 @@ fn join_direct(
direct.joining = true;
}
seat.wanted = Some(direct_id.clone());
ask_direct_join(wire, pending, refs, direct_id, Some(sdp), direct.intent.unwrap(), timing)
let sent = ask_direct_join(
wire,
pending,
refs,
direct_id.clone(),
Some(sdp),
direct.intent.unwrap(),
timing,
);
ctx.tiny_room(&direct_id, DIRECT_CALL_KBPS, false);
sent
}
Err(words) => {
if let Some(intent) = direct.intent {
Expand Down
8 changes: 8 additions & 0 deletions crates/mediad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ fn main() -> ExitCode {
}
return ExitCode::SUCCESS;
}
// The lab's high-band driver. A build without this opens the audio engine below and stays up.
if env::var("TINYCLIENT_PROVE").ok().as_deref() == Some("high-band") {
if let Err(err) = mediad::process::prove_high_band() {
eprintln!("high-band: {err}");
return ExitCode::from(1);
}
return ExitCode::SUCCESS;
}
let _log = protocol::log_policy::install("mediad", protocol::log_policy::LogPolicy::from_env());
protocol::crash::install_panic_hook("mediad");
let code = mediad::serve::run(&args);
Expand Down
433 changes: 392 additions & 41 deletions crates/mediad/src/process.rs

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions e2e/scenarios/high-band-kept/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Enhanced noise keeps the high band, joined at the path's lag

Run with `E2E_APP_DIR` pointing to a directory containing the built `mediad`
and `E2E_OUT` pointing to an evidence directory, then run `python drive.py`.

This is a **headless DSP regression**, not native window or phone UI proof.
It starts the real mediad process with `TINYCLIENT_PROVE=high-band`; that
build runs `mediad::process::prove_high_band` and exits 0 only when both
hold:

- An impulse's high band (the high-pass's response) lands with its peak at
`impulse + RECON_DELAY`, to the sample - the ring that delays the band
above the 7.2 kHz cut hands over exactly `DELAY`, not a whole frame.
- The sparkle above the cut rides the send at exactly the isolation's own gain,
whatever the model decides about the synthetic voice under it: front, voice
isolation, the bridge, the rejoin, and back. The high band follows the
isolation's gain, so it keeps what a voice keeps and loses what the model
silences. The lag itself is pinned by the impulse check; a full-path lag
measurement is not asserted, because the model attenuates synthetic
speech-like signals by tens of decibels and the correlation peak rides the
residue.

With base `7ffa840` there is no rejoin and no proof hook: the variable is
ignored, mediad opens the audio engine and stays up, and the driver fails.
With the intermediate rejoin that read the ring slot it wrote, the high band
came back 457 samples (9.5 ms) late and the lag step fails. With this branch
it exits zero in about a second, no devices opened.

The same assertions run as
`cargo test -p mediad --lib the_high_band_joins_at_the_path_delay`, but this
scenario proves the shipped binary carries the proof hook, the way the lab
can run it on every desktop platform.
9 changes: 9 additions & 0 deletions e2e/scenarios/high-band-kept/drive.linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# high-band-kept on Linux. The lab runs this with bash while ffmpeg films the display.
set -u
HERE=$(cd "$(dirname "$0")" && pwd)
if command -v python3 >/dev/null 2>&1; then
exec python3 "$HERE/drive.py"
fi
echo "python3 is not on PATH" >&2
exit 1
9 changes: 9 additions & 0 deletions e2e/scenarios/high-band-kept/drive.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# high-band-kept on macOS. The lab runs this with bash while ffmpeg films the tinyclient window.
set -u
HERE=$(cd "$(dirname "$0")" && pwd)
if command -v python3 >/dev/null 2>&1; then
exec python3 "$HERE/drive.py"
fi
echo "python3 is not on PATH" >&2
exit 1
83 changes: 83 additions & 0 deletions e2e/scenarios/high-band-kept/drive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
"""Enhanced noise keeps the band above its 7.2 kHz cut, joined at the path's lag.

Starts this build's mediad with TINYCLIENT_PROVE=high-band. That build exits 0
only when the high band rejoins the reconstruction at the path's lag (an
impulse's high-passed response peaks at impulse + RECON_DELAY, and the 10 kHz
sparkle reaches the send at exactly the isolation's own gain, whatever the
model decides about the voice under it). A build from before the rejoin ignores
the variable and opens the audio engine, so this driver fails there; the
intermediate build that rejoined the high band a frame late fails the lag.

Env from the lab: E2E_OUT, E2E_T0, E2E_APP_DIR.
"""

import os
import subprocess
import sys
import time

OUT = os.environ.get("E2E_OUT", "")
T0 = float(os.environ.get("E2E_T0") or time.time())
APP = os.environ.get("E2E_APP_DIR", "")

FAILED = False
STEPS = ""


def now():
return time.time() - T0


def step(words, ok):
global FAILED
if not ok:
FAILED = True
line = '{"t": %s, "step": "%s", "ok": %s}' % (round(now(), 1), words.replace('"', "'"), "true" if ok else "false")
print(("[ok] " if ok else "[FAILED] ") + words, flush=True)
if STEPS:
with open(STEPS, "a", encoding="utf-8") as handle:
handle.write(line + "\n")


def mediad_bin(app_dir):
name = "mediad.exe" if sys.platform == "win32" else "mediad"
if sys.platform == "darwin" and app_dir.endswith(".app"):
return os.path.join(app_dir, "Contents", "MacOS", "mediad")
return os.path.join(app_dir, name)


def main():
global STEPS
if not OUT or not APP:
print("E2E_OUT and E2E_APP_DIR are required", file=sys.stderr)
return 1
os.makedirs(OUT, exist_ok=True)
STEPS = os.path.join(OUT, "steps.jsonl")
open(STEPS, "w", encoding="utf-8").close()
binary = mediad_bin(APP)
if not os.path.isfile(binary):
step("mediad is in E2E_APP_DIR", False)
return 1

env = os.environ.copy()
env["TINYCLIENT_PROVE"] = "high-band"
kwargs = {"env": env, "stdin": subprocess.DEVNULL}
if sys.platform == "win32":
kwargs["creationflags"] = 0x08000000
with open(os.path.join(OUT, "app.out.log"), "w", encoding="utf-8") as out, open(os.path.join(OUT, "app.err.log"), "w", encoding="utf-8") as err:
kwargs["stdout"] = out
kwargs["stderr"] = err
proc = subprocess.Popen([binary], **kwargs)
try:
code = proc.wait(timeout=45)
except subprocess.TimeoutExpired:
proc.kill()
proc.wait(timeout=5)
code = None
step("the high band survives Enhanced and joins at the path's lag", code == 0)
return 1 if FAILED else 0


if __name__ == "__main__":
sys.exit(main())
17 changes: 17 additions & 0 deletions e2e/scenarios/high-band-kept/drive.windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# high-band-kept on Windows. The lab runs this in the console session it is already filming.
$ErrorActionPreference = 'Stop'
$drive = Join-Path $PSScriptRoot 'drive.py'
if (Get-Command py -ErrorAction SilentlyContinue) {
& py -3 $drive
exit $LASTEXITCODE
}
if (Get-Command python -ErrorAction SilentlyContinue) {
& python $drive
exit $LASTEXITCODE
}
if (Get-Command python3 -ErrorAction SilentlyContinue) {
& python3 $drive
exit $LASTEXITCODE
}
Write-Host 'python is not on PATH (tried py -3, python, python3)'
exit 1
12 changes: 12 additions & 0 deletions e2e/scenarios/high-band-kept/scenario.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "high-band-kept",
"title": "Enhanced noise keeps the microphone's band above its 7.2 kHz cut, joined at the path's lag",
"platforms": ["windows", "linux", "macos"],
"not_applicable": {
"android": "The phone proof build does not start desktop mediad. The same process check is in the library the phone links.",
"ios": "The phone proof build does not start desktop mediad. The same process check is in the library the phone links."
},
"needs": [],
"release": false,
"max_still_seconds": 45
}
Loading