Table of Contents

Class SingleSampleInstrument

Namespace
NAudio.Sampler
Assembly
NAudio.Sampler.dll

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.

public sealed class SingleSampleInstrument
Inheritance
SingleSampleInstrument
Inherited Members

Constructors

SingleSampleInstrument(float[], int, int, float[])

Creates an instrument from a sample buffer, mapped across the whole keyboard at the given root key.

public SingleSampleInstrument(float[] data, int sampleRate, int rootKey = 60, float[] dataRight = null)

Parameters

data float[]

The sample, or the left channel of a stereo sample (-1..1).

sampleRate int

The sample's recording rate in Hz.

rootKey int

The MIDI key that plays it at recorded pitch (default 60).

dataRight float[]

The right channel of a stereo sample, or null for mono.

Properties

AttackSeconds

Amplitude-envelope attack in seconds (default 0, instant).

public float AttackSeconds { get; set; }

Property Value

float

DecaySeconds

Amplitude-envelope decay in seconds (default 0).

public float DecaySeconds { get; set; }

Property Value

float

DelaySeconds

Amplitude-envelope delay in seconds (default 0).

public float DelaySeconds { get; set; }

Property Value

float

End

Playback end in frames (default the sample length).

public int End { get; set; }

Property Value

int

HiKey

Highest mapped MIDI key, inclusive (default 127).

public int HiKey { get; set; }

Property Value

int

HiVelocity

Highest mapped velocity, inclusive (default 127).

public int HiVelocity { get; set; }

Property Value

int

HoldSeconds

Amplitude-envelope hold in seconds (default 0).

public float HoldSeconds { get; set; }

Property Value

float

IsStereo

Whether the loaded sample is stereo.

public bool IsStereo { get; }

Property Value

bool

Length

The sample length in frames.

public int Length { get; }

Property Value

int

LoKey

Lowest mapped MIDI key, inclusive (default 0).

public int LoKey { get; set; }

Property Value

int

LoVelocity

Lowest mapped velocity, inclusive (default 0).

public int LoVelocity { get; set; }

Property Value

int

LoopCrossfadeSeconds

Loop-seam crossfade length in seconds (default 0). Smooths the loop wrap when the loop points don't fall on matching samples. Limited by the audio before LoopStart, so set a loop start that has some lead-in.

public float LoopCrossfadeSeconds { get; set; }

Property Value

float

LoopEnd

Loop end in frames (default the sample length).

public int LoopEnd { get; set; }

Property Value

int

LoopMode

Loop behaviour (default none).

public LoopMode LoopMode { get; set; }

Property Value

LoopMode

LoopStart

Loop start in frames (default 0).

public int LoopStart { get; set; }

Property Value

int

Pan

Pan, −1 (left) … +1 (right) (default 0, centre).

public float Pan { get; set; }

Property Value

float

ReleaseSeconds

Amplitude-envelope release in seconds (default 0.01, an anti-click tail).

public float ReleaseSeconds { get; set; }

Property Value

float

RootKey

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

public int RootKey { get; set; }

Property Value

int

SampleRate

The sample's recording rate in Hz.

public int SampleRate { get; }

Property Value

int

Start

Playback start in frames (default 0).

public int Start { get; set; }

Property Value

int

SustainLevel

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

public float SustainLevel { get; set; }

Property Value

float

TuneCents

Fixed detune in cents (default 0).

public double TuneCents { get; set; }

Property Value

double

VelocityTrackingPercent

Velocity-to-amplitude tracking percent (default 100; 0 = velocity ignored).

public float VelocityTrackingPercent { get; set; }

Property Value

float

VolumeDb

Gain in decibels (default 0).

public float VolumeDb { get; set; }

Property Value

float