Tone.Sampler

↳ EXTENDS Tone.Instrument

A sampler instrument which plays an audio buffer through an amplitude envelope and a filter envelope. The sampler takes an Object in the constructor which maps a sample name to the URL of the sample. Nested Objects will be flattened and can be accessed using a dot notation (see the example).

CONSTRUCTOR

new Tone.Sampler (
urls
, [
options
] )
urls

the urls of the audio file

type: Object or string
options

the options object for the synth

type: Object
optional

DEFAULTS

{
sample : 0 ,
pitch : 0 ,
player :
{
loop : false
}
,
envelope :
{
attack : 0.001 ,
decay : 0 ,
sustain : 1 ,
release : 0.1
}
,
filterEnvelope :
{
attack : 0.001 ,
decay : 0.001 ,
sustain : 1 ,
release : 0.5 ,
baseFrequency : 20 ,
octaves : 10
}
,
filter :
{
type : lowpass
}
}

EXAMPLE

var sampler = new Sampler({
	A : {
		1 : "./audio/casio/A1.mp3",
		2 : "./audio/casio/A2.mp3",
	},
	"B.1" : "./audio/casio/B1.mp3",
}).toMaster();

//listen for when all the samples have loaded
Tone.Buffer.onload = function(){
	sampler.triggerAttack("A.1", time, velocity);
};

Members

.envelope

↝ Tone.AmplitudeEnvelope #

The amplitude envelope.

</>

.filter

↝ Tone.Filter #

The filter.

</>

.filterEnvelope

↝ Tone.FrequencyEnvelope #

The filter envelope.

</>

.pitch

↝ Interval #

Repitch the sampled note by some interval (measured in semi-tones).

EXAMPLE

sampler.pitch = -12; //down one octave
sampler.pitch = 7; //up a fifth
</>

.player

↝ Tone.Player #

The sample player.

</>

.reverse

↝ boolean #

The direction the buffer should play in

</>

.sample

↝ number or string #

The name of the sample to trigger.

EXAMPLE

//set the sample to "A.2" for next time the sample is triggered
sampler.sample = "A.2";
</>
↳ inherited from Tone.Instrument
∿

.volume

↝ Decibels #

The volume of the output in decibels.

EXAMPLE

source.volume.value = -6;
</>

Methods

.dispose ( )

#
↪ returns Tone.Sampler

this

Clean up.

</>

.triggerAttack ( )

#
sample

The name of the sample to trigger, defaults to the last sample used.

type: string
optional
time

The time when the sample should start

type: Time
default: now
velocity

The velocity of the note

type: number
default: 1
↪ returns Tone.Sampler

this

Start the sample and simultaneously trigger the envelopes.

EXAMPLE

sampler.triggerAttack("B.1");
</>

.triggerRelease ( )

#
time

The time when the note should release

type: Time
default: now
↪ returns Tone.Sampler

this

Start the release portion of the sample. Will stop the sample once the envelope has fully released.

EXAMPLE

sampler.triggerRelease();
</>
↳ inherited from Tone.Instrument

.triggerAttackRelease ( )

#
note

The note to trigger.

duration

How long the note should be held for before triggering the release.

type: Time
time

When the note should be triggered.

type: Time
default: now
velocity

The velocity the note should be triggered at.

default: 1
↪ returns Tone.Instrument

this

Trigger the attack and then the release after the duration.

EXAMPLE

//trigger "C4" for the duration of an 8th note
synth.triggerAttackRelease("C4", "8n");
</>
docs generated Sep 15 2019