pd-andy/elm-web-audio/1.0.0

NOTE: the latest version is 2.3.0

Renamed to hayleigh-dot-dev/elm-web-audio. It is published under that name, and new versions come out there.

Versions published as pd-andy/elm-web-audio still install under that name. 5 versions of 5 come from the new location (see their notes).

Rerouted (fork, verified). The original repository is gone. This copy comes from a fork that still has the tag. The Lamdera package server serves a copy recovered from https://github.com/munozu/elm-web-audio (a fork).

What we checked: Rebuilt with git archive from commit fbc26be44106 of https://github.com/munozu/elm-web-audio (a fork) (zip prefix pd-andy-elm-web-audio-8afb671/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 09b6be680f8e7e3d31ca5863d612826b0444df15.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/pd-andy/elm-web-audio/zipball/1.0.0/

WebAudio

Types

type Node

The core building block of any Web Audio signal graph. Keyed nodes are just like regular nodes but with an additonal Key property. This allows Ref nodes to reference them elsewhere in the graph!

type alias Type =
String

A simple type alias representing the type of Node. This could be something like "OscillatorNode" or "RefNode".

type alias Key =
String

A simple type alias representing unique key used to identify nodes. Use Keys like you would use the id attribute on a HTML element.

type alias Graph =
List Node

Basic Constructors

node : Type -> List Property -> List Node -> Node

General way to construct Web Audio nodes. This is used to create all the helper functions below. You can use this function to define custom nodes by partially applying just the type parameter. This is handy if you're using a library like Tone.js and want to use those nodes in Elm.

omniOscillator : List Property -> List Node -> Node
omniOscillator =
    node "Tone-OmniOscillatorNode"


myOsc =
    omniOscillator
        [ Property.freq 440 ]
        [ dac ]
ref : Key -> Node

A ref node is used to refer to a keyed node elsewhere in the graph. This is how we connect multiple "chains" of nodes together and represet a graph in a simple list.

key : Key -> Node -> Node

Use this function to apply a key to a node. In the case of already keyed nodes, or ref nodes, this will update the key to the new value.

a = osc [ Property.freq 440 ] [ dac ]
b = keyedGain "b" [ Property.gain 0.5 ] [ dac ]
c = ref "b"


key a "myOsc" -- Give a the key "myOsc"
key b "myGain" -- Rename b's key to "myGain"
key c "myOsc" -- c is now a RefNode to "myOsc"

Web Audio Nodes

Common audio nodes

oscillator : List Property -> List Node -> Node

See: https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode Common properties:

  • frequency
  • detune
  • type
osc : List Property -> List Node -> Node

An alias for oscillator.

An alias for audioDestination.

See: https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode Common properties:

  • buffer
  • detune
  • loop
  • loopStart
  • loopEnd
  • playbackRate
delay : List Property -> List Node -> Node

Utility nodes

Signal processing nodes

biquadFilter : List Property -> List Node -> Node

See: https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode Common properties:

  • frequency
  • detune
  • Q
  • type
convolver : List Property -> List Node -> Node

See: https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode Common properties:

  • buffer
  • normalize | normalise

See: https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode Common properties:

  • threshold
  • knee
  • ratio
  • reduction
  • attack
  • release
panner : List Property -> List Node -> Node

See: https://developer.mozilla.org/en-US/docs/Web/API/PannerNode Common properties:

  • coneInnerAngle
  • coneOuterAngle
  • coneOuterGain
  • distanceModel
  • maxDistance
  • orientationX
  • orientationY
  • orientationZ
  • panningModel
  • positionX
  • positionY
  • positionZ
  • refDistance
  • rolloffFactor
waveShaper : List Property -> List Node -> Node

JSON Encoding

To turn the json in Web Audio nodes, you need to know what that data looks like. Here's a breakdown of how everything is encoded:

Node:

{
    "type": "OscillatorNode",
    "properties": [
        ...
    ],
    "connections": [
        ...
    ]
}

Keyed:

{
    "key": "myOsc",
    "type": "OscillatorNode",
    "properties": [
        ...
    ],
    "connections": [
        ...
    ]
}

Ref:

{
    "key": "myOsc",
    "type": "RefNode"
}

Properties can come in two types, AudioParam and NodeProperty. While the Web Audio API doesn't make an official distinction between the two, how they are used differs.

AudioParams represent parameters that can be updated at either audio rate (a-rate) or control rate (k-rate). Other audio nodes can connect to an AudioParam and modulate its value in real time. Examples of AudioParams include frequency, gain, and delayTime.

AudioParam:

{
    "type": "AudioParam",
    "label": "frequency",
    "value": 440
}

NodeProperties are any other parameter on an audio node. An example of a NodeProperty is an OscillatorNode's "type" parameter.

NodeProperty:

{
   "type": "NodeProperty",
   "label": "type",
   "value": "square"
}
encode : Node -> Value

Converts a Node into a Json value. Use this to send a node through a port to javascipt, where it can be constructed into a Web Audio node!

encodeGraph : Graph -> Value

Encode a graph of nodes into a Json value. More than likely you'll use this more than encode