Tone.js/Tone/component/AmplitudeEnvelope.js

47 lines
No EOL
1.6 KiB
JavaScript

define(["Tone/core/Tone", "Tone/component/Envelope"], function(Tone){
"use strict";
/**
* @class A Tone.Envelope connected to a gain node which can be used as an amplitude envelope. Unlike
* the Tone.Envelope, a signal can be connected to the input of Tone.AmplitudeEnvelope.
* Read more about ADSR Envelopes on
* <a href="https://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" target="_blank">Wikipedia</a>.
*
* @constructor
* @extends {Tone.Envelope}
* @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.
* @example
* var ampEnv = new Tone.AmplitudeEnvelope({
* "attack": 0.1,
* "decay": 0.2,
* "sustain": 1.0,
* "release": 0.8
* }).toMaster();
* var osc = new Tone.Oscillator().connect(ampEnv).start();
* ampEnv.triggerAttackRelease("8t");
*/
Tone.AmplitudeEnvelope = function(){
Tone.Envelope.apply(this, arguments);
/**
* the input node
* @type {GainNode}
* @private
*/
this.input = this.output = this.context.createGain();
this._sig.connect(this.output.gain);
};
Tone.extend(Tone.AmplitudeEnvelope, Tone.Envelope);
return Tone.AmplitudeEnvelope;
});