UNPKG

vox-saver

Version:

Takes a JavaScript Object of .vox file data and returns a Byte Array with all the containing informations

20 lines (14 loc) 548 B
// see https://en.wikipedia.org/wiki/IEEE_754 const signedToUnsigned = (signed : number) : number => { return signed < 0 ? signed + 256 : signed; } const write4ByteFloat = (floatingPointNumber : number) : Array<number> => { const floatArray = new Float32Array(1); floatArray[0] = floatingPointNumber; const byteArray = new Int8Array(floatArray.buffer); const reducedByteArray = Array.from(byteArray.slice(0, 4)) .map(val => signedToUnsigned(val)); return reducedByteArray.reverse(); } export = write4ByteFloat;