@audc/libsamplerate
Version:
Native bindings for libsamplerate
49 lines • 1.65 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SRC_LINEAR = exports.SRC_ZERO_ORDER_HOLD = exports.SRC_SINC_FASTEST = exports.SRC_SINC_MEDIUM_QUALITY = exports.SRC_SINC_BEST_QUALITY = exports.SampleRate = void 0;
const stream_1 = require("stream");
const bindings_1 = __importDefault(require("bindings"));
const { SampleRateStream } = (0, bindings_1.default)('node-libsamplerate');
let defaultOpts = {
type: 2,
channels: 2,
fromRate: 48000,
fromDepth: 16,
toRate: 44100,
toDepth: 16
};
class SampleRate extends stream_1.Transform {
_samplerate;
constructor(opts) {
opts ||= defaultOpts;
if (!(opts.fromDepth == 16 || opts.fromDepth == 32))
throw new Error('Invalid source bit depth');
if (!(opts.toDepth == 16 || opts.toDepth == 32))
throw new Error('Invalid target bit depth');
super(opts);
this._samplerate = new SampleRateStream(opts);
}
setRatio(ratio) {
this._samplerate.setRatio(ratio);
}
_final(cb) {
process.nextTick(() => {
this._samplerate.reset();
});
cb();
}
_transform(chunk, _encoding, cb) {
this.push(this._samplerate.transform(chunk));
cb();
}
}
exports.SampleRate = SampleRate;
exports.SRC_SINC_BEST_QUALITY = 0;
exports.SRC_SINC_MEDIUM_QUALITY = 1;
exports.SRC_SINC_FASTEST = 2;
exports.SRC_ZERO_ORDER_HOLD = 3;
exports.SRC_LINEAR = 4;
//# sourceMappingURL=index.js.map
;