node-web-audio-api
Version:
Web Audio API implementation for Node.js
162 lines (133 loc) • 6.03 kB
JavaScript
// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
// //
// //
// //
// ██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ //
// ██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ //
// ██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗ //
// ██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║ //
// ╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝ //
// ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ //
// //
// //
// - This file has been generated --------------------------- //
// //
// //
// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
/* eslint-disable no-unused-vars */
import conversions from 'webidl-conversions';
import nativeBinding from '../load-native.js';
import {
toSanitizedSequence,
} from './lib/cast.js';
import {
isFunction,
kEnumerableProperty,
} from './lib/utils.js';
import {
throwSanitizedError,
} from './lib/errors.js';
import {
kNapiObj,
kAudioBuffer,
} from './lib/symbols.js';
import {
AudioParam,
} from './AudioParam.js';
import {
AudioBuffer,
} from './AudioBuffer.js';
import {
PeriodicWave,
} from './PeriodicWave.js';
import {
BaseAudioContext,
} from './BaseAudioContext.js';
/* eslint-enable no-unused-vars */
import {
AudioNode,
} from './AudioNode.js';
export class DelayNode extends AudioNode {
#delayTime = null;
constructor(context, options) {
if (arguments.length < 1) {
throw new TypeError(`Failed to construct 'DelayNode': 1 argument required, but only ${arguments.length} present`);
}
if (!(context instanceof BaseAudioContext)) {
throw new TypeError(`Failed to construct 'DelayNode': argument 1 is not of type BaseAudioContext`);
}
const parsedOptions = {};
if (options && typeof options !== 'object') {
throw new TypeError('Failed to construct \'DelayNode\': argument 2 is not of type \'DelayOptions\'');
}
if (options && options.maxDelayTime !== undefined) {
parsedOptions.maxDelayTime = conversions['double'](options.maxDelayTime, {
context: `Failed to construct 'DelayNode': Failed to read the 'maxDelayTime' property from DelayOptions: The provided value (${options.maxDelayTime}})`,
});
} else {
parsedOptions.maxDelayTime = 1;
}
if (options && options.delayTime !== undefined) {
parsedOptions.delayTime = conversions['double'](options.delayTime, {
context: `Failed to construct 'DelayNode': Failed to read the 'delayTime' property from DelayOptions: The provided value (${options.delayTime}})`,
});
} else {
parsedOptions.delayTime = 0;
}
if (options && options.channelCount !== undefined) {
parsedOptions.channelCount = conversions['unsigned long'](options.channelCount, {
enforceRange: true,
context: `Failed to construct 'DelayNode': Failed to read the 'channelCount' property from DelayOptions: The provided value '${options.channelCount}'`,
});
}
if (options && options.channelCountMode !== undefined) {
parsedOptions.channelCountMode = conversions['DOMString'](options.channelCountMode, {
context: `Failed to construct 'DelayNode': Failed to read the 'channelCount' property from DelayOptions: The provided value '${options.channelCountMode}'`,
});
}
if (options && options.channelInterpretation !== undefined) {
parsedOptions.channelInterpretation = conversions['DOMString'](options.channelInterpretation, {
context: `Failed to construct 'DelayNode': Failed to read the 'channelInterpretation' property from DelayOptions: The provided value '${options.channelInterpretation}'`,
});
}
let napiObj;
try {
napiObj = new nativeBinding.NapiDelayNode(context[kNapiObj], parsedOptions);
} catch (err) {
throwSanitizedError(err);
}
super(context, {
[kNapiObj]: napiObj,
});
this.#delayTime = new AudioParam({
[kNapiObj]: this[kNapiObj].delayTime,
});
}
get delayTime() {
if (!(this instanceof DelayNode)) {
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'DelayNode\'');
}
return this.#delayTime;
}
}
Object.defineProperties(DelayNode, {
length: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 1,
},
});
Object.defineProperties(DelayNode.prototype, {
[Symbol.toStringTag]: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 'DelayNode',
},
delayTime: kEnumerableProperty,
});