Skip to content

Fix macOS mic TX: platform-aware sample rate negotiation#642

Merged
ten9876 merged 8 commits into
aethersdr:mainfrom
boydsoftprez:fix/macos-mic-sample-rate
Apr 4, 2026
Merged

Fix macOS mic TX: platform-aware sample rate negotiation#642
ten9876 merged 8 commits into
aethersdr:mainfrom
boydsoftprez:fix/macos-mic-sample-rate

Conversation

@boydsoftprez

@boydsoftprez boydsoftprez commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • macOS mic TX was broken: built-in mic (mono-only) was rejected by the old macOS-only code path that only tried 48kHz and 24kHz stereo
  • Even after fixing format negotiation, Core Audio's internal resampler produces gravelly audio when asked for 24kHz (a non-standard rate it claims to support)
  • Unified the sample rate negotiation across all platforms into a single loop that tries stereo first, then mono, across 3 rates
  • macOS prefers 48kHz first (r8brain handles the clean 2:1 downsample), Linux/Windows prefer 24kHz first (avoids resampling)

Test plan

  • Mac built-in mic (mono 48kHz): raw capture WAV clean, post-resample WAV clean
  • On-air TX test with compression=none: clean audio confirmed on second receiver
  • On-air TX test with compression=opus: clean audio confirmed
  • Linux build: verify 24kHz-first ordering still works (no regression)
  • Windows build: verify no regression
  • USB mic on macOS: verify stereo 48kHz path works

🤖 Generated with Claude Code

boydsoftprez and others added 8 commits April 3, 2026 15:29
Three issues fixed:

1. VITA-49 Opus TX packets were zero-padded to 32-bit word alignment.
   FlexLib Opus packets are byte-centric — the 1-3 trailing zero bytes
   corrupted the radio's Opus decoder, causing distorted transmitted
   audio on all PC mic configurations.

2. Mono-only USB mic devices (e.g. Plantronics BT600) were rejected
   because format negotiation only tried stereo. Extended fallback:
   24k stereo → 48k stereo → 44.1k stereo → mono at 48k/44.1k/24k.

3. 48kHz→24kHz TX downsampling used naive 2:1 decimation (drop every
   other sample) with no anti-aliasing filter, causing aliasing.
   Replaced with r8brain polyphase resampler (already used for RX).

Co-Authored-By: JJ Boyd ~ boydsoftprez ~ KG4VCF <kg4vcf@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two MSVC-specific APIs missing from MinGW headers:

1. TCP_INFO_v0 and SIO_TCP_INFO (Windows 10 1703+ kernel RTT) are
   defined in MSVC's mstcpip.h but not MinGW's. Added manual
   struct/macro definitions guarded by #ifndef SIO_TCP_INFO.

2. _dupenv_s is MSVC-specific secure CRT. Replaced with standard
   std::getenv("APPDATA") for Thetis FFTW wisdom import path.

Co-Authored-By: JJ Boyd ~ boydsoftprez ~ KG4VCF <kg4vcf@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ethersdr#625)

The TunerApplet power and SWR gauges always showed 0 because meter data
comes from the TGXL's direct TCP connection (port 9010), not the radio's
VITA-49 meter stream. Three issues fixed:

1. TgxlConnection discarded all R responses (status poll replies) which
   contain fwd= and swr= fields. Now parses R response bodies as KV
   pairs and emits statusUpdated().

2. TunerModel had no fwd/swr fields. Now parses fwd (dBm→watts) and
   swr (return loss dB→ratio) from both stateUpdated and statusUpdated
   signals, emitting metersChanged() for the gauge.

3. Removed txMetersChanged→TunerApplet connection that was overwriting
   TGXL readings with exciter power values.

TGXL protocol: fwd is reported in dBm (watts = 10^(dBm/10)/1000),
swr is reported as negative return loss in dB
(rho = 10^(rl/20), SWR = (1+rho)/(1-rho)).

Fixes aethersdr#625

Co-Authored-By: JJ Boyd ~ boydsoftprez ~ KG4VCF <kg4vcf@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… ordering

macOS Core Audio claims to support 24kHz mic input via isFormatSupported()
but its internal resampler produces gravelly/distorted audio at that
non-standard rate. The previous code also had a macOS-only path that only
tried 48kHz and 24kHz stereo, failing entirely on the Mac built-in mic
(mono-only device).

Replace the platform-split negotiation with a unified loop that tries
stereo then mono across three rates. macOS prefers 48kHz first (letting
r8brain handle the clean 2:1 downsample to 24kHz), while Linux/Windows
prefer 24kHz first (avoiding resampling when possible).

Verified on-air: clean TX audio in both Opus and uncompressed modes
using Mac built-in mic (mono 48kHz capture → r8brain → 24kHz stereo).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ten9876

ten9876 commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

Claude here. Great follow-up to the Opus padding fix — unified sample rate negotiation across platforms is the right call. The macOS 24kHz Core Audio quirk is a nasty gotcha.

73, Jeremy KK7GWY & Claude (AI dev partner)

@ten9876 ten9876 enabled auto-merge (squash) April 4, 2026 03:44
auto-merge was automatically disabled April 4, 2026 03:46

Pull request was closed

@boydsoftprez boydsoftprez reopened this Apr 4, 2026
@ten9876 ten9876 merged commit acdce02 into aethersdr:main Apr 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants