Tone.js/Tone/component/AmplitudeEnvelope.js

60 lines
2 KiB
JavaScript
Raw Normal View History

2015-08-16 19:15:10 +00:00
define(["Tone/core/Tone", "Tone/component/Envelope", "Tone/core/Gain"], function(Tone){
2014-09-20 19:18:08 +00:00
"use strict";
/**
* @class Tone.AmplitudeEnvelope is a Tone.Envelope connected to a gain node.
* Unlike Tone.Envelope, which outputs the envelope's value, Tone.AmplitudeEnvelope accepts
* an audio signal as the input and will apply the envelope to the amplitude
2015-07-04 19:25:37 +00:00
* of the signal. Read more about ADSR Envelopes on [Wikipedia](https://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope).
2014-09-20 19:18:08 +00:00
*
* @constructor
* @extends {Tone.Envelope}
2015-06-14 00:20:36 +00:00
* @param {Time|Object} [attack] The amount of time it takes for the envelope to go from
* 0 to it's maximum value.
* @param {Time} [decay] The period of time after the attack that it takes for the envelope
* to fall to the sustain value.
* @param {NormalRange} [sustain] The percent of the maximum value that the envelope rests at until
* the release is triggered.
* @param {Time} [release] The amount of time after the release is triggered it takes to reach 0.
2015-02-27 21:53:10 +00:00
* @example
* var ampEnv = new Tone.AmplitudeEnvelope({
* "attack": 0.1,
* "decay": 0.2,
* "sustain": 1.0,
* "release": 0.8
* }).toMaster();
* //create an oscillator and connect it
2015-06-20 23:25:49 +00:00
* var osc = new Tone.Oscillator().connect(ampEnv).start();
* //trigger the envelopes attack and release "8t" apart
2015-06-20 23:25:49 +00:00
* ampEnv.triggerAttackRelease("8t");
2014-09-20 19:18:08 +00:00
*/
Tone.AmplitudeEnvelope = function(){
Tone.Envelope.apply(this, arguments);
/**
* the input node
* @type {GainNode}
2015-02-27 21:53:10 +00:00
* @private
2014-09-20 19:18:08 +00:00
*/
2015-08-16 19:15:10 +00:00
this.input = this.output = new Tone.Gain();
2014-11-02 01:55:19 +00:00
this._sig.connect(this.output.gain);
2014-09-20 19:18:08 +00:00
};
Tone.extend(Tone.AmplitudeEnvelope, Tone.Envelope);
2015-08-16 19:15:10 +00:00
/**
* Clean up
* @return {Tone.AmplitudeEnvelope} this
*/
Tone.AmplitudeEnvelope.prototype.dispose = function(){
this.input.dispose();
this.input = null;
Tone.Envelope.prototype.dispose.call(this);
return this;
};
2014-09-20 19:18:08 +00:00
return Tone.AmplitudeEnvelope;
});