new WebAudioAPI()
Returns a singleton instance of the WebAudioAPI interface.
Classes
Methods
-
analyzeAudio(analysisType, opt trackName) → {Any}
-
Analyzes the current realtime audio output according to the specified
analysisType.The
trackNameparameter is optional, and if left blank, will cause the analysis to be carried out on the aggregate output over all tracks and all applied effects.The type of return value from this function will depend on the analysis being carried out and can be determined by examining the corresponding concrete definitions of the AnalysisBase interface.
Parameters:
Name Type Attributes Description analysisTypenumber Audio AnalysisType to execute
trackNamestring <optional>
Name of the track whose audio should be analyzed
Returns:
Any -Result of the specified analysis
- See:
-
async applyMasterEffect(effectName, effectType)
-
Applies a new master effect to the aggregate output from all tracks at the specified time.
Calling this function affects the sequential ordering in which master effects will be processed, with each new call appending the corresponding effect to the end of the processing sequence.
The parameters of the added effect will be set to their default values such that the result of adding the effect will not be audible. In order to manipulate and utilize this effect, use the updateMasterEffect() function.
If a master effect with the specified
effectNamehas already been applied, then calling this function will simply re-order the effect to move it to the very end of the effect processing sequence, without changing its parameter values.Parameters:
Name Type Description effectNamestring User-defined name to associate with the master effect
effectTypenumber Master EffectType to apply
- See:
-
async applyTrackEffect(trackName, effectName, effectType)
-
Applies a new effect to the specified track at the specified time.
Calling this function affects the sequential ordering in which effects will be processed within the specified track, with each new call appending the corresponding effect to the end of the processing sequence.
The parameters of the added effect will be set to their default values such that the result of adding the effect will not be audible. In order to manipulate and utilize this effect, use the updateTrackEffect() function.
If an effect with the specified
effectNamehas already been applied to the specified track, then calling this function will simply re-order the effect to move it to the very end of the effect processing sequence, without changing its parameter values.Parameters:
Name Type Description trackNamestring Name of the track on which to apply the effect
effectNamestring User-defined name to associate with the track effect
effectTypenumber Track-specific EffectType to apply
- See:
-
clearAllTracks()
-
Cancels all current and scheduled audio from playing on all existing tracks.
-
clearTrack(name)
-
Cancels all current and scheduled audio from playing on the specified track.
Parameters:
Name Type Description namestring Name of the track to clear
-
async connectAudioInputDeviceToTrack(trackName, audioInputDeviceName)
-
Connects an audio input device to the specified audio track.
Note: A single audio input device can be connected to multiple audio tracks, but an audio track can only be connected to a single audio input device.
Parameters:
Name Type Description trackNamestring Name of the track to which to connect the audio input device
audioInputDeviceNamestring Name of the audio input device to connect to the track
-
async connectMidiDeviceToTrack(trackName, midiDeviceName)
-
Connects a MIDI device to the specified audio track.
Note: A single MIDI device can be connected to multiple audio tracks, but an audio track can only be connected to a single MIDI device.
Parameters:
Name Type Description trackNamestring Name of the track to which to connect the MIDI device
midiDeviceNamestring Name of the MIDI device to connect to the track
-
convertNoteDurationToSeconds(duration) → {number}
-
Parameters:
Name Type Description durationnumber Note Duration to convert to seconds
Returns:
number -Number of seconds corresponding to the specified
durationat current Tempo settings -
convertSecondsToNoteDuration(seconds) → {number}
-
Converts a number of seconds into the nearest corresponding note Duration given the current Tempo settings.
Parameters:
Name Type Description secondsnumber Number of seconds to convert to a note Duration
-
createAudioBufferFromSamples(sampleRate, samples) → {AudioBuffer}
-
Converts a 2D array of floating point
samplesinto an AudioBuffer object with the specifiedsampleRate.Parameters:
Name Type Description sampleRatenumber Sample rate at which the audio data was recorded
samplesArray.<Array.<number>> 2D array of floating point audio samples to encode
Returns:
AudioBuffer -Newly created AudioBuffer containing the audio data
- See:
-
createTrack(name)
-
Creates a track capable of playing sequential audio. A single track can only utilize a single instrument at a time.
Parameters:
Name Type Description namestring Name of the newly created track
-
async decodeAudioClip(audioClip) → {AudioBuffer}
-
Decodes an ArrayBuffer containing an audio clip into an AudioBuffer object.
Parameters:
Name Type Description audioClipArrayBuffer | Blob Array buffer or blob containing the audio clip to decode
Returns:
AudioBuffer -Decoded audio buffer for the specified audio clip
- See:
-
deregisterMidiDeviceCallback(midiDeviceName)
-
Removes a user-registered callback from the specified MIDI device so that it will no longer fire upon reception of a MIDI event.
Parameters:
Name Type Description midiDeviceNamestring Name of the MIDI device for which to stop receiving events
-
async disconnectAudioInputDeviceFromTrack(trackName)
-
Disconnects all audio input devices from the specified audio track.
Parameters:
Name Type Description trackNamestring Name of the track from which to disconnect the audio input devices
-
async disconnectMidiDeviceFromTrack(trackName)
-
Disconnects all MIDI devices from the specified audio track.
Parameters:
Name Type Description trackNamestring Name of the track from which to disconnect the MIDI devices
-
async encodeAudioAs(encodingType, sampleRate, samples) → {Blob}
-
Encodes a 2D array of floating point
samplesinto a Blob containing raw audio data according to the specifiedsampleRateand EncodingType specified in theencodingTypeparameter.Parameters:
Name Type Description encodingTypenumber Numeric value corresponding to the desired EncodingType
sampleRatenumber Sample rate at which the audio data was recorded
samplesArray.<Array.<number>> 2D array of floating point audio samples to encode
- See:
-
getAvailableAnalysisTypes() → {Object.<string, number>}
-
Returns a listing of all available audio analysis types in the WebAudioAPI library.
This function can be used to enumerate available analysis options for displaying on a web page.
Returns:
Object.<string, number> -Listing of all available audio analysis types in the WebAudioAPI library
- See:
-
async getAvailableAudioInputDevices() → {Promise.<Array.<string>>}
-
Returns a listing of the available audio input devices connected to the client device.
Individual results from this function call can be passed directly to the connectAudioInputDeviceToTrack() function to attach an input device to a specified audio track.
Returns:
Promise.<Array.<string>> -Listing of all available audio input devices connected to the client
-
async getAvailableAudioOutputDevices() → {Promise.<Array.<string>>}
-
Returns a listing of the available audio output devices connected to the client device.
Individual results from this function call can be passed directly to the selectAudioOutputDevice() function to choose where to direct all audio output.
Returns:
Promise.<Array.<string>> -Listing of all available audio output devices connected to the client
-
getAvailableEffectParameters(effectType) → {Array.<EffectParameter>}
-
Returns a list of effect-specific EffectParameters for manipulation in the
effectOptionsparameter of the updateMasterEffect() or the updateTrackEffect() function.This function can be used to enumerate available effect parameters for displaying on a web page. Note, however, that the
effectTypeparameter must be the numeric value associated with a certain EffectType, not a string-based key.Parameters:
Name Type Description effectTypenumber The EffectType for which to return a parameter list
-
getAvailableEffects() → {Object.<string, number>}
-
Returns a listing of all available effects in the WebAudioAPI library.
This function can be used to enumerate available effect options for displaying on a web page. Note, however, that the
effectTypeparameter passed to either the applyMasterEffect() or the applyTrackEffect() function must be the numeric value associated with a certain EffectType, not a string-based key.- See:
-
getAvailableEncoders() → {Object.<string, number>}
-
Returns a listing of all available encoders in the WebAudioAPI library.
This function can be used to enumerate available encoding options for displaying on a web page.
Returns:
Object.<string, number> -Listing of all available encoding types in the WebAudioAPI library
- See:
-
async getAvailableInstruments(instrumentLibraryLocation) → {Promise.<Array.<string>>}
-
Returns a listing of the available instruments located in the specified asset library.
Individual results from this function call can be passed directly to the updateInstrument() function to load a specific instrument into an audio track.
Parameters:
Name Type Description instrumentLibraryLocationstring Absolute or relative URL pointing to a WebAudioAPI instrument library
Returns:
Promise.<Array.<string>> -Listing of all available instrument names
-
getAvailableKeySignatures() → {Object.<string, number>}
-
Returns a full listing of recognized key signatures by the WebAudioAPI library.
This function can be used to enumerate available key signatures for displaying on a web page. Note, however, that the
keySignatureparameter passed to the updateKeySignature() function must be the location of the desired key on the circle of fifths associated with a certain KeySignature, not a string-based key signature.- See:
-
async getAvailableMidiDevices() → {Promise.<Array.<string>>}
-
Returns a listing of the available MIDI devices connected to the client device.
Individual results from this function call can be passed directly to the connectMidiDeviceToTrack() function to attach a MIDI device to a specified audio track.
Returns:
Promise.<Array.<string>> -Listing of all available MIDI devices connected to the client device
-
getAvailableModificationParameters(modificationType) → {Object.<string, Object.<string, Array.<string>>>}
-
Returns a list of modification-specific parameters for use in the
modificationOptionsparameter of the getModification() function or an empty list if the specified modification does not require any parameters.This function can be used to enumerate available modification parameters for displaying on a web page. Note, however, that the
modificationTypeparameter must be the numeric value associated with a certain ModificationType, not a string-based key.The object returned from this function will contain 2 keys: 'required' and 'optional'. These keys can be used to access sub-objects with 2 keys: 'singleNote' and 'sequence'. These keys hold arrays containing the string-based names of parameters that are available for manipulation within the given modification.
Parameter values within the "sequence" array indicate parameters that have meaning when used with the playSequence() function. Parameter values within the "singleNote" array indicate parameters that have meaning when used with the playNote() function.
Parameters:
Name Type Description modificationTypenumber The ModificationType for which to return a parameter list
Returns:
Object.<string, Object.<string, Array.<string>>> -List of modification-specific parameter keys and when they are required
- See:
-
getAvailableNoteDurations() → {Object.<string, number>}
-
Returns a full listing of recognized note durations by the WebAudioAPI library.
This function can be used to enumerate available duration options for displaying on a web page. Note, however, that the
durationparameter passed to the playNote() function must be the numeric value associated with a certain Duration, not a string-based key.- See:
-
getAvailableNoteModifications() → {Object.<string, number>}
-
Returns a listing of all available note modifications in the WebAudioAPI library.
This function can be used to enumerate available note modification options for displaying on a web page. Note, however, that the modification
typeparameter passed to the getModification() function must include the numeric value associated with a certain ModificationType, not a string-based key.Returns:
Object.<string, number> -Listing of all available note modifications in the WebAudioAPI library
- See:
-
getAvailableNotes() → {Object.<string, number>}
-
Returns a full listing of recognized musical notes by the WebAudioAPI library.
This function can be used to enumerate available note options for displaying on a web page. Note, however, that the
noteparameter passed to the playNote() function must be the numeric MIDI value associated with a certain Note, not a string-based key.- See:
-
getCurrentMasterEffectParameters(effectName) → {Object}
-
Returns the current parameter settings for the specified master effect.
Parameters:
Name Type Description effectNamestring Name of the master effect for which to retrieve current settings
Returns:
Object -Effect-specific parameter values with keys as returned by getAvailableEffectParameters()
-
getCurrentTime() → {number}
-
Returns the current global time since the WebAudioAPI library was started or resumed using the start() function.
-
getCurrentTrackEffectParameters(trackName, effectName) → {Object}
-
Returns the current parameter settings for a track-specific effect.
Parameters:
Name Type Description trackNamestring Name of the track for which to retrieve current effect settings
effectNamestring Name of the track effect for which to retrieve current settings
Returns:
Object -Effect-specific parameter values with keys as returned by getAvailableEffectParameters()
-
getKeySignature() → {Key}
-
Returns the current global Key parameters for all audio tracks.
-
getModification(modificationType, opt modificationOptions) → {ModificationDetails}
-
Returns a properly formatted structure containing the relevant musical modification and parameters passed into this function.
Note that the
modificationOptionsparameter should normally be either omitted/undefined or anObjectcontaining the required keys as returned by the getAvailableModificationParameters() function; however, if there is only one required key, you may simply pass a numerical value tomodificationOptionsinstead of explicitly enumerating an Object with the single required key.Parameters:
Name Type Attributes Description modificationTypenumber Number corresponding to the ModificationType to generate
modificationOptionsObject | number <optional>
Potential modification-specific options as returned by getAvailableModificationParameters()
Returns:
ModificationDetails -A structure containing the relevant musical modification details passed into this function
- See:
-
getTempo() → {Tempo}
-
Returns the current global Tempo parameters for all audio tracks.
-
getVersion() → {string}
-
Returns the current WebAudioAPI library version number.
Returns:
string -Current library version number
-
async playChord(trackName, chord, startTime, opt modifications, opt areDrumNotes) → {Promise.<number>}
-
Schedules a chord of notes to be played on a specific track.
Note that the
chordparameter should be an array of[note, duration, mods]tuples, where thenoteparameter should correspond to a valid MIDI note number, thedurationparameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(), andmodsmay either be a single modification to the chord, a list of modifications, or omitted completely.The
modificationsparameter is optional, and if included, may either be a single ModificationDetails structure or a list of such structures. This structure should be obtained from the getModification() function.Parameters:
Name Type Attributes Default Description trackNamestring Name of the track on which to play the note
chordArray.<Array> Array of
[note, duration, mods]corresponding to the chord to be playedstartTimenumber Global API time at which to start playing the chord
modificationsArray.<ModificationDetails> <optional>
Optional individual or list of modifications to apply to the chord
areDrumNotesboolean <optional>
false Optional flag indicating whether this chord contains only drum notes (i.e., not affected by key or duration)
Returns:
Promise.<number> -Duration (in seconds) of the chord being played
-
async playClip(trackName, audioClip, startTime, opt duration) → {Promise.<number>}
-
Schedules an audio clip to be played on a specific track for some duration of time.
The format of the audio clip in the
audioClipparameter may be a data buffer containing raw audio-encoded data (such as from a WAV file), a blob containing audio-encoded data, an already-decoded audio buffer, or a MidiClip or AudioClip that was recorded using this library.If the
durationparameter is not specified or is set tonull, the audio clip will play to completion.Parameters:
Name Type Attributes Description trackNamestring Name of the track on which to play the clip
audioClipArrayBuffer | AudioBuffer | Blob | MidiClip | AudioClip Object containing audio data to play
startTimenumber Global API time at which to start playing the clip
durationnumber <optional>
Number of seconds for which to continue playing the clip
Returns:
Promise.<number> -Duration (in seconds) of the clip being played
- See:
-
async playFile(trackName, fileURL, startTime, opt duration) → {Promise.<number>}
-
Schedules an audio file to be played on a specific track for some duration of time.
If the
durationparameter is not specified or is set tonull, the audio file will play to completion.Parameters:
Name Type Attributes Description trackNamestring Name of the track on which to play the file
fileURLstring URL location pointing to an audio file
startTimestring Global API time at which to start playing the file
durationnumber <optional>
Number of seconds for which to continue playing the file
Returns:
Promise.<number> -Duration (in seconds) of the file being played
-
async playNote(trackName, note, startTime, duration, opt modifications, opt isDrumNote) → {Promise.<number>}
-
Schedules a note to be played on a specific track for some duration of time.
Note that the
durationparameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(). Likewise, thenoteparameter should correspond to a MIDI note number as associated with one of the notes returned from getAvailableNotes().The
modificationsparameter is optional, and if included, may either be a single ModificationDetails structure or a list of such structures. This structure should be obtained from the getModification() function.Parameters:
Name Type Attributes Default Description trackNamestring Name of the track on which to play the note
notenumber MIDI Note number to be played
startTimenumber Global API time at which to start playing the note
durationnumber Duration for which to continue playing the note
modificationsModificationDetails | Array.<ModificationDetails> <optional>
Optional individual or list of modifications to apply to the note
isDrumNoteboolean <optional>
false Optional flag indicating whether this note is a drum note (i.e., not affected by key or duration)
Returns:
Promise.<number> -Duration (in seconds) of the note being played
-
async playSequence(trackName, sequence, startTime, opt modifications, opt areDrumNotes) → {Promise.<number>}
-
Schedules a musical sequence to be played on a specific track.
Note that the
sequenceparameter should be an array containing either chords (as defined in the playChord() function) or[note, duration, mods]tuples, where thenoteparameter should correspond to a valid MIDI note number, thedurationparameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations(), andmodsmay either be a single modification that affects the whole sequence, a list of modifications, or omitted completely.The
modificationsparameter is optional, and if included, may either be a single ModificationDetails structure or a list of such structures. This structure should be obtained from the getModification() function.Parameters:
Name Type Attributes Default Description trackNamestring Name of the track on which to play the note
sequenceArray.<(Array|Array.<Array>)> Array of
[note, duration, mods]and/or chords corresponding to the sequence to be playedstartTimenumber Global API time at which to start playing the sequence
modificationsArray.<ModificationDetails> <optional>
Optional individual or list of modifications to apply to the sequence
areDrumNotesboolean <optional>
false Optional flag indicating whether this sequence contains only drum notes (i.e., not affected by key or duration)
Returns:
Promise.<number> -Duration (in seconds) of the sequence being played
-
recordAudioClip(trackName, startTime, opt duration) → {AudioClip}
-
Schedules an audio clip to be recorded on a specific track for some duration of time.
If the
durationparameter is not specified or is set tonull, the audio clip will continue to record until manually stopped by the finalize() function on the returned AudioClip object.Note that the recorded audio clip will not include any effects that might exist on the target track. This is so that recording on an effect-modified track and then immediately playing back on the same track will not cause the effects to be doubled.
Parameters:
Name Type Attributes Description trackNamestring Name of the track on which to record the audio clip
startTimenumber Global API time at which to start recording the audio clip
durationnumber <optional>
Number of seconds for which to continue recording the audio clip
- See:
-
recordMidiClip(trackName, startTime, opt duration) → {MidiClip}
-
Schedules a MIDI clip to be recorded on a specific track for some duration of time.
If the
durationparameter is not specified or is set tonull, the MIDI clip will continue to record until manually stopped by the finalize() function on the returned MidiClip object.Note that the recorded MIDI clip will not include any effects that might exist on the target track. This is so that recording on an effect-modified track and then immediately playing back on the same track will not cause the effects to be doubled.
Parameters:
Name Type Attributes Description trackNamestring Name of the track on which to record the MIDI clip
startTimenumber Global API time at which to start recording the MIDI clip
durationnumber <optional>
Number of seconds for which to continue recording the MIDI clip
- See:
-
recordOutput(opt trackName, opt startTime, opt duration) → {AudioRecording}
-
Schedules an audio recording to be executed on the cumulative output of the specified audio track for some duration of time.
If the
trackNameparameter is not specified or is set tonull, the audio recording will include the cumulative output of all audio tracks and effects.If the
startTimeparameter is not specified or is set tonull, the audio recording will begin immediately.If the
durationparameter is not specified or is set tonull, the audio recording will continue until manually stopped by the finalize() function on the returned AudioRecording object.Note that the recorded audio will include all existing effects.
Parameters:
Name Type Attributes Description trackNamestring <optional>
Name of the track from which to record all audio output
startTimenumber <optional>
Global API time at which to start recording the audio output
durationnumber <optional>
Number of seconds for which to continue recording the audio output
- See:
-
registerMidiDeviceCallback(midiDeviceName, midiEventCallback)
-
Registers a callback function to receive incoming events from the specified MIDI device.
The
midiEventCallbackparameter should be a function that receives one parameter of type MIDIMessageEvent.Note: A callback may be registered for a MIDI device that is also connected to an audio track; however, only one top-level event callback can be registered to a MIDI device at a time.
Parameters:
Name Type Description midiDeviceNamestring Name of the MIDI device for which to receive events
midiEventCallbackMidiEventCallback Callback to fire when a MIDI event is received
-
removeAllTracks()
-
Removes all existing audio tracks and cancels all current and scheduled audio.
-
async removeInstrument(trackName)
-
Removes the instrument used to play back audio on the specified track.
Parameters:
Name Type Description trackNamestring Name of the track from which to remove the current instrument
-
async removeMasterEffect(effectName) → {Promise.<(Effect|null)>}
-
Removes the specified master effect from being applied.
Parameters:
Name Type Description effectNamestring Name of the master effect to be removed
- See:
-
removeTrack(name)
-
Removes the specified audio track and cancels any audio scheduled for playback on this track from playing or starting to play in the future.
Parameters:
Name Type Description namestring Name of the track to remove
-
async removeTrackEffect(trackName, effectName)
-
Removes the specified effect from being applid on the corresponding track.
Parameters:
Name Type Description trackNamestring Name of the track from which to remove the effect
effectNamestring Name of the track effect to be removed
-
async selectAudioOutputDevice(audioOutputDeviceName)
-
Redirects all audio output to the specified device.
Parameters:
Name Type Description audioOutputDeviceNamestring Name of the output device to which to direct all audio
-
async start()
-
Starts the WebAudioAPI library and allows audio playback to resume.
-
async startNote(trackName, note, opt velocity) → {Promise.<Object>}
-
Immediately begins playing a note on the specified track. Playback continues until the note is explicitly stopped using the stopNote() function.
Note that the
noteparameter should correspond to a MIDI note number as associated with one of the notes returned from getAvailableNotes().Parameters:
Name Type Attributes Default Description trackNamestring Name of the track on which to start playing the note
notenumber MIDI Note number to be played
velocitynumber <optional>
0.75 Intensity of the note to play between [0.0, 1.0]
Returns:
Promise.<Object> -Reference to the newly scheduled note
- See:
-
stop()
-
Stops the WebAudioAPI library and pauses any currently playing audio.
-
async stopNote(trackName, note)
-
Immediately stop playing a note on the specified track. The note to be stopped must be a reference to an actively playing note that was previously returned from the startNote() function.
Parameters:
Name Type Description trackNamestring Name of the track on which to stop playing the note
noteObject Reference to an active note that was started using startNote()
-
async updateInstrument(trackName, instrumentName)
-
Updates the instrument used to play back audio on the specified track.
The instrument name must refer to a valid instrument as returned by the getAvailableInstruments() function.
Parameters:
Name Type Description trackNamestring Name of the track for which to update the instrument
instrumentNamestring Name of the instrument to assign to the track
-
updateKeySignature(keySignature)
-
Updates the global key signature parameters for all audio tracks.
The
keySignatureparameter should correspond to the location of the desired key on the circle of fifths as returned by the getAvailableKeySignatures() function. Alternately, you can specify the number of sharps as a positive value or the number of flats as a negative value.Parameters:
Name Type Description keySignaturenumber Numerical KeySignature indicator based on its circle of fifths position
-
async updateMasterEffect(effectName, effectOptions, opt updateTime, opt transitionLength)
-
Updates the parameters of a master effect at the specified time.
Calling this function will not affect the sequential processing order of any applied effects.
Note that the
updateTimeparameter can be omitted to immediately cause the requested changes to take effect.Parameters:
Name Type Attributes Description effectNamestring Name of the master effect to be updated
effectOptionsObject Effect-specific options as returned by getAvailableEffectParameters()
updateTimenumber <optional>
Global API time at which to update the effect
transitionLengthnumber <optional>
Number of seconds over which to update the effect
-
updateTempo(beatBase, beatsPerMinute, timeSignatureNumerator, timeSignatureDenominator)
-
Updates the global tempo parameters for all audio tracks.
The
beatBaseparameter should correspond to the beat scaling factor associated with one of the note durations from getAvailableNoteDurations().Any parameter may be set to
nullto keep it unchanged between consecutive function calls.Parameters:
Name Type Description beatBasenumber | null Note Duration corresponding to a global beat
beatsPerMinutenumber | null Number of global beats per minute
timeSignatureNumeratornumber | null Number of beats per measure
timeSignatureDenominatornumber | null Note Duration corresponding to a measure beat
-
async updateTrackEffect(trackName, effectName, effectOptions, opt updateTime, opt transitionLength)
-
Updates the parameters of a track-specific effect at the specified time.
Calling this function will not affect the sequential processing order of any applied effects.
Note that the
updateTimeparameter can be omitted to immediately cause the requested changes to take effect.Parameters:
Name Type Attributes Description trackNamestring Name of the track for which to update the effect
effectNamestring Name of the track effect to be updated
effectOptionsObject Effect-specific options as returned by getAvailableEffectParameters()
updateTimenumber <optional>
Global API time at which to update the effect
transitionLengthnumber <optional>
Number of seconds over which to update the effect