Timbre.js

JavaScript Library for Objective Sound Programming
system requirements: Chrome 14- or Firefox 4-

ADSREnvelope

Control signal generator which outputs shaped Attack-Decay-Sustain-Release envelopes.

Constructor

adsr = T("adsr", table="linear", a=200, d=500, sl=0.5, r=500, reversed=false);

// a  [Number] Attack time in msec
// d  [Number] Decay time in msec
// sl [Number] Sustain Level
// r  [Number] Release time in msec

// Other constructors
T("adsr", [table], decay);
T("adsr", [table], attack, decay);
T("adsr", [table], attack, decay, release);
T("adsr", [table], attack, decay, sustain-level, release);
T("adsr", [table], delay, attack, delay, sustain-level, release);
        

Properties

adsr.table    // [String] Envelope curve

adsr.delay    // [Number] Delay time in msec
adsr.a        // [Number] Attack time in msec
adsr.d        // [Number] Decay time in msec
adsr.s        // [Number] Sustain time in msec
adsr.r        // [Number] Release time in msec

adsr.al       // [Number] Attack Level
adsr.dl       // [Number] Decay Level
adsr.sl       // [Number] Sustain Level
adsr.rl       // [Number] Release Level

adsr.reversed // [Boolean] Reverse envelope

adsr.currentTime // [Readonly] Current position in msec of the envelope
adsr.status      // [Readonly] The status of envelope
        

Methods

// Trigger the envelope
adsr.bang();


// Send a keyoff message to release
adsr.keyoff();
        

Events

// Script to be run when the envelope status reach 'A'
adsr.onA = function() {
    synth.freq.value = 880;
};


// Script to be run when the envelope status reach 'D'
adsr.onD = function() {
    synth.freq.value = 660;
};


// Script to be run when the envelope status reach 'S'
adsr.onS = function() {
    synth.freq.value = 440;
};


// Script to be run when the envelope status reach 'R'
adsr.onR = function() {
    synth.freq.value = 220;
};

// Script to be run when the envelope status reach the end
adsr.onended = function() {};
        

Example: Envelope curve

adsr  = T("adsr", 250, 1000, 0.5, 500);
synth = T("*", adsr, T("tri", 880, 0.25));
    
timeout = T("timeout", 3000, function() {
    adsr.keyoff();
});
adsr.onbang = function() {
    this.table = "32db";
};
adsr.onD = function() {
    this.table = "~32db";
};
synth.play();          
        

Example: Controll Oscillator's Frequecny

adsr  = T("adsr", 200, 500, 0.75, 500).set("delay", 200);
synth = T("tri", adsr, 0.25);

adsr.al = 0.2;
adsr.dl = 1.0;
adsr.mul = 880;
adsr.add = 440;

synth.play();
        

See Also:

T("perc")