Files
SonicForgeStudio/fx_chain_architecture.md

5.2 KiB

TECHNICAL SPECIFICATION: AUDIO FX PROCESSING PIPELINE

This document describes the Digital Signal Processing (DSP) architecture within the Audio Engine, tracing the complete path from raw sound sources (MIDI, Audio Clips) through insert FX chains to hardware outputs and offline rendering.


1. SIGNAL FLOW TOPOLOGY

Audio processing executes sequentially (or via a Directed Acyclic Graph - DAG) in fixed-size sample buffers (e.g., 512 samples/block).

[ SOUND SOURCES ON TRACK ]
  ├── MIDI Item   --> [ VSTi / Soundfont ] --(Rendered Audio)--> Audio Buffer
  └── Audio Clip  -------------------------------------------> Audio Buffer
                                                                  │
                                                                  ▼
[ TRACK FX CHAIN ] <---------------- (Managed via Modal UI)       │
  ├── Slot 1: Custom FX (In-house DSP)                            │
  ├── Slot 2: VST FX (e.g., FabFilter, Waves)                     │
  └── Slot n: VST FX (e.g., iZotope Ozone)                        │
                                                                  │
[ AUDIO MIXER / SUMMING BUS ] <-----------------------------------+ (Summed from all tracks)
  │ (Linear Signal Summing)
  ▼
[ MASTER FX CHAIN ]
  ├── Slot 1: VST EQ / Compressor (Mastering)
  └── Slot n: VST Limiter (Peak Limiting / Output Optimization)
  │
  ▼
[ MAIN OUT (FINAL DISTRIBUTION) ]
  ├── 1. Realtime Preview (Direct Hardware Output via ASIO/WASAPI/WebAudio)
  └── 2. Offline Export   (Rendered to .WAV, .MP3, .OGG)


2. COMPONENT DEEP DIVE

Step 1: Sound Sources

Every track hosts source items (Clips/Regions). Prior to entering the FX Chain, source data is converted into a normalized 32-bit or 64-bit floating-point Audio Buffer ([-1.0, +1.0]).

  • Audio Clip: Raw audio data (WAV, MP3) is read from disk or memory, decoded, and buffered directly to the track's audio buffer.
  • MIDI Item: MIDI events (Note On, Note Off, Pitch Bend) are read in real time and routed to a Virtual Instrument (VSTi or SoundFont player). The synthesizer processes these events, renders audio samples, and writes them directly to the track buffer.

Step 2: Track FX Chain

Performs isolated signal processing on individual tracks.

  • UI Layer: Exposed via a dedicated FX Rack Modal on each track. Users can insert, remove, bypass, and reorder processing slots.

  • Engine Architecture: Supports two parallel plugin formats:

  • Custom FX: Built-in DSP algorithms compiled into the core engine (C++, WebAssembly, or DSP Scripting).

  • 3rd-Party VST/VST3 Plugins: External commercial processors (e.g., FabFilter, Waves, iZotope). Communication occurs via the VST SDK or a dedicated process bridge using Shared Memory (SHM).

  • Serial Processing Pipeline: Track audio buffers pass sequentially from Slot 1 through Slot n. Each slot modifies the memory buffer in place before passing it to the subsequent plugin:

Buffer_{\text{out}} = Plugin_n(Plugin_{n-1}(...Plugin_1(Buffer_{\text{in}})...))

Step 3: Summing & Master FX Chain

Once tracks complete their individual Track FX processing, their outputs route to the main mixer:

  • Signal Summing: Audio buffers from Track 1 through Track N are summed linearly—applying track volume gain scaling and constant-power pan laws—into a unified stereo Master Audio Buffer:
Buffer_{\text{Master}}(t) = \sum_{i=1}^{N} Gain_i \cdot Pan_i(Buffer_i(t))
  • Master FX Chain: The summed Master Buffer passes through global insert slots. Operates identical to the Track FX Chain, targeting master bus processing (e.g., Master Bus EQ, Multiband Compression, and Brickwall Limiting) to ensure target loudness compliance without digital clipping.

Step 4: Main Output & Final Routing

Exiting the Master FX Chain, the engine directs the stereo buffer based on execution mode:

  • Realtime Preview Mode:

  • Audio buffers stream in fixed blocks (e.g., 256/512 samples) to low-latency driver APIs (ASIO, WASAPI, CoreAudio, or WebAudio).

  • Enables zero-latency parameter updates as users adjust UI controls.

  • Offline Export Mode (Bouncing):

  • Bypasses realtime driver clocking to process buffers at maximum CPU speed.

  • Writes output buffers sequentially into audio encoders using libraries such as libsndfile (WAV), LAME (MP3), or libvorbis (OGG).


3. STATE & LIFECYCLE MANAGEMENT

  • Thread Safety (Zero-Allocation Audio Thread): Plugin parameters and structural chain updates originate on the UI Thread. The real-time Audio Thread communicates via lock-free SPSC queues or spinlocks to avoid audio dropouts (glitches) caused by thread contention or heap allocations (malloc).
  • State Persistence: Parameters across all Custom FX and VST FX are serialized into JSON or Base64 binary chunks and saved within the main DAW project file.
  • Plugin Delay Compensation (PDC): Lookahead processors and complex plugins introduce execution latency. The engine queries each plugin's latency (getLatencySamples()), calculates the cumulative delay along each track path, and delays shorter paths accordingly so all tracks sum in sample-accurate phase alignment.