securityos/node_modules/winamp-eqf/parser.js

42 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
var CONSTANTS = require("./constants");
function parser(arrayBuffer) {
var data = {};
var i = 0;
var arr = new Int8Array(arrayBuffer);
// Parse header
data.type = String.fromCharCode.apply(
null,
arr.slice(i, CONSTANTS.HEADER.length)
);
if (data.type !== CONSTANTS.HEADER) {
throw new Error("Invalid .eqf file.");
}
i += CONSTANTS.HEADER.length;
// Skip "<ctrl-z>!--"
i += 4;
// Get the presets
data.presets = [];
while (i < arr.length) {
var preset = {};
// Get the name
var nameStart = i;
var nameEnd = nameStart + 257; // Str is fixed length
// Str is null terminated
while (arr[i] !== 0 && i <= nameEnd) {
i++;
}
preset.name = String.fromCharCode.apply(null, arr.slice(nameStart, i));
i = nameEnd; // Skip over any unused bytes
// Get the levels
CONSTANTS.PRESET_VALUES.forEach(function(valueName) {
preset[valueName] = 64 - arr[i++]; // Adjust for inverse values
});
data.presets.push(preset);
}
return data;
}
module.exports = parser;