Commit Graph

616 Commits (f522b46fa8ef008bc6570ad6d75ed0726d42e97c)

Author SHA1 Message Date
Steve Pinkham f522b46fa8 fix(audio): re-block captured RX audio into whole DSP blocks
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>
2026-07-24 21:34:19 -04:00
Steve Pinkham 3a56ebdb35 perf(audio): lower RX latency with blocksize=0 and set the input ring depth explicitly
blocksize=4800 makes PortAudio hand the RX callback fixed 100 ms blocks,
so received audio sits in the input buffer for up to 100 ms before the
demodulator can see it, and that delay is paid again on every ARQ
turnaround. With blocksize=0 PortAudio delivers whatever is available
(small blocks in the 10 to 50 ms range in our measurements), cutting the
RX buffering delay to a fraction of the old fixed block.

On its own, blocksize=0 also shrinks the negotiated input ring. We
measured 40 ms total where blocksize=4800 had negotiated 200 ms on a
CM108 USB codec, which makes short processing stalls more likely to
drop audio. The explicit latency=0.2 closes that gap: it requests a
200 ms ring built from small periods, so the stream keeps the old depth
while gaining the low latency.

The explicit ring depth also makes the negotiation deterministic on
virtual devices. On snd-aloop (the ALSA loopback used for hardware-free
testing) the default "high" latency maps to only two periods. At 100 ms
periods that double buffer misses its service deadline on a fixed cycle
and the capture stream drops audio continuously from the moment it
opens, leaving the modem deaf on that device class. With an explicit
depth the same stream runs clean; we measured buffer 12000 frames with
2400 frame periods and zero overflows, identically on two machines.

TX stays at blocksize=2400; only the RX side changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 07:20:19 -04:00
Steve Pinkham d8da991d61 perf(audio): run RX DSP off the real-time input callback
The sounddevice RX callback did all of the RX DSP inline: resample 48->8 kHz,
an FFT for the spectrum / channel-busy detection, optional level normalisation,
and a push into every decode mode's demod buffer. Running that on the real-time
audio thread means any delay in it -- a long GIL hold by another thread, a slow
resample on a constrained CPU -- can push the callback past its deadline and
overflow the capture stream.

Make the callback real-time-safe: it now only copies the captured block onto a
queue and returns. A dedicated worker thread (rx_audio_processing_worker) drains
the queue and runs the same DSP. The audio thread's work is now bounded and
constant.

This is also a prerequisite for lowering the input blocksize (next commit): a
smaller blocksize means a shallower capture ring, which only stays safe once the
DSP is off the real-time thread.

The DSP itself is unchanged -- the processing is moved verbatim, not altered.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 07:20:19 -04:00
dj2ls 27383c7de3 linting 2026-07-23 08:59:21 +02:00
DJ2LS c24760e896
Merge pull request #1109 from spinkham/fix/send-arq-raw
fix send_arq_raw: busy check always fired, and the command class didn't exist
2026-07-23 08:51:48 +02:00
DJ2LS 93e0159fb9
Merge pull request #1110 from spinkham/fix/irs-success-event
restore the IRS success event that was lost in an April 2024 merge
2026-07-23 08:51:37 +02:00
dj2ls 7e33527123 old broadcasts expire 2026-07-23 08:42:42 +02:00
Steve Pinkham f19c775a3a fix: emit arq-session-finished on IRS success again (lost April 2024)
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>
2026-07-22 18:30:05 -04:00
Steve Pinkham f49e5076b3 fix: send_arq_raw referenced a command class that doesn't exist
command_arq_raw.SendARQRawCommand isn't defined anywhere; the class is
ARQRawCommand. The always-503 busy bug hid this AttributeError, so the
endpoint can never have worked end to end.
2026-07-12 12:38:16 -04:00
Steve Pinkham 8def0df2ae fix: send_arq_raw busy check compared a threading.Event, not the ARQ state
POST /modem/send_arq_raw returned 503 Modem Busy on every request:
is_modem_busy is a threading.Event and the object is always truthy.
Use getARQ() like the beacon, message send and CQ handler do.

Note for later readers: is_set() would be inverted, since setARQ(True)
clears the event. getARQ() == True means busy.
2026-07-12 12:38:16 -04:00
Mashintime 58d60bc5c3 Fix a logger error message on win everytime an api call is mode 2026-02-10 20:39:35 -05:00
DJ2LS e3aca6feea
Merge pull request #1052 from as3ii/ruff2 2026-01-10 21:41:48 +01:00
as3ii e2b2c73f1a
Fixed other module's paths 2026-01-10 20:27:19 +01:00
as3ii 646174b75d
Fixed ruff F811 and F401 2026-01-10 19:11:47 +01:00
as3ii bec3a28364
Fixed ruff F841 2026-01-10 19:11:47 +01:00
as3ii ed4c79cd2a
Fixed ruff F541 2026-01-10 19:11:47 +01:00
as3ii 8f7113fd3e
Fixed ruff E7 2026-01-10 19:11:47 +01:00
as3ii f88f5fe2a3
Increased max line length to 120, reformatted everything
In practice, in this commit I've increased from 100 to 120 the maximum
allowed line length for python files and re-run ruff's formatter.
2026-01-10 19:11:26 +01:00
dj2ls e5e7ff6baf fixed another wrong path 2026-01-09 20:02:28 +01:00
dj2ls fd88a318f2 support for M1+ chips 2026-01-09 08:42:12 +01:00
DJ2LS 56f7632ed0
Delete freedata_server/nmea.py 2026-01-08 17:45:50 +01:00
dj2ls e5b4f4cc6d removed stats publishing 2026-01-08 17:36:13 +01:00
dj2ls 987539ce13 bump version 2026-01-08 17:29:21 +01:00
DJ2LS 68a4bdcff9
Merge branch 'develop' into ls-audio 2026-01-08 17:27:47 +01:00
dj2ls a4451f8300 fixing some path related issues - trying to merge this PR soon 2026-01-08 17:14:52 +01:00
dj2ls 69bfd4c052 make norm a setting - trying to merge this PR soon 2026-01-08 16:48:25 +01:00
DJ2LS 04366b0cb6
Merge branch 'develop' into ls-norm 2026-01-08 16:28:45 +01:00
as3ii 191c94c942
Executed `ruff format --preview`, small update to CONTRIBUTING.md 2025-11-13 23:48:17 +01:00
as3ii 90a1e7c2f7
Removed redefined set_tuner() flrig's function (ruff F811) 2025-11-13 23:43:04 +01:00
as3ii 1f4efac11e
Substituted unused variables with wildcard (ruff F841)
See https://peps.python.org/pep-0634/#wildcard-pattern
2025-11-13 23:31:09 +01:00
as3ii b187628c3e
Fixed `undefined name` errors (ruff F812) 2025-11-13 23:07:06 +01:00
as3ii 444c0d37cf
Removed f-strings without placeholders (ruff F541) 2025-11-13 22:45:07 +01:00
as3ii fbb151838b
Fixed ruff F403 and F405
Now all F4 rules are fixed
2025-11-13 22:39:46 +01:00
as3ii 4a458730ea
Removed unused imports
Ruff's rule F401
2025-11-13 20:12:55 +01:00
as3ii b86cea188b
Fixed ruff rule E713, E721 and E722
See https://peps.python.org/pep-0008/#programming-recommendations
2025-11-13 20:05:47 +01:00
as3ii 0deef898ff
Fixed ruff rule E401 and E402
See https://peps.python.org/pep-0008/#imports
2025-11-13 19:55:53 +01:00
as3ii 6f7288335f
Switched from editing `sys.path` to proper PEP8 imports
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`.
2025-11-13 19:49:38 +01:00
as3ii 23f1aab5aa
Removed references to pylint and useless file encoding 2025-11-13 16:32:23 +01:00
as3ii 66b2c6bf4e
Run `ruff format`
This applies mostly the same rules that `black` used.

This commit should not have introduced any logical or functional
changes, only fixing style consistency
2025-11-13 15:53:43 +01:00
DJ2LS c1097c162b
Merge branch 'develop' into ls-norm 2025-11-12 11:46:27 +01:00
DJ2LS 9cb5e0a6d5
Merge branch 'develop' into ls-audio 2025-11-12 11:46:21 +01:00
as3ii 602b982f81
Removed setup.py, fixed build of pip module 2025-11-11 23:19:20 +01:00
Erik de Wildt 64d41de67e Add distance unit setting to choose between Kilometer or Miles. 2025-10-29 10:17:36 +01:00
DJ2LS edb2f5c0f3
Merge branch 'develop' into ls-norm 2025-10-27 08:48:24 +01:00
DJ2LS 4d968898d5
Merge branch 'develop' into ls-audio 2025-10-27 08:47:14 +01:00
DJ2LS 1aba07e379 bump version 2025-09-22 08:45:01 +02:00
Mashintime edc3ba5e16
rigctlyd.py Fix invalid escape sequence
Not sure if a bug unique to python on windows, but rigctl chk_vfo and dump_caps would not work until I escaped the \'s in the funcitons remarks.  Rigctl would not work at all because of these errors.
2025-09-21 11:23:21 -04:00
DJ2LS 341383fafd
Merge pull request #1012 from DJ2LS/develop
Develop
2025-09-21 15:23:50 +02:00
DJ2LS a03b749e4e
Merge pull request #1010 from DJ2LS/ls-rigctld 2025-09-21 15:17:03 +02:00
DJ2LS b8f8f4438f
Merge branch 'develop' into ls-audio 2025-09-21 13:54:09 +02:00