UNPKG

react-native-audio-api

Version:

react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification

117 lines (116 loc) 3.94 kB
"use strict"; import { InvalidAccessError, NotSupportedError } from "../errors/index.js"; import AnalyserNode from "./AnalyserNode.web.js"; import AudioDestinationNode from "./AudioDestinationNode.web.js"; import AudioBuffer from "./AudioBuffer.web.js"; import AudioBufferSourceNode from "./AudioBufferSourceNode.web.js"; import BiquadFilterNode from "./BiquadFilterNode.web.js"; import IIRFilterNode from "./IIRFilterNode.web.js"; import GainNode from "./GainNode.web.js"; import OscillatorNode from "./OscillatorNode.web.js"; import PeriodicWave from "./PeriodicWave.web.js"; import StereoPannerNode from "./StereoPannerNode.web.js"; import ConstantSourceNode from "./ConstantSourceNode.web.js"; import WaveShaperNode from "./WaveShaperNode.web.js"; import ConvolverNode from "./ConvolverNode.web.js"; import DelayNode from "./DelayNode.web.js"; export default class OfflineAudioContext { constructor(arg0, arg1, arg2) { if (typeof arg0 === 'object') { this.context = new window.OfflineAudioContext(arg0); } else if (typeof arg0 === 'number' && typeof arg1 === 'number' && typeof arg2 === 'number') { this.context = new window.OfflineAudioContext(arg0, arg1, arg2); } else { throw new NotSupportedError('Invalid constructor arguments'); } this.sampleRate = this.context.sampleRate; this.destination = new AudioDestinationNode(this, this.context.destination); } get currentTime() { return this.context.currentTime; } get state() { return this.context.state; } createOscillator() { return new OscillatorNode(this); } createConstantSource() { return new ConstantSourceNode(this); } createGain() { return new GainNode(this); } createDelay(maxDelayTime) { return new DelayNode(this, { maxDelayTime }); } createStereoPanner() { return new StereoPannerNode(this); } createBiquadFilter() { return new BiquadFilterNode(this); } createConvolver() { return new ConvolverNode(this); } createIIRFilter(feedforward, feedback) { return new IIRFilterNode(this, { feedforward, feedback }); } createBufferSource(options) { return new AudioBufferSourceNode(this, options); } createBuffer(numberOfChannels, length, sampleRate) { if (numberOfChannels < 1 || numberOfChannels >= 32) { throw new NotSupportedError(`The number of channels provided (${numberOfChannels}) is outside the range [1, 32]`); } if (length <= 0) { throw new NotSupportedError(`The number of frames provided (${length}) is less than or equal to the minimum bound (0)`); } if (sampleRate < 8000 || sampleRate > 96000) { throw new NotSupportedError(`The sample rate provided (${sampleRate}) is outside the range [8000, 96000]`); } return new AudioBuffer({ numberOfChannels, length, sampleRate }); } createPeriodicWave(real, imag, constraints) { if (real.length !== imag.length) { throw new InvalidAccessError(`The lengths of the real (${real.length}) and imaginary (${imag.length}) arrays must match.`); } return new PeriodicWave(this, { real, imag, ...constraints }); } createAnalyser() { return new AnalyserNode(this); } createWaveShaper() { return new WaveShaperNode(this, this.context.createWaveShaper()); } async decodeAudioDataSource(source) { const arrayBuffer = await fetch(source).then(response => response.arrayBuffer()); return this.decodeAudioData(arrayBuffer); } async decodeAudioData(arrayBuffer) { return new AudioBuffer(await this.context.decodeAudioData(arrayBuffer)); } async startRendering() { return new AudioBuffer(await this.context.startRendering()); } async resume() { await this.context.resume(); } async suspend(suspendTime) { await this.context.suspend(suspendTime); } } //# sourceMappingURL=OfflineAudioContext.web.js.map