orion-engine
Version:
A simple and lightweight web based game development library
96 lines (95 loc) • 3.97 kB
TypeScript
import { AudioEngineInterface } from './types';
export declare class AudioEngine implements AudioEngineInterface {
private _context;
private _sources;
private _cached_buffers;
/**
* Creates a new AudioEngine instance.
* @param to_cache URLs of the sounds to cache if any.
*/
constructor(to_cache?: string[]);
/**
* Caches the sounds with the given URLs.
* @param urls URLs of the sounds to cache.
*/
cache_audio(urls: string[]): Promise<void>;
get context(): AudioContext;
get sources(): AudioBufferSourceNode[];
get cached_buffers(): Map<string, AudioBuffer>;
/**
* Plays the sound with the given URL.
* @param url URL of the sound to play.
* @param use_fade Whether to fade the sound out after it has finished playing.
* @returns
*/
play_sound(url: string, use_fade: boolean): Promise<number>;
/**
* Fade the sound with the given source ID.
* @param source_id Source ID of the sound to fade.
* @param duration Duration of the fade in seconds.
* @returns
*/
fade_sound(source_id: number, duration: number): void;
/**
* Fade the sound with the given source ID after the duration of the sound.
* @param source_id Source ID of the sound to fade.
* @param duration Duration of the fade in seconds.
* @returns
*/
fade_sound_after_delay(source_id: number, duration: number): void;
/**
* Stops the sound with the given source ID.
* @param source_id Source ID of the sound to stop.
* @returns
*/
stop_sound(source_id: number): void;
/**
* Stops all sounds that are currently playing.
*/
stop_all_sounds(): void;
/**
* Set the pitch of the sound with the given source ID.
* @param source_id Source ID of the sound to modify the pitch.
* @param pitch Pitch of the sound. Should be a positive number.
*/
set_pitch(source_id: number, pitch: number): void;
/**
* Enable or disable looping for the sound with the given source ID.
* @param source_id Source ID of the sound to enable or disable looping.
* @param loop Whether to enable or disable looping for the sound.
*/
set_loop(source_id: number, loop: boolean): void;
/**
* Apply distortion effect to the sound with the given source ID.
* @param source_id Source ID of the sound to apply the distortion effect.
* @param amount Amount of distortion to apply to the sound.
*/
apply_distortion(source_id: number, amount: number): void;
/**
* Helper function to create a distortion curve
* @param amount
* @returns
*/
private make_distortion_curve;
/**
* Apply reverb effect to the sound with the given source ID.
* @param source_id Source ID of the sound to apply the reverb effect.
* @param duration Duration of the reverb effect in seconds.
* @param decay Rate at which the reverb trails off after the sound stops.
*/
apply_reverb(source_id: number, duration: number, decay: number): void;
/**
* Apply chorus effect to the sound with the given source ID.
* @param source_id Source ID of the sound to apply the chorus effect.
* @param delay Time delay between the original sound and the chorus sound in seconds.
* @param depth Depth of the chorus effect. Should be between 0 and 1.
* @param rate Frequency of the LFO that modulates the delay time in Hz.
*/
apply_chorus(source_id: number, delay: number, depth: number, rate: number): void;
/**
* Apply an equalizer effect to the sound with the given source ID.
* @param source_id Source ID of the sound to apply the equalizer effect.
* @param bands An array of gain values for each frequency band.
*/
apply_equalizer(source_id: number, bands: number[]): void;
}