Audio

The CCC-pattern for Web Audio

In software unit testing we have the AAA-pattern (Arrange, Act, Assert).

Now I want to introduce the CCC-pattern for Web Audio.

  1. Create
  2. Configure
  3. Connect
  4. (Carry out)

Example

const ctx = new AudioContext()

// create
const tone = ctx.createOscillator()
const gain = ctx.createGain()

// configure
tone.frequency.value = 440
gain.gain.value = 1

// connect
tone.connect(gain)
    .connect(ctx.destination)

// carry out
tone.start()

Also note the builder pattern for connecting audio nodes.