Mooog examples

4. Envelopes

ADSR

Oscillator#saw

Parameter control envelopes are a fundamental part of electronic sound production. Mooog's adsr() method allows you to easily apply the traditional A(ttack) D(elay) S(ustain) R(elease) envelope to any AudioParam. You specify a base value, a peak attack value, a sustain value, and an array of durations for the phases of the envelope.

  • 4 values produce a complete ADSR envelope
  • 3 values produce a simpler ASR envelope
  • If you're triggering sounds based on user input then you can give a two-value times array and only the attack, delay, and sustain portions of the envelope will be produced. You'll then need to use one of the other ramping functions to terminate the envelope when appropriate – remembering to set from_now: true or the ramps will be calculated beginning at the previously scheduled event instead of the time you callparam().
M = new Mooog();
M.track( "osc",
    { id: "saw", node_type: "Oscillator", type: "sawtooth" },
    { id: "filter", node_type: "BiquadFilter", frequency: 300, Q: 30 },
    { id: "amplitude", node_type: "Gain", gain: 0 }
);
M.node('saw').start();

$(document)
    .on("mousedown", ".adsr1", function(){
        M.node("filter").adsr( "frequency", { base: 300, a: 10000, s:2500, times: [0.5, 0.5, 0, 3] } );
        M.node("amplitude").adsr( "gain", { base: 0, a: 1, s: 0.7, times: [0.1, 0.9, 0, 3] } );
    })
    .on("mousedown", ".adsr2", function(){
        M.node("filter").adsr( "frequency", { base: 300, a: 10000, s:2500, times: [0.5, 0.5] } );
        M.node("amplitude").adsr( "gain", { base: 0, a: 1, s: 0.7, times: [0.1, 0.9] } );
    })
    .on("mouseup", ".adsr2", function(){
        M.node("filter").param( { frequency: 300, at: 3, ramp: "expo", from_now: true } );
        M.node("amplitude").param( { gain: 0, at: 3, ramp: "expo", from_now: true } );
    })



<< 3. Tracks
5. Browser Support >>

AudioContext not fully supported

Your browser doesn't fully support the current AudioContext spec, so these examples may not function.

For more information, see the section on browser support.