With blocksize=0 PortAudio picks the capture block size per device. On
the devices measured for the previous commit it happened to deliver
multiple-of-6 block sizes, but other hardware returns 512/1024-class
blocks. codec2's resample48_to_8 asserts len(input) % 6 == 0
(FDMDV_OS_48), so on such a device every captured block raised
AssertionError, the DSP chain never ran, and RX was completely deaf.
The fix decouples the capture block size from the DSP block size
instead of pinning the stream back to blocksize=4800, which is the
configuration that negotiates a two-period ring on snd-aloop and drops
audio continuously (the deaf-on-loopback case the previous commit
fixed). Captured audio is appended to a carry buffer and the DSP chain
runs once per whole RX_DSP_BLOCK_48K (4800 samples, 100 ms) available;
the remainder carries into the next captured block, so the sample
stream handed to the resampler stays gapless (its filter memory spans
blocks) and always has a valid length, whatever the device delivers.
Running the DSP only on whole 4800-sample blocks also fixes three
silent degradations that short blocks caused:
- calculate_fft pads its input to 800 samples at 8 kHz, so short
blocks fed the waterfall, channel-busy detection and audio_dbfs
mostly zeros
- enqueue_streaming_audio_chunks zero-pads every block up to 2400
samples and emits one chunk per block regardless of size, so short
blocks streamed mostly silence and flooded the RX audio queue
- normalize_audio (rx_auto_audio_level, on by default) normalizes per
block, so shorter blocks made the auto level faster and jumpier
Tests: the old test captured 4800-frame blocks, a multiple of 6, which
is exactly why this was never caught. The capture size is now 512 and
TestRxAudioReblocking covers odd sizes never reaching the resampler,
exact block accounting including the carried remainder, sample-stream
preservation (nothing dropped, duplicated or reordered), and every
re-blocked block being accepted end to end by the real codec2
resampler. Against the pre-fix code 5 of the 6 tests fail; with the
fix all pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Exercise the callback/worker split from the previous commit:
- the worker drains rx_audio_in_queue and runs the relocated RX DSP
(resample 48->8 kHz, FFT, demod-buffer push) on an enqueued block, and
- the callback drops (and counts via rx_audio_dropped_blocks) instead of
blocking when the queue is full -- the real-time-safety property the
change exists to provide.
Both feed synthetic int16 blocks straight to the callback, so they need no
audio hardware and run under the existing `unittest discover tests` suite.
The live ARQ transfer test uses an in-memory queue and never touches the
sounddevice path, so this is new coverage rather than a changed test.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The IRS success branch set ENDED and returned without the
session-finished event, while abort, failure and the ISS success path
all send one. A successful inbound raw transfer was invisible to every
websocket/REST consumer, and the received payload was dropped with it
(handle_raw returns the data into a call chain that discards it).
c2388a65 emitted exactly this event, data= included; it vanished by
ef18f4cc without that commit's IRS diff touching the lines, so this
looks like a merge casualty rather than a decision. Restore the event
and add a regression test: one finished event with success=True,
payload round-trips through the base64 data field.
The original also pushed session statistics gated on enable_stats, but
that key is no longer in the config schema (config.py STATION), so the
strict lookup raises KeyError; the two existing stats sites in the
failure and abort paths have the same latent problem. Restoring just
the event here; the stats question is worth its own look.
No setARQ(False) here: dispatch() already clears busy on this path.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
See: https://peps.python.org/pep-0008/#imports
Here absolute imports have been used to avoid the error
`ImportError: attempted relative import with no known parent package`.
This applies mostly the same rules that `black` used.
This commit should not have introduced any logical or functional
changes, only fixing style consistency