Commit Graph

140 Commits

Author SHA1 Message Date
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 ab7a6bc71c ux: drop redundant 'Reset Sel' button; full-width 'Clear Selection'
Reset Sel advertised an 'R' key that was never bound and only set the
selection to the current view, overlapping Clear/Esc. Removed it and made
Clear a single full-width button labelled to match the Esc shortcut.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 09:06:14 -07:00
tyler 99c7d43637 refactor: table-driven keymap dispatch + auto-derived help list
Replace the global key handling scattered through the main loop with a single
KEYMAP table (key, gate, action, help text) and a DispatchKeymap() pass. The
About/Help overlay now renders its key list straight from the table, so the
on-screen shortcuts can never drift from the actual bindings.

- Order-sensitive keys (Space, Esc) stay inline where their frame ordering
  matters; they carry action==NULL and appear in the table for the help list.
- Adds the F11 fullscreen binding the sidebar button already advertised but
  that was never actually wired up.
- Fix About title em-dash rendering as '?' (font is ASCII-only); use a hyphen.

Launch render verified pixel-identical (AE=0); keys verified via injected input.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 09:05:37 -07:00
tyler 53f7fa6047 refactor: extract Clicked() + DrawPanelBox() sidebar widget helpers
Collapse the repeated 'CheckCollisionPointRec + IsMouseButtonPressed' click
test and the 'DrawRectangleRec + DrawRectangleLinesEx' panel chrome into two
helpers used across the sidebar buttons. Pure readability; render output is
pixel-identical (verified AE=0 vs baseline).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 08:59:08 -07:00
tyler c75e014b88 ui: stop the scope label colliding with the time-axis labels
The "Waveform (Time/Amplitude)" label was drawn in the same ~30px band as
the time-axis labels and the horizontal scrollbar, so it overlapped the
"0.0s / 7.7s / ..." ticks. Shorten to "Waveform" and tuck it faded inside
the scope's top-left, clear of that band.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 02:07:53 -07:00
tyler dd0ad9506a refactor: centralize screen layout in ComputeLayout()
The spectrogram layout metrics (sidebar width, margins, freq-label width,
scrollbar sizes, spectroHeight, viewBounds) were computed with identical
formulas in three places — the input, selection, and render passes — so a
layout tweak meant editing all three in sync (as the scope divider change
just did). Introduce a Layout struct + ComputeLayout(); each site now
unpacks from it into its existing locals, leaving every downstream
coordinate reference untouched. Verified pixel-identical to the previous
build (ImageMagick AE = 0).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 02:05:19 -07:00
tyler 487e3ad85b refactor: extract shared ComputeSegment for STFT passes
ComputeSTFTIncremental (overview, skipFactor-strided) and
ComputeNextHighResChunk (high-res fill) had ~50 lines of identical
per-segment code (windowing, FFT, bin fill for both the normal and
derivative spectra). Extract it into ComputeSegment() with a reusable
SegScratch buffer set (allocated once per pass, no per-segment malloc).
Each caller keeps only its own skip logic. Behavior-preserving — verified
the rendered spectrogram is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 02:02:46 -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 c4d1d096ad feat: scope toggle collapses the divider; drag handle to show/hide
Toggling the scope off (P) now drops the divider to the bottom so the
spectrogram fills the whole view, instead of leaving an empty gap. The
divider handle is always drawn and grabbable: drag it up from the bottom
to bring the scope back, or drag it down past ~88% to hide it. Layout uses
an effective-divider helper (1.0 when hidden) so all three layout sites
stay in sync.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:51:03 -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
tyler ebe35bcd95 fix: plug memory leaks on file reload and texture regen
Three leaks, all at the relevant choke points:

- ComputeSTFTInit reallocated result->segments without freeing the old
  array, and runs twice per load (load site + loadingPhase 0), so every
  file load leaked the STFT. Free the previous result at the top.
- LoadWavFile malloc'd signal->samples without freeing the previous
  buffer; free it just before the alloc (after all failure returns, so a
  failed load never frees the existing signal).
- GenerateSpectrogramTexture overwrote *image with a fresh GenImageColor
  without unloading the old one — leaked an image buffer on every reload
  and every dB-floor/colormap regen. Unload first (NULL-safe on first use).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:04:05 -07:00
tyler ec5f77f6ef feat: cache STFT results per FFT size, fix load segfault
Add an LRU cache (4 entries) of fully-computed STFT results keyed by FFT
size, so toggling FFT size restores a cached result instead of recomputing.

Fix the segfault that hit right after the loading screen for files long
enough to use a skipFactor > 1 overview: SaveToCache() deep-copied every
segment using segment[0].numBins and memcpy'd from each segment's spectrum,
but a sparse overview leaves most segments with spectrum == NULL, so it
memcpy'd from NULL.

- Add IsSTFTComplete() / CopySTFT() helpers; CopySTFT copies sparse
  segments as NULL instead of dereferencing them.
- Only cache complete (full-resolution) results; never the sparse overview.
- Make a cache hit actually skip recomputation (and stop leaking): restore
  the cached result, mark it finished, and rebuild the texture. On a miss,
  free the current STFT before recomputing.
- Drop the per-frame re-save that ran every frame while zoomed in.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 01:00:46 -07:00
tyler 475520b1db feat: add background high-res STFT computation with idle detection
After initial overview loads, compute full-res segments in the background
while the user is idle (200 segments/frame, pauses on any interaction).
Foreground high-res computes zoomed-in segments immediately for
responsiveness. Computed segments persist — zooming out never recomputes.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-05-25 00:00:07 -07:00
tyler 0e72bf4172 feat: add waveform scope view with resizable divider
- Create primitives.h/c for waveform visualization (time/amplitude display)
- Scope view draws signal as per-pixel min/max envelope (Audacity-style)
- Add draggable divider between spectrogram and scope (30%-80% range)
- Fix selection bounds to use correct spectrogram area (not full viewport)
- Scope syncs with spectrogram zoom/pan for aligned time axis
2026-05-24 23:35:17 -07:00
tyler cc58965acc feat: add signal stats panel for selection region
Display Duration, Energy, Peak amplitude, RMS amplitude, and PAPR for
the current time/frequency selection. The stats box:
- Appears next to the selection box (right side, or left if not enough room)
- Centers vertically on the selection box
- Uses a semi-transparent dark background with yellow border
- Updates live while dragging the selection
- Computed in utils.c with ComputeSignalStats()
2026-05-24 22:49:44 -07:00
tyler 0c64202670 feat: add playhead indicator during audio playback
Add a red vertical line that tracks playback position within the
selected region. The playhead shows the current position in the
spectrogram as audio plays, making it easy to see what part of
the signal is currently being heard.

- playheadT tracks 0-1 normalized position in the selection
- Red line drawn across the spectrogram viewport while playing
- Semi-transparent red highlight behind the line for visibility
- Reset playhead to 0 when playback stops or is stopped
2026-05-24 22:32:48 -07:00
tyler 78cd21c957 fix: dynamic frequency labels and fix frequency clamping crash
- Frequency tick/label intervals now adapt to zoom level instead of
  always showing 0–Nyquist (5Hz → 10kHz depending on zoom)
- Labels use coarser spacing than ticks to avoid clutter
- Fix segfault when zooming out past signal bounds by properly clamping
  freqViewStart/freqViewEnd to [0,1] with correct width preservation
  in zoom, pan, and scrollbar drag
- Fix firstTick calculation that was off-by-one
2026-05-24 22:14:17 -07:00
tyler 1cbba956b8 feat: add PNG export for spectrogram image
Add Export PNG button and keyboard shortcut (E) to export the
spectrogramImage as a PNG file. Supports:
  - Cropping to the current time/frequency selection region
  - Optional upscaling via the export scale slider (0.0x to 10.0x)
  - Exporting the full unscaled image when no selection and scale is 0

Exports to the app's working directory via raylib's ExportImage.
Export status shown as a brief toast notification.

Known issues:
  - Frequency scale doesn't adjust properly when zooming (freqView
    clamps to [0,1] range but zoom factor isn't frequency-aware)
  - Hardcoded export filenames; no filename/path picker yet
2026-05-24 21:28:30 -07:00
tyler c03d236230 feat: implement adaptive-resolution STFT with on-demand high-res computation
For long signals (>60s), initial load computes every Nth segment at
reduced resolution for a fast overview. Full resolution is computed on
demand as the user zooms into specific regions, starting at the current
viewport and computing 50 segments at a time.

Key changes:
- Add skipFactor and highResFinished fields to SpectrogramApp
- ComputeSTFTInit uses calloc to NULL-initialize segments
- ComputeSTFTIncremental skips non-aligned segments (skipFactor stride)
- ComputeSTFTHighResRange computes full-res for a range [start, end)
- GenerateSpectrogramTexture skips NULL segments for normalization
- Zoom trigger computes high-res only for the visible viewport range,
  50 segments at a time, staying within viewStart..viewEnd
- No initial high-res block — only fills on-demand as user explores
2026-05-15 09:41:41 -07:00
tyler b6942d8577 Refactor: extract platform abstraction for subprocess spawning
Move all Unix-specific syscalls (fork, execvp, waitpid, strerror, /tmp)
into a platform layer so the same spectrogram.c can target Windows
(CreateProcess) and WebAssembly (stubs). Key changes:

- src/platform.h: public API with spawn handle, error codes, path helpers
- src/platform_linux.c: fork/execvp implementation, /tmp, strerror
- src/platform_win32.c: CreateProcess implementation, temp dir lookup
- src/platform_web.c: stub implementations (no subprocess support on web)
- src/spectrogram.c: consume only platform.h; replace pid_t/fork/execvp
  with Platform_SpawnChild/WaitForChild; use Platform_GetTempDir() for
  /tmp path; replace strdup with malloc/memcpy for portability
- Build: add platform_*.c to gmake, Premake, and build_web.sh
2026-05-14 18:16:21 -07:00
tyler e42554e6fd Enable raylib 6 HiDPI/HighDPI support for proper font and UI scaling
Add FLAG_WINDOW_HIGHDPI to enable raylib's automatic framebuffer
scaling on HiDPI displays. Layout coordinates use logical screen size
only, so UI stays proportional to window size while text and graphics
render at full framebuffer resolution for crisp output on any monitor.

Also fix hardcoded pixel offsets in selection bounds rectangle to use
selScale consistently.
2026-05-14 17:01:15 -07:00
tyler 4331d010e5 Add incremental loading progress, auto-scaled amplitude, DPI-aware TTF fonts, and better file browser scaling
- Add incremental STFT processing with loading overlay and progress bar
- Add auto-scaling amplitude (max dB, max-40dB floor) for low-signal files
- Replace fixed bitmap text with TTF font scaled by window size for crisp rendering at any resolution
- Fix command-line file path resolution relative to original working directory
- Scale file browser dialog dimensions by GetUIScale() to prevent text overlap
- Disable ESC key closing the window
- Fix FFT size changes to restart STFT computation
2026-05-14 16:01:22 -07:00
tyler 9d0008ac2c Add FLAG_WINDOW_RESIZABLE, fullscreen button, and proportional UI scaling
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-15 15:40:17 -07:00
tyler da37cecb59 Add web build support with custom shell HTML
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-12 21:28:18 -07:00
tyler ecbbba36db Fix layout: proper spacing for labels and scrollbars, remove axis title text
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-11 22:15:25 -07:00
tyler b4c23d61a8 Add frequency zoom, scrollbars, dynamic layout that fills window
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-11 21:49:26 -07:00
tyler c0044c37da Simplify UI: fixed FFT 128 with synchrosqueezing always on, removed FFT slider and SQ checkbox
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-11 00:09:54 -07:00
tyler d11546d282 Fix synchrosqueezing: correct complex division sign and add noise threshold
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-10 23:44:37 -07:00
tyler 0bc30832be Implement synchrosqueezing transform for sharp spectrogram display
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-10 23:27:56 -07:00
tyler 5b2d8ddb33 Suppress INFO texture logs
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-04 21:21:18 -07:00
tyler b3eb2ea991 Fix playback auto-reset, add ffmpeg conversion, fix file browser Open button click
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-30 21:38:32 -07:00
tyler 5e7841fa76 Fix sidebar layout: sidebar on left (320px), spectrogram on right. SPACE toggles play/stop. dB floor triggers immediate redraw.
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-30 21:07:47 -07:00
tyler 87183cbe7d Add sidebar UI with sliders, buttons, checkboxes. ESC clears selections instead of exiting
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-30 20:05:57 -07:00
tyler bbd476c389 Remove reassignment code - back to standard spectrogram
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-30 19:40:20 -07:00
tyler c00c665226 Implement reassignment method for sharp time-frequency localization
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 23:25:47 -07:00
tyler bca898516b Add configurable FFT size (512-8192), 75% overlap for smoother display
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 23:16:49 -07:00
tyler 10e7a68baa Fix zoom to cursor, trigger re-render on palette/dB changes, improve controls
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 23:10:16 -07:00
tyler 377ba3616a Fix texture caching, file browser segfault, and compiler warnings
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 22:42:22 -07:00
tyler 6355db4e03 Fix snprintf truncation warnings
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 22:29:12 -07:00
tyler 99ef486c5f Add file browser, zoom/pan controls, improved UI
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 22:06:13 -07:00
tyler c5234d5799 Add spectrogram viewer with FFT bandpass filter, file browser, zoom/pan controls
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-27 21:56:47 -07:00
Jeffery Myers b32f9edd5f use correct software define 2026-03-23 15:45:13 -07:00
Jeffery Myers cd3340ce57 build in the root, so that vscode can find the files 2026-02-25 13:54:12 -08:00
Jeffery Myers 4cf96e771f add info about software render target 2026-01-13 11:47:28 -08:00
Jeffery Myers 759d3ff61a better filters for game and app resources 2026-01-07 18:49:51 -08:00
Jeffery Myers 3f4dfdc483 remove exe from common launch commands and let each platform define it's own 2026-01-07 08:53:30 -08:00
Jeffery Myers c8e40f3845 Revise license section in README.md
Updated license information to reflect CC0 1.0.
2026-01-06 16:34:47 -08:00