synths

This module provides some typical syntetizers components, like vca, vcf and some syntetizers

Source:
Example
// a dual osc synth sound
synth(
 frequency: 440,
 oscillators: { ratios: [1, 5/7, 9/8], types: 'saw' },
 attack: 0.1, release: 0.1,
 filter: { frequency: 'follow' }
  ).connect(dest()).start()

Methods

(static) bank(frequencies, options) → {AudioNode}

Create a bank of oscillators.

Parameters:
Name Type Description
frequencies Array.<Float>

an array with the frequencies

options Object

(Optional) options can include:

  • frequencies: an array with the frequencies of the oscillators (will override ratios)
  • ratios: an array of relative freqnecies of the oscillators (in combination iwth frequency paramter)
  • frequency: the base frequency of the oscillators (only used if frequencies)
  • types: a value or an array of oscillator types. If the array is shorter than the frequencies array, it's assumed to be circular.
  • gains: a value or an array of gain values. If the array is shorter than the frequencies array, it's assumed to be circular.
  • compensate: if true, the gain of the bank will be reduced by the number of oscillators (true by default)
Source:
Returns:
Type
AudioNode
Example
// create three sines with unrelated frequencies:
bank({ frequencies: [1345.387, 435.392, 899.432] })
// create three sawtooth with relative frequencies:
bank({ frequency: 440, ratios: [1, 2, 2.4] , types: 'sawtooth' })
// create two squares of 400 and 800 and two sawtooths of 600 and 1200
// (the types are cyclic)
bank({ frequencies: [400, 600, 800, 1200], types: ['square', 'sawtooth'] })
// specify gains
bank({ frequencies: [440, 660], gains: [0.6, 0.2] })

(static) subtractive(source, options)

A subtractive synthetizer (oscillator bank -> VCF -> VCA)

Parameters:
Name Type Description
source AudioNode | Number | String

The subtractive synth source

options Object

(Optional) the configuration may include:

  • gain: the gain (defaults to 1)
  • adsr: the parameters of the gain envelop in the form [attack, decay, sustain, release]
  • attack, decay, sustain, release: the parameters of the gain envelope. It will override the one provided by adsr parameter if any
  • filter: an object with the filter properties
  • filter.type: the filter type ('lowpass' by default)
  • filter.frequency: the filter frequency (can be follow to use the options.frequency value)
  • filter.adsr: the filter envelope
  • filter.attack, filter.decay, filter.sustain, filter.release: the individual filter envelope parameters
  • filter.octaves: the number of the octaves of the filter envelope (1 by default)
Source:
Example
// a 300Hz sawtooth with adsr and lowass filter at 600
subtractive({ frequency: 300, type: 'sawtooth', adsr: [0.01, 0.1, 0.8, 1], filter: { type: 'lowpass', frequency: 600 } })
// a custom source node
substractive({ source: add(white(), square(500)), attack: 0.1, duration: 1 })
// connected in a chain
connect(sample('snare.wav', subtractive({ attack: 0.1 }))

(static) vca(options) → {AudioNode}

Create a VCA: an amplifier controlled by an ADSR envelope

Parameters:
Name Type Description
options Object

may include:

Source:
Returns:

a GainNode

  • db: the gain in decibels
  • gain: the gain (will override dB param)
  • attack, decay, sustain, release: the ADSR envelope parameters
  • context: the audio context
Type
AudioNode

(static) vcf(config) → {AudioNode}

Create a VCF: a filter controlled by an ADSR envelope

Parameters:
Name Type Description
config Object

may include:

Source:
Returns:

the BiquadFilterNode

  • type: filter type
  • frequency: filter frequency (can be a signal)
  • octaves: amplitude of the modulation in octaves (defaults to 2)
  • attack, decay, sustain, release: the adsr parameters
  • context: the audio context
Type
AudioNode
Example
conn(square({ frequency: 800 }), vcf({ frequency: 400, attack: 0.1 }))

(static) withDefaults()

Decorate a function to have default configuration

Source: