2014-09-20 19:18:08 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/Envelope"], function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2015-07-04 16:32:18 +00:00
|
|
|
* @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
|
2015-07-01 21:44:30 +00:00
|
|
|
* var ampEnv = new Tone.AmplitudeEnvelope({
|
|
|
|
* "attack": 0.1,
|
|
|
|
* "decay": 0.2,
|
|
|
|
* "sustain": 1.0,
|
|
|
|
* "release": 0.8
|
|
|
|
* }).toMaster();
|
2015-07-04 16:32:18 +00:00
|
|
|
* //create an oscillator and connect it
|
2015-06-20 23:25:49 +00:00
|
|
|
* var osc = new Tone.Oscillator().connect(ampEnv).start();
|
2015-07-04 16:32:18 +00:00
|
|
|
* //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
|
|
|
*/
|
2014-11-02 01:55:19 +00:00
|
|
|
this.input = this.output = this.context.createGain();
|
|
|
|
|
2014-11-04 05:44:16 +00:00
|
|
|
this._sig.connect(this.output.gain);
|
2014-09-20 19:18:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.AmplitudeEnvelope, Tone.Envelope);
|
|
|
|
|
|
|
|
return Tone.AmplitudeEnvelope;
|
|
|
|
});
|