Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream.js array buffer ajax #27

Open
annopnod opened this issue Sep 29, 2018 · 2 comments
Open

stream.js array buffer ajax #27

annopnod opened this issue Sep 29, 2018 · 2 comments

Comments

@annopnod
Copy link

IO.PrimitiveReader = function (data) {
var arr = Array.from(new Uint8Array(data));
var fn = {};
var position = 0;

    fn.read = function (length) {
        var result = arr.slice(position, position + length);
        position += length;
        return result;
    };

    /* read a big-endian 32-bit integer */
    fn.readInt32 = function () {
        var result = (
                (arr[position] << 24)
                + (arr[position + 1] << 16)
                + (arr[position + 2] << 8)
                + arr[position + 3]);
        position += 4;
        return result;
    }

    /* read a big-endian 16-bit integer */
    fn.readInt16 = function () {
        var result = (
                (arr[position] << 8)
                + arr[position + 1]);
        position += 2;
        return result;
    }

    /* read an 8-bit integer */
    fn.readInt8 = function (signed) {
        var result = arr[position];
        if (signed && result > 127)
            result -= 256;
        position += 1;
        return result;
    }

    fn.eof = function () {
        return position >= arr.length;
    }

    fn.readVarInt = function () {
        var result = 0;
        while (true) {
            var b = fn.readInt8();
            if (b & 0x80) {
                result += (b & 0x7f);
                result <<= 7;
            } else {
                /* b is the last byte */
                return result + b;
            }
        }
    };
    return fn;

};
@annopnod
Copy link
Author

change midifile.js

if (trackChunk.id != 'MTrk') {
throw "Unexpected chunk - expected MTrk, got "+ trackChunk.id;
}

if (headerChunk.id != 'MThd' || headerChunk.length != 6) {
throw "Bad .mid file - header not found";
}

change trackChunk.id

String.fromCharCode.apply(null, trackChunk.id)

@annopnod
Copy link
Author

work it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant