2019-01-27 18:05:20 +00:00
|
|
|
import Tone from "../core/Tone";
|
|
|
|
import "../component/Envelope";
|
|
|
|
import "../core/Gain";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* of the signal. Read more about ADSR Envelopes on [Wikipedia](https://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope).
|
|
|
|
*
|
|
|
|
* @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();
|
|
|
|
* //create an oscillator and connect it
|
|
|
|
* var osc = new Tone.Oscillator().connect(ampEnv).start();
|
|
|
|
* //trigger the envelopes attack and release "8t" apart
|
|
|
|
* ampEnv.triggerAttackRelease("8t");
|
|
|
|
*/
|
|
|
|
Tone.AmplitudeEnvelope = function(){
|
|
|
|
|
|
|
|
Tone.Envelope.apply(this, arguments);
|
2014-09-20 19:18:08 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-27 18:05:20 +00:00
|
|
|
* the input node
|
|
|
|
* @type {GainNode}
|
|
|
|
* @private
|
2014-09-20 19:18:08 +00:00
|
|
|
*/
|
2019-01-27 18:05:20 +00:00
|
|
|
this.input = this.output = new Tone.Gain();
|
2014-09-20 19:18:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
this._sig.connect(this.output.gain);
|
|
|
|
};
|
2014-11-02 01:55:19 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Tone.extend(Tone.AmplitudeEnvelope, Tone.Envelope);
|
2014-09-20 19:18:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
/**
|
|
|
|
* Clean up
|
|
|
|
* @return {Tone.AmplitudeEnvelope} this
|
|
|
|
*/
|
|
|
|
Tone.AmplitudeEnvelope.prototype.dispose = function(){
|
|
|
|
Tone.Envelope.prototype.dispose.call(this);
|
|
|
|
return this;
|
|
|
|
};
|
2014-09-20 19:18:08 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
export default Tone.AmplitudeEnvelope;
|
2015-08-16 19:15:10 +00:00
|
|
|
|