Commit Graph

10 Commits

Author SHA1 Message Date
tyler ac262505c1 feat: headless PNG render, mLnL annotations, and per-frame sched offset
Commit the accumulated working-tree changes as one snapshot.

- Headless render: `--render OUT.png INPUT.wav` draws the spectrogram
  (full window, or `--pane` for the spectrogram pane only) to a PNG
  with no visible window. Options: `--annotations`/`--no-annotations`,
  `--annotation-opacity`, `--width`/`--height`.
- mLnL annotations: parse the optional `mLnL` RIFF chunk (schema v2)
  and render tx_frame/assertion/control overlays, a timeline lane, and
  a waveform-scope echo, with hover tooltips on the spectrogram,
  timeline, and scope.
- sched_offset_ms: parse the per-frame intent->air latency and surface
  it in the hover tooltips (boxes stay air-anchored upstream).
- Supporting: build wiring (rspektrum.make), shared types/headers,
  web-build and capture-script tweaks, and removal of the old
  synchrosqueezing LaTeX doc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-29 12:19:37 -07:00
tyler e8ed19d338 feat: spectrum-slice (PSD) panel + two-point marker/ruler tool
Spectrum slice (S): floating panel plotting the time-averaged power
spectrum of the current selection (or the visible view when there's no
selection). Frequency on X over the region's band, auto-ranged dB on Y,
with a peak marker. Backed by ComputePowerSpectrum() in stft.c (mean
linear power per bin over the time span). The selection stat panel now
biases to the left when this panel is up so the two don't overlap.

Marker/ruler tool (M): press-drag-release drops point A and B; the
overlay shows crosshairs, a connecting line, and a readout of the
ham-useful deltas — Δt, Δf, tone spacing (1/Δt), and drift (Δf/Δt).
Marker mode swaps the LMB-drag gesture from box-select to marker drop
(Alt/middle still pan); RMB/Esc clear the measurement. Markers reset on
new-file load alongside the selection.

Both are gated toggles (off by default), wired into the keymap (so they
self-document in the About dialog) and the sidebar.

Verified headlessly: idle viewport pixel-identical to baseline (AE=0,
deterministic); both panels render correctly with sensible numbers.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 10:53:57 -07:00
tyler ee9eac786c feat: live cursor readout (time / frequency / STFT level)
Floating tag follows the pointer over the spectrogram showing the time,
frequency, and STFT magnitude (dB) under the cursor — the standard
spectrum-analyzer probe. Suppressed while selecting/panning (which have
their own readout) and when a modal is open.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 10:29:36 -07:00
tyler 26afc4b30e feat: frequency-aware selection stats (peak/center freq, occupied BW, SNR)
The selection readout was time-domain only — Energy/Peak/RMS/PAPR computed
from the whole-bandwidth waveform in the time span, ignoring the box's
frequency bounds entirely. The 2D box only measured one axis.

Add ComputeSpectralStats (stft.c): measures the boxed band from the STFT
magnitude (not the synchrosqueezed display buffer, which relocates energy)
and reports peak frequency, power-weighted centroid ("power center"),
occupied bandwidth (in-band span >3 dB over a median noise floor — robust
for both tones and noise-like bursts), and in-band SNR.

Also fold the two near-identical stats-panel blocks in render.c into one
DrawStatPanel + BuildSelectionStatLines helper so the live-drag and
committed-selection readouts can't drift.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 10:26:37 -07:00
tyler f91cae77e8 refactor: group viewport/zoom/pan state into a Viewport sub-struct
The visible-window + pan-anchor state was 10 flat fields (viewStart, viewEnd,
freqView*, pan*) used densely throughout the zoom/pan/scrollbar code. Group
them into a Viewport sub-struct (app.view.*).

Rename anchored strictly to 'app.' so ScopeView's own view->viewStart/viewEnd
(same field names) are untouched. Settled render verified pixel-identical
(AE=0); End/zoom path verified via injected key input.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 09:17:26 -07:00
tyler 8e4250ae63 refactor: group selection state into a Selection sub-struct + ClearSelection()
The box-selection state was 11 fields spread across three comment blocks
(time sel, freq sel, drag state). Consolidate them into one Selection
sub-struct (app.sel.*) and extract the 4-line 'clear to full range' block —
duplicated in 5 places — into a ClearSelection() helper.

Pure mechanical rename (anchored to app./spa-> so the ScopeView fields of the
same name are untouched) + behavior-identical dedup. Fully-settled render
verified pixel-identical (AE=0).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 09:15:50 -07:00
tyler 7240cf8ecf refactor: modal-gate helper + data-driven colormap table
Two extensibility easy-wins, both behavior-preserving:

- UiModalOpen() centralizes the "an overlay owns input" check that was
  copy-pasted as `!showFileBrowser && !showAbout` across 6 input gates.
  New overlays now update one place.
- Colormaps become a COLORMAPS[] table (name + function) indexed by enum.
  GetColormapColor and the sidebar both read it, so adding a colormap is
  one enum value + one Cmap* fn + one row — and the sidebar name can no
  longer drift from the enum (deleted the parallel colormapNames[] array).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:53:55 -07:00
tyler 3863ab8620 feat: dB scale modes (relative/absolute dBFS), about dialog, fix white-out
dB floor handling:
- Fix the white-out/inversion when the floor was cranked up: guard the
  (ceiling - floor) range in ColorizeSpectrogram so floor >= ceiling
  degrades to a hard threshold instead of dividing by ~0 (white) or a
  negative (inverted colors).
- Add two amplitude scale modes, toggled in the sidebar:
  * Relative: ceiling tracks the signal peak, floor sits N dB below it
    (slider = dynamic range, 10..100 dB). Floor can't cross the ceiling.
  * Absolute: fixed dBFS scale (0 dBFS = full scale), slider sets an
    absolute floor in dBFS. Brightness reflects real level.
  Mode + both slider values persist across loads. This replaces the
  amplitudeUserSet flag — storing the intent (range / absolute floor)
  preserves it across re-scales structurally.

About / Help dialog (no help menu existed):
- F1 or sidebar button; documents the scale modes and the caveats
  (dBFS not dBm — a WAV has no power reference; ~6 dB Hann window
  offset; pixels are reassigned energy, not raw bins) plus key list.
- Modal: underlying spectrogram input is gated while open; open/close
  handled in the main loop so the opening click can't self-close it and
  a dismissing click can't fall through into a selection.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:43:02 -07:00
tyler ddbbe2734c perf+ux: cache reassignment, keep manual dB floor, dedupe load paths
- Split GenerateSpectrogramTexture into ComputeSpectrogramReassignment
  (the expensive synchrosqueezing, cached in app.reassignBuffer) and
  ColorizeSpectrogram (cheap). dB-floor and colormap changes now only
  re-colorize instead of recomputing the whole reassignment every frame —
  the dB slider and colormap switching are smooth on large files.
- AutoScaleAmplitude no longer overwrites a dB floor the user set by hand
  (amplitudeUserSet flag, reset per file load).
- Extract ResetForNewSignal() used by all three load paths; removes the
  duplicated reset blocks and the double ComputeSTFTInit per load. Drag-drop
  now resets the selection like the browser already did.
- Remove the dead lastInteractedFrame field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:26:51 -07:00
tyler 3a8f20b783 refactor: split spectrogram.c into per-concern modules
spectrogram.c was ~2950 lines holding everything. Break it into cohesive
translation units; spectrogram.c keeps only globals + the main frame loop.

New modules:
- spectrogram_types.h  shared types, constants, extern globals, inline math
- fft.c/.h             FFT, bit-reverse, twiddle (standalone, no app deps)
- stft.c/.h            STFT compute, adaptive resolution, FFT-size LRU cache
- audio.c/.h           WAV/ffmpeg load, FreeSignal, bandpass, playback
- render.c/.h          UI scaling, colormaps, texture gen, on-screen drawing
- ui.c/.h              file browser, sidebar, sliders, PNG export

Also:
- utils.c now includes utils.h instead of re-typedef'ing AudioSignal/
  SignalStats (they had to be hand-synced before).
- Remove dead code: ApplyHannWindow and ComputeSTFTHighResRange were never
  called (the live high-res path is ComputeNextHighResChunk).
- Delete the unused raylib-template main.c.
- rspektrum.make: build the new units. premake5.lua: glob src/**.c so a
  future regen stays correct.

Pure code movement otherwise; no behavior change. Builds clean (-Wshadow).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:15:51 -07:00