Skip to content

feat(audio): add FFT signal-path diagnostics (slice 3)#56

Merged
vxcozy merged 1 commit into
mainfrom
fix/viz-audio-sync
Apr 18, 2026
Merged

feat(audio): add FFT signal-path diagnostics (slice 3)#56
vxcozy merged 1 commit into
mainfrom
fix/viz-audio-sync

Conversation

@vxcozy
Copy link
Copy Markdown
Owner

@vxcozy vxcozy commented Apr 18, 2026

Summary

Slice 3 diagnostics for the braille-visualisers-don't-react-to-music bug (CLI-88 / clitunes-of7). Instrumentation only — no root-cause fix yet.

  • tracing::trace! in the TUI render loop, once per ~60 frames, gated behind RUST_LOG=clitunes::audio=trace. Reports frames_read from the SPMC consumer, peak windowed sample, peak FFT magnitude, and negotiated sample rate.
  • Regression test on FftTap::snapshot_from proving a known sinusoid preserves amplitude (within 5% of the Hann-windowed peak) and that the FFT magnitude peaks at the input frequency bin.

Why

The user reports braille visualisers don't visibly react to Spotify playback. Two candidate failure modes:

  1. FFT tap is silent on the Spotify path (PCM never reaches the SPMC ring the TUI client consumes).
  2. FFT tap has signal but per-viz sample-reading clamps the motion out of visibility.

Walking the code path the plumbing looks sound — SpotifySource::run pulls frames off the librespot sink and calls TeeWriter::write, which fans out to both the cpal output ring AND the SPMC producer the TUI opens via PcmTap. Radio uses the same TeeWriter, and the user has confirmed radio visualisers work — so a silent SPMC path on Spotify would be a surprising regression.

Highest-confidence hypothesis (pending live-Spotify trace): signal is present on the SPMC ring but the per-viz clamps are tuned hot enough that only loud transients register at reasonable playback volumes. The snapshot_from test now pins the invariant that the FFT tap itself is not dropping signal, so if live traces show non-zero peak_sample we know the fix belongs in the visualiser layer (slice 2 territory, handled in parallel).

Leaving CLI-88 / clitunes-of7 open until the live trace lands.

Test plan

  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace --all-features (all green, including the new snapshot_from_preserves_sine_amplitude_and_peaks_at_frequency)
  • Run RUST_LOG=clitunes::audio=trace cargo run -p clitunes against Spotify playback, confirm peak_sample and peak_mag are non-zero once a track starts, and file the follow-up fix based on what the numbers say.

Slice 3 instrumentation for the braille-visualisers-don't-react bug.
Adds a per-~60-frame `trace!` in the TUI render loop, gated behind
`RUST_LOG=clitunes::audio=trace`, that reports frames read from the
SPMC consumer, peak windowed sample, and peak FFT magnitude. This
isolates whether the signal is lost upstream (empty ring on the
Spotify path) or downstream (visualiser clamp math).

Also adds a `snapshot_from` regression test that proves a known-
amplitude sinusoid survives the Hann-windowed FFT tap: windowed peak
tracks input amplitude within 5%, and the magnitude peaks at the
input frequency bin. If this test ever fails, the break is inside
the tap and the diagnostic traces can be skipped.

Refs clitunes-of7 / CLI-88 (left open pending live-Spotify trace).
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vxcozy vxcozy merged commit ddecec9 into main Apr 18, 2026
12 checks passed
@vxcozy vxcozy deleted the fix/viz-audio-sync branch April 18, 2026 17:06
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.

1 participant