linx-simulator2/node_modules/mumble-client-codecs-node/lib/encode-worker.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-18 08:11:16 +00:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (self) {
var opusEncoder;
self.addEventListener('message', function (e) {
var data = e.data;
if (data.action === 'reset') {
if (opusEncoder) {
opusEncoder.destroy();
opusEncoder = null;
}
} else if (data.action === 'encodeOpus') {
if (!opusEncoder) {
opusEncoder = new _libopus.Encoder({
unsafe: true,
channels: data.numberOfChannels,
rate: MUMBLE_SAMPLE_RATE
});
}
var encoded = opusEncoder.encode(new Float32Array(data.buffer));
var buffer = (0, _toArraybuffer2.default)(encoded);
self.postMessage({
target: data.target,
buffer: buffer,
position: data.position
}, [buffer]);
}
});
};
var _libopus = require('libopus.js');
var _toArraybuffer = require('to-arraybuffer');
var _toArraybuffer2 = _interopRequireDefault(_toArraybuffer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var MUMBLE_SAMPLE_RATE = 48000;