How to use the platform/platform.Uint8Array function in platform

To help you get started, we’ve selected a few platform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
// [2][22]
const mp3_pretab_ptr = new Uint8Array([
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
]);

const ci_table = new Float32Array([
    -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037
]);

const mp3_huffcodes_1 = new Uint16Array([
    0x0001, 0x0001, 0x0001, 0x0000
]);

const mp3_huffbits_1 = new Uint8Array([
    1,  3,  2,  3
]);

const mp3_huffcodes_2 = new Uint16Array([
    0x0001, 0x0002, 0x0001, 0x0003, 0x0001, 0x0001, 0x0003, 0x0002,
    0x0000
]);

const mp3_huffbits_2 = new Uint8Array([
    1,  3,  6,  3,  3,  5,  5,  5,
    6
]);

const mp3_huffcodes_3 = new Uint16Array([
    0x0003, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0003, 0x0002,
    0x0000
github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
6,  6,  6, 3, 12,  9,  9, 6, 6, 12,  9, 6,
    8,  8,  5, 0, 15, 12,  9, 0, 6, 18,  9, 0
]);

const mp3_quad_codes = [
    new Uint8Array([1,  5,  4,  5,  6,  5,  4,  4, 7,  3,  6,  0,  7,  2,  3,  1]),
    new Uint8Array([15, 14, 13, 12, 11, 10,  9,  8, 7,  6,  5,  4,  3,  2,  1,  0])
];

const mp3_quad_bits = [
    new Uint8Array([1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6]),
    new Uint8Array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4])
];

// [9][22]
const band_size_long = new Uint8Array([
    4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
    12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158, /* 44100 */
    4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
    12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192, /* 48000 */
    4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
    16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26, /* 32000 */
    6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
    20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, /* 22050 */
    6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
    18, 22, 26, 32, 38, 46, 52, 64, 70, 76, 36, /* 24000 */
    6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
    20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, /* 16000 */
    6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
    20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, /* 11025 */
    6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
    20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, /* 12000 */
github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
var table_ptr = table_index * 2;

    if (table_index < 0) {
        return -1;
    }

    for (var i = 0; i < table_size; ++i) {
        table[table_ptr + (i * 2) + 1] = 0; // bits
        table[table_ptr + (i * 2)] = -1; // codes
    }

    const bits_view = bits_size === 1 ? new Uint8Array(bits.buffer) :
                   bits_size === 2 ? new Uint16Array(bits.buffer) :
                   new Uint32Array(bits.buffer);

    const codes_view = codes_size === 1 ? new Uint8Array(codes.buffer) :
                       codes_size === 2 ? new Uint16Array(codes.buffer) :
                       new Uint32Array(codes.buffer);

    for (var i = 0; i < nb_codes; ++i) {
        n = bits_view[i];
        code = codes_view[i];

        if (n <= 0) continue;

        n -= n_prefix;
        code_prefix2 = code >>> n;

        if (n > 0 && code_prefix2 === code_prefix) {
            if (n <= table_nb_bits) {
                j = (code << (table_nb_bits - n)) & (table_size - 1);
                nb = 1 << (table_nb_bits -n);
github petkaantonov / HTML-Music-Player / src / metadata / mp3_metadata.js View on Github external
tagMap[0x504943 | 0] = tagMap[0x41504943 | 0] = function(offset, fileView, flags, version, size, tagData) {
    const originalOffset = offset;
    const encoding = fileView.getUint8(offset);
    offset++;
    let type;
    const buffer = fileView.block();
    let {start} = fileView;
    let pictureKind = -1;
    const decoder = decoders[encoding];

    if (!decoder) return;

    const nullLength = (encoding === 1 || encoding === 2) ? 2 : 1;

    if (version <= 2) {
        type = `image/${decoder.decode(new Uint8Array(buffer.buffer, offset - start, 3))}`;
        offset += 3;
    } else {
        const length = distanceUntilNull(offset - start, buffer, size - (offset - originalOffset), 1);
        const typeString = decoder.decode(new Uint8Array(buffer.buffer, offset - start, length)).toLowerCase();
        offset += (length + 1);

        if (typeString.indexOf(`/`) === -1) {
            if (/jpg|jpeg|png/.test(typeString)) {
                type = `image/${typeString}`;
            } else {
                return;
            }
        } else {
            type = typeString.toLowerCase();
        }
    }
github petkaantonov / HTML-Music-Player / src / metadata / mp3_metadata.js View on Github external
tagMap[0x434f4d4d | 0] = tagMap[0x434f4d | 0] = function(offset, fileView, flags, version, size, data) {
    const originalOffset = offset;
    const encoding = fileView.getUint8(offset);
    const buffer = fileView.block();
    offset++;
    decoders[0].decode(new Uint8Array(buffer.buffer, offset - fileView.start, 3));
    offset += 3;

    const decoder = decoders[encoding];
    if (!decoder) return;

    const nullLength = (encoding === 1 || encoding === 2) ? 2 : 1;
    let length = distanceUntilNull(offset - fileView.start, buffer, size - 4, nullLength);
    const key = decoder.decode(new Uint8Array(buffer.buffer, offset - fileView.start, length));

    offset += (length + nullLength);
    length = distanceUntilNull(offset - fileView.start, buffer, (size - (offset - originalOffset)), nullLength);
    const value = decoder.decode(new Uint8Array(buffer.buffer, offset - fileView.start, length));

    if (key === `iTunSMPB` || key === ``) {
        const matches = riTunesGapless.exec(value.trim());
        if (matches) {
            data.encoderDelay = parseInt(matches[1], 16);
            data.encoderDelay = Math.min(65536, Math.max(0, data.encoderDelay));
            data.encoderPadding = parseInt(matches[2], 16);
            data.encoderPadding = Math.min(65536, Math.max(0, data.encoderPadding));
        }
    }
};
github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
this.switch_point = 0;
    this.table_select0 = 0;
    this.table_select1 = 0;
    this.table_select2 = 0;
    this.subblock_gain0 = 0;
    this.subblock_gain1 = 0;
    this.subblock_gain2 = 0;
    this.scalefac_scale = 0;
    this.count1table_select = 0;
    this.region_size0 = 0;
    this.region_size1 = 0;
    this.region_size2 = 0;
    this.preflag = 0;
    this.short_start = 0;
    this.long_end = 0;
    this.scale_factors = new Uint8Array(40);
    this.sb_hybrid = new Int32Array(SB_HYBRID_SIZE);
}
github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
function Mp3Context(opts) {
    EventEmitter.call(this);
    this.id = id++;
    opts = Object(opts);
    var targetBufferLengthSeconds = "targetBufferLengthSeconds" in opts ? (
      Math.max(Math.min(opts.targetBufferLengthSeconds, MAX_BUFFER_LENGTH_SECONDS),
               MIN_BUFFER_LENGTH_SECONDS) || DEFAULT_BUFFER_LENGTH_SECONDS)
      : DEFAULT_BUFFER_LENGTH_SECONDS;

    var dataType = opts.dataType === INT16 ? INT16 : FLOAT;
    this.targetBufferLengthSeconds = targetBufferLengthSeconds;
    this.dataType = dataType;
    this.granules = [new Granule(), new Granule(), new Granule(), new Granule()];
    this.last_buf = new Uint8Array(LAST_BUF_SIZE);
    this.last_buf_size = 0;
    this.frame_size = 0;
    this.free_format_next_header = 0;
    this.error_protection = 0;
    this.sample_rate = 0;
    this.sample_rate_index = 0;
    this.bit_rate = 0;
    this.gb = new BitStream();
    this.in_gb = new BitStream();
    this.nb_channels = 0;
    this.mode = 0;
    this.mode_ext = 0;
    this.lsf = 0;
    this.synth_buf = [
        new Int16Array(512 * 2),
        new Int16Array(512 * 2)
github petkaantonov / HTML-Music-Player / src / metadata / mp3_metadata.js View on Github external
if (flags.hasBeenUnsynchronized) {
        data = new Uint8Array(dataLength);
        let actualLength = 0;
        for (let j = 0; j < dataLength; ++j) {
            const i = offset - fileView.start + j;
            const value = buffer[i];
            if (value === 0xFF &&
                ((i + 1) < buffer.length) &&
                buffer[i + 1] === 0x00) {
                ++j;
            }
            data[actualLength] = value;
            actualLength++;
        }
        if (actualLength !== dataLength) {
            data = new Uint8Array(data.buffer, offset - fileView.start, actualLength);
        }
    } else {
        data = new Uint8Array(buffer.buffer, offset - fileView.start, dataLength);
    }

    pictures.push({
        image: new Blob([data], {type}),
        pictureKind: pictureKinds[pictureKind],
        description
    });
};
github petkaantonov / HTML-Music-Player / src / util.js View on Github external
export function hexString(arrayBuffer) {
    if (arrayBuffer.byteLength === 20) {
        const view = new DataView(arrayBuffer);
        const a = view.getUint32(0, false).toString(16);
        const b = view.getUint32(4, false).toString(16);
        const c = view.getUint32(8, false).toString(16);
        const d = view.getUint32(12, false).toString(16);
        const e = view.getUint32(16, false).toString(16);
        return (padding[a.length] + a) +
              (padding[b.length] + b) +
              (padding[c.length] + c) +
              (padding[d.length] + d) +
              (padding[e.length] + e);
    } else {
        let ret = ``;
        const view = new Uint8Array(arrayBuffer);
        for (let i = 0; i < view.length; ++i) {
            const byte = view[i].toString(16);
            ret += (bytePadding[byte.length] + byte);
        }
        return ret;
    }
}
github petkaantonov / HTML-Music-Player / src / codecs / mp3.js View on Github external
const mp3_huffcodes_5 = new Uint16Array([
    0x0001, 0x0002, 0x0006, 0x0005, 0x0003, 0x0001, 0x0004, 0x0004,
    0x0007, 0x0005, 0x0007, 0x0001, 0x0006, 0x0001, 0x0001, 0x0000
]);

const mp3_huffbits_5 = new Uint8Array([
    1,  3,  6,  7,  3,  3,  6,  7,
    6,  6,  7,  8,  7,  6,  7,  8
]);

const mp3_huffcodes_6 = new Uint16Array([
    0x0007, 0x0003, 0x0005, 0x0001, 0x0006, 0x0002, 0x0003, 0x0002,
    0x0005, 0x0004, 0x0004, 0x0001, 0x0003, 0x0003, 0x0002, 0x0000
]);

const mp3_huffbits_6 = new Uint8Array([
    3,  3,  5,  7,  3,  2,  4,  5,
    4,  4,  5,  6,  6,  5,  6,  7
]);

const mp3_huffcodes_7 = new Uint16Array([
    0x0001, 0x0002, 0x000a, 0x0013, 0x0010, 0x000a, 0x0003, 0x0003,
    0x0007, 0x000a, 0x0005, 0x0003, 0x000b, 0x0004, 0x000d, 0x0011,
    0x0008, 0x0004, 0x000c, 0x000b, 0x0012, 0x000f, 0x000b, 0x0002,
    0x0007, 0x0006, 0x0009, 0x000e, 0x0003, 0x0001, 0x0006, 0x0004,
    0x0005, 0x0003, 0x0002, 0x0000
]);

const mp3_huffbits_7 = new Uint8Array([
    1,  3,  6,  8,  8,  9,  3,  4,
    6,  7,  7,  8,  6,  5,  7,  8,
    8,  9,  7,  7,  8,  9,  9,  9,