Namespace NAudio.Sampler
Classes
- FileSfzSampleLoader
Loads SFZ samples from disk, resolving relative paths against a base directory and decoding each fully into memory. WAV is read directly; other formats (FLAC, Ogg-Vorbis, Opus, …) decode through
NAudio.SoundFile(libsndfile). If libsndfile is unavailable or the file cannot be decoded, the load fails gracefully (the region is skipped).
- SamplerEngine
The shared polyphonic sampler engine: a pool of NAudio.Sampler.SamplerVoices driven by MIDI, rendering 32-bit float stereo through the ISampleProvider pull model, with voice stealing, exclusive (choke) groups, sustain-pedal hold, per-channel controller state, and shared reverb/chorus send buses. Format-specific subclasses (SoundFontSampler, SfzSampler) only supply the regions a note should play; everything else lives here so both formats run through one engine.
- SfzSampler
A polyphonic software sampler that plays an SFZ instrument, rendering 32-bit float stereo through the ISampleProvider pull model. Built on the shared SamplerEngine, so it gets the same voice engine as SoundFontSampler (pitch, looping, DAHDSR envelope, resonant filter, pan, voice stealing, exclusive groups, reverb/chorus sends).
An SFZ file is a single instrument (no banks/programs), so every channel plays the same region set. Regions whose sample is missing are dropped at load time. Note-on selection (keyswitches, round-robin, random layers, CC gating) and the Tier-1 opcode coverage are applied by the engine and NAudio.Sampler.SfzRegionProjector.
- SingleSampleInstrument
The "drop a sample on the keyboard" instrument: a single audio buffer (a loaded WAV or a recorded snippet) auto-mapped across the keyboard at a chosen root key, with editable start/end and loop points, loop mode, tuning, gain, pan, velocity tracking and an amplitude envelope. It is the simplest producer of the format-neutral region the voice plays; edits are picked up by the next note (see SingleSampleSampler).
Properties are plain mutable settings so a UI can bind to them directly.
- SingleSampleSampler
Plays a SingleSampleInstrument polyphonically as an ISampleProvider, through the shared SamplerEngine (so it gets pitch, looping, the amplitude envelope, pan, voice stealing and the reverb/chorus sends for free). Edits to Instrument are reflected by the next note played.
- SoundFontModulatorMath
The SoundFont 2.04 modulator transform curves (§8.2.4) and source evaluation. A modulator's source controller value is normalised to [0, 1], shaped by one of four curves (linear / concave / convex / switch) in the direction and polarity selected by the source's
DandPbits, and the result drives the modulator amount.The spec gives the concave law only "as variations of" a logarithmic equation, so these use the standard 96 dB convention: the concave curve spans the SoundFont peak-attenuation range, which makes the implicit velocity→attenuation default modulator (§8.4.1) reproduce the familiar near-square-law velocity response. The bar is musical fidelity to the spec, not sample-identity with any particular synth (the fidelity bar stated in Docs/Architecture/SamplerDesign.md). Public and static so the transforms can be unit-tested directly.
- SoundFontSampler
A polyphonic software sampler that plays a NAudio.SoundFont in response to MIDI note and controller events, rendering 32-bit float stereo through the standard NAudio ISampleProvider pull model. Drive it live (feed live MIDI-in events) or offline (feed a MidiFile's events on a schedule and render to a WAV).
Built on the shared SamplerEngine: pitch, looping, DAHDSR amplitude and modulation envelopes, two per-voice LFOs, a modulated resonant low-pass filter, the SoundFont modulator engine (default + file modulators), reverb/chorus sends, voice stealing, exclusive-class choke, and channel state (program/bank, pitch-bend, sustain, controllers).
- WaveSampleLoader
Decodes an audio file (or any ISampleProvider) fully into mono/stereo float channel buffers for the sampler — the in-memory, random-access form the voice engine plays from. WAV is read directly (including any loop points authored in its
smplchunk); other formats decode through any provided ISampleProvider (e.g.NAudio.SoundFile.SoundFileReaderfor FLAC/Ogg). Shared by the SFZ sample loader and the single-sample instrument.
Structs
- SampleLoop
Loop points embedded in a sample file (e.g. a WAV
smplchunk), in sample frames. Start is inclusive and End is exclusive (one past the last looped frame), matching the engine's NAudio.Sampler.SampleData convention — note the WAVsmplchunk itself stores an inclusive end, converted on read.
Interfaces
- ISfzSampleLoader
Loads an SFZ region's sample file into a mono float buffer. Pluggable so the format coverage can grow (WAV today; FLAC/Ogg via NAudio.SoundFile later) and so tests can supply synthetic samples.
Enums
- SamplerCrossfadeCurve
The curve a key/velocity crossfade uses to turn a fade position (0..1) into a gain (SFZ
xf_keycurve/xf_velcurve).
- SamplerFilterType
The resonant filter shape a region uses. SoundFont is always LowPass; SFZ selects it via
fil_type.
- SamplerTrigger
When a region triggers a voice (SFZ
trigger). SoundFont regions are always Attack.