import { EventEmitter } from 'pixi.js'; import { Filterable } from '../Filterable'; import { IMediaContext } from '../interfaces'; /** * Main class to handle WebAudio API. There's a simple chain * of AudioNode elements: analyser > compressor > context.destination. * any filters that are added are inserted between the analyser and compressor nodes * @memberof webaudio */ declare class WebAudioContext extends Filterable implements IMediaContext { /** * Context Compressor node * @readonly */ compressor: DynamicsCompressorNode; /** * Context Analyser node * @readonly */ analyser: AnalyserNode; /** * Global speed of all sounds * @readonly */ speed: number; /** * Sets the muted state. * @default false */ muted: boolean; /** * Sets the volume from 0 to 1. * @default 1 */ volume: number; /** * Handle global events * @type {PIXI.EventEmitter} */ events: EventEmitter; /** The instance of the AudioContext for WebAudio API. */ private _ctx; /** The instance of the OfflineAudioContext for fast decoding audio. */ private _offlineCtx; /** Current paused status */ private _paused; /** * Indicated whether audio on iOS has been unlocked, which requires a touchend/mousedown event that plays an * empty sound. Only ever goes from true to false. */ private _locked; /** The paused state saved by a window blur, or undefined when no blur is waiting for its focus */ private _pausedOnBlur; /** Set to false ignore suspending when window is blurred */ autoPause: boolean; constructor(); /** Handle mobile WebAudio context resume */ private onFocus; /** Handle mobile WebAudio context suspend */ private onBlur; /** * Try to unlock audio on iOS. This is triggered from either WebAudio plugin setup (which will work if inside of * a `mousedown` or `touchend` event stack), or the first document touchend/mousedown event. If it fails (touchend * will fail if the user presses for too long, indicating a scroll event instead of a click event. * * Note that earlier versions of iOS supported `touchstart` for this, but iOS9 removed this functionality. Adding * a `touchstart` event to support older platforms may preclude a `mousedown` even from getting fired on iOS9, so we * stick with `mousedown` and `touchend`. * * Once unlocked, the same events restart a context that iOS stopped (app switch, call, headphones unplugged) * unless it's paused. */ private _unlock; /** * Clear the lock once the context is running, whatever started it. Firefox and Safari only * update the state when resume() settles, so this also runs on `statechange` and after each resume(). */ private _checkUnlocked; /** * Start the context again when something other than `paused` stopped it: iOS suspends or interrupts it * on an app switch, a call or when headphones are unplugged, and may only let it resume in a user gesture. */ private _recover; /** Stop listening for the events that unlock or restart the context. */ private _removeUnlockListeners; /** Resume the context, then suspend it again if that settles while paused. */ private _resume; /** * Plays an empty sound in the web audio context. This is used to enable web audio on iOS devices, as they * require the first sound to be played inside of a user initiated event (touch/click). * If the context is paused, it's suspended again as soon as it has started. */ playEmptySound(): void; /** * Get AudioContext class, if not supported returns `null` * @type {AudioContext} * @readonly */ static get AudioContext(): typeof AudioContext; /** * Get OfflineAudioContext class, if not supported returns `null` * @type {OfflineAudioContext} * @readonly */ static get OfflineAudioContext(): typeof OfflineAudioContext; /** Destroy this context. */ destroy(): void; /** * The WebAudio API AudioContext object. * @readonly * @type {AudioContext} */ get audioContext(): AudioContext; /** * The WebAudio API OfflineAudioContext object. * @readonly * @type {OfflineAudioContext} */ get offlineContext(): OfflineAudioContext; /** * Pauses all sounds, even though we handle this at the instance * level, we'll also pause the audioContext so that the * time used to compute progress isn't messed up. * The audioContext follows the last value set, including when * it's changed more than once in the same tick. * While not paused, a context stopped by the browser is resumed on the next tap, * including one stopped by calling `audioContext.suspend()` directly. Use `paused` or * `pauseAll()` to pause. * @default false */ set paused(paused: boolean); get paused(): boolean; /** Emit event when muted, volume or speed changes */ refresh(): void; /** Emit event when muted, volume or speed changes */ refreshPaused(): void; /** * Toggles the muted state. * @return The current muted state. */ toggleMute(): boolean; /** * Toggles the paused state. * @return The current muted state. */ togglePause(): boolean; /** * Decode the audio data * @param arrayBuffer - Buffer from loader * @param callback - Called once when decoding finishes, with the browser's error or the decoded buffer. */ decode(arrayBuffer: ArrayBuffer, callback: (err?: Error, buffer?: AudioBuffer) => void): void; } export { WebAudioContext };