UNPKG

ez-web-audio

Version:

Making the Web Audio API super EZ since 2024.

98 lines 3.86 kB
import { TimeObject } from './utils/create-time-object'; import { Playable } from './interfaces/playable'; import { Connectable, Connection } from './interfaces/connectable'; import { ControlType, ParamController, RampType, RatioType, SeekType, BaseParamController } from './param-controller'; /** * The Sound class provides the core functionality for * interacting with the Web Audio API's AudioContext, and is the base class for * all other {{#crossLinkModule "Audio"}}{{/crossLinkModule}} types. It prepares * an audio source, provides various methods for interacting with the audio source, * creates {{#crossLink "AudioNode"}}AudioNodes{{/crossLink}} from the * nodes array, sets up the necessary nodes/routing between them, * and provides some methods to {{#crossLink "Playable/play:method"}}{{/crossLink}} * and {{#crossLink "Sound/stop:method"}}{{/crossLink}} the audio source. * * @public * @class Sound * @implements Playable */ export declare class Sound implements Playable, Connectable { protected audioContext: AudioContext; private audioBuffer; private gainNode; private pannerNode; private bufferSourceNode; private controller; _isPlaying: boolean; protected _startedPlayingAt: number; startOffset: number; connections: Connection[]; constructor(audioContext: AudioContext, audioBuffer: AudioBuffer); private setup; wireConnections(): void; addConnection(connection: Connection): void; removeConnection(name: string): void; getConnection(name: string): Connection | undefined; getNodeFrom<T extends AudioNode | StereoPannerNode>(connectionName: string): T | undefined; get audioSourceNode(): AudioBufferSourceNode; update(type: ControlType): { to: (value: number) => { from: (method: RatioType) => void; }; }; changePanTo(value: number): void; changeGainTo(value: number): { from: (method: RatioType) => void; }; onPlaySet(type: ControlType): { to: (value: number) => { at: (time: number) => void; endingAt: (time: number, rampType?: RampType) => void; }; }; onPlayRamp(type: ControlType, rampType?: RampType): { from: (startValue: number) => { to: (endValue: number) => { in: (endTime: number) => void; }; }; }; play(): void; playFor(duration: number): void; playAt(time: number): void; stop(): void; get isPlaying(): boolean; get duration(): TimeObject; get percentGain(): number; /** * Gets the bufferSource and stops the initAudio, * changes it's play position, and restarts the audio. * * returns a pojo with the `from` method that `value` is curried to, allowing * one to specify which type of value is being provided. * * @example * // for a Sound instance with a duration of 100 seconds, these will all * // move the play position to 90 seconds. * soundInstance.seek(0.9).from('ratio'); * soundInstance.seek(0.1).from('inverseRatio') * soundInstance.seek(90).from('percent'); * soundInstance.seek(90).from('seconds'); * * @param {number} amount The new play position value. */ seek(amount: number): { from: (type: SeekType) => void; }; } export declare class SoundController extends BaseParamController implements ParamController { private bufferSourceNode; protected gainNode: GainNode; protected pannerNode: StereoPannerNode; constructor(bufferSourceNode: AudioBufferSourceNode, gainNode: GainNode, pannerNode: StereoPannerNode); updateAudioSource(source: AudioBufferSourceNode): void; setValuesAtTimes(): void; private applyValues; private applyRampValues; } //# sourceMappingURL=sound.d.ts.map