Skip to content

refactor: decomposition and tests - #42

Open
Horuse wants to merge 7 commits into
mainfrom
refactor/decomposition-and-tests
Open

refactor: decomposition and tests#42
Horuse wants to merge 7 commits into
mainfrom
refactor/decomposition-and-tests

Conversation

@Horuse

@Horuse Horuse commented Sep 10, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

  1. Decomposes monolithic files into focused submodules:

    • src-tauri/src/audio/pipeline/dag.rs (2,030 lines) -> src-tauri/src/audio/pipeline/dag/{staging, nodes, graph, builder, mod}.rs.
    • src-tauri/src/audio/graph.rs (1,493 lines) -> src-tauri/src/audio/graph/{types, validate, tests, mod}.rs.
    • src-tauri/src/audio/effects/mod.rs (1,094 lines) -> src-tauri/src/audio/effects/{controls, registry, instantiate, mod}.rs.
    • src-tauri/src/commands.rs (870 lines) -> src-tauri/src/commands/{pipeline, devices, apps, plugins, virtual_devices, network, updater, audio_files, debug, helpers, mod}.rs.
  2. Deduplicates cross-platform boilerplate:

    • Audio device name disambiguation (unique_named) unified in src-tauri/src/audio/device/mod.rs.
    • App icon caching unified in src-tauri/src/audio/system_audio/mod.rs.
    • Extracted shared CPAL speaker stream resolution and handle management to src-tauri/src/audio/pipeline/output/cpal_speaker.rs.
    • Extracted shared CPAL input stream management to src-tauri/src/audio/pipeline/input/cpal_input.rs.
  3. Fixes Graphic EQ Phase Cancellation DSP bug:

    • Replaced the 9-stage Linkwitz-Riley crossover ladder with 10 cascaded 2nd-order peaking biquads (Audio EQ Cookbook).
    • Invariant verified: at 0 dB gain across all bands, magnitude response is identically flat ($\pm 0.05\text{ dB}$, bit-exact identity) with zero phase cancellation.
    • Reduced per-frame biquad processing from 72 to 20 passes in stereo (3.6x speedup).
  4. Comprehensive Audio Quality & Invariant Test Suite:

    • Added 62 automated integration tests in src-tauri/tests/ (audio_quality.rs, boundary_and_precision.rs, pipeline_scenarios.rs) covering bit-exact bypass, runtime parameter updates, resampler transparency, limiter brickwall ceilings, compressor release ballistics, declicker impulse suppression, and multi-node pipeline simulations.
    • Added global bun run test script running cargo test suite with --test-threads=1 to prevent concurrent native plugin loading crashes.
  5. Architectural & Design Documentation:

    • Documented universal constraints and limits in docs/RULES.md.
    • Documented practical hardware-instrument UI aesthetic rules in docs/UI.md.

Why is this the right approach?

  • Maintainability & Modularity: Core files previously exceeded 1,000–2,000 lines, mixing AST validation, DSP processing, state ring management, and IPC commands in single files. Splitting them into bounded single-responsibility modules makes code easier to navigate and maintain without touching runtime semantics.
  • Deduplication without abstraction overhead: CPAL input and output stream orchestration across Linux, macOS, and Windows was duplicated with subtle differences. Moving shared mechanics to cpal_speaker.rs and cpal_input.rs preserves platform-specific device logic while eliminating redundant code.
  • Audio Integrity: Crossover ladders inherently produce asymmetric phase shifts when band slices are recombined, causing phase cancellation and frequency dips even when bands are set to 0 dB. Cascaded peaking biquads are the industry standard in DAWs and hardware racks: when $A = 1$ (0 dB), the numerator and denominator polynomials match, yielding a mathematically transparent identity filter with $0^\circ$ phase shift and $0\text{ dB}$ attenuation.

Checklist

  • Diff is limited to the change — no unrelated edits
  • bun run check passes
  • cargo check --manifest-path src-tauri/Cargo.toml passes
  • bun run format leaves the tree clean
  • Generated TS types are committed with the Rust change (if any)
  • No new dependency without a reason in the PR description
  • I read the RT audio path section of docs/CONCEPT.md and confirmed this change adds no allocations, locks, or syscalls to cpal / SCK callbacks or DspWorker::run

Platform coverage

  • Developed on: macOS (Apple Silicon)
  • Tested on: macOS — all 192 tests passing via bun run test (130 unit tests, 29 audio quality tests, 21 boundary and precision tests, 12 pipeline scenarios)
  • What I did to test: Ran cargo check, bun run check, bun run generate, and full integration test suite verifying DSP algorithms, gain scaling, resamplers, pipeline routing, and EQ flatness.
  • Not tested: Linux / Windows hardware runtimes (PipeWire / WASAPI live streams)

Touches src-tauri/src/audio/pipeline/output/cpal_speaker.rs and src-tauri/src/audio/pipeline/input/cpal_input.rs which unify shared stream setup for macOS, Linux, and Windows CPAL backends.

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