Repository navigation
fix(hl2): stop splicing TX audio that arrives in bursts. Principle VIII. - #6005
Conversation
…dsets) Qt 6.8's macOS QAudioSource flushes captured audio in 4096-byte chunks (1024 frames of 16-bit stereo) whatever the device rate. At 48 kHz that is one 512-sample (24 kHz) Hl2TxDsp block per delivery; at 24 kHz -- a Bluetooth headset microphone such as AirPods Max -- it is two, every time. Hl2TxDsp::modulate() exchanged them back-to-back with the non-blocking TXA channel. The second exchange underran before WDSP's worker had produced the first block's output; fexchange2 zeroed it and advanced its read index, and from then on the two-slot output ring was read out of step with the worker, so every later block boundary was a splice. modulatorFaultBlocks counted the one underrun (2 per over) and nothing for the ~250 splices after it. Measured on hpsdrsim (hl2-lab d161), 1 kHz tone through BlackHole at 24 kHz: 252 phase discontinuities in 5.5 s, one every 21.3 ms, before; 0 after. Speech: 5 ms envelope flutter 3.58/s -> 0.0/s (48 kHz baseline 0.13/s). Hl2TxDsp now queues levelled audio and exchanges a block only when the channel reports the previous block's output ready, retrying from a 1 ms timer on its own thread; nothing blocks the I/O thread, a paced caller never waits, and a stalled worker is exchanged anyway after one block period (counted and logged as before). The readiness query is local WDSP patch 14 (GetChannelOutputReady, via WdspChannel::outputReady()), which also moves dexchange()'s r2_havesamps increment after the copy into r2 so "ready" means the block is in the ring. A fixed time spacing was tried first and failed under ctest -j6: a loaded worker outlasted it. hl2_txdsp_capture_burst_test feeds a tone as 48/24/16 kHz devices deliver it, running the event loop between deliveries, and requires zero faults, the full IQ count, no envelope hole and a phase-continuous tone. It fails on origin/main (1 fault and 122 splices at 24 kHz) and passes with this change, including 5 of 5 runs under 16 CPU hogs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for this one, @on8st — a two-slot ring being read out of step for the rest of an over, with the fault counter reporting 2 out of ~250, is exactly the kind of near-silent defect that's miserable to find. The 252 → 2 phase-break measurement and the "before: chopped, after: clean" A/B on hpsdrsim are the right shape of evidence, and numbering the WDSP patch 15 with the reason written down in What failed
Everything else on that commit was either green or still running:
Being straight with you about one limit: the CI tooling I have returns per-step status only, not the compiler output, so I'm not going to quote you an error line I haven't actually read. Please open the What I can do is tell you where to look. All eight files in the diff are portable on inspection — no 1. Caveat worth stating:
2. 3. The Not a CI infrastructure failureWorth ruling out explicitly, since that's the other common answer: all the fragile setup steps (Restore Qt, FFTW3, DeepFilterNet3, sccache, MSVC env, hidapi, PortAudio) succeeded, One thing to watch once it buildsNot a build problem, so separate from the above: Docs, for reference: Very likely a one-line portability fix on a genuinely good change. Drop the first 🤖 aethersdr-agent · cost: $6.8739 · model: claude-opus-5 |
…e VIII.
check-windows failed on this PR with C2375 ("'GetChannelOutputReady':
redefinition; different linkage", iobuffs.c): the definition carries
PORT (__declspec(dllexport)) and the iobuffs.h declaration did not.
MSVC rejects adding dllexport on a redeclaration; clang only warns
(-Wdll-attribute-on-redeclaration), which is why macOS and Linux built.
Declare it the way fexchange2 is declared one line above. No change
on platforms where the attribute is not an error.
Refs: aethersdr#6004
There was a problem hiding this comment.
Issue fit
Yes, for the mechanism it names. #6004's cause section and this diff line up exactly: modulate() exchanged every block a delivery carried back-to-back against a bfo = 0 channel, the second call took fexchange2's *error += -2 branch, and that branch advances r2_outidx without consuming (third_party/wdsp/upstream/iobuffs.c:645) so the two-slot ring (r2_active_buffsize = DSP_MULT * r2_size, iobuffs.c:406) is read out of step for the rest of the over. The gate + patch 15 is the right shape of fix, and the reorder in dexchange() genuinely is required by it rather than decoration — I traced r2_havesamps and confirmed upstream publishes the count at iobuffs.c:711 before the data was in r2, which only matters to a host that exchanges the instant the count says ready.
Two requirements from the issue are not covered: 44.1 kHz (18 splices in the issue's own table, the second-worst rate) is not exercised by the new test, and the 6 splices the issue measured at 48 kHz have no explanation in this diff — the new control case asserts splices == 0 at 48 kHz, which is in tension with the issue's own 48 kHz row. Neither blocks; say what the 48 kHz residue is or that it's out of scope.
Scope
| File / group | What it changes | Claimed? | Verdict |
|---|---|---|---|
Hl2TxDsp.cpp/.h |
queue + readiness gate + 1 ms retry timer | yes | in scope |
WdspChannel.cpp/.h |
outputReady(), same fence as processIq() |
yes | in scope |
third_party/wdsp/.../iobuffs.c/.h, aether_wdsp.h |
new GetChannelOutputReady() export |
yes | in scope; new vendored-API surface, documented |
iobuffs.c dexchange() reorder |
publish-after-copy, applies to every channel, RX included | yes, in the patch doc | in scope but global — see below |
AETHERSDR-PATCHES.md |
patch 15 entry + numbering note vs #5965 | yes | in scope, canon-compliant |
tests/hl2_txdsp_capture_burst_test.cpp, tests.cmake |
new registered target | yes | in scope |
Nothing in the diff is unexplained by #6004. No CHANGELOG.md edit — correct. No settings, no flat keys, no new UI, no preference change. Two things for the maintainer rather than the author:
- The
dexchange()reorder changes the vendored DSP for all channels, not just HL2 TX. I convinced myself it's safe (blocking hosts are released bySem_OutReady, which is signalled after both the copy and the count either way —iobuffs.c:713; for a non-blocking host the credit only becomes visible later, never earlier), but a global change to the shared WDSP core riding a single-backend bug fix is a maintainer call. - Patch numbering is coordinated with open #5965 in its own commit. Fine, just noting it's a cross-PR dependency on a number.
Sibling call site, checked: Hl2RxDsp::processIqBlock (Hl2RxDsp.cpp:712) has the identical while (… >= block) back-to-back processIq loop against the same non-blocking channel, and its comment even calls Underrun "normal". It is not affected in practice: RX dspBlockSize is 1024 (Hl2RxDsp.h:88) while EP6 deliveries are 126 samples per DDC, so the loop runs at most once per call. Worth knowing that the guard is absent there if RX block sizing ever drops.
Socket tests: none. The new test binds nothing — no QTcpServer/QUdpSocket/bind/listen/connectToHost, no fake peer. It is a socket-free CTest driving real DSP, which is the correct layer per AGENTS.md.
Blockers
1. The stall fallback force-exchanges, which is precisely the corruption this PR exists to prevent — and at the targeted rates it is the normal path, not a rare one. (Hl2TxDsp.cpp:277, Hl2TxDsp.cpp:256, inline)
The gate is bypassed when m_lastExchange.nsecsElapsed() >= exchangeStallNs(), and exchangeStallNs() is one block period — 21.33 ms at 512/24 kHz. But m_lastExchange is restarted on every exchange, so at 24 kHz (42.7 ms deliveries) the gap between the last exchange of one delivery and the first block of the next is ~41 ms, and at 16 kHz ~63 ms. Both exceed 21.33 ms, so the first block of every delivery is exchanged with no readiness check at all — the gate only ever governs the second and later blocks inside a burst.
Usually harmless, because after 41 ms idle the worker has finished. It is not harmless when the worker happens to be behind at that instant — preempted under load, or mid-beginControlOperation() from a setMode/setFilter during the over, where outputReady() returns false by design. Then processIq underruns, and by the PR's own argument (Hl2TxDsp.cpp:270-274, and the patch doc's "every later block boundary is a splice") that one forced underrun ruins the rest of the over. The PR states a fixed time spacing already lost to a loaded worker under ctest -j6; this fallback reintroduces a time-based decision at the one moment the readiness answer is being ignored.
Two things would fix it, and I'd take both:
- Time the wait from when the block became due, not from the last exchange. A block that has waited a whole block period has genuinely been starved; "no exchange happened for a block period" is trivially true whenever the caller is idle.
- On a real stall, drop the block rather than exchange it. Dropping loses 21 ms of audio and keeps the ring in step; exchanging loses the same 21 ms (the output is zeroed) and desyncs the ring permanently. The worker already has input from the previous exchange, so dropping cannot starve it into never producing output. This is strictly better by the PR's own reasoning, and
m_txFaultBlockscan still count it.
2. m_lastExchange is never invalidated, so every over opens on the bypass path. (Hl2TxDsp.cpp:216, inline)
resetModulatorState() and buildModulator() clear m_exchangePending and stop the timer but leave m_lastExchange valid and holding a timestamp from the previous over — minutes old. So the first block of every over takes the branch in finding 1 unconditionally. It is probably benign because DiscardTXAChannelData reprimes r2_havesamps (iobuffs.c:509), so outputReady() is true anyway at key-down; but the guard is off at the one moment the channel state has just changed, and that's the wrong place for it to be off. m_lastExchange.invalidate() alongside the two existing clears.
Nits (non-blocking)
m_exchangePendingis unbounded and now silent. (Hl2TxDsp.cpp:245) Before this PR, a caller faster than the channel got counted, logged underruns — the fault counter was the overrun signal. Now the overrun turns into queue depth and transmit latency instead, withmodulatorFaultBlocks()at zero. The drain is CPU-bound rather than real-time-bound so a burst does clear, but there is no cap and no warning if it doesn't. A depth watermark with a rate-limitedqCWarningwould keep the diagnostic the old behaviour gave for free.- The timer-thread comment states the wrong reason. (
Hl2TxDsp.cpp:335-337) AQObject's thread affinity comes from the thread that constructs it, not from its parent —new QTimer(this)from a foreign thread would log "Cannot create children for a parent that is in a different thread" and the timer would never fire. It is correct here only becauseexchangeDueBlocks()is reachable only fromprocessAudioBlock(queued tom_ioThread,Hl2Backend.cpp:416/5659) and from the timer itself. Worth restating as "only ever called on the I/O thread" so the invariant a future caller must not break is the one written down. - The new test is wall-clock paced and likely to be flaky in the sanitizer lane. (
tests/hl2_txdsp_capture_burst_test.cpp:194) It runs ~6.3 s of real time across three cases, and its own comment concedes the control case fails "if the machine is too loaded to judge the rest" — it fails rather than skips. Under TSan/ASan the WDSP worker and the 1 ms timer both slow down by a large factor while the test's delivery cadence stays pinned to real time; withexchangeStallNs()at 21.33 ms, a slowed worker produces exactly the forced underruns of finding 1 andcheck(r.faults == 0, …)goes red. It's a registeredadd_test, sofull-suite.ymlandsanitizers.ymlpick it up. Reasoned from the code, not observed — but it's the kind of failure that gets a target quarantined. - The patch doc over-claims what the test pins.
AETHERSDR-PATCHES.mdsayshl2_txdsp_capture_burst_test"pins the behaviour". It pins the gate — neuteroutputReady()toreturn trueand the test goes red. It does not pin thedexchange()reorder, which is a narrow data race and probably untestable deterministically. Saying so is more useful than implying coverage that isn't there.
What I tried to break
- Startup deadlock. My first suspicion was that
outputReady()must be false before any input has been fed — no input, nodexchange(), nor2_havesamps— which would make the gate break on the very first block, arm the timer, and spin forever with zero IQ. It doesn't:create_iobuffsprimesr2_havesamps = (DSP_MULT - 1) * r2_size(iobuffs.c:416), so there is exactly one block of credit at channel open and the first exchange proceeds.flush_iobuffsreprimes the same way (iobuffs.c:509), so a discard-and-restart over is also fine. Survived. - Off-by-one credit. Checked whether the primed credit could permit two back-to-back exchanges: it can only if
r2_size > out_size, i.e.dsp_outsize > out_size. For this TX geometrydspSampleRate == outputSampleRate == 48 kHzsodsp_outsize == out_size == 1024and the credit is exactly one block. Survived — but it is geometry-dependent, not structural. - Fence and lifetime on the new query.
WdspChannel::outputReady()reproducesprocessIq'sm_controlOperation/m_callbacksInFlightsequence verbatim, including the recheck after the increment, so the destructor's drain (WdspChannel.cpp:456) covers it.GetChannelOutputReadytakesr2_ControlSection— the same lockfexchange2takes to read the same counter — so the read is not torn and the CS gives the acquire fence that makes the worker'smemcpyvisible. Survived. - The reordered
dexchange()against blocking hosts. TracedSem_OutReady: released atiobuffs.c:713, after both the copy and the count in either ordering, sobfochannels are unaffected andwdsp_channel_test's offline path sees no change. Survived. - Sibling call site.
Hl2RxDsp::processIqBlockloops the same way; cleared on block-size arithmetic (1024-sample block vs 126-sample deliveries), not on assumption. - Timer lifetime and over boundaries. The timer is parented to
this, single-shot, re-armed only while a whole block is pending, stopped by bothreset()andbuildModulator(), andonExchangeTimer()re-checkspermitsDispatch()before emitting — so a lapsed grant drops the tail instead of transmitting it. Principle VI holds on this path. Survived. M_PIon MSVC. Flagged it, then cleared it:hl2_txdsp_test.cppusesM_PIwith only<cmath>and builds oncheck-windowstoday, because the Qt headers these tests pull in set_USE_MATH_DEFINES. Not a finding.- CI. All five checks green on
e3d9c10(build, check-windows, check-macos, static checks, sanitizer-configures). Those are compile gates; the per-PRctestis-R-filtered and does not include the new target, so green says nothing about whetherhl2_txdsp_capture_burst_testpasses anywhere.
What I could not check: nothing here was run. No build, no test execution, no radio, no macOS QAudioSource. Every finding above is reasoned from the code in /tmp/aetherclaude/pr-6005 and from the vendored WDSP source, and the two claims I most want settled empirically are (a) hl2_txdsp_capture_burst_test under -DENABLE_SANITIZERS, and (b) whether an over with a mid-over setMode/setFilter survives the bypass in finding 1.
Recommendation
Request changes — narrowly, on findings 1 and 2. The diagnosis is excellent and the seam is in the right place: asking the worker instead of guessing at a spacing is the correct call, the WDSP patch is minimal and properly documented, and the underlying trace (advance-without-consume in a two-slot ring) checks out line by line. But the stall fallback's threshold is shorter than the delivery period at exactly the rates this PR targets, which leaves the readiness check switched off for the first block of every delivery, and the action it takes on stall is the one action the PR argues is unrecoverable. Timing the wait per pending block and dropping rather than force-exchanging should be a small change, and it would make the guard hold in the loaded case the PR itself identifies as untested. The nits can ride along or follow.
Thanks for the measurements in #6004 — the per-rate splice table and the "326 of 326 deliveries" figure are what made this reviewable at all.
🤖 aethersdr-agent · cost: $10.1681 · model: claude-opus-5
|
It was your third candidate. The first MSVC error in that The definition carries The other two did not bite: the burst test compiled under MSVC with ON8ST |
|
Antares Detector — candidate vulnerable file(s)
The Hl2AdcPairing implementation performs ADC slice sampling-rate selection and overload/pairing logic on hardware sample rates (Hz or kHz). It likely maps those values into DSP-usable rates and allocates buffers for processing; without validating that the supplied sampleRate is within an expected range before conversion, it can allocate memory based on untrusted input. The Hl2Backend is implicated because it calls adcPairing to decide slice selection, making this a source of unsafe rate conversion. Localized by Cisco Foundation AI Antares-1B running locally in the AetherClaude sandbox, seeded by the Cartographer security map. Advisory only — please verify before acting. 🤖 aethersdr-agent · cost: $11.2518 · model: claude-opus-5 |
…nciple VIII. main() skipped under `#if !AETHER_HL2_TX_TXA`. aethersdr#5906 removes that build option and with it every definition of the macro, and an undefined macro reads as 0 in #if -- so after aethersdr#5906 this test would skip itself, report Passed, and run none of its checks. Found by a local integration build of the open HL2 PRs: on aethersdr#5906 + this branch it printed the phasing- modulator skip line. Skip only when the macro is DEFINED and 0, i.e. an explicit phasing build. Verified on aethersdr#5906 + this branch: the test runs and passes.
Review of aethersdr#6005 found the stall fallback was the normal path at the rates this PR targets: the deadline ran from the previous exchange, so after a 24 kHz (42.7 ms) or 16 kHz (64 ms) delivery gap the first block of every delivery skipped the readiness check. And on a real stall it force-exchanged, which underruns and desyncs WDSP's two-slot output ring for the rest of the over -- the corruption this PR exists to stop. Now the deadline runs from when a block reached the head of the queue, and a block whose worker has not answered within a block period is dropped, not exchanged: both lose the block's audio, only the exchange desyncs the ring. Drops are counted (modulatorStallDrops, also in modulatorFaultBlocks) and logged. The deadline is invalidated at every over boundary (reset and buildModulator), so an over never opens on the previous one's clock. Also from the review: a rate-limited warning when the queue passes four blocks, since overrun now shows as latency rather than faults; the timer comment now states the real invariant (I/O thread only); the burst test gains a 44.1 kHz case, two seam-driven stall cases that fail on the old gate, and exits 77 rather than failing when load stalls the worker -- an underrun still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The patch doc said hl2_txdsp_capture_burst_test pins patch 15. It pins the output-ready query and the gate built on it; the dexchange() reorder closes a cross-thread window no deterministic test here reaches, and rests on the argument in the doc. Say so, as the aethersdr#6005 review asked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Top-level reply (on the review)Both blockers were right, and the first one is the bad news: as first posted, this PR force-exchanged in exactly the case it exists for. At 24 and 16 kHz the gap between deliveries (42.7 / 64 ms) is longer than the 21.33 ms deadline, and the deadline ran from the previous exchange, so the first block of every delivery skipped the readiness check. A stall there would have caused the ring desync this PR is meant to fix. Fixed in 423a8ca. Details are in the inline replies. Two things I cannot close, stated up front:
44.1 kHz is now covered ( Inline repliesHl2TxDsp.cpp:278 — Blocker 1Agreed on both points, and I made both changes (423a8ca):
Test:
Restoring the old gate (deadline from the last exchange, force-exchange) turns this red. Four checks fail: the idle-arrival block is exchanged while the worker is not ready, and the stalled worker's block is force-exchanged instead of being dropped and counted. Hl2TxDsp.cpp:256 — threshold scaleAgreed. The problem was the reference point, not the length. Measured from when the block became due, one block period means what the comment always claimed: the worker has not turned a block round in a whole block period, and a TXA block normally takes it well under a millisecond. The comment at Hl2TxDsp.cpp:216 — Blocker 2Agreed, and fixed as you suggested (423a8ca): Hl2TxDsp.cpp:245 — unbounded, silent queueAgreed on the diagnostic, done (423a8ca, Hl2TxDsp.cpp:337 — timer commentI have one correction to the review, and I made the change anyway. The old comment did not attribute the timer's affinity to its parent. It said the timer is "created on first use, so it is born on the thread this object lives on", which is the constructing-thread rule. What it left out is the part you named: that is true only because every caller is on the I/O thread. The comment ( tests/hl2_txdsp_capture_burst_test.cpp:194 — sanitizer flakeAgreed, and the exit-77 route is taken (423a8ca). The rate cases now separate two outcomes:
The two stall cases do not depend on load: they drive the stall through the seam. Both coverage notes are addressed: 44.1 kHz above, and the patch doc in the next item. (review body) AETHERSDR-PATCHES.md over-claimsAgreed, corrected in ffdd1e7. The doc now says the test pins the query and the gate. It also says the test does not pin the 73, ON8ST |
The comment on processAudioBlock() explained the capture-burst defect through macOS's 1024-frame QAudioSource flush alone, which read as a 24/16 kHz microphone problem. The condition is any delivery of two or more 512-sample blocks at the 24 kHz transport rate, whatever the device rate. The pull path used on Linux and Windows hands over everything TxCaptureBuffer holds on each read, and the queued hops between the audio, GUI and I/O threads can run deliveries back to back; both produce the same burst at 48 kHz. Name them so the next reader does not scope the fix to one platform. Comment only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I wrote earlier that I had not seen the changed test run in the sanitizer lane. It has now been run under the sanitizers, locally, at
Flags, taken from
Configured with Results, five runs each:
On the flake the review predicted for The TSan reports, and why they are not this PR's:
One extra check, because Positive control for the ASan + UBSan lane: a small program with a signed overflow and a heap use-after-free, built and run with the same flags and options, reports both. Still not run: the weekly lane itself (Linux, instrumented Qt, leak detection on, whole suite), and Windows ctest. 73, ON8ST |
main condensed the comment blocks in Hl2TxDsp.{h,cpp} (aethersdr#6072) that this
branch had edited. Resolution: main's condensed text is kept, and only
what this branch makes true is re-applied on top: a delivery can carry
two or more blocks, so each exchange waits for the channel's output.
The code of the exchange gate is this branch's, unchanged.
The comments this branch adds in src/ are brought under the comment
rule (what is true now, five lines or fewer). No behaviour change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…15's RX effect. Principle VIII. The two seam-driven stall cases held the worker "stalled" for ~3 ms of wall clock against a 21.3 ms drop deadline and failed outright if the process was descheduled past it. They now time the hold from the delivery, and a hold that outlived the deadline marks the case inconclusive (exit 77), as the rate cases already do. A drop inside the deadline still fails, so the mutations the cases pin (no deadline reset per over, force-exchange on stall, gate removed) still go red. AETHERSDR-PATCHES.md patch 15 now says what the dexchange() reorder does to RX channels (count visible one memcpy later; priming, indices and Sem_OutReady untouched, so no latency change; an exchange inside that window underruns where upstream's order handed back a torn block) and its upstream status (TAPR 2.10 still counts before it copies). It also records the spin-host measurement behind the reorder: torn blocks in 3 of 15 runs with upstream's order, 0 of 20 with the reorder. Hl2TxDsp.h no longer says a caller faster than real time gets Underrun: the gate queues it and warns. Comments in the burst test and iobuffs.c are cut to AGENTS.md's comment policy, with the review history and lab narrative removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ten9876
left a comment
There was a problem hiding this comment.
Approving at 0fee91cd. That is on8st's fix, plus my 79f016e5, plus two GitHub update-branch merges of main (#6007, #6021). Neither merge overlaps the files this PR touches.
Fixed in this pass (79f016e5)
- The stall cases could fail under load. The automated review pass found that both seam-driven cases held a fake stall for about 3 ms of wall clock against the 21.3 ms drop deadline, and failed outright if the process was descheduled past it. They now time the hold from the delivery. A hold that outlives the deadline marks the case inconclusive (exit 77, as the rate cases already do), and a drop inside the deadline still fails. A forced 25 ms hold gives
rc=77with no FAIL lines. Hl2TxDsp.hwas stale. TheprocessAudioBlock()comment said a caller faster than real time "gets Underrun". With the gate it grows a warned queue, and the comment now says so.- Patch 15's doc was missing two things.
AETHERSDR-PATCHES.mdnow states what thedexchange()reorder does to RX and gives its upstream status. On RX, the count becomes visible onememcpylater. Priming, ring indices andSem_OutReadyare untouched, so no channel gains latency. An exchange that lands inside that window underruns, where upstream's order handed back a torn block. Upstream status: TAPR 2.10 still counts before it copies, and there is no query. The doc also records a spin-host measurement: torn blocks in 3 of 15 runs with upstream's order, and 0 of 20 with the reorder. - Comments now follow AGENTS.md § Comments. The test header, the iobuffs.c patch comments and the review-history references are cut down.
- PR body. I removed a stray SHA line, described the stall path as it is now (drop, not exchange), and listed 44.1 kHz.
Verified (Linux, local)
-
Mutations. Each of these turned
hl2_txdsp_capture_burst_testred:- gate disabled: 14 FAILs, 82 splices at 24 kHz;
- patch 15 reverted (query returns 1, reorder undone): 9 FAILs;
- query alone returns 1: 9 FAILs;
- stall drop replaced by exchange: 3 FAILs;
resetModulatorState()invalidate removed: 3 FAILs.
Reverting only the reorder stays green in this test, as the patch doc states. It is supported by the spin-host measurement instead.
-
Plain runs. The burst test passed 5/5, and 5/5 again under 16 CPU hogs, with every rate case at
faults 0 (stall drops 0) ... splices 0. -
ASan+UBSan, leaks on, C instrumented. The burst test passed 5/5 with zero ASan and zero UBSan errors. All 12
wdsp_*,hl2_rxdsp*andhl2_txdsp*tests pass. LSan reports onlycreate_calcc(calcc.c:1079, the PureSignal semaphores never closed). That is upstream code, and the unchangedhl2_txdsp_testandwdsp_channel_testleak from the same frame, so it is not this PR's. -
Full ctest. I ran 546 tests on the merged head, with socket-owning tests excluded. All pass except
connection_panel_size_test, a known local failure (#5811). -
Static gates.
check_engine_boundary,gen_touchpoint_manifest --check,check_capability_recordsandcheck_command_planegive output identical to the merge base.
Not verified: Windows ctest, the weekly TSan lane, and a live HL2. No transmitter was keyed.
…ciple VI. (#6104) ## Summary On HL2 and Icom, a TUNE power change made while TUNE is keyed now reaches the carrier. Before this, the value waited for the next key-down, and the operator saw a "dropped" notice for a control that looks live. This PR also fixes two TX-power defects in the same paths: - **HL2 transmit tail.** At TUNE release the RF drive was restored right after MOX-off, but the HL2 keeps radiating for its FIFO drain plus PTT hang after the MOX-off frame. The restore landed under the still-draining full-scale tune tone. The drive restore and the receive filter switch now wait out that tail. (Found by ON8ST.) - **Icom restore.** An RF power change made during TUNE was written over the tune drive and then lost at the unkey. ## What changed **Seam and capability** - `IRadioBackend::setTunePower(int)` is a new verb with a default no-op, next to `setTxPower`. It never keys. A backend that generates its own carrier re-applies drive to a carrier in progress and otherwise does nothing; the next `setTune()` carries the value. Owner-thread contract as for `setTxPower`. - `RadioCapabilities::TransmitDriveControl::tunePowerAppliesLive` defaults to `false`. It is a field inside the existing record, not a top-level bool, so `FROZEN_BOOL_COUNT` stays at 71 (`check_capability_records.py --strict` reports 71 on both base and head). The contract text in `IRadioBackend.h` and `docs/architecture/radio-capabilities-map.md` are updated to match. **Models** - New signal `TransmitModel::tunePowerCommandIssued(int)`. Only `setTunePower()` emits it, after `commandReady`, mirroring `rfPowerCommandIssued`. `applyChanges()` (status decode) never emits it. - `RadioModel` connects to it in the constructor's model-lifetime block, next to `rfPowerCommandIssued` (#4599). It forwards a change only when all of these hold: - `isTuning()` is true - a live `TxActivity::Tune` contribution exists - the backend declares `tunePowerAppliesLive` - The connect checks `tunePowerAppliesLive` before calling `setTunePower`. The behaviour is the same for every real backend, because the base verb is a no-op. The check makes the contract explicit: the field promises the verb is real, and a backend that doesn't declare it is never handed the call. - Both the forward and the drop-notice gate use one predicate, `RadioModel::tuneCarrierLive()`: `isTuning()` AND a live `TxActivity::Tune`. The gate is `routed = canTransmit && transmitDriveControl && (!isTuning() || (tuneCarrierLive() && tunePowerAppliesLive))`. While tuning, a value that is not forwarded live always keeps its notice: a backend without the field, or a tune state decoded off the radio with no TUNE this client admitted. - Every `TransmitDriveControl` is built with the field stated explicitly, as the ADDING A FIELD rule requires: `true` on HL2 and Icom, `false` on Flex (whose tune power travels as command-plane text) and ANAN. Sim and RTL declare no record. **HL2** - `Hl2Backend::setTunePower` writes only the drive register, through `applyDrive()`, so the clamp and the transmit gate still apply. It doesn't touch `m_rfPowerPercent`, band memory or `notifyOperatingStateChanged`, and it doesn't route through `setTxPower` or re-call `setTune(true)`. - It acts only while `m_tuning` is true. It also acts only while the TUNE operation, stored as `m_tuneOperation` in `setTune(true)`, still permits dispatch. That optional defence is included: a TUNE whose admission was revoked or emergency-stopped takes no drive change. Every unkey and the connection reset clear `m_tuneOperation`, so it never outlives the carrier. - `tunePowerAppliesLive = true` in the HL2 capabilities. **Icom** - `IcomCivBackend::setTunePower` writes CI-V `14 0A` (the tune drive) while tuning and does nothing otherwise. It also requires the same admission `setTune(true)` checked: the TUNE operation stored there, and the backend's transmit context. The operation is cleared at every unkey and session reset. A refusal is logged on `aether.icom.tx`, because the verb returns nothing to `RadioModel`. `tunePowerAppliesLive = true` in the Icom capabilities. - **Restore fix.** `setTxPower` during TUNE now records the value in `m_preTuneTxPowerPercent`, which the unkey (and the disconnect emergency path) writes back. It no longer writes over the tune drive. - The raw write is factored into `writeTxPowerLevel()`. The TUNE re-request branch in `setTune(true)` and the `tx.power` controls scrub both use it, so neither can stamp the tune drive into the restore slot. - **Readback during TUNE.** The CI-V read that confirms the tune-drive write (`14 0A`) is no longer published as `TransmitDelta::rfPower` while tuning. The periodic poll already skipped that read during TUNE. Without this, `TransmitModel::rfPower()` showed the tune level. A relative control (the power wheel, or a CAT/TCI read-modify-write) would then step from that level, and the result would become the value the unkey restores. Example: 100% RF and 10% tune, then one wheel step, left the radio at 11%. *Visible effect:* on Icom the RF power slider no longer jumps to the tune level while TUNE is keyed. It keeps the operator's RF power, matching Flex. (Found by code review of this branch.) **Evidence for the readback leak, and its limits.** This comes from the code path and a scripted-reply unit test. It is **not hardware-verified**: no Icom was on the bench. - Icom has no tune-carrier command, so TUNE writes the tune level into `14 0A`. - `sendUserCommand()` queues a confirming read of that level 60 ms later (`queueRead(..., now + 60)`). - The `kRfPower` reply handler published it as `TransmitDelta::rfPower`. - `icom_backend_seam_test` scripts that CI-V reply. It does not observe a real radio's answer. **Still wanted:** a CI-V capture from a real Icom of TUNE plus one RF-power wheel step. It should show the confirming `14 0A` read during TUNE and confirm that the restore after the unkey is the operator's RF power. ## The HL2 transmit tail (found by ON8ST) ON8ST showed from the gateware RTL that the HL2 keeps transmitting after the MOX-off frame: - MOX travels with the samples, not as a register. `dsopenhpsdr1.v:351-352` tags each sample with `ds_cmd_ptt`. - In `PTTTX`, `radio.v` drains the keyed samples already queued in the FIFO (`tx_buffer_latency`, 20 ms default, `radio.v:934`). AetherSDR never writes 0x17, so the default applies. - It then holds the last sample for `ptt_hang_time` (12 ms default, `radio.v:935`, 1036-1047). `tx_on` stays high until the state machine reaches `NOTX` (`radio.v:1002`). - Drive is not buffered. `ad9866ctrl.v:134-140` loads the TX gain as soon as the command arrives. So restoring RF drive one frame after MOX-off still landed under roughly 20 + 12 ms of full-scale tune carrier. ON8ST's unit (gateware 74.2) unkeyed itself 40-54 ms after the host stopped sending keyed frames. The same applies to the receive filter switch at unkey. **Why a timer, not `tx_on`.** `tx_on` is reported only in the discovery / alternate-port reply: `resp_control` (`control.v:899`) feeds `usopenhpsdr1.v:292` (`6'h20`). The EP6 stream's responses carry `ptt_resp = cw_on | ext_ptt` instead (`control.v:456`, 472-475), which a host MOX never raises. `MetisProtocol.cpp:546` is in `parseDiscoveryReply()`. Reading `tx_on` mid-stream would mean polling the discovery port during TX, which the stream-free telemetry design avoids because that reply preempts EP6 (`Hl2TelemetryCadence.h`). Gateware without `EXTENDED_RESP` also sends zeros there, so a "`tx_on` low" trigger would fail open. **Fix (`Hl2Backend`).** - Every key-up arms a transmit tail of `kTxTailHoldMs` = 70 ms, after the MOX-off is queued. - 70 ms is never below the existing RX unkey hold (a `static_assert` pins it). It covers the gateware's 20 + 12 ms default tail and ON8ST's 40-54 ms measurement. The RX-hold measurement of the same tail on one HL2 was 51.66-66.15 ms, n = 11. - While the tail is pending, `applyBandFilter()` keeps the transmit filter byte, and `setTxPower()` records an owed RF drive without writing it. - When the tail ends, the receive filter and the owed RF drive are applied. - A re-key cancels the tail, so a restore is never applied over a new carrier, and the drive stays owed to the next unkey's tail. - A disconnect or connection reset drops the tail. Icom is unchanged: its PTT-off is queued before the power restore, and the radio owns its own timing. **Maintainer decisions (Jeremy):** 1. A fixed 70 ms timer ends the tail. There is no `tx_on` poll, and 0x17 is not written. 2. A voice key inside the tail of a TUNE release keeps the tune drive for that transmission. The restore is cancelled, never applied over the new carrier, and RF drive returns at the next unkey's tail. 3. The transmit filter byte is held for the tail on every unkey, including CW break-in elements. ## Out of scope (unchanged) - No changes to TCI `tune_drive` or MIDI power limits. Note that TCI `tune_drive` and the automation `transmit tunepower` verb go through `TransmitModel::setTunePower`, so on HL2/Icom they now also apply live while TUNE is keyed, as they already did on Flex. - No slider dimming or tooltip UX for backends that don't declare the field. - No tune-power ceiling tied to RF power. Flex keeps them independent, and so does this PR. - Drag flood is accepted as is, matching RF power: no coalescing and no debounce. ## Tests (all socket-free; nothing keys real hardware) - `transmit_seam_drop_notice_test`: - Flag on: `setTunePower(30)` arrives exactly once, with no re-key and no drop notice. - Flag off: no call, and the notice stays. - Not tuning: no call, and the next `startTune` carries the value. - A decoded tune power while keyed (`applyChanges`, a different value) sends no call. - After `stopTune`, no call. - A tune state decoded off the radio (`applyChanges`, `tune=true`) with no live Tune activity: no call, and the drop notice stands. This pins the Tune-activity check on its own, in both the forward and the gate. - `hl2_tx_gate_test` reads the 0x09 bank bytes off the real EP2 packet builder. | Step | 0x09 bank result | |---|---| | RF power 40% | drive 102 | | TUNE at 10% | drive 25 | | live 60% | drive 153, PA on | | 150% | 255 | | −5% | 0, PA off | | release | 102 restored | | 80% after release | no bank, no keyed frame | | gate closed while tuning | 0, PA off | | TUNE operation emergency-stopped | no bank | | release | stored TUNE operation dropped | | stopped client | no bank | The same file has the transmit-tail tests, with the hold parked so each test ends the tail itself: - The unkey's queued calls post no RF-drive restore; walked packet by packet with an event filter on `MetisClient`. - The tail ending restores RF drive. - A re-key inside the tail cancels it; no restore under the new carrier, and the next unkey's tail pays it. - TUNE re-keyed inside the tail keeps its tune drive. - RF power set during the tail waits for it. - A live tune drive with no key-time tune power is still restored. - A disconnect drops the tail. - On a TX-only filter board, the TX byte holds through the tail, and through a retune inside it, until the tail ends. - The real timer ends a 20 ms tail. - `icom_backend_seam_test` checks the CI-V `14 0A` writes: - The capability is declared. - Not tuning: no write. - While tuning: the live 25% is written, with no re-key. - RF 50% during TUNE: no write, and it is held for restore. - A TUNE re-request writes 15% and keeps 50% held. - A `tx.power` scrub during TUNE re-asserts the live 15% and keeps 50% held. - Release writes 50%. - After release: no write, and the stored TUNE operation is dropped. - A TUNE whose operation was emergency-stopped: no write. - A lapsed transmit context with the operation still live: no write, and one warning logged. - An RF power readback of the tune level during TUNE publishes no `rfPower`. The premise is checked first: the same readback outside TUNE does publish. ### Mutation results (each mutation made its test fail, then the file was restored and verified by sha256 against HEAD) | Mutation | Result | |---|---| | RadioModel connect deleted | RED | | gate reverted to `!tuneKeyed` | RED | | flag ignored (gate + connect) | RED | | wired from `tunePowerChanged` instead | RED | | `isTuning`/Tune-activity check removed | RED | | Tune-activity check alone removed | RED | | HL2 `m_tuning` guard removed | RED | | HL2 implemented via `setTxPower` | RED | | HL2 `applyDrive` bypassed | RED | | HL2 tune-operation check removed | RED | | HL2 flag not declared | RED | | HL2 tail deferral removed (restore at unkey) | RED | | HL2 re-key cancel removed | RED | | HL2 `setTxPower` tail check removed | RED | | HL2 filter predicate ignores the tail | RED | | HL2 disconnect cancel removed | RED | | HL2 `setTunePower` not marking drive owed | RED | | Icom restore fix reverted | RED | | Icom `setTunePower` guard removed | RED | | Icom `setTunePower` no-op | RED | | Icom TUNE re-request via `setTxPower` | RED | | Icom scrub via `setTxPower` | RED | | Icom flag not declared | RED | | Icom tune-drive readback published during TUNE | RED | | Icom tune-operation check removed | RED | | Icom tune operation not stored at `setTune(true)` | RED | | Icom tune operation not cleared at unkey | RED | | Icom transmit-context check removed | RED | | Icom refusal warning removed | RED | | Drop-notice gate ignores `tuneCarrierLive` | RED | | Forward uses `isTuning()` alone | RED | | HL2 tune operation not cleared at unkey | RED | ## Merge with main The branch was cut from `2d5712946`. It now carries signed merges of `origin/main` up to `c7513e125` (27 commits, including #6062, #6005, #5979, #5982, #5976, #6011, #5980, #6019, #5981, #6012 and #6050 on HL2, and #6049 in `RadioModel`). Every merge was clean. The files both sides touched (`Hl2Backend.cpp/.h`, `IRadioBackend.h`, `RadioModel.cpp`, `radio-capabilities-map.md`) needed no manual resolution, and none of main's changes in them touch keying, drive or TUNE. Everything below was re-run on the current head. ## Static gates (merge base `c7513e125` vs merged head, findings diffed per file) `check_engine_boundary.py --strict`, `gen_touchpoint_manifest.py --check`, `check_capability_records.py --strict` and `check_command_plane.py --strict` all produce identical findings on base and head once line numbers are normalised: - Engine boundary: 102 tracked findings, 0 blocking. - Touchpoint manifest: up to date. - Capability records: 71 bools. - Command plane: 401 commands across 32 files. No ratchet moved, and no new wire text was added. `gen_seam_probe_table.py --check` is clean (51 signals): this PR adds a seam verb but no seam signal. ## Not verified - No live-radio test on HL2 or Icom; per the TX rules, nothing was keyed. The Icom path, including the readback leak and its guard, is proven only against the backend's CI-V output and scripted CI-V replies. A real-Icom CI-V capture of TUNE plus one RF-power wheel step is still wanted. - Icom's RF-power readback is suppressed during TUNE. CI-V cannot tell the confirming read of the tune drive from a front-panel change, so an RF-power knob turned on the radio during TUNE is not seen and the unkey restores the pre-TUNE value (the code comment says so). - The HL2 transmit-tail fix has no hardware test. Its 70 ms rests on the gateware source defaults and on bench measurements made before it existed: ON8ST's 40-54 ms unkey, and the RX unkey-hold measurement of the same tail. Nothing here observed `tx_on` or RF output with this change. - Full default ctest at -j8 on the merged head, with every test whose source uses a socket API excluded (523 of 620 run; the pty-backed `thumbdv_queue_test` and four new socket tests from main are excluded too): all pass except `connection_panel_size_test`, which is a known local failure (#5811). `transmit_seam_drop_notice_test`, `hl2_tx_gate_test` and `icom_backend_seam_test` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Closes #6004.
The defect is TX audio reaching
Hl2TxDsp::modulate()in bursts of two or more 512-sample blocks. The stage always runs at the fixed 24 kHz transport rate (TxVoiceProcessor::kTransportRate), whatever the device rate.modulate()exchanged the blocks of a burst back-to-back with the non-blocking TXA channel. The second underran,fexchange2advanced its read index anyway, and WDSP's two-slot output ring was then read out of step, splicing every later block boundary.modulatorFaultBlocksonly counted the first underrun.Known routes to a burst:
QAudioSourcedelivers 1024 frames per flush regardless of the device rate. At 24 kHz (Bluetooth headset mics such as AirPods Max) that is two blocks per delivery, and at 16 kHz three.TxCaptureBufferreturns everything available on each read, so any read of 2048 or more frames at 48 kHz reachesmodulate()as two blocks. VE3LPR saw the underrun that starts the splicing with a 48 kHz input on Linux ([bug] Hermes-Lite 2 v26.8.4 — Transmitted USB/LSB audio distorted; ALC meter swings full range despite controlled AetherVOICE levels (HL2) #5198, HL2: TX audio spliced when it reaches the modulator in bursts (macOS 24/16 kHz mics, Linux 48 kHz) #6004).Fix
Hl2TxDspqueues levelled audio and exchanges a block only whenWdspChannel::outputReady()reports the previous output is ready. It retries from a 1 ms timer on its own thread, so nothing blocks the I/O thread. A head block whose worker has not answered within one block period of becoming due is dropped, not exchanged (an exchange would desync the ring), and counted inmodulatorFaultBlocks()andmodulatorStallDrops(). Queue depth above four blocks is warned once per excursion. Every over starts with an empty queue and a fresh deadline.GetChannelOutputReady()and makesdexchange()publish a block intor2_havesampsonly after copying it. The reorder applies to every channel;AETHERSDR-PATCHES.mddocuments its effect on RX (no latency change; the count becomes visible onememcpylater). It is numbered 15 because fix(wdsp): free the minimum-phase design workspace after each design, and disclose #5954's costs. Principle VIII. #5965 claims 14.Evidence
Measured on hpsdrsim with a 24 kHz input:
Verified by ear with a real AirPods Max microphone, on the simulator (before: chopped, after: clean) and on the air through a real HL2 by the operator.
Tests
New
hl2_txdsp_capture_burst_test: a 1 kHz tone delivered as 48, 44.1, 24 and 16 kHz devices group it, plus two seam-driven stall cases (deadline from due, drop not exchange; fresh deadline per over). Onmainthe 24 kHz case reports 1 fault and ~120 splices in 2 s; with the fix all cases pass. A rate case whose worker is stalled by machine load exits 77 (skipped); an underrun always fails. It does not pin thedexchange()reorder, which rests on the argument and measurement in the patch doc.Not in this PR
A single 64–88 ms gap can occur right after key-up because the outgoing sample queue starts empty. It also happens at 48 kHz and on
main. It will be a separate change, since the fix (a short pre-roll) changes transmit timing.🤖 Generated with Claude Code