load

This module contains some functions to fetch and decode audio files.

Source:

Methods

(static) decodeAudio(context, array) → {Promise.<AudioBuffer>}

Decode an array buffer into an AudioBuffer.

Parameters:
Name Type Description
context AudioContext

(Optional) the context to be used (can be null to use synth-kit's default audio context)

array Array

(Optional) the array to be decoded. If not given, it returns a function that decodes the buffer so it can be chained with fetch function (see example)

Source:
Returns:

a promise that resolves to an audio buffer

Type
Promise.<AudioBuffer>
Example
fecth('sound.mp3').then(decodeAudio())

(static) fetch(url, type) → {Promise}

Fetch an url and return a promise

Parameters:
Name Type Description
url String

the url

type String

can be 'text' or 'arraybuffer'

Source:
Returns:

a promise to the result

Type
Promise

(static) load(url, options) → {Promise.<AudioBuffer>}

Load a remote audio file and return a promise.

Parameters:
Name Type Description
url String
options Object

(Optional) may include:

  • context: the audio context
Source:
Returns:

a promise that resolves to an AudioBuffer

Type
Promise.<AudioBuffer>
Example
load('sound.mp3').then(function (buffer) {
  sample(buffer, true).start()
}