Mooog examples

1. Basic Connections

Fan-out with connect()

The connect method returns the source node, which is useful for fanout. It retains the existing connection of the source node to the AudioDestination, so in this example you'll hear the oscillator as well as the delays.

M = new Mooog();
M.node( { id: "osc", node_type: "Oscillator", type: "triangle" } )
    .connect(
        M.node( { id: "short_delay", node_type: "Delay", delayTime: 0.25 } )
    )
    .connect(
        M.node( { id: "long_delay", node_type: "Delay", delayTime: 0.75 } )
    )

$(document)
    .on("mousedown", ".trigger1", function(){
        M.node("osc").start();
    })
    .on("mouseup", ".trigger1", function(){
        M.node("osc").stop();
    })



Series connections with chain()

The chain method returns the destination node and automatically disconnects the source from the AudioDestination, which is useful for effects chains. In this example we also use the buffer_source_file parameter of the Convolver to quickly load an impulse response file. The use of chain() to the Convolver means we don't (and can't) hear any dry signal without making additional connections from the previous node. In most cases using the Track object's send would be preferable since it gives us more flexibility.

M = new Mooog();
M.node( { id: "osc2", node_type: "Oscillator", type: "sawtooth" } )
    .chain(
        M.node( { id: "filter", node_type: "BiquadFilter", frequency: 400 } )
    )
    .chain(
        M.node( { id: "pre-reverb", node_type: "Gain", gain: 0.6 } )
    )
    .chain(
        M.node( { id: "reverb", node_type: "Convolver", buffer_source_file: "sound/impulse-responses/st-andrews-church-ortf-shaped.mp3" } )
    )

$(document)
    .on("mousedown", ".trigger2", function(){
        M.node("osc2").start();
    })
    .on("mouseup", ".trigger2", function(){
        M.node("osc2").stop();
    })
2. Parameters >>

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.