### Install standardized-audio-context Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md The standardized-audio-context package can be installed using npm. ```shell npm install standardized-audio-context ``` -------------------------------- ### Create a sine wave using AudioContext Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md A basic example demonstrating how to create an AudioContext, an oscillator node, connect it to the destination, and start it to produce a sine wave. ```js import { AudioContext } from 'standardized-audio-context'; const audioContext = new AudioContext(); const oscillatorNode = audioContext.createOscillator(); oscillatorNode.connect(audioContext.destination); oscillatorNode.start(); ``` -------------------------------- ### decodeAudioData standalone wrapper Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md Example of using the standalone decodeAudioData function with a native AudioContext. ```javascript import { decodeAudioData } from 'standardized-audio-context'; const nativeAudioContext = new AudioContext(); const response = await fetch('/a-super-cool-audio-file'); const arrayBuffer = await response.arrayBuffer(); const audioBuffer = await decodeAudioData(nativeAudioContext, arrayBuffer); ``` -------------------------------- ### Create a sine wave using OscillatorNode constructor Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md An alternative approach to creating a sine wave by using the OscillatorNode constructor directly instead of the factory method. ```js import { AudioContext, OscillatorNode } from 'standardized-audio-context'; const audioContext = new AudioContext(); const oscillatorNode = new OscillatorNode(audioContext); oscillatorNode.connect(audioContext.destination); oscillatorNode.start(); ``` -------------------------------- ### Import using jspm Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md Loading standardized-audio-context with a service like jspm, requiring a URL for the import statement. ```js import { AudioContext, OfflineAudioContext } from 'https://jspm.dev/standardized-audio-context'; ``` -------------------------------- ### isSupported() Promise Usage Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md The isSupported() function returns a promise that resolves to a boolean indicating browser support for the standardized-audio-context functionality. ```javascript import { isSupported } from 'standardized-audio-context'; isSupported().then((isSupported) => { if (isSupported) { // yeah everything should work } else { // oh no this browser seems to be outdated } }); ``` -------------------------------- ### Import AudioContext and OfflineAudioContext Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md Importing AudioContext and OfflineAudioContext from the standardized-audio-context package for use in JavaScript. ```js import { AudioContext, OfflineAudioContext } from 'standardized-audio-context'; ``` -------------------------------- ### IOfflineAudioContext Interface Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md TypeScript interface for the OfflineAudioContext, detailing its properties and methods. ```typescript interface IOfflineAudioContext extends EventTarget { readonly audioWorklet?: IAudioWorklet; readonly currentTime: number; readonly destination: IAudioDestinationNode; readonly length: number; readonly listener: IAudioListener; onstatechange: null | TEventHandler; readonly sampleRate: number; readonly state: TAudioContextState; createAnalyser(): IAnalyserNode; createBiquadFilter(): IBiquadFilterNode; createBuffer(numberOfChannels: number, length: number, sampleRate: number): IAudioBuffer; createBufferSource(): IAudioBufferSourceNode; createChannelMerger(numberOfInputs?: number): IAudioNode; createChannelSplitter(numberOfOutputs?: number): IAudioNode; createConstantSource(): IConstantSourceNode; createConvolver(): IConvolverNode; createDelay(maxDelayTime?: number): IDelayNode; createDynamicsCompressor(): IDynamicsCompressorNode; createGain(): IGainNode; createIIRFilter(feedforward: number[], feedback: number[]): IIIRFilterNode; createOscillator(): IOscillatorNode; createPanner(): IPannerNode; createPeriodicWave(real: number[], imag: number[], constraints?: Partial): IPeriodicWave; createStereoPanner(): IStereoPannerNode; createWaveShaper(): IWaveShaperNode; decodeAudioData( audioData: ArrayBuffer, successCallback?: TDecodeSuccessCallback, errorCallback?: TDecodeErrorCallback ): Promise; startRendering(): Promise; } ``` -------------------------------- ### IAudioContext Interface Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md TypeScript interface for the AudioContext, detailing its properties and methods. ```typescript interface IAudioContext extends EventTarget { readonly audioWorklet?: IAudioWorklet; readonly baseLatency: number; readonly currentTime: number; readonly destination: IAudioDestinationNode; readonly listener: IAudioListener; onstatechange: null | TEventHandler; readonly sampleRate: number; readonly state: TAudioContextState; close(): Promise; createAnalyser(): IAnalyserNode; createBiquadFilter(): IBiquadFilterNode; createBuffer(numberOfChannels: number, length: number, sampleRate: number): IAudioBuffer; createBufferSource(): IAudioBufferSourceNode; createChannelMerger(numberOfInputs?: number): IAudioNode; createChannelSplitter(numberOfOutputs?: number): IAudioNode; createConstantSource(): IConstantSourceNode; createConvolver(): IConvolverNode; createDelay(maxDelayTime?: number): IDelayNode; createDynamicsCompressor(): IDynamicsCompressorNode; createGain(): IGainNode; createIIRFilter(feedforward: number[], feedback: number[]): IIIRFilterNode; createMediaElementSource(mediaElement: HTMLMediaElement): IMediaElementAudioSourceNode; createMediaStreamDestination(): IMediaElementAudioDestinationNode; createMediaStreamSource(mediaStream: MediaStream): IMediaStreamAudioSourceNode; createMediaStreamTrackSource(mediaStreamTrack: MediaStreamTrack): IMediaStreamTrackAudioSourceNode; createOscillator(): IOscillatorNode; createPanner(): IPannerNode; createPeriodicWave(real: number[], imag: number[], constraints?: Partial): IPeriodicWave; createStereoPanner(): IStereoPannerNode; createWaveShaper(): IWaveShaperNode; decodeAudioData( audioData: ArrayBuffer, successCallback?: TDecodeSuccessCallback, errorCallback?: TDecodeErrorCallback ): Promise; resume(): Promise; suspend(): Promise; } ``` -------------------------------- ### isAnyAudioNode() Usage Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md This helper function identifies an AudioNode, returning true if the value is an AudioNode, regardless of whether it was created with standardized-audio-context or natively. ```javascript import { OfflineAudioContext, isAnyAudioNode } from 'standardized-audio-context'; // This will create a native AudioContext. const nativeAudioContext = new AudioContext(); isAnyAudioNode(nativeAudioContext.createGain()); // true // This will create an OfflineAudioContext from standardized-audio-context. const offlineAudioContext = new OfflineAudioContext({ length: 10, sampleRate: 44100 }); isAnyAudioNode(offlineAudioContext.createGain()); // true ``` -------------------------------- ### isAnyAudioContext() Usage Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md This utility function determines if a given value is an AudioContext, excluding OfflineAudioContext. It works for both standardized and native AudioContext instances. ```javascript import { AudioContext, isAnyAudioContext } from 'standardized-audio-context'; // This will create an AudioContext from standardized-audio-context. const audioContext = new AudioContext(); isAnyAudioContext(audioContext); // true // This will create a native AudioContext. const nativeAudioContext = new window.AudioContext(); isAnyAudioContext(nativeAudioContext); // true ``` -------------------------------- ### isAnyAudioParam() Usage Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md Similar to isAnyAudioNode(), this helper function checks if a value is an AudioParam, returning true if it is, irrespective of its creation method (standardized or native). ```javascript import { OfflineAudioContext, isAnyAudioParam } from 'standardized-audio-context'; // This will create a native AudioContext. const nativeAudioContext = new AudioContext(); isAnyAudioParam(nativeAudioContext.createGain().gain); // true // This will create an OfflineAudioContext from standardized-audio-context. const offlineAudioContext = new OfflineAudioContext({ length: 10, sampleRate: 44100 }); isAnyAudioParam(offlineAudioContext.createGain().gain); // true ``` -------------------------------- ### isAnyOfflineAudioContext() Usage Source: https://github.com/chrisguttandin/standardized-audio-context/blob/master/README.md This utility function checks if a given value is an OfflineAudioContext. It does not distinguish between instances created by standardized-audio-context or natively. ```javascript import { OfflineAudioContext, isAnyOfflineAudioContext } from 'standardized-audio-context'; // This will create an OfflineAudioContext from standardized-audio-context. const offlineAudioContext = new OfflineAudioContext({ length: 10, sampleRate: 44100 }); isAnyOfflineAudioContext(offlineAudioContext); // true // This will create a native OfflineAudioContext. const nativeOfflineAudioContext = new window.OfflineAudioContext(1, 10, 44100); isAnyOfflineAudioContext(nativeOfflineAudioContext); // true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.