LittleJS Audio System
- ZzFX Sound Effects and ZzFXM Music
- Caches sounds and music for fast playback
- Can attenuate and apply stereo panning to sounds
- Ability to play mp3, ogg, and wave files
- Speech synthesis wrapper functions
- ZzFX Sound Effects and ZzFXM Music
- Caches sounds and music for fast playback
- Can attenuate and apply stereo panning to sounds
- Ability to play mp3, ogg, and wave files
- Speech synthesis wrapper functions
- Source:
Members
# (static) audioContext
Audio context used by the engine
- Source:
# (static, constant) zzfxR
Sample rate used for all ZzFX sounds
- Default Value:
- 44100
- Source:
Methods
# (static) getNoteFrequency(semitoneOffset, rootNoteFrequencyopt) → {Number}
Get frequency of a note on a musical scale
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
semitoneOffset |
Number | How many semitones away from the root note | ||
rootNoteFrequency |
Number |
<optional> |
220 | Frequency at semitone offset 0 |
- Source:
Returns:
- The frequency of the note
- Type
- Number
# (static) playAudioFile(url, volumeopt, loopopt) → {HTMLAudioElement}
Play an mp3 or wav audio from a local file or url
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
String | Location of sound file to play | ||
volume |
Number |
<optional> |
1 | How much to scale volume by |
loop |
Boolean |
<optional> |
1 | True if the music should loop when it reaches the end |
- Source:
Returns:
- The audio element for this sound
- Type
- HTMLAudioElement
# (static) playSamples(sampleChannels, volumeopt, rateopt, panopt, loopopt) → {AudioBufferSourceNode}
Play cached audio samples with given settings
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sampleChannels |
Array | Array of arrays of samples to play (for stereo playback) | ||
volume |
Number |
<optional> |
1 | How much to scale volume by |
rate |
Number |
<optional> |
1 | The playback rate to use |
pan |
Number |
<optional> |
0 | How much to apply stereo panning |
loop |
Boolean |
<optional> |
0 | True if the sound should loop when it reaches the end |
- Source:
Returns:
- The audio node of the sound played
- Type
- AudioBufferSourceNode
# (static) speak(text, languageopt, volumeopt, rateopt, pitchopt) → {SpeechSynthesisUtterance}
Speak text with passed in settings
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text |
String | The text to speak | ||
language |
String |
<optional> |
The language/accent to use (examples: en, it, ru, ja, zh) | |
volume |
Number |
<optional> |
1 | How much to scale volume by |
rate |
Number |
<optional> |
1 | How quickly to speak |
pitch |
Number |
<optional> |
1 | How much to change the pitch by |
- Source:
Returns:
- The utterance that was spoken
- Type
- SpeechSynthesisUtterance
# (static) stopSpeech()
Stop all queued speech
- Source:
# (static) zzfx(…zzfxSound) → {Array}
Generate and play a ZzFX sound
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
zzfxSound |
Array |
<repeatable> |
Array of ZzFX parameters, ex. [.5,.5] |
- Source:
Returns:
- Array of audio samples
- Type
- Array
# (static) zzfxG(volume)
Generate samples for a ZzFX sound
Parameters:
Name | Type | Description |
---|---|---|
volume |
- Source:
# (static) zzfxM(instruments, patterns, sequence, BPMopt) → {Array}
Generate samples for a ZzFM song with given parameters
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
instruments |
Array | Array of ZzFX sound paramaters | ||
patterns |
Array | Array of pattern data | ||
sequence |
Array | Array of pattern indexes | ||
BPM |
Number |
<optional> |
125 | Playback speed of the song in BPM |
- Source:
Returns:
- Left and right channel sample data
- Type
- Array