# Audio Units

This documents the audio units exported by FRP.Behavior.Audio.

The convention for audio units is the following:

  • highpass :: A highpass filter
  • highpassT :: A highpass filter using an AudioParameter, which has a temporal offset.
  • highpass_ :: A named highpass filter. Naming audio units speeds up computation a bit and may get rid of some artifacts.
  • highpassT_ :: A named highpass filter with a AudioParameters.

All audio units have these four varieties. Any audio unit that is not a generator takes one or many audio units as inputs. In addition, some audio units (like speaker and gain) have a variety with an apostrophe (speaker' and gain') that accept a single audio unit instead of a list.

For an alternative way to construct audio units that allows for cycles (ie feedback loops), check out the audio graph guide.

# speaker

speaker :: forall ch. Pos ch => NonEmpty List (AudioUnit ch) -> AudioUnit ch

Send sound to the speaker.

If you want sound to be played from your speaker, you must use this function Otherwise, the audio graph will render but no sound will come out.

# microphone

microphone :: AudioUnit D1

The microphone.

Make sure to enable the microphone before using this.

# audioWorkletGenerator

audioWorkletGenerator :: forall ch. Pos ch => String -> Object Number -> AudioUnit ch

A custom audio worklet generator.

  • s: A unique identifier for the audio worklet to be used. The worklet should be preloaded before using this.
  • params: The custom params passed to the audio worklet.

# audioWorkletProcessor

audioWorkletProcessor :: forall ch. Pos ch => String -> Object Number -> AudioUnit ch -> AudioUnit ch

A custom audio worklet processor

  • s: A unique identifier for the audio worklet to be used. The worklet should be preloaded before using this.
  • params: The custom params passed to the audio worklet

# play

play :: forall ch. Pos ch => String -> AudioUnit ch

Play an audio track.

  • s: A unique identifier for the audio track to be played. This should match an identifier passed to runInBrowser.

# playBuf

playBuf :: forall ch. Pos ch => String -> Number -> AudioUnit ch

Play a sound from a buffer

  • s: A unique identifier for the audio buffer to be played. This should match an identifier passed to runInBrowser
  • n: The playback rate. 1.0 is unit, 0.5 is twice as slow, 2.0 is twice as fast.

# loopBuf

loopBuf :: forall ch. Pos ch => String -> Number -> Number -> Number -> AudioUnit ch

Loop a sound from a buffer

  • s: A unique identifier for the audio buffer to be played. This should match an identifier passed to runInBrowser
  • n: The playback rate. 1.0 is unit, 0.5 is twice as slow, 2.0 is twice as fast.
  • st: Where in the sound the loop should start (in seconds)
  • st: Where in the sound the loop should end (in seconds). Set to 0.0 to go to the end of the sound.

# recorder

recorder :: forall ch. Pos ch => String -> AudioUnit ch -> AudioUnit ch

A recorder. Records AudioUnit ch to the recorder named by the String argument and returns the same AudioUnit ch.

# lowpass

lowpass :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A lowpass filter.

# highpass

highpass :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A lowpass filter.

# bandpass

bandpass :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A bandpass filter.

# lowshelf

lowshelf :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A lowshelf filter.

# highshelf

highshelf :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A highshelf filter.

# peaking

peaking :: forall ch. Pos ch => Number -> Number -> Number -> AudioUnit ch -> AudioUnit ch

A peaking filter. This is like a bandpass filter with an extra vector of control

# notch

notch :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

A notch filter. The opposite of bandpass.

# allpass

allpass :: forall ch. Pos ch => Number -> Number -> AudioUnit ch -> AudioUnit ch

An allpass filter. Lets all frequencies through, but alters the phase relationship.

# convolver

convolver :: forall ch. Pos ch => String -> AudioUnit ch -> AudioUnit ch

A convolver (reverb)

  • s: A unique identifier for the audio buffer to be used as the impulse response. This should match an identifier passed to runInBrowser.

# dynamicsCompressor

dynamicsCompressor :: forall ch. Pos ch => Number -> Number -> Number -> Number -> Number -> AudioUnit ch -> AudioUnit ch

A compressor

  • threshold: the decibel value above which the compression will start taking effect.
  • knee: a decibel value representing the range above the threshold where the curve smoothly transitions to the compressed portion.
  • ratio: the amount of change, in dB, needed in the input for a 1 dB change in the output.
  • attack: the amount of time, in seconds, required to reduce the gain by 10 dB.
  • release: the amount of time, in seconds, required to increase the gain by 10 dB.

# dup1

dup1 :: forall ch. Pos ch => AudioUnit D1 -> (AudioUnit D1 -> AudioUnit ch) -> AudioUnit ch

Duplicate a mono sound.

Equivalent to creating a sound twice, but more memory efficient in that it avoids duplication.

# dup2

dup2 :: forall ch. Pos ch => AudioUnit D2 -> (AudioUnit D2 -> AudioUnit ch) -> AudioUnit ch

Duplicate a stereo sound.

Equivalent to creating a sound twice, but more memory efficient in that it avoids duplication.

# dup3

dup3 :: forall ch. Pos ch => AudioUnit D3 -> (AudioUnit D3 -> AudioUnit ch) -> AudioUnit ch

Duplicate a three-channel sound

# dup4

dup4 :: forall ch. Pos ch => AudioUnit D4 -> (AudioUnit D4 -> AudioUnit ch) -> AudioUnit ch

Duplicate a four-channel sound

# dup5

dup5 :: forall ch. Pos ch => AudioUnit D5 -> (AudioUnit D5 -> AudioUnit ch) -> AudioUnit ch

Duplicate a five-channel sound

# waveShaper

waveShaper :: forall ch. Pos ch => String -> Oversample -> AudioUnit ch -> AudioUnit ch

A wave shaper. Used to create distortion/overdrive.

  • s: A unique identifier for the float array with the wave shape. This should match an identifier passed to runInBrowser.
  • o: An oversampling factor (None TwoX FourX)

# decodeAudioDataFromUri

decodeAudioDataFromUri :: AudioContext -> String -> Effect (Promise BrowserAudioBuffer)

# periodicOsc

periodicOsc :: String -> Number -> AudioUnit D1

A periodic oscillator. Used to create an oscillator based on complex numbers that describe the overtones. See PeriodicWave(opens new window) for more information

  • s: A unique identifier for the periodic wave to use. This should match an identifier passed to runInBrowser.
  • f: The fundamental frequency

# sinOsc

sinOsc :: Number -> AudioUnit D1

A sine wave oscillator.

  • f: The fundamental frequency

# sawtoothOsc

sawtoothOsc :: Number -> AudioUnit D1

A sawtooth oscillator.

  • f: The fundamental frequency

# traingleOsc

traingleOsc :: Number -> AudioUnit D1

A triangle oscillator.

  • f: The fundamental frequency

# squareOsc

squareOsc :: Number -> AudioUnit D1

A square oscillator.

  • f: The fundamental frequency

# split1

split1 :: forall ch. Pos ch => AudioUnit D1 -> (Vec D1 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

A splitter for a mono sound. Effectively a no-op, same as dup1.

# split2

split2 :: forall ch. Pos ch => AudioUnit D2 -> (Vec D2 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

A splitter for a stereo sound.

# split3

split3 :: forall ch. Pos ch => AudioUnit D3 -> (Vec D3 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

A splitter for a three-channel sound.

# split4

split4 :: forall ch. Pos ch => AudioUnit D4 -> (Vec D4 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

A splitter for a four-channel sound.

# split5

split5 :: forall ch. Pos ch => AudioUnit D5 -> (Vec D5 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

A splitter for a five-channel sound.

# panner

panner :: Number -> AudioUnit D2 -> AudioUnit D2

A stereo panner.

n: The place in the stero field to place the sound. -1.0 is all the way left, 1.0 is all the way right.

# mul

mul :: forall ch. Pos ch => NonEmpty List (AudioUnit ch) -> AudioUnit ch

Multiply signals

# add

add :: forall ch. Pos ch => NonEmpty List (AudioUnit ch) -> AudioUnit ch

Add several signals.

# merger

merger :: forall ch. Pos ch => Vec ch (AudioUnit D1) -> AudioUnit ch

A merger of mono audio channels.

Accepts a vector of mono audio and produces the merged result.

# constant

constant :: Number -> AudioUnit D1

A constant signal.

  • n : The constant number.

# delay

delay :: forall ch. Pos ch => Number -> AudioUnit ch -> AudioUnit ch

A delayed signal.

  • n : The number of seconds to delay.

# gain

gain :: forall ch. Pos ch => Number -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

A volume control.

  • n : The amount of volume attenuation or augmentation. 0.0 is off, 1.0 is unit. The same as mul.

# speaker_

speaker_ :: forall ch. Pos ch => String -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# microphone_

microphone_ :: String -> AudioUnit D1

# audioWorkletGenerator_

audioWorkletGenerator_ :: forall ch. Pos ch => String -> String -> Object Number -> AudioUnit ch

# audioWorkletProcessor_

audioWorkletProcessor_ :: forall ch. Pos ch => String -> String -> Object Number -> AudioUnit ch -> AudioUnit ch

# play_

play_ :: forall ch. Pos ch => String -> String -> AudioUnit ch

# playBuf_

playBuf_ :: forall ch. Pos ch => String -> String -> Number -> AudioUnit ch

# loopBuf_

loopBuf_ :: forall ch. Pos ch => String -> String -> Number -> Number -> Number -> AudioUnit ch

# lowpass_

lowpass_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# highpass_

highpass_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# bandpass_

bandpass_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# lowshelf_

lowshelf_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# highshelf_

highshelf_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# peaking_

peaking_ :: forall ch. Pos ch => String -> Number -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# notch_

notch_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# allpass_

allpass_ :: forall ch. Pos ch => String -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# convolver_

convolver_ :: forall ch. Pos ch => String -> String -> AudioUnit ch -> AudioUnit ch

# dynamicsCompressor_

dynamicsCompressor_ :: forall ch. Pos ch => String -> Number -> Number -> Number -> Number -> Number -> AudioUnit ch -> AudioUnit ch

# dup1_

dup1_ :: forall ch. Pos ch => String -> AudioUnit D1 -> (AudioUnit D1 -> AudioUnit ch) -> AudioUnit ch

# dup2_

dup2_ :: forall ch. Pos ch => String -> AudioUnit D2 -> (AudioUnit D2 -> AudioUnit ch) -> AudioUnit ch

# dup3_

dup3_ :: forall ch. Pos ch => String -> AudioUnit D3 -> (AudioUnit D3 -> AudioUnit ch) -> AudioUnit ch

# dup4_

dup4_ :: forall ch. Pos ch => String -> AudioUnit D4 -> (AudioUnit D4 -> AudioUnit ch) -> AudioUnit ch

# dup5_

dup5_ :: forall ch. Pos ch => String -> AudioUnit D5 -> (AudioUnit D5 -> AudioUnit ch) -> AudioUnit ch

# waveShaper_

waveShaper_ :: forall ch. Pos ch => String -> String -> Oversample -> AudioUnit ch -> AudioUnit ch

# periodicOsc_

periodicOsc_ :: String -> String -> Number -> AudioUnit D1

# sinOsc_

sinOsc_ :: String -> Number -> AudioUnit D1

# sawtoothOsc_

sawtoothOsc_ :: String -> Number -> AudioUnit D1

# traingleOsc_

traingleOsc_ :: String -> Number -> AudioUnit D1

# squareOsc_

squareOsc_ :: String -> Number -> AudioUnit D1

# split1_

split1_ :: forall ch. Pos ch => String -> AudioUnit D1 -> (Vec D1 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

# split2_

split2_ :: forall ch. Pos ch => String -> AudioUnit D2 -> (Vec D2 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

# split3_

split3_ :: forall ch. Pos ch => String -> AudioUnit D3 -> (Vec D3 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

# split4_

split4_ :: forall ch. Pos ch => String -> AudioUnit D4 -> (Vec D4 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

# split5_

split5_ :: forall ch. Pos ch => String -> AudioUnit D5 -> (Vec D5 (AudioUnit D1) -> AudioUnit ch) -> AudioUnit ch

# panner_

panner_ :: String -> Number -> AudioUnit D2 -> AudioUnit D2

# mul_

mul_ :: forall ch. Pos ch => String -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# add_

add_ :: forall ch. Pos ch => String -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# merger_

merger_ :: forall ch. Pos ch => String -> Vec ch (AudioUnit D1) -> AudioUnit ch

# constant_

constant_ :: String -> Number -> AudioUnit D1

# delay_

delay_ :: forall ch. Pos ch => String -> Number -> AudioUnit ch -> AudioUnit ch

# gain_

gain_ :: forall ch. Pos ch => String -> Number -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# audioWorkletGeneratorT

audioWorkletGeneratorT :: forall ch. Pos ch => String -> Object (AudioParameter Number) -> AudioUnit ch

# audioWorkletProcessorT

audioWorkletProcessorT :: forall ch. Pos ch => String -> Object (AudioParameter Number) -> AudioUnit ch -> AudioUnit ch

# playBufT

playBufT :: forall ch. Pos ch => String -> AudioParameter Number -> AudioUnit ch

# loopBufT

loopBufT :: forall ch. Pos ch => String -> AudioParameter Number -> Number -> Number -> AudioUnit ch

# lowpassT

lowpassT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# highpassT

highpassT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# bandpassT

bandpassT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# lowshelfT

lowshelfT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# highshelfT

highshelfT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# peakingT

peakingT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# notchT

notchT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# allpassT

allpassT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# dynamicsCompressorT

dynamicsCompressorT :: forall ch. Pos ch => AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# periodicOscT

periodicOscT :: String -> AudioParameter Number -> AudioUnit D1

# sinOscT

sinOscT :: AudioParameter Number -> AudioUnit D1

# sawtoothOscT

sawtoothOscT :: AudioParameter Number -> AudioUnit D1

# traingleOscT

traingleOscT :: AudioParameter Number -> AudioUnit D1

# squareOscT

squareOscT :: AudioParameter Number -> AudioUnit D1

# pannerT

pannerT :: AudioParameter Number -> AudioUnit D2 -> AudioUnit D2

# constantT

constantT :: AudioParameter Number -> AudioUnit D1

# delayT

delayT :: forall ch. Pos ch => AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# gainT

gainT :: forall ch. Pos ch => AudioParameter Number -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# audioWorkletGeneratorT_

audioWorkletGeneratorT_ :: forall ch. Pos ch => String -> String -> Object (AudioParameter Number) -> AudioUnit ch

# audioWorkletProcessorT_

audioWorkletProcessorT_ :: forall ch. Pos ch => String -> String -> Object (AudioParameter Number) -> AudioUnit ch -> AudioUnit ch

# playBufT_

playBufT_ :: forall ch. Pos ch => String -> String -> AudioParameter Number -> AudioUnit ch

# loopBufT_

loopBufT_ :: forall ch. Pos ch => String -> String -> AudioParameter Number -> Number -> Number -> AudioUnit ch

# lowpassT_

lowpassT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# highpassT_

highpassT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# bandpassT_

bandpassT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# lowshelfT_

lowshelfT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# highshelfT_

highshelfT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# peakingT_

peakingT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# notchT_

notchT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# allpassT_

allpassT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# dynamicsCompressorT_

dynamicsCompressorT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# periodicOscT_

periodicOscT_ :: String -> String -> AudioParameter Number -> AudioUnit D1

# sinOscT_

sinOscT_ :: String -> AudioParameter Number -> AudioUnit D1

# sawtoothOscT_

sawtoothOscT_ :: String -> AudioParameter Number -> AudioUnit D1

# traingleOscT_

traingleOscT_ :: String -> AudioParameter Number -> AudioUnit D1

# squareOscT_

squareOscT_ :: String -> AudioParameter Number -> AudioUnit D1

# pannerT_

pannerT_ :: String -> AudioParameter Number -> AudioUnit D2 -> AudioUnit D2

# constantT_

constantT_ :: String -> AudioParameter Number -> AudioUnit D1

# delayT_

delayT_ :: forall ch. Pos ch => String -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# gainT_

gainT_ :: forall ch. Pos ch => String -> AudioParameter Number -> NonEmpty List (AudioUnit ch) -> AudioUnit ch

# speaker'

speaker' :: forall ch. Pos ch => AudioUnit ch -> AudioUnit ch

# gain'

gain' :: forall ch. Pos ch => Number -> AudioUnit ch -> AudioUnit ch

A variant of gain that accepts a single audio unit instead of a non-empty list.

# gainT'

gainT' :: forall ch. Pos ch => AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# gain_'

gain_' :: forall ch. Pos ch => String -> Number -> AudioUnit ch -> AudioUnit ch

# gainT_'

gainT_' :: forall ch. Pos ch => String -> AudioParameter Number -> AudioUnit ch -> AudioUnit ch

# AudioParameter

newtype AudioParameter a
  = AudioParameter { param :: a, timeOffset :: Number }