node-web-audio-api
Version:
Web Audio API implementation for Node.js
78 lines (67 loc) • 2.49 kB
JavaScript
import conversions from 'webidl-conversions';
import nativeBinding from '../load-native.js';
import { throwSanitizedError } from './lib/errors.js';
import { toSanitizedSequence } from './lib/cast.js';
import { kNapiObj } from './lib/symbols.js';
import { kHiddenProperty } from './lib/utils.js';
import { BaseAudioContext } from './BaseAudioContext.js';
export class PeriodicWave {
constructor(context, options) {
if (arguments.length < 1) {
throw new TypeError(`Failed to construct 'PeriodicWave': 1 argument required, but only ${arguments.length} present`);
}
if (!(context instanceof BaseAudioContext)) {
throw new TypeError(`Failed to construct 'PeriodicWave': argument 1 is not of type BaseAudioContext`);
}
const parsedOptions = {};
if (options && 'real' in options) {
try {
parsedOptions.real = toSanitizedSequence(options.real, Float32Array);
} catch (err) {
throw new TypeError(`Failed to construct 'PeriodicWave': Failed to read the 'real' property from PeriodicWaveOptions: The provided value ${err.message}`);
}
}
if (options && 'imag' in options) {
try {
parsedOptions.imag = toSanitizedSequence(options.imag, Float32Array);
} catch (err) {
throw new TypeError(`Failed to construct 'PeriodicWave': Failed to read the 'imag' property from PeriodicWaveOptions: The provided value ${err.message}`);
}
}
// disableNormalization = false
if (options && 'disableNormalization' in options) {
parsedOptions.disableNormalization = conversions['boolean'](options.disableNormalization, {
context: `Failed to construct 'PeriodicWave': Failed to read the 'disableNormalization' property from PeriodicWaveOptions: The provided value`,
});
} else {
parsedOptions.disableNormalization;
}
try {
const napiObj = new nativeBinding.NapiPeriodicWave(context[kNapiObj], parsedOptions);
Object.defineProperty(this, kNapiObj, {
value: napiObj,
...kHiddenProperty,
});
} catch (err) {
throwSanitizedError(err);
}
}
}
Object.defineProperties(PeriodicWave, {
length: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 1,
},
});
Object.defineProperties(PeriodicWave.prototype, {
[Symbol.toStringTag]: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 'PeriodicWave',
},
});