linx-simulator2/node_modules/mumble-client-codecs-node/lib/decode-worker.js
2019-09-18 11:11:16 +03:00

41 lines
1001 B
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (self) {
var opusDecoder;
self.addEventListener('message', function (e) {
var data = e.data;
if (data.action === 'reset') {
if (opusDecoder) {
opusDecoder.destroy();
opusDecoder = null;
}
self.postMessage({
action: 'reset'
});
} else if (data.action === 'decodeOpus') {
if (!opusDecoder) {
opusDecoder = new _libopus.Decoder({
unsafe: true,
channels: 1, // TODO
rate: MUMBLE_SAMPLE_RATE
});
}
var input = data.buffer ? Buffer.from(data.buffer) : null;
var decoded = opusDecoder.decodeFloat32(input);
self.postMessage({
action: 'decoded',
buffer: decoded.buffer,
target: data.target,
position: data.position
}, [decoded.buffer]);
}
});
};
var _libopus = require('libopus.js');
var MUMBLE_SAMPLE_RATE = 48000;