Class 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).
public sealed class SoundFontSampler : SamplerEngine, IMidiInstrument, ISampleProvider
- Inheritance
-
SoundFontSampler
- Implements
- Inherited Members
- Extension Methods
Constructors
SoundFontSampler(SoundFont, int, int)
Creates a sampler for the given SoundFont.
public SoundFontSampler(SoundFont soundFont, int sampleRate = 44100, int maxVoices = 64)
Parameters
soundFontSoundFontThe loaded SoundFont to play.
sampleRateintOutput sample rate in Hz (default 44100).
maxVoicesintMaximum simultaneous voices (default 64).
Fields
PercussionBank
The SoundFont bank holding GM percussion kits.
public const int PercussionBank = 128
Field Value
Properties
PercussionChannel
The MIDI channel (0-based) treated as the GM percussion channel: its notes always resolve against the percussion bank (PercussionBank = 128), regardless of any bank-select messages — note numbers pick the drum, not a pitch. Defaults to 9 (MIDI channel 10). Set to -1 to disable, e.g. for a non-GM SoundFont with no percussion bank.
public int PercussionChannel { get; set; }
Property Value
TreatGsXgDrumBanksAsPercussion
Whether a channel whose selected bank MSB (CC0) is 120 or 127 resolves its notes against the percussion bank, exactly like the forced percussion channel. Roland GS selects rhythm parts with bank MSB 120 on any channel and Yamaha XG uses MSB 127 for its drum kits, so honouring those two values lets GS/XG-authored MIDI files play drums on channels other than 10. Default true. This is a heuristic on the bank number alone: full GS/XG mode detection via SysEx (GS Reset / XG System On, part-mode messages) remains unsupported. Normal variation banks (e.g. CC0 = 8) are unaffected.
public bool TreatGsXgDrumBanksAsPercussion { get; set; }