Table of Contents

Class SfzMappedRegion

Namespace
NAudio.Sfz
Assembly
NAudio.Core.dll

An SFZ region with its Tier-1 and Tier-2 opcodes interpreted into typed, engine-ready synthesis parameters: absolute key/velocity ranges (note names resolved, offsets applied), tuning in cents, volume in dB, pan normalised to ±1, the amplitude envelope in seconds, the filter, loop behaviour, sample offsets, group/trigger routing, note-on selection (keyswitches, round-robin, random and CC windows), crossfades, the per-region LFOs/EGs and EQ bands, effect sends and release decay.

This is the SFZ semantic layer, the counterpart to the SoundFont generator model. It does not load samples or touch the voice engine — projecting both formats onto one neutral model the engine plays is the next step.

public sealed class SfzMappedRegion
Inheritance
SfzMappedRegion
Inherited Members

Properties

AmpLfo

Amplitude (tremolo) LFO (amplfo_freq/amplfo_depth/amplfo_delay; depth in dB).

public SfzLfo AmpLfo { get; }

Property Value

SfzLfo

AmpVelTrack

Velocity-to-amplitude tracking percentage (amp_veltrack, default 100).

public float AmpVelTrack { get; }

Property Value

float

AmpegAttack

Amplitude-envelope attack in seconds (ampeg_attack).

public float AmpegAttack { get; }

Property Value

float

AmpegDecay

Amplitude-envelope decay in seconds (ampeg_decay).

public float AmpegDecay { get; }

Property Value

float

AmpegDelay

Amplitude-envelope delay in seconds (ampeg_delay).

public float AmpegDelay { get; }

Property Value

float

AmpegHold

Amplitude-envelope hold in seconds (ampeg_hold).

public float AmpegHold { get; }

Property Value

float

AmpegRelease

Amplitude-envelope release in seconds (ampeg_release).

public float AmpegRelease { get; }

Property Value

float

AmpegSustain

Amplitude-envelope sustain level, 0…1 (ampeg_sustain%, default 1).

public float AmpegSustain { get; }

Property Value

float

CcGates

CC value windows that must all hold for the region to sound (loccN/hiccN).

public IReadOnlyList<(int Controller, int Low, int High)> CcGates { get; }

Property Value

IReadOnlyList<(int Controller, int Low, int High)>

CutoffHz

Filter cutoff in Hz (cutoff), valid when HasCutoff.

public float CutoffHz { get; }

Property Value

float

Effect1Percent

Send level to the first effect bus as a percentage (effect1, default 0).

public float Effect1Percent { get; }

Property Value

float

Effect2Percent

Send level to the second effect bus as a percentage (effect2, default 0).

public float Effect2Percent { get; }

Property Value

float

End

Sample end in frames (end, an inclusive index per the SFZ spec), meaningful when HasEnd is true. An explicit −1 means the region is disabled (not played) per the spec.

public int End { get; }

Property Value

int

EqBands

The EQ bands the region specifies (eq1_/eq2_/eq3_*), with unspecified members defaulted (centre frequency 50/500/5000 Hz by band, bandwidth 1 octave, gain 0); null when no EQ opcode is present.

public IReadOnlyList<SfzEqBand> EqBands { get; }

Property Value

IReadOnlyList<SfzEqBand>

FilterEg

Filter-cutoff modulation envelope (fileg_*; depth in cents).

public SfzModulationEnvelope FilterEg { get; }

Property Value

SfzModulationEnvelope

FilterLfo

Filter-cutoff LFO (fillfo_freq/fillfo_depth/fillfo_delay; depth in cents).

public SfzLfo FilterLfo { get; }

Property Value

SfzLfo

FilterType

The filter family (fil_type, default low-pass).

public SfzFilterType FilterType { get; }

Property Value

SfzFilterType

Group

Exclusive group (group, 0 = none).

public int Group { get; }

Property Value

int

HasCutoff

Whether a filter cutoff was specified.

public bool HasCutoff { get; }

Property Value

bool

HasEnd

Whether an end opcode was specified.

public bool HasEnd { get; }

Property Value

bool

HasLoopEnd

Whether a loop_end/loopend opcode was specified.

public bool HasLoopEnd { get; }

Property Value

bool

HasLoopMode

Whether a loop_mode/loopmode opcode was specified.

public bool HasLoopMode { get; }

Property Value

bool

HasLoopStart

Whether a loop_start/loopstart opcode was specified.

public bool HasLoopStart { get; }

Property Value

bool

HiKey

Highest MIDI key (inclusive) the region responds to (default 127).

public int HiKey { get; }

Property Value

int

HiVel

Highest velocity (inclusive) the region responds to (default 127).

public int HiVel { get; }

Property Value

int

HighRandom

High end of the random window (hirand, default 1).

public float HighRandom { get; }

Property Value

float

KeyFadeCurve

Key-crossfade curve (xf_keycurve, default power).

public SfzCrossfadeCurve KeyFadeCurve { get; }

Property Value

SfzCrossfadeCurve

KeyFadeInHigh

Key crossfade-in high.

public int KeyFadeInHigh { get; }

Property Value

int

KeyFadeInLow

Key crossfade-in low/high (xfin_lokey/xfin_hikey), or −1.

public int KeyFadeInLow { get; }

Property Value

int

KeyFadeOutHigh

Key crossfade-out high.

public int KeyFadeOutHigh { get; }

Property Value

int

KeyFadeOutLow

Key crossfade-out low/high (xfout_lokey/xfout_hikey), or −1.

public int KeyFadeOutLow { get; }

Property Value

int

KeyswitchDefault

The keyswitch active before any is pressed (sw_default), or −1.

public int KeyswitchDefault { get; }

Property Value

int

KeyswitchHigh

Highest keyswitch key (sw_hikey), or −1.

public int KeyswitchHigh { get; }

Property Value

int

KeyswitchLast

The keyswitch that must have been pressed last (sw_last), or −1.

public int KeyswitchLast { get; }

Property Value

int

KeyswitchLow

Lowest keyswitch key (sw_lokey), or −1 if no keyswitch range.

public int KeyswitchLow { get; }

Property Value

int

LoKey

Lowest MIDI key (inclusive) the region responds to (default 0).

public int LoKey { get; }

Property Value

int

LoVel

Lowest velocity (inclusive) the region responds to (default 0).

public int LoVel { get; }

Property Value

int

LoopEnd

Loop end in frames (loop_end, an inclusive index per the SFZ spec), meaningful when HasLoopEnd is true; overrides any loop end embedded in the sample file.

public int LoopEnd { get; }

Property Value

int

LoopMode

Loop behaviour (loop_mode). Only meaningful when HasLoopMode is true: per the SFZ spec an absent opcode defaults to loop_continuous when the sample file defines a loop (e.g. a WAV smpl chunk) and no_loop otherwise, which only the sample loader can decide.

public SfzLoopMode LoopMode { get; }

Property Value

SfzLoopMode

LoopStart

Loop start in frames (loop_start), meaningful when HasLoopStart is true; overrides any loop start embedded in the sample file.

public int LoopStart { get; }

Property Value

int

LowRandom

Low end of the random window (lorand, default 0).

public float LowRandom { get; }

Property Value

float

OffBy

The group whose notes this region silences (off_by, 0 = none).

public int OffBy { get; }

Property Value

int

OffMode

How this region is silenced by its group (off_mode, default fast).

public SfzOffMode OffMode { get; }

Property Value

SfzOffMode

Offset

Sample start offset in frames (offset, default 0).

public int Offset { get; }

Property Value

int

OnCcTriggers

CC value windows that trigger the region when the controller rises into them (on_loccN/on_hiccN); null when the region is not CC-triggered.

public IReadOnlyList<(int Controller, int Low, int High)> OnCcTriggers { get; }

Property Value

IReadOnlyList<(int Controller, int Low, int High)>

Pan

Pan normalised to −1 (left) … +1 (right) from SFZ's −100…100.

public float Pan { get; }

Property Value

float

PitchEg

Pitch modulation envelope (pitcheg_*; depth in cents).

public SfzModulationEnvelope PitchEg { get; }

Property Value

SfzModulationEnvelope

PitchKeycenter

The key that plays the sample at its recorded pitch (default 60).

public int PitchKeycenter { get; }

Property Value

int

PitchKeytrack

Cents per key of pitch tracking across the keyboard (default 100).

public int PitchKeytrack { get; }

Property Value

int

PitchLfo

Pitch (vibrato) LFO (pitchlfo_freq/pitchlfo_depth/pitchlfo_delay; depth in cents).

public SfzLfo PitchLfo { get; }

Property Value

SfzLfo

Polyphony

Maximum simultaneous voices (polyphony, −1 = unlimited).

public int Polyphony { get; }

Property Value

int

Region

The underlying parsed region (raw opcodes, resolved sample path).

public SfzRegion Region { get; }

Property Value

SfzRegion

ReleaseDecayDbPerSecond

Release-trigger decay in dB per second the note was held (rt_decay, default 0).

public float ReleaseDecayDbPerSecond { get; }

Property Value

float

ResonanceDb

Filter resonance in dB (resonance, default 0).

public float ResonanceDb { get; }

Property Value

float

Sample

The region's sample path (from Sample).

public string Sample { get; }

Property Value

string

SequenceLength

Round-robin length (seq_length, default 1 = none).

public int SequenceLength { get; }

Property Value

int

SequencePosition

This region's 1-based round-robin slot (seq_position, default 1).

public int SequencePosition { get; }

Property Value

int

Trigger

When the region plays (trigger, default attack).

public SfzTrigger Trigger { get; }

Property Value

SfzTrigger

TuneCents

Fixed detune in cents (tune/pitch plus transpose×100).

public double TuneCents { get; }

Property Value

double

VelocityCurvePoints

The region's velocity-curve points (amp_velcurve_N): the normalised amplitude (0…1) at velocity N (1…127), sorted by velocity; null when the region defines none. Points whose N is outside 1…127 or whose value does not parse are ignored; levels are clamped to 0…1. Resolve the full per-velocity curve with BuildVelocityCurve().

public IReadOnlyList<(int Velocity, float Level)> VelocityCurvePoints { get; }

Property Value

IReadOnlyList<(int Velocity, float Level)>

VelocityFadeCurve

Velocity-crossfade curve (xf_velcurve, default power).

public SfzCrossfadeCurve VelocityFadeCurve { get; }

Property Value

SfzCrossfadeCurve

VelocityFadeInHigh

Velocity crossfade-in high.

public int VelocityFadeInHigh { get; }

Property Value

int

VelocityFadeInLow

Velocity crossfade-in low/high (xfin_lovel/xfin_hivel), or −1.

public int VelocityFadeInLow { get; }

Property Value

int

VelocityFadeOutHigh

Velocity crossfade-out high.

public int VelocityFadeOutHigh { get; }

Property Value

int

VelocityFadeOutLow

Velocity crossfade-out low/high (xfout_lovel/xfout_hivel), or −1.

public int VelocityFadeOutLow { get; }

Property Value

int

VolumeDb

Region gain in decibels (volume, default 0).

public float VolumeDb { get; }

Property Value

float

Methods

BuildVelocityCurve()

Resolves VelocityCurvePoints into a full 128-entry curve indexed by MIDI velocity: defined points give their level, undefined velocities are linearly interpolated between the nearest defined neighbours — from (0, 0) below the lowest defined point and to (127, 1) above the highest, unless velocity 127 is itself defined. Returns null when the region defines no points; the resolved curve replaces the default velocity-squared term inside the amp_veltrack law.

public float[] BuildVelocityCurve()

Returns

float[]

Map(SfzRegion, int, int)

Interprets a parsed SfzRegion's opcodes. The noteOffset and octaveOffset (from the instrument's <control> section) transpose incoming MIDI notes; here that is realised by shifting the explicitly specified key-valued opcodes the opposite way.

public static SfzMappedRegion Map(SfzRegion region, int noteOffset = 0, int octaveOffset = 0)

Parameters

region SfzRegion
noteOffset int
octaveOffset int

Returns

SfzMappedRegion

Remarks

key versus explicit lokey/hikey/pitch_keycenter: strict SFZ semantics apply opcodes in document order (the later one wins), but the merged opcode set this maps from no longer carries that order. This mapping deliberately deviates with a pragmatic rule: key supplies defaults for whichever of the three are not explicitly present, and an explicit opcode always wins regardless of where it was written — so <group> key=36 <region> lokey=35 hikey=37 keeps the region's range, with the keycenter defaulting from key.

Matches(int, int)

Whether this region should sound for the given key and velocity.

public bool Matches(int key, int velocity)

Parameters

key int
velocity int

Returns

bool