Tone.js/src/instrument/Sampler.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-03-24 17:41:08 +00:00
///////////////////////////////////////////////////////////////////////////////
//
// SAMPLE PLAYER
//
// dependencies : Tone, Player, Envelope, LFO
///////////////////////////////////////////////////////////////////////////////
2014-03-19 21:25:49 +00:00
2014-03-24 17:41:08 +00:00
Tone.Sampler = function(url){
Tone.call(this);
//components
this.player = new Tone.Player(url);
this.envelope = new Tone.Envelope(.1, .01, .1, 1);
this.filter = this.context.createBiquadFilter();
this.filter.type = "lowpass";
this.filter.Q.value = 12;
this.filterEnvelope = new Tone.Envelope(.4, 0, 1, .6, this.filter.frequency, 0, 1200);
//connect it up
this.chain(this.player, this.envelope, this.filter, this.output);
2014-03-19 21:25:49 +00:00
}
2014-03-24 17:41:08 +00:00
Tone.extend(Tone.Sampler, Tone);
2014-03-26 19:38:21 +00:00
//@param {function()=} callback
2014-03-19 21:25:49 +00:00
Tone.Sampler.prototype.load = function(callback){
2014-03-24 17:41:08 +00:00
this.player.load(callback);
}
Tone.Sampler.prototype.triggerAttack = function(startTime){
this.player.start(startTime);
this.envelope.triggerAttack(startTime);
this.filterEnvelope.triggerAttack(startTime);
2014-03-19 21:25:49 +00:00
}
2014-03-24 17:41:08 +00:00
Tone.Sampler.prototype.triggerRelease = function(stopTime){
stopTime = this.defaultArg(stopTime, this.now());
this.player.stop(stopTime + Math.max(this.envelope.release, this.filterEnvelope.release));
this.envelope.triggerRelease(stopTime);
this.filterEnvelope.triggerRelease(stopTime);
2014-03-19 21:25:49 +00:00
}