LittleJS Audio System
- ZzFX Sound Effects - ZzFX Sound Effect Generator
- ZzFXM Music - ZzFXM Music System
- 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 functions
- Source
Members
(static) audioContext :AudioContext
Audio context used by the engine
- AudioContext
- Source
(static, constant) zzfxR
Sample rate used for all ZzFX sounds
- Default Value
- 44100
- Source
Methods
(static) getNoteFrequency(semitoneOffset, rootFrequencyopt) → {Number}
Get frequency of a note on a musical scale
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
semitoneOffset | Number | How many semitones away from the root note | ||
rootFrequency | Number | <optional> | 220 | Frequency at semitone offset 0 |
- Source
- The frequency of the note
- Type:
- Number
(static) playAudioFile(url, volumeopt, loopopt) → {HTMLAudioElement}
Play an mp3, ogg, or wav audio from a local file or url
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> | false | True if the music should loop |
- Source
- The audio element for this sound
- Type:
- HTMLAudioElement
(static) playSamples(sampleChannels, volumeopt, rateopt, panopt, loopopt, sampleRateopt) → {AudioBufferSourceNode}
Play cached audio samples with given settings
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> | false | True if the sound should loop when it reaches the end |
sampleRate | Number | <optional> | 44100 | Sample rate for the sound |
- Source
- The audio node of the sound played
- Type:
- AudioBufferSourceNode
(static) speak(text, languageopt, volumeopt, rateopt, pitchopt) → {SpeechSynthesisUtterance}
Speak text with passed in settings
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
- The utterance that was spoken
- Type:
- SpeechSynthesisUtterance
(static) speakStop()
Stop all queued speech
- Source
(static) zzfx(…zzfxSound) → {AudioBufferSourceNode}
Generate and play a ZzFX sound
Name | Type | Attributes | Description |
---|---|---|---|
zzfxSound | Array | <repeatable> | Array of ZzFX parameters, ex. [.5,.5] |
- Source
- The audio node of the sound played
- Type:
- AudioBufferSourceNode
(static) zzfxG(volumeopt, randomnessopt, frequencyopt, attackopt, sustainopt, releaseopt, shapeopt, shapeCurveopt, slideopt, deltaSlideopt, pitchJumpopt, pitchJumpTimeopt, repeatTimeopt, noiseopt, modulationopt, bitCrushopt, delayopt, sustainVolumeopt, decayopt, tremoloopt, filteropt) → {Array}
Generate samples for a ZzFX sound
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
volume | Number | <optional> | 1 | Volume scale (percent) |
randomness | Number | <optional> | 0.05 | How much to randomize frequency (percent Hz) |
frequency | Number | <optional> | 220 | Frequency of sound (Hz) |
attack | Number | <optional> | 0 | Attack time, how fast sound starts (seconds) |
sustain | Number | <optional> | 0 | Sustain time, how long sound holds (seconds) |
release | Number | <optional> | 0.1 | Release time, how fast sound fades out (seconds) |
shape | Number | <optional> | 0 | Shape of the sound wave |
shapeCurve | Number | <optional> | 1 | Squarenes of wave (0=square, 1=normal, 2=pointy) |
slide | Number | <optional> | 0 | How much to slide frequency (kHz/s) |
deltaSlide | Number | <optional> | 0 | How much to change slide (kHz/s/s) |
pitchJump | Number | <optional> | 0 | Frequency of pitch jump (Hz) |
pitchJumpTime | Number | <optional> | 0 | Time of pitch jump (seconds) |
repeatTime | Number | <optional> | 0 | Resets some parameters periodically (seconds) |
noise | Number | <optional> | 0 | How much random noise to add (percent) |
modulation | Number | <optional> | 0 | Frequency of modulation wave, negative flips phase (Hz) |
bitCrush | Number | <optional> | 0 | Resamples at a lower frequency in (samples*100) |
delay | Number | <optional> | 0 | Overlap sound with itself for reverb and flanger effects (seconds) |
sustainVolume | Number | <optional> | 1 | Volume level for sustain (percent) |
decay | Number | <optional> | 0 | Decay time, how long to reach sustain after attack (seconds) |
tremolo | Number | <optional> | 0 | Trembling effect, rate controlled by repeat time (precent) |
filter | Number | <optional> | 0 | Filter cutoff frequency, positive for HPF, negative for LPF (Hz) |
- Source
- Array of audio samples
- Type:
- Array
(static) zzfxM(instruments, patterns, sequence, BPMopt) → {Array}
Generate samples for a ZzFM song with given 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
- Left and right channel sample data
- Type:
- Array