react-native-audio-api
Version:
react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification
52 lines (51 loc) • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PeriodicWaveOptionsValidator = exports.OscillatorOptionsValidator = exports.ConvolverOptionsValidator = exports.AnalyserOptionsValidator = void 0;
var _errors = require("./errors");
const AnalyserOptionsValidator = exports.AnalyserOptionsValidator = {
validate(options) {
if (!options) {
return;
}
const allowedFFTSize = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768];
if (options.fftSize && !allowedFFTSize.includes(options.fftSize)) {
throw new _errors.IndexSizeError(`fftSize must be one of the following values: ${allowedFFTSize.join(', ')}`);
}
}
};
const ConvolverOptionsValidator = exports.ConvolverOptionsValidator = {
validate(options) {
if (!options) {
return;
}
if (options.buffer) {
const numberOfChannels = options.buffer.numberOfChannels;
if (numberOfChannels !== 1 && numberOfChannels !== 2 && numberOfChannels !== 4) {
throw new _errors.NotSupportedError(`The number of channels provided (${numberOfChannels}) in impulse response for ConvolverNode buffer must be 1 or 2 or 4.`);
}
}
}
};
const OscillatorOptionsValidator = exports.OscillatorOptionsValidator = {
validate(options) {
if (!options) {
return;
}
if (options.type === 'custom' && !options.periodicWave) {
throw new _errors.NotSupportedError("'type' cannot be set to 'custom' without providing a 'periodicWave'.");
}
}
};
const PeriodicWaveOptionsValidator = exports.PeriodicWaveOptionsValidator = {
validate(options) {
if (!options) {
return;
}
if (options.real && options.imag && options.real.length !== options.imag.length) {
throw new _errors.NotSupportedError("'real' and 'imag' arrays must have the same length");
}
}
};
//# sourceMappingURL=options-validators.js.map