atem-connection
Version:
Typescript Node.js library for connecting with an ATEM switcher.
80 lines • 2.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isRunningInTests = exports.assertNever = exports.omit = exports.commandStringify = exports.combineComponents = exports.getComponents = exports.padToMultiple = exports.BalanceToInt = exports.IntToBalance = exports.DecibelToUInt16BE = exports.UInt16BEToDecibel = exports.bufToNullTerminatedString = exports.bufToBase64String = void 0;
function bufToBase64String(buffer, start, length) {
return buffer.toString('base64', start, start + length);
}
exports.bufToBase64String = bufToBase64String;
function bufToNullTerminatedString(buffer, start, length) {
const slice = buffer.slice(start, start + length);
const nullIndex = slice.indexOf('\0');
return slice.toString('utf8', 0, nullIndex < 0 ? slice.length : nullIndex);
}
exports.bufToNullTerminatedString = bufToNullTerminatedString;
function UInt16BEToDecibel(input) {
// 0 = -inf, 32768 = 0, 65381 = +6db
return Math.round(Math.log10(input / 32768) * 20 * 100) / 100;
}
exports.UInt16BEToDecibel = UInt16BEToDecibel;
function DecibelToUInt16BE(input) {
return Math.floor(Math.pow(10, input / 20) * 32768);
}
exports.DecibelToUInt16BE = DecibelToUInt16BE;
function IntToBalance(input) {
// -100000 = -50, 0x0000 = 0, 0x2710 = +50
return Math.round(input / 200);
}
exports.IntToBalance = IntToBalance;
function BalanceToInt(input) {
return Math.round(input * 200);
}
exports.BalanceToInt = BalanceToInt;
function padToMultiple(val, multiple) {
const r = val % multiple;
if (r === 0) {
return val;
}
else {
return val + (multiple - r);
}
}
exports.padToMultiple = padToMultiple;
function getComponents(val) {
const res = [];
for (let next = 1; next <= val; next = next << 1) {
if ((val & next) > 0) {
res.push(next);
}
}
return res;
}
exports.getComponents = getComponents;
function combineComponents(vals) {
let res = 0;
for (const val of vals) {
res |= val;
}
return res;
}
exports.combineComponents = combineComponents;
function commandStringify(command) {
return JSON.stringify(command, (_key, value) => (typeof value === 'bigint' ? value.toString() : value));
}
exports.commandStringify = commandStringify;
function omit(o, ...keys) {
const obj = { ...o };
for (const key of keys) {
delete obj[key];
}
return obj;
}
exports.omit = omit;
function assertNever(_val) {
// Nothing to do
}
exports.assertNever = assertNever;
function isRunningInTests() {
return process.env.JEST_WORKER_ID !== undefined;
}
exports.isRunningInTests = isRunningInTests;
//# sourceMappingURL=atemUtil.js.map