User guide4 min read

SoundFont 2 (SF2) Basics & Web Preloading Architecture

Overview of SoundFont 2 (.sf2) binary sound banks, PCM samples, ADSR envelopes, and Web Worker background preloading & smart preset slicing.

1. What is SoundFont 2 (SF2)?

SoundFont 2 (.sf2) is an open industry-standard binary file format based on the RIFF specification. It acts as a digital instrument bank containing recorded audio waveforms (PCM samples) and synthesis parameters used by software synthesizers to play MIDI music files.

Core Components of an SF2 Sound Bank

Audio Data
PCM Waveform Samples

Raw recorded digital audio samples of acoustic and electronic instruments (e.g. Grand Piano, Bass, Guitars, Drums, Brass).

Pitch Mapping
Keyzones & Velocity Layers

Maps recorded audio samples across the 88 piano keys and different keypress velocity levels (soft to loud notes).

Synthesis Engine
ADSR Envelopes & Presets

Defines Attack, Decay, Sustain, Release times, LFO filters, and assigns instruments to General MIDI program numbers (0-127).

2. SF2 Preloading & Smart Preset Slicing Architecture

Full SoundFont 2 files often range from 100MB to over 1GB. Loading an entire 500MB file into main browser memory at once causes UI freezing and excessive RAM consumption. Next Karaoke solves this using a 2-tier preloading and extraction strategy:

Preloading & Slicing Workflow

  1. 1
    1. Background Web Worker Offloading: Entire SF2 binary parsing, RIFF chunk indexing, and sample extraction tasks run in a separate Background Web Worker thread, keeping the main UI responsive at 60 FPS.
  2. 2
    2. Smart Preset Slicing (On-Demand Extraction): When a song loads, the system inspects the MIDI file to identify ONLY the instrument programs actually played in that song. The Worker extracts only those required preset samples using binary file slicing (Blob.slice()).
  3. 3
    3. Transient & Persistent Caching (IndexedDB / Cache Storage): Extracted instrument packages are stored in browser memory and local persistent storage (IndexedDB / Cache Storage). Subsequent songs using the same instruments load instantly without re-downloading or re-parsing.