Budget a linked pair on line frames; A is still silent with the peer alive

--line-frames N on run and link stops each side once it has exchanged N line
frames. Bridge.line_frame_budget trips Machine.request_stop from
_service_line_frame, so both ends leave at the same point in call time and
--instructions is only a ceiling.

300 frames on a 403 pair: both ends reach exactly 30.00 s of codec time
against 22.82 s and 15.89 s before, both still connected at exit, two
samples left in each buffer. The divergence and the dead-socket drop are
gone.

It changed nothing about the audio. Over 30 s with the peer alive
throughout, a-tx is 240,000 zeros and line_tx_nonzero is 5,176 - the same
count as the truncated run. So the previous commit's conclusion, that A's
silence followed from producing its audio after B had exited, is refuted.
The truncation was real and worth fixing and was not the cause.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Cryan209andClaude Opus 5 committed 2026-09-19 13:04:52 +12:00
1 parent a97f71f288
commit f59a824865
6 files changed
+42412

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# 403 pair budgeted on line frames
```sh
./courier link artifacts/courier-board-21210-capture-403/courier-board.rom \
--with-dsp --nvram-fixture idsdl403 --board-id 7 --dip-preset default --tick-ms 5 \
--audio-dir <dir> --line-frames 300 \
--a-at ATX0 --a-at ATDT5551234 --b-at ATA \
--instructions 250000000 --summary
```
Both ends stop at 300 line frames - 30.00 s of codec time each, against
22.82 s and 15.89 s when budgeted on instructions. Neither socket closes
early; both report `connected: true` and `buffer_left: 2`.
File diff suppressed because it is too large. Load diff
+16
View File
@@ -507,6 +507,13 @@ class CourierDspBridge:
# originate early return below is the only originate/answer asymmetry
# in _service_line, and a 69%/99% split between the two ends is what
# put it under suspicion. See docs/v8-call-overlay-misplacement.md.
# Budget the run on line frames, not x86 instructions. Two instances
# given the same instruction budget stop at different points in call
# time - measured at 22.82 s against 15.89 s on a 403 pair, a 44%
# divergence - and the shorter-lived end silently truncates the call
# for both. See docs/v8-call-overlay-misplacement.md.
self.line_frame_budget: int | None = None
self.on_line_frame_budget = None
self._line_service = {
"calls": 0,
"no_codec_clock": 0,
@@ -514,6 +521,7 @@ class CourierDspBridge:
"fallback_frames": 0,
"drained_frames": 0,
"buffer_left": 0,
"budget_frames": 0,
}
# `out 0x1e, 4` at 0x8e631 starts an overlay transfer.
self.transfer_start_command = 4
@@ -2833,6 +2841,13 @@ class CourierDspBridge:
samples=samples,
)
)
if (
self.line_frame_budget is not None
and self.line.frames >= self.line_frame_budget
and self.on_line_frame_budget is not None
):
self.on_line_frame_budget()
self.on_line_frame_budget = None
incoming = self.line.receive_audio()
if incoming:
self._line_rx_peak = max(self._line_rx_peak, max(abs(sample) for sample in incoming))
@@ -2896,6 +2911,7 @@ class CourierDspBridge:
line_service=dict(
self._line_service,
buffer_left=len(self._exchange_line_buffer),
budget_frames=self.line_frame_budget or 0,
),
overlay_words_verified=self.overlay_words_verified,
overlay_words_unreadable=self.overlay_words_unreadable,
+21
View File
@@ -254,6 +254,8 @@ def _worker_command(args: argparse.Namespace) -> list[str]:
command.extend(("--line-record", str(Path(args.line_record).resolve())))
if args.line_listen:
command.append("--line-listen")
if args.line_frames is not None:
command.extend(("--line-frames", str(args.line_frames)))
# A linked instance always needs a DAA: the link drives its line state
# frame by frame, starting from a line with nothing on the far end.
daa_line = args.daa_line or ("dial-tone" if args.sip_server else None)
@@ -391,6 +393,8 @@ def _link_side(args: argparse.Namespace, commands: list[str], listen: bool) -> l
"--board-id",
args.board_id,
]
if args.line_frames is not None:
command.extend(("--line-frames", str(args.line_frames)))
if args.line_audio_only:
command.append("--line-audio-only")
if args.audio_dir:
@@ -1151,6 +1155,15 @@ def build_parser() -> argparse.ArgumentParser:
help="share a two-wire line with another instance over this UNIX socket; "
"implies --with-dsp and supersedes --daa-line",
)
run.add_argument(
"--line-frames",
type=_number,
default=None,
metavar="N",
help="stop once this many line frames have been exchanged, so a pair "
"ends at the same point in call time rather than the same instruction "
"count; --instructions becomes a ceiling",
)
run.add_argument(
"--exchange",
action="store_true",
@@ -1313,6 +1326,14 @@ def build_parser() -> argparse.ArgumentParser:
help="run the C52 on both sides",
)
link.add_argument("--dsp-batch", type=_number, default=256, metavar="N")
link.add_argument(
"--line-frames",
type=_number,
default=None,
metavar="N",
help="stop both sides after this many line frames, so the pair ends at "
"the same point in call time; --instructions becomes a ceiling",
)
link.add_argument(
"--socket",
default=DEFAULT_LINE_SOCKET,
+9
View File
@@ -123,6 +123,10 @@ def main() -> int:
parser.add_argument("--exchange-hotline", action="store_true")
parser.add_argument("--line-link")
parser.add_argument("--line-listen", action="store_true")
parser.add_argument(
"--line-frames", type=int, default=None,
help="stop once this many line frames have been exchanged; the pair's "
"real budget, where --instructions is only a ceiling")
parser.add_argument("--line-audio-only", action="store_true")
parser.add_argument("--line-record")
parser.add_argument("--daa-codec", action="store_true")
@@ -273,6 +277,11 @@ def main() -> int:
console=console,
cpu_engine=args.cpu_engine,
)
if args.line_frames is not None and machine.dsp_bridge is not None:
# Both ends stop at the same point in call time rather than at the
# same instruction count, which they reach at different moments.
machine.dsp_bridge.line_frame_budget = args.line_frames
machine.dsp_bridge.on_line_frame_budget = machine.request_stop
if console is not None:
# Detaching the terminal closes its end of the channel, which the
# console notices; a signal covers the case where the parent goes
+60
View File
@@ -255,6 +255,66 @@ see above - and that is not explained by the truncation, because the dispatcher
is entered from the first seconds. Both faults are live; this one has to be
cleared first, because it makes every run unreadable after 15.89 s.
## Budgeting on line frames: the truncation is fixed, and A is still silent
`--line-frames N` on `run` and `link` stops each side once it has exchanged N
line frames. `Bridge.line_frame_budget` trips `Machine.request_stop` from
`_service_line_frame`, so both ends leave at the same point in *call* time and
`--instructions` is only a ceiling.
`artifacts/v8-line-frames-403-01/`, 300 frames against a 250 M ceiling:
| | A (originate) | B (answer) |
|---|---:|---:|
| `line.frames` | 300 | 300 |
| `line.connected` at exit | **True** | **True** |
| `line.error` | none | none |
| `buffer_left` | 2 | 2 |
| x86 instructions | 97,386,495 | 111,219,711 |
| codec samples | 216,007 | 216,007 |
| **codec time** | **30.00 s** | **30.00 s** |
The divergence is gone: identical call time, the instruction counts differing by
14% as they should, no socket closing under the other end, nothing left in
either buffer. The mechanism works.
**And it changed nothing about the audio.** Over 30 s, with both ends alive
throughout:
| wav | frames | peak | nonzero | span |
|---|---:|---:|---:|---|
| `b-tx` | 240,000 | 17,188 | 23,841 | 12.03 s - 15.01 s |
| `a-rx` | 240,000 | 17,188 | 23,841 | 12.03 s - 15.01 s |
| **`a-tx`** | **240,000** | **0** | **0** | - |
| **`b-rx`** | **240,000** | **0** | **0** | - |
`line_tx_nonzero` is 5,176 on A, the same figure as the truncated run, and
`a-tx` is 240,000 zeros.
> **Superseded.** The section above concluded that A's silence followed from
> the truncation - that every nonzero sample A produced was generated after B
> had gone. **That is refuted.** Given 30 s with the peer alive the whole time,
> A produces exactly the same 5,176 nonzero samples and still puts none of them
> on the wire. The truncation was real and worth fixing, but it was not why A
> is silent.
### What that leaves
The samples are in the core's own buffer - `m_line_tx` holds 216,007 words of
which 5,176 are nonzero, and the same array is what `line_tx_samples` hands the
bridge. `_exchange_tx_index` starts at zero, no core rebuild happened
(`core_rebuilt_at: 0` on both ends), and essentially the whole array was
consumed: 240,000 line samples shipped against 216,007 codec samples produced,
which at 7200-to-8000 is the entire stream. So the nonzero words were read out
of the array and did not survive to the socket.
Two candidates, neither tested: the codec-to-line conversion in
`_take_line_audio`, and whichever of the four `m_line_tx.push_back` sites on the
core side A's nonzero writes come from - `line_dac_writes` is 0, so they are not
the datapump's DAC slot. B's audio crosses the same conversion intact, which
argues against the resampler and for the write path, but that is an argument,
not a measurement.
### The next question, singular
Does `@48` ever get written on this image - by any site, in any configuration?