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

121 lines (120 loc) 4.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _types = require("../types"); var _errors = require("../errors"); class AudioParam { constructor(audioParam, context) { this.audioParam = audioParam; this.context = context; this.value = audioParam.value; this.defaultValue = audioParam.defaultValue; this.minValue = audioParam.minValue; this.maxValue = audioParam.maxValue; } get value() { return this.audioParam.value; } set value(value) { this.audioParam.value = value; } setValueAtTime(value, startTime) { if (startTime < 0) { throw new _errors.RangeError(`startTime must be a finite non-negative number: ${startTime}`); } this.checkCurveExclusion({ type: _types.AutomationEventType.SET_VALUE, automationTime: startTime }); const clampedTime = Math.max(startTime, this.context.currentTime); this.audioParam.setValueAtTime(value, clampedTime); return this; } linearRampToValueAtTime(value, endTime) { if (endTime < 0) { throw new _errors.RangeError(`endTime must be a finite non-negative number: ${endTime}`); } this.checkCurveExclusion({ type: _types.AutomationEventType.LINEAR_RAMP, automationTime: endTime }); const clampedTime = Math.max(endTime, this.context.currentTime); this.audioParam.linearRampToValueAtTime(value, clampedTime); return this; } exponentialRampToValueAtTime(value, endTime) { if (value === 0) { throw new _errors.RangeError(`value must be a non-zero number: ${value}`); } if (endTime <= 0) { throw new _errors.RangeError(`endTime must be a finite non-negative number: ${endTime}`); } this.checkCurveExclusion({ type: _types.AutomationEventType.EXPONENTIAL_RAMP, automationTime: endTime }); const clampedTime = Math.max(endTime, this.context.currentTime); this.audioParam.exponentialRampToValueAtTime(value, clampedTime); return this; } setTargetAtTime(target, startTime, timeConstant) { if (startTime < 0) { throw new _errors.RangeError(`startTime must be a finite non-negative number: ${startTime}`); } if (timeConstant < 0) { throw new _errors.RangeError(`timeConstant must be a finite non-negative number: ${timeConstant}`); } this.checkCurveExclusion({ type: _types.AutomationEventType.SET_TARGET, automationTime: startTime }); const clampedTime = Math.max(startTime, this.context.currentTime); this.audioParam.setTargetAtTime(target, clampedTime, timeConstant); return this; } setValueCurveAtTime(values, startTime, duration) { if (startTime < 0) { throw new _errors.RangeError(`startTime must be a finite non-negative number: ${startTime}`); } if (duration <= 0) { throw new _errors.RangeError(`duration must be a finite strictly-positive number: ${duration}`); } if (values.length < 2) { throw new _errors.InvalidStateError(`values must contain at least two values`); } const clampedTime = Math.max(startTime, this.context.currentTime); this.checkCurveExclusion({ type: _types.AutomationEventType.SET_VALUE_CURVE, automationTime: clampedTime, duration }); this.audioParam.setValueCurveAtTime(values, clampedTime, duration); return this; } cancelScheduledValues(cancelTime) { if (cancelTime < 0) { throw new _errors.RangeError(`cancelTime must be a finite non-negative number: ${cancelTime}`); } const clampedTime = Math.max(cancelTime, this.context.currentTime); this.audioParam.cancelScheduledValues(clampedTime); return this; } cancelAndHoldAtTime(cancelTime) { if (cancelTime < 0) { throw new _errors.RangeError(`cancelTime must be a finite non-negative number: ${cancelTime}`); } const clampedTime = Math.max(cancelTime, this.context.currentTime); this.audioParam.cancelAndHoldAtTime(clampedTime); return this; } checkCurveExclusion(eventData) { const checkExclusionResult = this.audioParam.checkCurveExclusion(eventData); if (checkExclusionResult.status === 'error') { throw new _errors.NotSupportedError(checkExclusionResult.message); } } } exports.default = AudioParam; //# sourceMappingURL=AudioParam.js.map