@knopkem/little-game-engine-ts
Version:
LittleGameEngineTS - Tiny and Fast HTML5 Game Engine typescript port of LittleJS
106 lines (105 loc) • 6.22 kB
TypeScript
/**
* LittleJS Audio System
* <br> - ZzFX Sound Effects and ZzFXM Music
* <br> - Caches sounds and music for fast playback
* <br> - Can attenuate and apply stereo panning to sounds
* <br> - Ability to play mp3, ogg, and wave files
* <br> - Speech synthesis wrapper functions
* @namespace Audio
*/
/** Sound Object - Stores a zzfx sound for later use and can be played positionally */
export declare class Sound {
cachedSamples: any;
randomness: any;
range: any;
taper: any;
/** Create a sound object and cache the zzfx samples for later use
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
* @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
*/
constructor(zzfxSound: any, range?: number, taper?: number);
/** Play the sound
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
* @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
* @param {Number} [randomnessScale=1] - How much to scale randomness
* @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
*/
play(pos: any, volume?: number, pitch?: number, randomnessScale?: number): any;
/** Play the sound as a note with a semitone offset
* @param {Number} semitoneOffset - How many semitones to offset pitch
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
* @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
*/
playNote(semitoneOffset: any, pos: any, volume?: number): any;
}
/** Music Object - Stores a zzfx music track for later use */
export declare class Music {
cachedSamples: any;
/** Create a music object and cache the zzfx music samples for later use
* @param {Array} zzfxMusic - Array of zzfx music parameters
*/
constructor(zzfxMusic: any);
/** Play the music
* @param {Number} [volume=1] - How much to scale volume by
* @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
* @return {AudioBufferSourceNode} - The audio node, can be used to stop sound later
*/
play(volume?: number, loop?: number): any;
}
/** Play an mp3 or wav audio from a local file or url
* @param {String} url - Location of sound file to play
* @param {Number} [volume=1] - How much to scale volume by
* @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
* @return {HTMLAudioElement} - The audio element for this sound
* @memberof Audio */
export declare function playAudioFile(url: any, volume?: number, loop?: boolean): HTMLAudioElement | undefined;
/** Speak text with passed in settings
* @param {String} text - The text to speak
* @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
* @param {Number} [volume=1] - How much to scale volume by
* @param {Number} [rate=1] - How quickly to speak
* @param {Number} [pitch=1] - How much to change the pitch by
* @return {SpeechSynthesisUtterance} - The utterance that was spoken
* @memberof Audio */
export declare function speak(text: any, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance | undefined;
/** Stop all queued speech
* @memberof Audio */
export declare const stopSpeech: () => void;
/** Get frequency of a note on a musical scale
* @param {Number} semitoneOffset - How many semitones away from the root note
* @param {Number} [rootNoteFrequency=220] - Frequency at semitone offset 0
* @return {Number} - The frequency of the note
* @memberof Audio */
export declare const getNoteFrequency: (semitoneOffset: any, rootFrequency?: number) => number;
/** Play cached audio samples with given settings
* @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
* @param {Number} [volume=1] - How much to scale volume by
* @param {Number} [rate=1] - The playback rate to use
* @param {Number} [pan=0] - How much to apply stereo panning
* @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
* @return {AudioBufferSourceNode} - The audio node of the sound played
* @memberof Audio */
export declare function playSamples(sampleChannels: any, volume?: number, rate?: number, pan?: number, loop?: number): any;
/** Generate and play a ZzFX sound
* @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
* @return {Array} - Array of audio samples
* @memberof Audio */
export declare const zzfx: (...zzfxSound: any[]) => any;
/** Sample rate used for all ZzFX sounds
* @default 44100
* @memberof Audio */
export declare const zzfxR = 44100;
/** Generate samples for a ZzFX sound
* @memberof Audio */
export declare function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number): number[];
/** Generate samples for a ZzFM song with given parameters
* @param {Array} instruments - Array of ZzFX sound paramaters
* @param {Array} patterns - Array of pattern data
* @param {Array} sequence - Array of pattern indexes
* @param {Number} [BPM=125] - Playback speed of the song in BPM
* @returns {Array} - Left and right channel sample data
* @memberof Audio */
export declare function zzfxM(instruments: any, patterns: any, sequence: any, BPM?: number): any[];