audio-player: comments for byte conversions

This commit is contained in:
Trek H 2019-08-11 16:30:13 +09:30
parent e6697b9de9
commit dc72371e74
1 changed files with 3 additions and 0 deletions

View File

@ -127,14 +127,17 @@ function decode(b) {
return result; return result;
} }
// int16ToBytes takes a number assumed to be an int 16 and converts it to an array containing bytes (Little Endian).
function int16ToBytes(num) { function int16ToBytes(num) {
return [(num & 0x00ff), (num & 0xff00) >> 8]; return [(num & 0x00ff), (num & 0xff00) >> 8];
} }
// bytesToInt16 takes an array of bytes (assumed to be values between 0 and 255), interprates them as little endian and converts it to an int16.
function bytesToInt16(b) { function bytesToInt16(b) {
return (b[0] | (b[1] << 8)); return (b[0] | (b[1] << 8));
} }
// bytesToInt32 takes an array of bytes (assumed to be values between 0 and 255), interprates them as little endian and converts it to an int32.
function bytesToInt32(b) { function bytesToInt32(b) {
return (b[0] | return (b[0] |
(b[1] << 8) | (b[1] << 8) |