Skip to content

Audio Analysis and DSP

davide108 edited this page Nov 23, 2026 · 1 revision

Audio Analysis & DSP Architecture

PulseDeck performs all audio indexing, DSP analysis, and dual-deck playback locally on your machine with zero cloud dependencies.


Background DSP Analysis Pipeline

Whenever new or modified tracks appear in watched folders (and Automatically Analyze New Tracks is enabled in Settings), AnalysisManager processes pending tracks sequentially in a dedicated Web Worker (analyzer.worker.ts) so the UI and audio playback stay smooth:

  1. Streaming & Decode: Fetches audio cleanly from main-process media://track/<id> (supporting HTTP 206 byte ranges) and decodes PCM via AudioContext.decodeAudioData.
  2. Mono Downmix & Resampling: Mixes multi-channel audio down to mono and resamples to 22,050 Hz using box-averaged pre-filtering when downsampling to suppress aliasing.
  3. 200-Bar Waveform Peaks: Computes peak amplitude across 200 slices normalized to [0..1], driving both the bottom PlayerBar scrubber and the Dual-Deck waveforms.
  4. Intro & Outro Silence Cues: Scans start and end RMS envelopes (25 ms windows) to mark smart introCueSec and outroCueSec boundaries so Auto-Mix avoids dead silence at track edges.
  5. Gated Loudness (ReplayGain) & Energy Score:
    • Computes integrated active loudness over 400 ms overlapping blocks with -60 dBFS absolute and -10 dB relative gating.
    • Derives replaygainDb targeting -14 dBFS (clamped within -12 dB .. +12 dB).
    • Combines active loudness (72%) and short-window 25 ms transient dynamic punch (28%) into a 0..1 Energy score.
  6. BPM Detection: Uses spectral flux / onset strength with autocorrelation and comb-filter tempo refinement (preserving existing embedded BPM tags when already valid, unless re-analyzed).
  7. Musical Key & Camelot Wheel Mapping (1A–12B): Computes a 12-bin chromagram via in-place Radix-2 FFT across Hann-windowed frames and correlates pitch-class profiles against Krumhansl-Schmuckler major & minor templates (C through B), mapping the result to DJ Camelot notation (1A–12B).

All computed fields are persisted back to SQLite (library.db) and preserved across untouched rescans.


Dual-Deck Web Audio Signal Chain

Both Deck A and Deck B have dedicated Web Audio DSP chains inside DualDeckEngine.ts feeding a shared master bus:

  [ Deck A AudioBufferSourceNode ]                       [ Deck B AudioBufferSourceNode ]
                │                                                       │
                ▼                                                       ▼
      LowShelf EQ (250 Hz)                                    LowShelf EQ (250 Hz)
                │                                                       │
                ▼                                                       ▼
      Peaking EQ (1,000 Hz)                                   Peaking EQ (1,000 Hz)
                │                                                       │
                ▼                                                       ▼
     HighShelf EQ (4,000 Hz)                                 HighShelf EQ (4,000 Hz)
                │                                                       │
                ▼                                                       ▼
  Color Filter (LPF / Bypass / HPF)                       Color Filter (LPF / Bypass / HPF)
                │                                                       │
                ▼                                                       ▼
     ReplayGain Trim GainNode                                ReplayGain Trim GainNode
                │                                                       │
                ▼                                                       ▼
      Channel Volume GainNode                                 Channel Volume GainNode
                │                                                       │
                ▼                                                       ▼
       Crossfade GainNode                                      Crossfade GainNode
                └───────────────────────────┬───────────────────────────┘
                                            ▼
                                    Master GainNode
                                            │
                                            ▼
                           DynamicsCompressor Safety Limiter
                                            │
                                            ▼
                             AnalyserNode (Spectrum Visualizer)
                                            │
                                            ▼
                               AudioContext.destination

Engine Safeguards

  • Master Safety Limiter: Prevents clipping when two loud tracks overlap or EQ/filters are boosted; toggleable in Settings → Audio Output & DSP.
  • ReplayGain Normalization: Balances perceived volume across older and modern mastered tracks automatically; toggleable live during playback.
  • Click-Free Parameter Scheduling: Uses cancelAndHoldAtTime + smooth linearRampToValueAtTime / 64-point float curves to avoid audio pops on crossfades, manual seeks, EQ changes, and filter sweeps.
  • AudioBuffer Lifecycle Cleanup: Releases completed AudioBufferSourceNode instances and stale buffers immediately once a deck finishes or transitions.

Main-Process media:// Streaming Security

PulseDeck enforces Electron security hardening (contextIsolation: true, nodeIntegration: false, sandbox: true, webSecurity: true) and never exposes arbitrary filesystem paths to the renderer. Instead, a custom media:// protocol handles:

  • media://track/<id> — Validates the track ID in SQLite, restricts streaming strictly to active indexed audio files, sets accurate audio MIME types, and handles HTTP 206 Partial Content byte-range requests.
  • media://artwork/<filename> — Confines access strictly inside userData/artwork/ to block path traversal.

Clone this wiki locally