Skip to content

Instantly share code, notes, and snippets.

@coleww
Created July 12, 2015 00:24
Show Gist options
  • Select an option

  • Save coleww/7d2c30606b02b7cf96b6 to your computer and use it in GitHub Desktop.

Select an option

Save coleww/7d2c30606b02b7cf96b6 to your computer and use it in GitHub Desktop.
web audio modules on NPM

Each "instrument"/module is an object filled with already-connected and setup audioNodes.

A very simple instrument might look like this:

{
  oscillator: OscillatorNode,
  filter: BiquadFilterNode,
  gain: GainNode
}

But of course the keys to the nodes are arbitrary, you might have 12 filter nodes in this instrument, use whatever pattern you like for naming these things. In this example, the nodes might be connected like so:

oscillator.connect(filter)
filter.connect(gain)

The instrument should respond to the following methods:

  • keys() => returns list of keys to audioNodes.
  • connect(destination) => connect the output nodes to a destination or other nodes. In the example this would be this.gain.connect(destination).
  • start() => calls start() on all the source nodes. In the example, this would be this.oscillator.start().
  • export() => returns JSON respresentation of the instrument state.
  • import(data) => loads a JSON of the instrument state.

An example of an implemented instrument

Multiple modules could be chained together into complex instruments, without having to pay attention to the low level details of connecting nodes or setting values to good defaults.

TODO:

  • needs some way of identifying what type of node something is (maybe check what it responds to?)
  • related to that, some way of programmatically generating UI for each node. That way given an instrument you could create a basic html unstyled component and then go from there.
  • set values on import through A-Param methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment