diff --git a/.gitignore b/.gitignore index b5ce8fdc4..23ea8bb92 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,8 @@ var sdist develop-eggs .installed.cfg -lib -lib64 +/lib +/lib64 # Installer logs pip-log.txt diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/utils/common.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/utils/common.js new file mode 100644 index 000000000..18f8f8450 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/utils/common.js @@ -0,0 +1,48 @@ +// reduce buffer size, avoiding mem copy +export function shrinkBuf(buf, size) { + if (buf.length === size) { + return buf; + } + if (buf.subarray) { + return buf.subarray(0, size); + } + buf.length = size; + return buf; +} + +export function arraySet(dest, src, src_offs, len, dest_offs) { + if (src.subarray && dest.subarray) { + dest.set(src.subarray(src_offs, src_offs + len), dest_offs); + return; + } + // Fallback to ordinary array + for (var i = 0; i < len; i++) { + dest[dest_offs + i] = src[src_offs + i]; + } +} + +// Join array of chunks to single array. +export function flattenChunks(chunks) { + var i, l, len, pos, chunk, result; + + // calculate data length + len = 0; + for (i = 0, l = chunks.length; i < l; i++) { + len += chunks[i].length; + } + + // join chunks + result = new Uint8Array(len); + pos = 0; + for (i = 0, l = chunks.length; i < l; i++) { + chunk = chunks[i]; + result.set(chunk, pos); + pos += chunk.length; + } + + return result; +} + +export var Buf8 = Uint8Array; +export var Buf16 = Uint16Array; +export var Buf32 = Int32Array; diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/adler32.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/adler32.js new file mode 100644 index 000000000..23f345eab --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/adler32.js @@ -0,0 +1,27 @@ +// Note: adler32 takes 12% for level 0 and 2% for level 6. +// It doesn't worth to make additional optimizationa as in original. +// Small size is preferable. + +export default function adler32(adler, buf, len, pos) { + var s1 = (adler & 0xffff) | 0, + s2 = ((adler >>> 16) & 0xffff) | 0, + n = 0; + + while (len !== 0) { + // Set limit ~ twice less than 5552, to keep + // s2 in 31-bits, because we force signed ints. + // in other case %= will fail. + n = len > 2000 ? 2000 : len; + len -= n; + + do { + s1 = (s1 + buf[pos++]) | 0; + s2 = (s2 + s1) | 0; + } while (--n); + + s1 %= 65521; + s2 %= 65521; + } + + return s1 | (s2 << 16) | 0; +} diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/constants.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/constants.js new file mode 100644 index 000000000..684bc0e51 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/constants.js @@ -0,0 +1,45 @@ +export default { + /* Allowed flush values; see deflate() and inflate() below for details */ + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + + /* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + //Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + //Z_VERSION_ERROR: -6, + + /* compression levels */ + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + + /* Possible values of the data_type field (though see inflate()) */ + Z_BINARY: 0, + Z_TEXT: 1, + //Z_ASCII: 1, // = Z_TEXT (deprecated) + Z_UNKNOWN: 2, + + /* The deflate compression method */ + Z_DEFLATED: 8, + //Z_NULL: null // Use -1 or null inline, depending on var type +}; diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/crc32.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/crc32.js new file mode 100644 index 000000000..80ad1d3e4 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/crc32.js @@ -0,0 +1,35 @@ +// Note: we can't get significant speed boost here. +// So write code to minimize size - no pregenerated tables +// and array tools dependencies. + +// Use ordinary array, since untyped makes no boost here +export default function makeTable() { + var c, + table = []; + + for (var n = 0; n < 256; n++) { + c = n; + for (var k = 0; k < 8; k++) { + c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; + } + table[n] = c; + } + + return table; +} + +// Create table on load. Just 255 signed longs. Not a problem. +var crcTable = makeTable(); + +function crc32(crc, buf, len, pos) { + var t = crcTable, + end = pos + len; + + crc ^= -1; + + for (var i = pos; i < end; i++) { + crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xff]; + } + + return crc ^ -1; // >>> 0; +} diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/deflate.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/deflate.js new file mode 100644 index 000000000..e93ef5a12 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/deflate.js @@ -0,0 +1,1863 @@ +import * as utils from '../utils/common.js'; +import * as trees from './trees.js'; +import adler32 from './adler32.js'; +import crc32 from './crc32.js'; +import msg from './messages.js'; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + +/* Allowed flush values; see deflate() and inflate() below for details */ +export const Z_NO_FLUSH = 0; +export const Z_PARTIAL_FLUSH = 1; +//export const Z_SYNC_FLUSH = 2; +export const Z_FULL_FLUSH = 3; +export const Z_FINISH = 4; +export const Z_BLOCK = 5; +//export const Z_TREES = 6; + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +export const Z_OK = 0; +export const Z_STREAM_END = 1; +//export const Z_NEED_DICT = 2; +//export const Z_ERRNO = -1; +export const Z_STREAM_ERROR = -2; +export const Z_DATA_ERROR = -3; +//export const Z_MEM_ERROR = -4; +export const Z_BUF_ERROR = -5; +//export const Z_VERSION_ERROR = -6; + +/* compression levels */ +//export const Z_NO_COMPRESSION = 0; +//export const Z_BEST_SPEED = 1; +//export const Z_BEST_COMPRESSION = 9; +export const Z_DEFAULT_COMPRESSION = -1; + +export const Z_FILTERED = 1; +export const Z_HUFFMAN_ONLY = 2; +export const Z_RLE = 3; +export const Z_FIXED = 4; +export const Z_DEFAULT_STRATEGY = 0; + +/* Possible values of the data_type field (though see inflate()) */ +//export const Z_BINARY = 0; +//export const Z_TEXT = 1; +//export const Z_ASCII = 1; // = Z_TEXT +export const Z_UNKNOWN = 2; + +/* The deflate compression method */ +export const Z_DEFLATED = 8; + +/*============================================================================*/ + +var MAX_MEM_LEVEL = 9; +/* Maximum value for memLevel in deflateInit2 */ +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_MEM_LEVEL = 8; + +var LENGTH_CODES = 29; +/* number of length codes, not counting the special END_BLOCK code */ +var LITERALS = 256; +/* number of literal bytes 0..255 */ +var L_CODES = LITERALS + 1 + LENGTH_CODES; +/* number of Literal or Length codes, including the END_BLOCK code */ +var D_CODES = 30; +/* number of distance codes */ +var BL_CODES = 19; +/* number of codes used to transfer the bit lengths */ +var HEAP_SIZE = 2 * L_CODES + 1; +/* maximum heap size */ +var MAX_BITS = 15; +/* All codes must not exceed MAX_BITS bits */ + +var MIN_MATCH = 3; +var MAX_MATCH = 258; +var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1; + +var PRESET_DICT = 0x20; + +var INIT_STATE = 42; +var EXTRA_STATE = 69; +var NAME_STATE = 73; +var COMMENT_STATE = 91; +var HCRC_STATE = 103; +var BUSY_STATE = 113; +var FINISH_STATE = 666; + +var BS_NEED_MORE = 1; /* block not completed, need more input or more output */ +var BS_BLOCK_DONE = 2; /* block flush performed */ +var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */ +var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ + +var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. + +function err(strm, errorCode) { + strm.msg = msg[errorCode]; + return errorCode; +} + +function rank(f) { + return (f << 1) - (f > 4 ? 9 : 0); +} + +function zero(buf) { + var len = buf.length; + while (--len >= 0) { + buf[len] = 0; + } +} + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->output buffer and copying into it. + * (See also read_buf()). + */ +function flush_pending(strm) { + var s = strm.state; + + //_tr_flush_bits(s); + var len = s.pending; + if (len > strm.avail_out) { + len = strm.avail_out; + } + if (len === 0) { + return; + } + + utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out); + strm.next_out += len; + s.pending_out += len; + strm.total_out += len; + strm.avail_out -= len; + s.pending -= len; + if (s.pending === 0) { + s.pending_out = 0; + } +} + +function flush_block_only(s, last) { + trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last); + s.block_start = s.strstart; + flush_pending(s.strm); +} + +function put_byte(s, b) { + s.pending_buf[s.pending++] = b; +} + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +function putShortMSB(s, b) { + // put_byte(s, (Byte)(b >> 8)); + // put_byte(s, (Byte)(b & 0xff)); + s.pending_buf[s.pending++] = (b >>> 8) & 0xff; + s.pending_buf[s.pending++] = b & 0xff; +} + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->input buffer and copying from it. + * (See also flush_pending()). + */ +function read_buf(strm, buf, start, size) { + var len = strm.avail_in; + + if (len > size) { + len = size; + } + if (len === 0) { + return 0; + } + + strm.avail_in -= len; + + // zmemcpy(buf, strm->next_in, len); + utils.arraySet(buf, strm.input, strm.next_in, len, start); + if (strm.state.wrap === 1) { + strm.adler = adler32(strm.adler, buf, len, start); + } else if (strm.state.wrap === 2) { + strm.adler = crc32(strm.adler, buf, len, start); + } + + strm.next_in += len; + strm.total_in += len; + + return len; +} + +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +function longest_match(s, cur_match) { + var chain_length = s.max_chain_length; /* max hash chain length */ + var scan = s.strstart; /* current string */ + var match; /* matched string */ + var len; /* length of current match */ + var best_len = s.prev_length; /* best match length so far */ + var nice_match = s.nice_match; /* stop if match long enough */ + var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0; /*NIL*/ + + var _win = s.window; // shortcut + + var wmask = s.w_mask; + var prev = s.prev; + + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + + var strend = s.strstart + MAX_MATCH; + var scan_end1 = _win[scan + best_len - 1]; + var scan_end = _win[scan + best_len]; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s.prev_length >= s.good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if (nice_match > s.lookahead) { + nice_match = s.lookahead; + } + + // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + // Assert(cur_match < s->strstart, "no future"); + match = cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ + + if ( + _win[match + best_len] !== scan_end || + _win[match + best_len - 1] !== scan_end1 || + _win[match] !== _win[scan] || + _win[++match] !== _win[scan + 1] + ) { + continue; + } + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2; + match++; + // Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + // Do nothing + } while ( + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && + scan < strend + ); + + // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (strend - scan); + scan = strend - MAX_MATCH; + + if (len > best_len) { + s.match_start = cur_match; + best_len = len; + if (len >= nice_match) { + break; + } + scan_end1 = _win[scan + best_len - 1]; + scan_end = _win[scan + best_len]; + } + } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0); + + if (best_len <= s.lookahead) { + return best_len; + } + return s.lookahead; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +function fill_window(s) { + var _w_size = s.w_size; + var p, n, m, more, str; + + //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = s.window_size - s.lookahead - s.strstart; + + // JS ints have 32 bit, block below not needed + /* Deal with !@#$% 64K limit: */ + //if (sizeof(int) <= 2) { + // if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + // more = wsize; + // + // } else if (more == (unsigned)(-1)) { + // /* Very unlikely, but possible on 16 bit machine if + // * strstart == 0 && lookahead == 1 (input done a byte at time) + // */ + // more--; + // } + //} + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) { + utils.arraySet(s.window, s.window, _w_size, _w_size, 0); + s.match_start -= _w_size; + s.strstart -= _w_size; + /* we now have strstart >= MAX_DIST */ + s.block_start -= _w_size; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + + n = s.hash_size; + p = n; + do { + m = s.head[--p]; + s.head[p] = m >= _w_size ? m - _w_size : 0; + } while (--n); + + n = _w_size; + p = n; + do { + m = s.prev[--p]; + s.prev[p] = m >= _w_size ? m - _w_size : 0; + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); + + more += _w_size; + } + if (s.strm.avail_in === 0) { + break; + } + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + //Assert(more >= 2, "more < 2"); + n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more); + s.lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s.lookahead + s.insert >= MIN_MATCH) { + str = s.strstart - s.insert; + s.ins_h = s.window[str]; + + /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask; + //#if MIN_MATCH != 3 + // Call update_hash() MIN_MATCH-3 more times + //#endif + while (s.insert) { + /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask; + + s.prev[str & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = str; + str++; + s.insert--; + if (s.lookahead + s.insert < MIN_MATCH) { + break; + } + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + // if (s.high_water < s.window_size) { + // var curr = s.strstart + s.lookahead; + // var init = 0; + // + // if (s.high_water < curr) { + // /* Previous high water mark below current data -- zero WIN_INIT + // * bytes or up to end of window, whichever is less. + // */ + // init = s.window_size - curr; + // if (init > WIN_INIT) + // init = WIN_INIT; + // zmemzero(s->window + curr, (unsigned)init); + // s->high_water = curr + init; + // } + // else if (s->high_water < (ulg)curr + WIN_INIT) { + // /* High water mark at or above current data, but below current data + // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + // * to end of window, whichever is less. + // */ + // init = (ulg)curr + WIN_INIT - s->high_water; + // if (init > s->window_size - s->high_water) + // init = s->window_size - s->high_water; + // zmemzero(s->window + s->high_water, (unsigned)init); + // s->high_water += init; + // } + // } + // + // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + // "not enough room for search"); +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +function deflate_stored(s, flush) { + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + var max_block_size = 0xffff; + + if (max_block_size > s.pending_buf_size - 5) { + max_block_size = s.pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s.lookahead <= 1) { + //Assert(s->strstart < s->w_size+MAX_DIST(s) || + // s->block_start >= (long)s->w_size, "slide too late"); + // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) || + // s.block_start >= s.w_size)) { + // throw new Error("slide too late"); + // } + + fill_window(s); + if (s.lookahead === 0 && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + + if (s.lookahead === 0) { + break; + } + /* flush the current block */ + } + //Assert(s->block_start >= 0L, "block gone"); + // if (s.block_start < 0) throw new Error("block gone"); + + s.strstart += s.lookahead; + s.lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + var max_start = s.block_start + max_block_size; + + if (s.strstart === 0 || s.strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s.lookahead = s.strstart - max_start; + s.strstart = max_start; + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + + s.insert = 0; + + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + + if (s.strstart > s.block_start) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + + return BS_NEED_MORE; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +function deflate_fast(s, flush) { + var hash_head; /* head of the hash chain */ + var bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s.lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { + break; /* flush the current block */ + } + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = 0 /*NIL*/; + if (s.lookahead >= MIN_MATCH) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head !== 0 /*NIL*/ && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s.match_length = longest_match(s, hash_head); + /* longest_match() sets match_start */ + } + if (s.match_length >= MIN_MATCH) { + // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only + + /*** _tr_tally_dist(s, s.strstart - s.match_start, + s.match_length - MIN_MATCH, bflush); ***/ + bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH); + + s.lookahead -= s.match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ + if (s.match_length <= s.max_lazy_match /*max_insert_length*/ && s.lookahead >= MIN_MATCH) { + s.match_length--; /* string at strstart already in table */ + do { + s.strstart++; + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s.match_length !== 0); + s.strstart++; + } else { + s.strstart += s.match_length; + s.match_length = 0; + s.ins_h = s.window[s.strstart]; + /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask; + + //#if MIN_MATCH != 3 + // Call UPDATE_HASH() MIN_MATCH-3 more times + //#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + //Tracevv((stderr,"%c", s.window[s.strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + + s.lookahead--; + s.strstart++; + } + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +function deflate_slow(s, flush) { + var hash_head; /* head of hash chain */ + var bflush; /* set if current block must be flushed */ + + var max_insert; + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s.lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { + break; + } /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = 0 /*NIL*/; + if (s.lookahead >= MIN_MATCH) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + + /* Find the longest match, discarding those <= prev_length. + */ + s.prev_length = s.match_length; + s.prev_match = s.match_start; + s.match_length = MIN_MATCH - 1; + + if ( + hash_head !== 0 /*NIL*/ && + s.prev_length < s.max_lazy_match && + s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD /*MAX_DIST(s)*/ + ) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s.match_length = longest_match(s, hash_head); + /* longest_match() sets match_start */ + + if ( + s.match_length <= 5 && + (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096)) /*TOO_FAR*/ + ) { + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s.match_length = MIN_MATCH - 1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) { + max_insert = s.strstart + s.lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + //check_match(s, s.strstart-1, s.prev_match, s.prev_length); + + /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match, + s.prev_length - MIN_MATCH, bflush);***/ + bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH); + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s.lookahead -= s.prev_length - 1; + s.prev_length -= 2; + do { + if (++s.strstart <= max_insert) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + } while (--s.prev_length !== 0); + s.match_available = 0; + s.match_length = MIN_MATCH - 1; + s.strstart++; + + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } else if (s.match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + //Tracevv((stderr,"%c", s->window[s->strstart-1])); + /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); + + if (bflush) { + /*** FLUSH_BLOCK_ONLY(s, 0) ***/ + flush_block_only(s, false); + /***/ + } + s.strstart++; + s.lookahead--; + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s.match_available = 1; + s.strstart++; + s.lookahead--; + } + } + //Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s.match_available) { + //Tracevv((stderr,"%c", s->window[s->strstart-1])); + /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); + + s.match_available = 0; + } + s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + + return BS_BLOCK_DONE; +} + +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +function deflate_rle(s, flush) { + var bflush; /* set if current block must be flushed */ + var prev; /* byte at distance one to match */ + var scan, strend; /* scan goes up to strend for length of run */ + + var _win = s.window; + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest run, plus one for the unrolled loop. + */ + if (s.lookahead <= MAX_MATCH) { + fill_window(s); + if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { + break; + } /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + s.match_length = 0; + if (s.lookahead >= MIN_MATCH && s.strstart > 0) { + scan = s.strstart - 1; + prev = _win[scan]; + if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) { + strend = s.strstart + MAX_MATCH; + do { + // Do nothing + } while ( + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + prev === _win[++scan] && + scan < strend + ); + s.match_length = MAX_MATCH - (strend - scan); + if (s.match_length > s.lookahead) { + s.match_length = s.lookahead; + } + } + //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (s.match_length >= MIN_MATCH) { + //check_match(s, s.strstart, s.strstart - 1, s.match_length); + + /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/ + bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH); + + s.lookahead -= s.match_length; + s.strstart += s.match_length; + s.match_length = 0; + } else { + /* No match, output a literal byte */ + //Tracevv((stderr,"%c", s->window[s->strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + + s.lookahead--; + s.strstart++; + } + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = 0; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +function deflate_huff(s, flush) { + var bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s.lookahead === 0) { + fill_window(s); + if (s.lookahead === 0) { + if (flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s.match_length = 0; + //Tracevv((stderr,"%c", s->window[s->strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + s.lookahead--; + s.strstart++; + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = 0; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +function Config(good_length, max_lazy, nice_length, max_chain, func) { + this.good_length = good_length; + this.max_lazy = max_lazy; + this.nice_length = nice_length; + this.max_chain = max_chain; + this.func = func; +} + +var configuration_table; + +configuration_table = [ + /* good lazy nice chain */ + new Config(0, 0, 0, 0, deflate_stored) /* 0 store only */, + new Config(4, 4, 8, 4, deflate_fast) /* 1 max speed, no lazy matches */, + new Config(4, 5, 16, 8, deflate_fast) /* 2 */, + new Config(4, 6, 32, 32, deflate_fast) /* 3 */, + + new Config(4, 4, 16, 16, deflate_slow) /* 4 lazy matches */, + new Config(8, 16, 32, 32, deflate_slow) /* 5 */, + new Config(8, 16, 128, 128, deflate_slow) /* 6 */, + new Config(8, 32, 128, 256, deflate_slow) /* 7 */, + new Config(32, 128, 258, 1024, deflate_slow) /* 8 */, + new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */, +]; + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +function lm_init(s) { + s.window_size = 2 * s.w_size; + + /*** CLEAR_HASH(s); ***/ + zero(s.head); // Fill with NIL (= 0); + + /* Set the default configuration parameters: + */ + s.max_lazy_match = configuration_table[s.level].max_lazy; + s.good_match = configuration_table[s.level].good_length; + s.nice_match = configuration_table[s.level].nice_length; + s.max_chain_length = configuration_table[s.level].max_chain; + + s.strstart = 0; + s.block_start = 0; + s.lookahead = 0; + s.insert = 0; + s.match_length = s.prev_length = MIN_MATCH - 1; + s.match_available = 0; + s.ins_h = 0; +} + +function DeflateState() { + this.strm = null; /* pointer back to this zlib stream */ + this.status = 0; /* as the name implies */ + this.pending_buf = null; /* output still pending */ + this.pending_buf_size = 0; /* size of pending_buf */ + this.pending_out = 0; /* next pending byte to output to the stream */ + this.pending = 0; /* nb of bytes in the pending buffer */ + this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ + this.gzhead = null; /* gzip header information to write */ + this.gzindex = 0; /* where in extra, name, or comment */ + this.method = Z_DEFLATED; /* can only be DEFLATED */ + this.last_flush = -1; /* value of flush param for previous deflate call */ + + this.w_size = 0; /* LZ77 window size (32K by default) */ + this.w_bits = 0; /* log2(w_size) (8..16) */ + this.w_mask = 0; /* w_size - 1 */ + + this.window = null; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. + */ + + this.window_size = 0; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + this.prev = null; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + this.head = null; /* Heads of the hash chains or NIL. */ + + this.ins_h = 0; /* hash index of string to be inserted */ + this.hash_size = 0; /* number of elements in hash table */ + this.hash_bits = 0; /* log2(hash_size) */ + this.hash_mask = 0; /* hash_size-1 */ + + this.hash_shift = 0; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + this.block_start = 0; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + this.match_length = 0; /* length of best match */ + this.prev_match = 0; /* previous match */ + this.match_available = 0; /* set if previous match exists */ + this.strstart = 0; /* start of string to insert */ + this.match_start = 0; /* start of matching string */ + this.lookahead = 0; /* number of valid bytes ahead in window */ + + this.prev_length = 0; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + this.max_chain_length = 0; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + this.max_lazy_match = 0; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ + // That's alias to max_lazy_match, don't use directly + //this.max_insert_length = 0; + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + this.level = 0; /* compression level (1..9) */ + this.strategy = 0; /* favor or force Huffman coding*/ + + this.good_match = 0; + /* Use a faster search when the previous match is longer than this */ + + this.nice_match = 0; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + + /* Didn't use ct_data typedef below to suppress compiler warning */ + + // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + // Use flat array of DOUBLE size, with interleaved fata, + // because JS does not support effective + this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); + this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2); + this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2); + zero(this.dyn_ltree); + zero(this.dyn_dtree); + zero(this.bl_tree); + + this.l_desc = null; /* desc. for literal tree */ + this.d_desc = null; /* desc. for distance tree */ + this.bl_desc = null; /* desc. for bit length tree */ + + //ush bl_count[MAX_BITS+1]; + this.bl_count = new utils.Buf16(MAX_BITS + 1); + /* number of codes at each bit length for an optimal tree */ + + //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */ + zero(this.heap); + + this.heap_len = 0; /* number of elements in the heap */ + this.heap_max = 0; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1]; + zero(this.depth); + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + this.l_buf = 0; /* buffer index for literals or lengths */ + + this.lit_bufsize = 0; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + this.last_lit = 0; /* running index in l_buf */ + + this.d_buf = 0; + /* Buffer index for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + this.opt_len = 0; /* bit length of current block with optimal trees */ + this.static_len = 0; /* bit length of current block with static trees */ + this.matches = 0; /* number of string matches in current block */ + this.insert = 0; /* bytes at end of window left to insert */ + + this.bi_buf = 0; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + this.bi_valid = 0; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + + // Used for window memory init. We safely ignore it for JS. That makes + // sense only for pointers and memory check tools. + //this.high_water = 0; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ +} + +function deflateResetKeep(strm) { + var s; + + if (!strm || !strm.state) { + return err(strm, Z_STREAM_ERROR); + } + + strm.total_in = strm.total_out = 0; + strm.data_type = Z_UNKNOWN; + + s = strm.state; + s.pending = 0; + s.pending_out = 0; + + if (s.wrap < 0) { + s.wrap = -s.wrap; + /* was made negative by deflate(..., Z_FINISH); */ + } + s.status = s.wrap ? INIT_STATE : BUSY_STATE; + strm.adler = + s.wrap === 2 + ? 0 // crc32(0, Z_NULL, 0) + : 1; // adler32(0, Z_NULL, 0) + s.last_flush = Z_NO_FLUSH; + trees._tr_init(s); + return Z_OK; +} + +function deflateReset(strm) { + var ret = deflateResetKeep(strm); + if (ret === Z_OK) { + lm_init(strm.state); + } + return ret; +} + +function deflateSetHeader(strm, head) { + if (!strm || !strm.state) { + return Z_STREAM_ERROR; + } + if (strm.state.wrap !== 2) { + return Z_STREAM_ERROR; + } + strm.state.gzhead = head; + return Z_OK; +} + +function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { + if (!strm) { + // === Z_NULL + return Z_STREAM_ERROR; + } + var wrap = 1; + + if (level === Z_DEFAULT_COMPRESSION) { + level = 6; + } + + if (windowBits < 0) { + /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } + + if ( + memLevel < 1 || + memLevel > MAX_MEM_LEVEL || + method !== Z_DEFLATED || + windowBits < 8 || + windowBits > 15 || + level < 0 || + level > 9 || + strategy < 0 || + strategy > Z_FIXED + ) { + return err(strm, Z_STREAM_ERROR); + } + + if (windowBits === 8) { + windowBits = 9; + } + /* until 256-byte window bug fixed */ + + var s = new DeflateState(); + + strm.state = s; + s.strm = strm; + + s.wrap = wrap; + s.gzhead = null; + s.w_bits = windowBits; + s.w_size = 1 << s.w_bits; + s.w_mask = s.w_size - 1; + + s.hash_bits = memLevel + 7; + s.hash_size = 1 << s.hash_bits; + s.hash_mask = s.hash_size - 1; + s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH); + + s.window = new utils.Buf8(s.w_size * 2); + s.head = new utils.Buf16(s.hash_size); + s.prev = new utils.Buf16(s.w_size); + + // Don't need mem init magic for JS. + //s.high_water = 0; /* nothing written to s->window yet */ + + s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + s.pending_buf_size = s.lit_bufsize * 4; + + //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + //s->pending_buf = (uchf *) overlay; + s.pending_buf = new utils.Buf8(s.pending_buf_size); + + // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`) + //s->d_buf = overlay + s->lit_bufsize/sizeof(ush); + s.d_buf = 1 * s.lit_bufsize; + + //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + s.l_buf = (1 + 2) * s.lit_bufsize; + + s.level = level; + s.strategy = strategy; + s.method = method; + + return deflateReset(strm); +} + +function deflateInit(strm, level) { + return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); +} + +function deflate(strm, flush) { + var old_flush, s; + var beg, val; // for gzip header write only + + if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) { + return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR; + } + + s = strm.state; + + if (!strm.output || (!strm.input && strm.avail_in !== 0) || (s.status === FINISH_STATE && flush !== Z_FINISH)) { + return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR); + } + + s.strm = strm; /* just in case */ + old_flush = s.last_flush; + s.last_flush = flush; + + /* Write the header */ + if (s.status === INIT_STATE) { + if (s.wrap === 2) { + // GZIP header + strm.adler = 0; //crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (!s.gzhead) { + // s->gzhead == Z_NULL + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0); + put_byte(s, OS_CODE); + s.status = BUSY_STATE; + } else { + put_byte( + s, + (s.gzhead.text ? 1 : 0) + + (s.gzhead.hcrc ? 2 : 0) + + (!s.gzhead.extra ? 0 : 4) + + (!s.gzhead.name ? 0 : 8) + + (!s.gzhead.comment ? 0 : 16) + ); + put_byte(s, s.gzhead.time & 0xff); + put_byte(s, (s.gzhead.time >> 8) & 0xff); + put_byte(s, (s.gzhead.time >> 16) & 0xff); + put_byte(s, (s.gzhead.time >> 24) & 0xff); + put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0); + put_byte(s, s.gzhead.os & 0xff); + if (s.gzhead.extra && s.gzhead.extra.length) { + put_byte(s, s.gzhead.extra.length & 0xff); + put_byte(s, (s.gzhead.extra.length >> 8) & 0xff); + } + if (s.gzhead.hcrc) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0); + } + s.gzindex = 0; + s.status = EXTRA_STATE; + } + } // DEFLATE header + else { + var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8; + var level_flags = -1; + + if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) { + level_flags = 0; + } else if (s.level < 6) { + level_flags = 1; + } else if (s.level === 6) { + level_flags = 2; + } else { + level_flags = 3; + } + header |= level_flags << 6; + if (s.strstart !== 0) { + header |= PRESET_DICT; + } + header += 31 - (header % 31); + + s.status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s.strstart !== 0) { + putShortMSB(s, strm.adler >>> 16); + putShortMSB(s, strm.adler & 0xffff); + } + strm.adler = 1; // adler32(0L, Z_NULL, 0); + } + } + + //#ifdef GZIP + if (s.status === EXTRA_STATE) { + if (s.gzhead.extra /* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + + while (s.gzindex < (s.gzhead.extra.length & 0xffff)) { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + break; + } + } + put_byte(s, s.gzhead.extra[s.gzindex] & 0xff); + s.gzindex++; + } + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (s.gzindex === s.gzhead.extra.length) { + s.gzindex = 0; + s.status = NAME_STATE; + } + } else { + s.status = NAME_STATE; + } + } + if (s.status === NAME_STATE) { + if (s.gzhead.name /* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + //int val; + + do { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + val = 1; + break; + } + } + // JS specific: little magic to add zero terminator to end of string + if (s.gzindex < s.gzhead.name.length) { + val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff; + } else { + val = 0; + } + put_byte(s, val); + } while (val !== 0); + + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (val === 0) { + s.gzindex = 0; + s.status = COMMENT_STATE; + } + } else { + s.status = COMMENT_STATE; + } + } + if (s.status === COMMENT_STATE) { + if (s.gzhead.comment /* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + //int val; + + do { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + val = 1; + break; + } + } + // JS specific: little magic to add zero terminator to end of string + if (s.gzindex < s.gzhead.comment.length) { + val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff; + } else { + val = 0; + } + put_byte(s, val); + } while (val !== 0); + + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (val === 0) { + s.status = HCRC_STATE; + } + } else { + s.status = HCRC_STATE; + } + } + if (s.status === HCRC_STATE) { + if (s.gzhead.hcrc) { + if (s.pending + 2 > s.pending_buf_size) { + flush_pending(strm); + } + if (s.pending + 2 <= s.pending_buf_size) { + put_byte(s, strm.adler & 0xff); + put_byte(s, (strm.adler >> 8) & 0xff); + strm.adler = 0; //crc32(0L, Z_NULL, 0); + s.status = BUSY_STATE; + } + } else { + s.status = BUSY_STATE; + } + } + //#endif + + /* Flush as much pending output as possible */ + if (s.pending !== 0) { + flush_pending(strm); + if (strm.avail_out === 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s.last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) { + return err(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s.status === FINISH_STATE && strm.avail_in !== 0) { + return err(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm.avail_in !== 0 || s.lookahead !== 0 || (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) { + var bstate = + s.strategy === Z_HUFFMAN_ONLY + ? deflate_huff(s, flush) + : s.strategy === Z_RLE + ? deflate_rle(s, flush) + : configuration_table[s.level].func(s, flush); + + if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) { + s.status = FINISH_STATE; + } + if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) { + if (strm.avail_out === 0) { + s.last_flush = -1; + /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate === BS_BLOCK_DONE) { + if (flush === Z_PARTIAL_FLUSH) { + trees._tr_align(s); + } else if (flush !== Z_BLOCK) { + /* FULL_FLUSH or SYNC_FLUSH */ + + trees._tr_stored_block(s, 0, 0, false); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush === Z_FULL_FLUSH) { + /*** CLEAR_HASH(s); ***/ /* forget history */ + zero(s.head); // Fill with NIL (= 0); + + if (s.lookahead === 0) { + s.strstart = 0; + s.block_start = 0; + s.insert = 0; + } + } + } + flush_pending(strm); + if (strm.avail_out === 0) { + s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + //Assert(strm->avail_out > 0, "bug2"); + //if (strm.avail_out <= 0) { throw new Error("bug2");} + + if (flush !== Z_FINISH) { + return Z_OK; + } + if (s.wrap <= 0) { + return Z_STREAM_END; + } + + /* Write the trailer */ + if (s.wrap === 2) { + put_byte(s, strm.adler & 0xff); + put_byte(s, (strm.adler >> 8) & 0xff); + put_byte(s, (strm.adler >> 16) & 0xff); + put_byte(s, (strm.adler >> 24) & 0xff); + put_byte(s, strm.total_in & 0xff); + put_byte(s, (strm.total_in >> 8) & 0xff); + put_byte(s, (strm.total_in >> 16) & 0xff); + put_byte(s, (strm.total_in >> 24) & 0xff); + } else { + putShortMSB(s, strm.adler >>> 16); + putShortMSB(s, strm.adler & 0xffff); + } + + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s.wrap > 0) { + s.wrap = -s.wrap; + } + /* write the trailer only once! */ + return s.pending !== 0 ? Z_OK : Z_STREAM_END; +} + +function deflateEnd(strm) { + var status; + + if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) { + return Z_STREAM_ERROR; + } + + status = strm.state.status; + if ( + status !== INIT_STATE && + status !== EXTRA_STATE && + status !== NAME_STATE && + status !== COMMENT_STATE && + status !== HCRC_STATE && + status !== BUSY_STATE && + status !== FINISH_STATE + ) { + return err(strm, Z_STREAM_ERROR); + } + + strm.state = null; + + return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; +} + +/* ========================================================================= + * Initializes the compression dictionary from the given byte + * sequence without producing any compressed output. + */ +function deflateSetDictionary(strm, dictionary) { + var dictLength = dictionary.length; + + var s; + var str, n; + var wrap; + var avail; + var next; + var input; + var tmpDict; + + if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) { + return Z_STREAM_ERROR; + } + + s = strm.state; + wrap = s.wrap; + + if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) { + return Z_STREAM_ERROR; + } + + /* when using zlib wrappers, compute Adler-32 for provided dictionary */ + if (wrap === 1) { + /* adler32(strm->adler, dictionary, dictLength); */ + strm.adler = adler32(strm.adler, dictionary, dictLength, 0); + } + + s.wrap = 0; /* avoid computing Adler-32 in read_buf */ + + /* if dictionary would fill window, just replace the history */ + if (dictLength >= s.w_size) { + if (wrap === 0) { + /* already empty otherwise */ + /*** CLEAR_HASH(s); ***/ + zero(s.head); // Fill with NIL (= 0); + s.strstart = 0; + s.block_start = 0; + s.insert = 0; + } + /* use the tail */ + // dictionary = dictionary.slice(dictLength - s.w_size); + tmpDict = new utils.Buf8(s.w_size); + utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0); + dictionary = tmpDict; + dictLength = s.w_size; + } + /* insert dictionary into window and hash */ + avail = strm.avail_in; + next = strm.next_in; + input = strm.input; + strm.avail_in = dictLength; + strm.next_in = 0; + strm.input = dictionary; + fill_window(s); + while (s.lookahead >= MIN_MATCH) { + str = s.strstart; + n = s.lookahead - (MIN_MATCH - 1); + do { + /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask; + + s.prev[str & s.w_mask] = s.head[s.ins_h]; + + s.head[s.ins_h] = str; + str++; + } while (--n); + s.strstart = str; + s.lookahead = MIN_MATCH - 1; + fill_window(s); + } + s.strstart += s.lookahead; + s.block_start = s.strstart; + s.insert = s.lookahead; + s.lookahead = 0; + s.match_length = s.prev_length = MIN_MATCH - 1; + s.match_available = 0; + strm.next_in = next; + strm.input = input; + strm.avail_in = avail; + s.wrap = wrap; + return Z_OK; +} + +export { + deflateInit, + deflateInit2, + deflateReset, + deflateResetKeep, + deflateSetHeader, + deflate, + deflateEnd, + deflateSetDictionary, +}; +export var deflateInfo = 'pako deflate (from Nodeca project)'; + +/* Not implemented +exports.deflateBound = deflateBound; +exports.deflateCopy = deflateCopy; +exports.deflateParams = deflateParams; +exports.deflatePending = deflatePending; +exports.deflatePrime = deflatePrime; +exports.deflateTune = deflateTune; +*/ diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/gzheader.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/gzheader.js new file mode 100644 index 000000000..8d59622e1 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/gzheader.js @@ -0,0 +1,35 @@ +export default function GZheader() { + /* true if compressed data believed to be text */ + this.text = 0; + /* modification time */ + this.time = 0; + /* extra flags (not used when writing a gzip file) */ + this.xflags = 0; + /* operating system */ + this.os = 0; + /* pointer to extra field or Z_NULL if none */ + this.extra = null; + /* extra field length (valid if extra != Z_NULL) */ + this.extra_len = 0; // Actually, we don't need it in JS, + // but leave for few code modifications + + // + // Setup limits is not necessary because in js we should not preallocate memory + // for inflate use constant limit in 65536 bytes + // + + /* space at extra (only when reading header) */ + // this.extra_max = 0; + /* pointer to zero-terminated file name or Z_NULL */ + this.name = ''; + /* space at name (only when reading header) */ + // this.name_max = 0; + /* pointer to zero-terminated comment or Z_NULL */ + this.comment = ''; + /* space at comment (only when reading header) */ + // this.comm_max = 0; + /* true if there was or will be a header crc */ + this.hcrc = 0; + /* true when done reading gzip header (not used when writing a gzip file) */ + this.done = false; +} diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inffast.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inffast.js new file mode 100644 index 000000000..0ed2cad46 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inffast.js @@ -0,0 +1,327 @@ +// See state defs from inflate.js +var BAD = 30; /* got a data error -- remain here until reset */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state.mode === LEN + strm.avail_in >= 6 + strm.avail_out >= 258 + start >= strm.avail_out + state.bits < 8 + + On return, state.mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm.avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm.avail_out >= 258 for each loop to avoid checking for + output space. + */ +export default function inflate_fast(strm, start) { + var state; + var _in; /* local strm.input */ + var last; /* have enough input while in < last */ + var _out; /* local strm.output */ + var beg; /* inflate()'s initial strm.output */ + var end; /* while out < end, enough space available */ + //#ifdef INFLATE_STRICT + var dmax; /* maximum distance from zlib header */ + //#endif + var wsize; /* window size or zero if not using window */ + var whave; /* valid bytes in the window */ + var wnext; /* window write index */ + // Use `s_window` instead `window`, avoid conflict with instrumentation tools + var s_window; /* allocated sliding window, if wsize != 0 */ + var hold; /* local strm.hold */ + var bits; /* local strm.bits */ + var lcode; /* local strm.lencode */ + var dcode; /* local strm.distcode */ + var lmask; /* mask for first level of length codes */ + var dmask; /* mask for first level of distance codes */ + var here; /* retrieved table entry */ + var op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + var len; /* match length, unused bytes */ + var dist; /* match distance */ + var from; /* where to copy match from */ + var from_source; + + var input, output; // JS specific, because we have no pointers + + /* copy state to local variables */ + state = strm.state; + //here = state.here; + _in = strm.next_in; + input = strm.input; + last = _in + (strm.avail_in - 5); + _out = strm.next_out; + output = strm.output; + beg = _out - (start - strm.avail_out); + end = _out + (strm.avail_out - 257); + //#ifdef INFLATE_STRICT + dmax = state.dmax; + //#endif + wsize = state.wsize; + whave = state.whave; + wnext = state.wnext; + s_window = state.window; + hold = state.hold; + bits = state.bits; + lcode = state.lencode; + dcode = state.distcode; + lmask = (1 << state.lenbits) - 1; + dmask = (1 << state.distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + top: do { + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + + here = lcode[hold & lmask]; + + dolen: for (;;) { + // Goto emulation + op = here >>> 24 /*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff /*here.op*/; + if (op === 0) { + /* literal */ + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + output[_out++] = here & 0xffff /*here.val*/; + } else if (op & 16) { + /* length base */ + len = here & 0xffff /*here.val*/; + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + len += hold & ((1 << op) - 1); + hold >>>= op; + bits -= op; + } + //Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + here = dcode[hold & dmask]; + + dodist: for (;;) { + // goto emulation + op = here >>> 24 /*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff /*here.op*/; + + if (op & 16) { + /* distance base */ + dist = here & 0xffff /*here.val*/; + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + } + dist += hold & ((1 << op) - 1); + //#ifdef INFLATE_STRICT + if (dist > dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } + //#endif + hold >>>= op; + bits -= op; + //Tracevv((stderr, "inflate: distance %u\n", dist)); + op = _out - beg; /* max distance in output */ + if (dist > op) { + /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } + + // (!) This block is disabled in zlib defailts, + // don't enable it for binary compatibility + //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + // if (len <= op - whave) { + // do { + // output[_out++] = 0; + // } while (--len); + // continue top; + // } + // len -= op - whave; + // do { + // output[_out++] = 0; + // } while (--op > whave); + // if (op === 0) { + // from = _out - dist; + // do { + // output[_out++] = output[from++]; + // } while (--len); + // continue top; + // } + //#endif + } + from = 0; // window index + from_source = s_window; + if (wnext === 0) { + /* very common case */ + from += wsize - op; + if (op < len) { + /* some from window */ + len -= op; + do { + output[_out++] = s_window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } else if (wnext < op) { + /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { + /* some from end of window */ + len -= op; + do { + output[_out++] = s_window[from++]; + } while (--op); + from = 0; + if (wnext < len) { + /* some from start of window */ + op = wnext; + len -= op; + do { + output[_out++] = s_window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + } else { + /* contiguous in window */ + from += wnext - op; + if (op < len) { + /* some from window */ + len -= op; + do { + output[_out++] = s_window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + while (len > 2) { + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + len -= 3; + } + if (len) { + output[_out++] = from_source[from++]; + if (len > 1) { + output[_out++] = from_source[from++]; + } + } + } else { + from = _out - dist; /* copy direct from output */ + do { + /* minimum length is three */ + output[_out++] = output[from++]; + output[_out++] = output[from++]; + output[_out++] = output[from++]; + len -= 3; + } while (len > 2); + if (len) { + output[_out++] = output[from++]; + if (len > 1) { + output[_out++] = output[from++]; + } + } + } + } else if ((op & 64) === 0) { + /* 2nd level distance code */ + here = dcode[(here & 0xffff) /*here.val*/ + (hold & ((1 << op) - 1))]; + continue dodist; + } else { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } else if ((op & 64) === 0) { + /* 2nd level length code */ + here = lcode[(here & 0xffff) /*here.val*/ + (hold & ((1 << op) - 1))]; + continue dolen; + } else if (op & 32) { + /* end-of-block */ + //Tracevv((stderr, "inflate: end of block\n")); + state.mode = TYPE; + break top; + } else { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } while (_in < last && _out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + _in -= len; + bits -= len << 3; + hold &= (1 << bits) - 1; + + /* update state and return */ + strm.next_in = _in; + strm.next_out = _out; + strm.avail_in = _in < last ? 5 + (last - _in) : 5 - (_in - last); + strm.avail_out = _out < end ? 257 + (end - _out) : 257 - (_out - end); + state.hold = hold; + state.bits = bits; + return; +} diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inflate.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inflate.js new file mode 100644 index 000000000..2b23fe437 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inflate.js @@ -0,0 +1,1641 @@ +import * as utils from '../utils/common.js'; +import adler32 from './adler32.js'; +import crc32 from './crc32.js'; +import inflate_fast from './inffast.js'; +import inflate_table from './inftrees.js'; + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + +/* Allowed flush values; see deflate() and inflate() below for details */ +//export const Z_NO_FLUSH = 0; +//export const Z_PARTIAL_FLUSH = 1; +//export const Z_SYNC_FLUSH = 2; +//export const Z_FULL_FLUSH = 3; +export const Z_FINISH = 4; +export const Z_BLOCK = 5; +export const Z_TREES = 6; + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +export const Z_OK = 0; +export const Z_STREAM_END = 1; +export const Z_NEED_DICT = 2; +//export const Z_ERRNO = -1; +export const Z_STREAM_ERROR = -2; +export const Z_DATA_ERROR = -3; +export const Z_MEM_ERROR = -4; +export const Z_BUF_ERROR = -5; +//export const Z_VERSION_ERROR = -6; + +/* The deflate compression method */ +export const Z_DEFLATED = 8; + +/* STATES ====================================================================*/ +/* ===========================================================================*/ + +var HEAD = 1; /* i: waiting for magic header */ +var FLAGS = 2; /* i: waiting for method and flags (gzip) */ +var TIME = 3; /* i: waiting for modification time (gzip) */ +var OS = 4; /* i: waiting for extra flags and operating system (gzip) */ +var EXLEN = 5; /* i: waiting for extra length (gzip) */ +var EXTRA = 6; /* i: waiting for extra bytes (gzip) */ +var NAME = 7; /* i: waiting for end of file name (gzip) */ +var COMMENT = 8; /* i: waiting for end of comment (gzip) */ +var HCRC = 9; /* i: waiting for header crc (gzip) */ +var DICTID = 10; /* i: waiting for dictionary check value */ +var DICT = 11; /* waiting for inflateSetDictionary() call */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ +var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */ +var STORED = 14; /* i: waiting for stored size (length and complement) */ +var COPY_ = 15; /* i/o: same as COPY below, but only first time in */ +var COPY = 16; /* i/o: waiting for input or output to copy stored block */ +var TABLE = 17; /* i: waiting for dynamic block table lengths */ +var LENLENS = 18; /* i: waiting for code length code lengths */ +var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */ +var LEN_ = 20; /* i: same as LEN below, but only first time in */ +var LEN = 21; /* i: waiting for length/lit/eob code */ +var LENEXT = 22; /* i: waiting for length extra bits */ +var DIST = 23; /* i: waiting for distance code */ +var DISTEXT = 24; /* i: waiting for distance extra bits */ +var MATCH = 25; /* o: waiting for output space to copy string */ +var LIT = 26; /* o: waiting for output space to write literal */ +var CHECK = 27; /* i: waiting for 32-bit check value */ +var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */ +var DONE = 29; /* finished check, done -- remain here until reset */ +var BAD = 30; /* got a data error -- remain here until reset */ +var MEM = 31; /* got an inflate() memory error -- remain here until reset */ +var SYNC = 32; /* looking for synchronization bytes to restart inflate() */ + +/* ===========================================================================*/ + +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_WBITS = MAX_WBITS; + +function zswap32(q) { + return ((q >>> 24) & 0xff) + ((q >>> 8) & 0xff00) + ((q & 0xff00) << 8) + ((q & 0xff) << 24); +} + +function InflateState() { + this.mode = 0; /* current inflate mode */ + this.last = false; /* true if processing last block */ + this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ + this.havedict = false; /* true if dictionary provided */ + this.flags = 0; /* gzip header method and flags (0 if zlib) */ + this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */ + this.check = 0; /* protected copy of check value */ + this.total = 0; /* protected copy of output count */ + // TODO: may be {} + this.head = null; /* where to save gzip header information */ + + /* sliding window */ + this.wbits = 0; /* log base 2 of requested window size */ + this.wsize = 0; /* window size or zero if not using window */ + this.whave = 0; /* valid bytes in the window */ + this.wnext = 0; /* window write index */ + this.window = null; /* allocated sliding window, if needed */ + + /* bit accumulator */ + this.hold = 0; /* input bit accumulator */ + this.bits = 0; /* number of bits in "in" */ + + /* for string and stored block copying */ + this.length = 0; /* literal or length of data to copy */ + this.offset = 0; /* distance back to copy string from */ + + /* for table and code decoding */ + this.extra = 0; /* extra bits needed */ + + /* fixed and dynamic code tables */ + this.lencode = null; /* starting table for length/literal codes */ + this.distcode = null; /* starting table for distance codes */ + this.lenbits = 0; /* index bits for lencode */ + this.distbits = 0; /* index bits for distcode */ + + /* dynamic table building */ + this.ncode = 0; /* number of code length code lengths */ + this.nlen = 0; /* number of length code lengths */ + this.ndist = 0; /* number of distance code lengths */ + this.have = 0; /* number of code lengths in lens[] */ + this.next = null; /* next available space in codes[] */ + + this.lens = new utils.Buf16(320); /* temporary storage for code lengths */ + this.work = new utils.Buf16(288); /* work area for code table building */ + + /* + because we don't have pointers in js, we use lencode and distcode directly + as buffers so we don't need codes + */ + //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */ + this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */ + this.distdyn = null; /* dynamic table for distance codes (JS specific) */ + this.sane = 0; /* if false, allow invalid distance too far */ + this.back = 0; /* bits back of last unprocessed length/lit */ + this.was = 0; /* initial length of match */ +} + +function inflateResetKeep(strm) { + var state; + + if (!strm || !strm.state) { + return Z_STREAM_ERROR; + } + state = strm.state; + strm.total_in = strm.total_out = state.total = 0; + strm.msg = ''; /*Z_NULL*/ + if (state.wrap) { + /* to support ill-conceived Java test suite */ + strm.adler = state.wrap & 1; + } + state.mode = HEAD; + state.last = 0; + state.havedict = 0; + state.dmax = 32768; + state.head = null /*Z_NULL*/; + state.hold = 0; + state.bits = 0; + //state.lencode = state.distcode = state.next = state.codes; + state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS); + state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS); + + state.sane = 1; + state.back = -1; + //Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +function inflateReset(strm) { + var state; + + if (!strm || !strm.state) { + return Z_STREAM_ERROR; + } + state = strm.state; + state.wsize = 0; + state.whave = 0; + state.wnext = 0; + return inflateResetKeep(strm); +} + +function inflateReset2(strm, windowBits) { + var wrap; + var state; + + /* get the state */ + if (!strm || !strm.state) { + return Z_STREAM_ERROR; + } + state = strm.state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } else { + wrap = (windowBits >> 4) + 1; + if (windowBits < 48) { + windowBits &= 15; + } + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) { + return Z_STREAM_ERROR; + } + if (state.window !== null && state.wbits !== windowBits) { + state.window = null; + } + + /* update state and reset the rest of it */ + state.wrap = wrap; + state.wbits = windowBits; + return inflateReset(strm); +} + +function inflateInit2(strm, windowBits) { + var ret; + var state; + + if (!strm) { + return Z_STREAM_ERROR; + } + //strm.msg = Z_NULL; /* in case we return an error */ + + state = new InflateState(); + + //if (state === Z_NULL) return Z_MEM_ERROR; + //Tracev((stderr, "inflate: allocated\n")); + strm.state = state; + state.window = null /*Z_NULL*/; + ret = inflateReset2(strm, windowBits); + if (ret !== Z_OK) { + strm.state = null /*Z_NULL*/; + } + return ret; +} + +function inflateInit(strm) { + return inflateInit2(strm, DEF_WBITS); +} + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +var virgin = true; + +var lenfix, distfix; // We have no pointers in JS, so keep tables separate + +function fixedtables(state) { + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + var sym; + + lenfix = new utils.Buf32(512); + distfix = new utils.Buf32(32); + + /* literal/length table */ + sym = 0; + while (sym < 144) { + state.lens[sym++] = 8; + } + while (sym < 256) { + state.lens[sym++] = 9; + } + while (sym < 280) { + state.lens[sym++] = 7; + } + while (sym < 288) { + state.lens[sym++] = 8; + } + + inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, { bits: 9 }); + + /* distance table */ + sym = 0; + while (sym < 32) { + state.lens[sym++] = 5; + } + + inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, { bits: 5 }); + + /* do this just once */ + virgin = false; + } + + state.lencode = lenfix; + state.lenbits = 9; + state.distcode = distfix; + state.distbits = 5; +} + +/* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called + when a window is already in use, or when output has been written during this + inflate call, but the end of the deflate stream has not been reached yet. + It is also called to create a window for dictionary data when a dictionary + is loaded. + + Providing output buffers larger than 32K to inflate() should provide a speed + advantage, since only the last 32K of output is copied to the sliding window + upon return from inflate(), and since all distances after the first 32K of + output will fall in the output data, making match copies simpler and faster. + The advantage may be dependent on the size of the processor's data caches. + */ +function updatewindow(strm, src, end, copy) { + var dist; + var state = strm.state; + + /* if it hasn't been done already, allocate space for the window */ + if (state.window === null) { + state.wsize = 1 << state.wbits; + state.wnext = 0; + state.whave = 0; + + state.window = new utils.Buf8(state.wsize); + } + + /* copy state->wsize or less output bytes into the circular window */ + if (copy >= state.wsize) { + utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0); + state.wnext = 0; + state.whave = state.wsize; + } else { + dist = state.wsize - state.wnext; + if (dist > copy) { + dist = copy; + } + //zmemcpy(state->window + state->wnext, end - copy, dist); + utils.arraySet(state.window, src, end - copy, dist, state.wnext); + copy -= dist; + if (copy) { + //zmemcpy(state->window, end - copy, copy); + utils.arraySet(state.window, src, end - copy, copy, 0); + state.wnext = copy; + state.whave = state.wsize; + } else { + state.wnext += dist; + if (state.wnext === state.wsize) { + state.wnext = 0; + } + if (state.whave < state.wsize) { + state.whave += dist; + } + } + } + return 0; +} + +function inflate(strm, flush) { + var state; + var input, output; // input/output buffers + var next; /* next input INDEX */ + var put; /* next output INDEX */ + var have, left; /* available input and output */ + var hold; /* bit buffer */ + var bits; /* bits in bit buffer */ + var _in, _out; /* save starting available input and output */ + var copy; /* number of stored or match bytes to copy */ + var from; /* where to copy match bytes from */ + var from_source; + var here = 0; /* current decoding table entry */ + var here_bits, here_op, here_val; // paked "here" denormalized (JS specific) + //var last; /* parent table entry */ + var last_bits, last_op, last_val; // paked "last" denormalized (JS specific) + var len; /* length to copy for repeats, bits to drop */ + var ret; /* return code */ + var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */ + var opts; + + var n; // temporary var for NEED_BITS + + var order = /* permutation of code lengths */ [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; + + if (!strm || !strm.state || !strm.output || (!strm.input && strm.avail_in !== 0)) { + return Z_STREAM_ERROR; + } + + state = strm.state; + if (state.mode === TYPE) { + state.mode = TYPEDO; + } /* skip check */ + + //--- LOAD() --- + put = strm.next_out; + output = strm.output; + left = strm.avail_out; + next = strm.next_in; + input = strm.input; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + _in = have; + _out = left; + ret = Z_OK; + + // goto emulation + inf_leave: for (;;) { + switch (state.mode) { + case HEAD: + if (state.wrap === 0) { + state.mode = TYPEDO; + break; + } + //=== NEEDBITS(16); + while (bits < 16) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.wrap & 2 && hold === 0x8b1f) { + /* gzip header */ + state.check = 0 /*crc32(0L, Z_NULL, 0)*/; + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = FLAGS; + break; + } + state.flags = 0; /* expect zlib header */ + if (state.head) { + state.head.done = false; + } + if ( + !(state.wrap & 1) /* check if zlib header allowed */ || + (((hold & 0xff) /*BITS(8)*/ << 8) + (hold >> 8)) % 31 + ) { + strm.msg = 'incorrect header check'; + state.mode = BAD; + break; + } + if ((hold & 0x0f) /*BITS(4)*/ !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// + len = (hold & 0x0f) /*BITS(4)*/ + 8; + if (state.wbits === 0) { + state.wbits = len; + } else if (len > state.wbits) { + strm.msg = 'invalid window size'; + state.mode = BAD; + break; + } + state.dmax = 1 << len; + //Tracev((stderr, "inflate: zlib header ok\n")); + strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/; + state.mode = hold & 0x200 ? DICTID : TYPE; + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + break; + case FLAGS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.flags = hold; + if ((state.flags & 0xff) !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + if (state.flags & 0xe000) { + strm.msg = 'unknown header flags set'; + state.mode = BAD; + break; + } + if (state.head) { + state.head.text = (hold >> 8) & 1; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = TIME; + /* falls through */ + case TIME: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.time = hold; + } + if (state.flags & 0x0200) { + //=== CRC4(state.check, hold) + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + hbuf[2] = (hold >>> 16) & 0xff; + hbuf[3] = (hold >>> 24) & 0xff; + state.check = crc32(state.check, hbuf, 4, 0); + //=== + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = OS; + /* falls through */ + case OS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.xflags = hold & 0xff; + state.head.os = hold >> 8; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = EXLEN; + /* falls through */ + case EXLEN: + if (state.flags & 0x0400) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length = hold; + if (state.head) { + state.head.extra_len = hold; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } else if (state.head) { + state.head.extra = null /*Z_NULL*/; + } + state.mode = EXTRA; + /* falls through */ + case EXTRA: + if (state.flags & 0x0400) { + copy = state.length; + if (copy > have) { + copy = have; + } + if (copy) { + if (state.head) { + len = state.head.extra_len - state.length; + if (!state.head.extra) { + // Use untyped array for more conveniend processing later + state.head.extra = new Array(state.head.extra_len); + } + utils.arraySet( + state.head.extra, + input, + next, + // extra field is limited to 65536 bytes + // - no need for additional size check + copy, + /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/ + len + ); + //zmemcpy(state.head.extra + len, next, + // len + copy > state.head.extra_max ? + // state.head.extra_max - len : copy); + } + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + state.length -= copy; + } + if (state.length) { + break inf_leave; + } + } + state.length = 0; + state.mode = NAME; + /* falls through */ + case NAME: + if (state.flags & 0x0800) { + if (have === 0) { + break inf_leave; + } + copy = 0; + do { + // TODO: 2 or 1 bytes? + len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ + if (state.head && len && state.length < 65536 /*state.head.name_max*/) { + state.head.name += String.fromCharCode(len); + } + } while (len && copy < have); + + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { + break inf_leave; + } + } else if (state.head) { + state.head.name = null; + } + state.length = 0; + state.mode = COMMENT; + /* falls through */ + case COMMENT: + if (state.flags & 0x1000) { + if (have === 0) { + break inf_leave; + } + copy = 0; + do { + len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ + if (state.head && len && state.length < 65536 /*state.head.comm_max*/) { + state.head.comment += String.fromCharCode(len); + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { + break inf_leave; + } + } else if (state.head) { + state.head.comment = null; + } + state.mode = HCRC; + /* falls through */ + case HCRC: + if (state.flags & 0x0200) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.check & 0xffff)) { + strm.msg = 'header crc mismatch'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + if (state.head) { + state.head.hcrc = (state.flags >> 9) & 1; + state.head.done = true; + } + strm.adler = state.check = 0; + state.mode = TYPE; + break; + case DICTID: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + strm.adler = state.check = zswap32(hold); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = DICT; + /* falls through */ + case DICT: + if (state.havedict === 0) { + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + return Z_NEED_DICT; + } + strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + /* falls through */ + case TYPE: + if (flush === Z_BLOCK || flush === Z_TREES) { + break inf_leave; + } + /* falls through */ + case TYPEDO: + if (state.last) { + //--- BYTEBITS() ---// + hold >>>= bits & 7; + bits -= bits & 7; + //---// + state.mode = CHECK; + break; + } + //=== NEEDBITS(3); */ + while (bits < 3) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.last = hold & 0x01 /*BITS(1)*/; + //--- DROPBITS(1) ---// + hold >>>= 1; + bits -= 1; + //---// + + switch (hold & 0x03 /*BITS(2)*/) { + case 0 /* stored block */: + //Tracev((stderr, "inflate: stored block%s\n", + // state.last ? " (last)" : "")); + state.mode = STORED; + break; + case 1 /* fixed block */: + fixedtables(state); + //Tracev((stderr, "inflate: fixed codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = LEN_; /* decode codes */ + if (flush === Z_TREES) { + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break inf_leave; + } + break; + case 2 /* dynamic block */: + //Tracev((stderr, "inflate: dynamic codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = TABLE; + break; + case 3: + strm.msg = 'invalid block type'; + state.mode = BAD; + } + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break; + case STORED: + //--- BYTEBITS() ---// /* go to byte boundary */ + hold >>>= bits & 7; + bits -= bits & 7; + //---// + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) { + strm.msg = 'invalid stored block lengths'; + state.mode = BAD; + break; + } + state.length = hold & 0xffff; + //Tracev((stderr, "inflate: stored length %u\n", + // state.length)); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = COPY_; + if (flush === Z_TREES) { + break inf_leave; + } + /* falls through */ + case COPY_: + state.mode = COPY; + /* falls through */ + case COPY: + copy = state.length; + if (copy) { + if (copy > have) { + copy = have; + } + if (copy > left) { + copy = left; + } + if (copy === 0) { + break inf_leave; + } + //--- zmemcpy(put, next, copy); --- + utils.arraySet(output, input, next, copy, put); + //---// + have -= copy; + next += copy; + left -= copy; + put += copy; + state.length -= copy; + break; + } + //Tracev((stderr, "inflate: stored end\n")); + state.mode = TYPE; + break; + case TABLE: + //=== NEEDBITS(14); */ + while (bits < 14) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.nlen = (hold & 0x1f) /*BITS(5)*/ + 257; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ndist = (hold & 0x1f) /*BITS(5)*/ + 1; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ncode = (hold & 0x0f) /*BITS(4)*/ + 4; + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// + //#ifndef PKZIP_BUG_WORKAROUND + if (state.nlen > 286 || state.ndist > 30) { + strm.msg = 'too many length or distance symbols'; + state.mode = BAD; + break; + } + //#endif + //Tracev((stderr, "inflate: table sizes ok\n")); + state.have = 0; + state.mode = LENLENS; + /* falls through */ + case LENLENS: + while (state.have < state.ncode) { + //=== NEEDBITS(3); + while (bits < 3) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.lens[order[state.have++]] = hold & 0x07; //BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + while (state.have < 19) { + state.lens[order[state.have++]] = 0; + } + // We have separate tables & no pointers. 2 commented lines below not needed. + //state.next = state.codes; + //state.lencode = state.next; + // Switch to use dynamic table + state.lencode = state.lendyn; + state.lenbits = 7; + + opts = { bits: state.lenbits }; + ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts); + state.lenbits = opts.bits; + + if (ret) { + strm.msg = 'invalid code lengths set'; + state.mode = BAD; + break; + } + //Tracev((stderr, "inflate: code lengths ok\n")); + state.have = 0; + state.mode = CODELENS; + /* falls through */ + case CODELENS: + while (state.have < state.nlen + state.ndist) { + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) - 1)]; /*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { + break; + } + //--- PULLBYTE() ---// + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_val < 16) { + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.lens[state.have++] = here_val; + } else { + if (here_val === 16) { + //=== NEEDBITS(here.bits + 2); + n = here_bits + 2; + while (bits < n) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + if (state.have === 0) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + len = state.lens[state.have - 1]; + copy = 3 + (hold & 0x03); //BITS(2); + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + } else if (here_val === 17) { + //=== NEEDBITS(here.bits + 3); + n = here_bits + 3; + while (bits < n) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 3 + (hold & 0x07); //BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } else { + //=== NEEDBITS(here.bits + 7); + n = here_bits + 7; + while (bits < n) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 11 + (hold & 0x7f); //BITS(7); + //--- DROPBITS(7) ---// + hold >>>= 7; + bits -= 7; + //---// + } + if (state.have + copy > state.nlen + state.ndist) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + while (copy--) { + state.lens[state.have++] = len; + } + } + } + + /* handle error breaks in while */ + if (state.mode === BAD) { + break; + } + + /* check for end-of-block code (better have one) */ + if (state.lens[256] === 0) { + strm.msg = 'invalid code -- missing end-of-block'; + state.mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state.lenbits = 9; + + opts = { bits: state.lenbits }; + ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts); + // We have separate tables & no pointers. 2 commented lines below not needed. + // state.next_index = opts.table_index; + state.lenbits = opts.bits; + // state.lencode = state.next; + + if (ret) { + strm.msg = 'invalid literal/lengths set'; + state.mode = BAD; + break; + } + + state.distbits = 6; + //state.distcode.copy(state.codes); + // Switch to use dynamic table + state.distcode = state.distdyn; + opts = { bits: state.distbits }; + ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts); + // We have separate tables & no pointers. 2 commented lines below not needed. + // state.next_index = opts.table_index; + state.distbits = opts.bits; + // state.distcode = state.next; + + if (ret) { + strm.msg = 'invalid distances set'; + state.mode = BAD; + break; + } + //Tracev((stderr, 'inflate: codes ok\n')); + state.mode = LEN_; + if (flush === Z_TREES) { + break inf_leave; + } + /* falls through */ + case LEN_: + state.mode = LEN; + /* falls through */ + case LEN: + if (have >= 6 && left >= 258) { + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + inflate_fast(strm, _out); + //--- LOAD() --- + put = strm.next_out; + output = strm.output; + left = strm.avail_out; + next = strm.next_in; + input = strm.input; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + if (state.mode === TYPE) { + state.back = -1; + } + break; + } + state.back = 0; + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) - 1)]; /*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { + break; + } + //--- PULLBYTE() ---// + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_op && (here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = + state.lencode[ + last_val + ((hold & ((1 << (last_bits + last_op)) - 1)) /*BITS(last.bits + last.op)*/ >> last_bits) + ]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (last_bits + here_bits <= bits) { + break; + } + //--- PULLBYTE() ---// + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + state.length = here_val; + if (here_op === 0) { + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + state.mode = LIT; + break; + } + if (here_op & 32) { + //Tracevv((stderr, "inflate: end of block\n")); + state.back = -1; + state.mode = TYPE; + break; + } + if (here_op & 64) { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break; + } + state.extra = here_op & 15; + state.mode = LENEXT; + /* falls through */ + case LENEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length += hold & ((1 << state.extra) - 1) /*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } + //Tracevv((stderr, "inflate: length %u\n", state.length)); + state.was = state.length; + state.mode = DIST; + /* falls through */ + case DIST: + for (;;) { + here = state.distcode[hold & ((1 << state.distbits) - 1)]; /*BITS(state.distbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { + break; + } + //--- PULLBYTE() ---// + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if ((here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = + state.distcode[ + last_val + ((hold & ((1 << (last_bits + last_op)) - 1)) /*BITS(last.bits + last.op)*/ >> last_bits) + ]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (last_bits + here_bits <= bits) { + break; + } + //--- PULLBYTE() ---// + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + if (here_op & 64) { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break; + } + state.offset = here_val; + state.extra = here_op & 15; + state.mode = DISTEXT; + /* falls through */ + case DISTEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.offset += hold & ((1 << state.extra) - 1) /*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } + //#ifdef INFLATE_STRICT + if (state.offset > state.dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } + //#endif + //Tracevv((stderr, "inflate: distance %u\n", state.offset)); + state.mode = MATCH; + /* falls through */ + case MATCH: + if (left === 0) { + break inf_leave; + } + copy = _out - left; + if (state.offset > copy) { + /* copy from window */ + copy = state.offset - copy; + if (copy > state.whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } + // (!) This block is disabled in zlib defailts, + // don't enable it for binary compatibility + //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR + // Trace((stderr, "inflate.c too far\n")); + // copy -= state.whave; + // if (copy > state.length) { copy = state.length; } + // if (copy > left) { copy = left; } + // left -= copy; + // state.length -= copy; + // do { + // output[put++] = 0; + // } while (--copy); + // if (state.length === 0) { state.mode = LEN; } + // break; + //#endif + } + if (copy > state.wnext) { + copy -= state.wnext; + from = state.wsize - copy; + } else { + from = state.wnext - copy; + } + if (copy > state.length) { + copy = state.length; + } + from_source = state.window; + } else { + /* copy from output */ + from_source = output; + from = put - state.offset; + copy = state.length; + } + if (copy > left) { + copy = left; + } + left -= copy; + state.length -= copy; + do { + output[put++] = from_source[from++]; + } while (--copy); + if (state.length === 0) { + state.mode = LEN; + } + break; + case LIT: + if (left === 0) { + break inf_leave; + } + output[put++] = state.length; + left--; + state.mode = LEN; + break; + case CHECK: + if (state.wrap) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { + break inf_leave; + } + have--; + // Use '|' insdead of '+' to make sure that result is signed + hold |= input[next++] << bits; + bits += 8; + } + //===// + _out -= left; + strm.total_out += _out; + state.total += _out; + if (_out) { + strm.adler = state.check = + /*UPDATE(state.check, put - _out, _out);*/ + state.flags + ? crc32(state.check, output, _out, put - _out) + : adler32(state.check, output, _out, put - _out); + } + _out = left; + // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too + if ((state.flags ? hold : zswap32(hold)) !== state.check) { + strm.msg = 'incorrect data check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: check matches trailer\n")); + } + state.mode = LENGTH; + /* falls through */ + case LENGTH: + if (state.wrap && state.flags) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { + break inf_leave; + } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.total & 0xffffffff)) { + strm.msg = 'incorrect length check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: length matches trailer\n")); + } + state.mode = DONE; + /* falls through */ + case DONE: + ret = Z_STREAM_END; + break inf_leave; + case BAD: + ret = Z_DATA_ERROR; + break inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + /* falls through */ + default: + return Z_STREAM_ERROR; + } + } + + // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + + if (state.wsize || (_out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH))) { + if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) { + state.mode = MEM; + return Z_MEM_ERROR; + } + } + _in -= strm.avail_in; + _out -= strm.avail_out; + strm.total_in += _in; + strm.total_out += _out; + state.total += _out; + if (state.wrap && _out) { + strm.adler = state.check = + /*UPDATE(state.check, strm.next_out - _out, _out);*/ + state.flags + ? crc32(state.check, output, _out, strm.next_out - _out) + : adler32(state.check, output, _out, strm.next_out - _out); + } + strm.data_type = + state.bits + + (state.last ? 64 : 0) + + (state.mode === TYPE ? 128 : 0) + + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0); + if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) { + ret = Z_BUF_ERROR; + } + return ret; +} + +function inflateEnd(strm) { + if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) { + return Z_STREAM_ERROR; + } + + var state = strm.state; + if (state.window) { + state.window = null; + } + strm.state = null; + return Z_OK; +} + +function inflateGetHeader(strm, head) { + var state; + + /* check state */ + if (!strm || !strm.state) { + return Z_STREAM_ERROR; + } + state = strm.state; + if ((state.wrap & 2) === 0) { + return Z_STREAM_ERROR; + } + + /* save header structure */ + state.head = head; + head.done = false; + return Z_OK; +} + +function inflateSetDictionary(strm, dictionary) { + var dictLength = dictionary.length; + + var state; + var dictid; + var ret; + + /* check state */ + if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { + return Z_STREAM_ERROR; + } + state = strm.state; + + if (state.wrap !== 0 && state.mode !== DICT) { + return Z_STREAM_ERROR; + } + + /* check for correct dictionary identifier */ + if (state.mode === DICT) { + dictid = 1; /* adler32(0, null, 0)*/ + /* dictid = adler32(dictid, dictionary, dictLength); */ + dictid = adler32(dictid, dictionary, dictLength, 0); + if (dictid !== state.check) { + return Z_DATA_ERROR; + } + } + /* copy dictionary to window using updatewindow(), which will amend the + existing dictionary if appropriate */ + ret = updatewindow(strm, dictionary, dictLength, dictLength); + if (ret) { + state.mode = MEM; + return Z_MEM_ERROR; + } + state.havedict = 1; + // Tracev((stderr, "inflate: dictionary set\n")); + return Z_OK; +} + +export { + inflateReset, + inflateReset2, + inflateResetKeep, + inflateInit, + inflateInit2, + inflate, + inflateEnd, + inflateGetHeader, + inflateSetDictionary, +}; +export var inflateInfo = 'pako inflate (from Nodeca project)'; + +/* Not implemented +exports.inflateCopy = inflateCopy; +exports.inflateGetDictionary = inflateGetDictionary; +exports.inflateMark = inflateMark; +exports.inflatePrime = inflatePrime; +exports.inflateSync = inflateSync; +exports.inflateSyncPoint = inflateSyncPoint; +exports.inflateUndermine = inflateUndermine; +*/ diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inftrees.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inftrees.js new file mode 100644 index 000000000..43976f007 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/inftrees.js @@ -0,0 +1,323 @@ +import * as utils from '../utils/common.js'; + +var MAXBITS = 15; +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +var lbase = [ + /* Length codes 257..285 base */ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, + 115, 131, 163, 195, 227, 258, 0, 0, +]; + +var lext = [ + /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, + 20, 20, 20, 21, 21, 21, 21, 16, 72, 78, +]; + +var dbase = [ + /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, + 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0, +]; + +var dext = [ + /* Distance codes 0..29 extra */ 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, + 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64, +]; + +export default function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) { + var bits = opts.bits; + //here = opts.here; /* table entry for duplication */ + + var len = 0; /* a code's length in bits */ + var sym = 0; /* index of code symbols */ + var min = 0, + max = 0; /* minimum and maximum code lengths */ + var root = 0; /* number of index bits for root table */ + var curr = 0; /* number of index bits for current table */ + var drop = 0; /* code bits to drop for sub-table */ + var left = 0; /* number of prefix codes available */ + var used = 0; /* code entries in table used */ + var huff = 0; /* Huffman code */ + var incr; /* for incrementing code, index */ + var fill; /* index for replicating entries */ + var low; /* low bits for current root entry */ + var mask; /* mask for low root bits */ + var next; /* next available space in table */ + var base = null; /* base value table to use */ + var base_index = 0; + // var shoextra; /* extra bits table to use */ + var end; /* use base and extra for symbol > end */ + var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */ + var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */ + var extra = null; + var extra_index = 0; + + var here_bits, here_op, here_val; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) { + count[len] = 0; + } + for (sym = 0; sym < codes; sym++) { + count[lens[lens_index + sym]]++; + } + + /* bound code lengths, force root to be within code lengths */ + root = bits; + for (max = MAXBITS; max >= 1; max--) { + if (count[max] !== 0) { + break; + } + } + if (root > max) { + root = max; + } + if (max === 0) { + /* no symbols to code at all */ + //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ + //table.bits[opts.table_index] = 1; //here.bits = (var char)1; + //table.val[opts.table_index++] = 0; //here.val = (var short)0; + table[table_index++] = (1 << 24) | (64 << 16) | 0; + + //table.op[opts.table_index] = 64; + //table.bits[opts.table_index] = 1; + //table.val[opts.table_index++] = 0; + table[table_index++] = (1 << 24) | (64 << 16) | 0; + + opts.bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) { + if (count[min] !== 0) { + break; + } + } + if (root < min) { + root = min; + } + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) { + return -1; + } /* over-subscribed */ + } + if (left > 0 && (type === CODES || max !== 1)) { + return -1; /* incomplete set */ + } + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) { + offs[len + 1] = offs[len] + count[len]; + } + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) { + if (lens[lens_index + sym] !== 0) { + work[offs[lens[lens_index + sym]]++] = sym; + } + } + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + // poor man optimization - use if-else instead of switch, + // to avoid deopts in old v8 + if (type === CODES) { + base = extra = work; /* dummy value--not used */ + end = 19; + } else if (type === LENS) { + base = lbase; + base_index -= 257; + extra = lext; + extra_index -= 257; + end = 256; + } else { + /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize opts for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = table_index; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = -1; /* trigger new sub-table when len > root */ + used = 1 << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type === LENS && used > ENOUGH_LENS) || (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + /* process all codes and make table entries */ + for (;;) { + /* create table entry */ + here_bits = len - drop; + if (work[sym] < end) { + here_op = 0; + here_val = work[sym]; + } else if (work[sym] > end) { + here_op = extra[extra_index + work[sym]]; + here_val = base[base_index + work[sym]]; + } else { + here_op = 32 + 64; /* end of block */ + here_val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1 << (len - drop); + fill = 1 << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val | 0; + } while (fill !== 0); + + /* backwards increment the len-bit code huff */ + incr = 1 << (len - 1); + while (huff & incr) { + incr >>= 1; + } + if (incr !== 0) { + huff &= incr - 1; + huff += incr; + } else { + huff = 0; + } + + /* go to next symbol, update count, len */ + sym++; + if (--count[len] === 0) { + if (len === max) { + break; + } + len = lens[lens_index + work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) !== low) { + /* if first time, transition to sub-tables */ + if (drop === 0) { + drop = root; + } + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = 1 << curr; + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) { + break; + } + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1 << curr; + if ((type === LENS && used > ENOUGH_LENS) || (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + /* point entry in root table to sub-table */ + low = huff & mask; + /*table.op[low] = curr; + table.bits[low] = root; + table.val[low] = next - opts.table_index;*/ + table[low] = (root << 24) | (curr << 16) | (next - table_index) | 0; + } + } + + /* fill in remaining table entry if code is incomplete (guaranteed to have + at most one remaining entry, since if the code is incomplete, the + maximum code length that was allowed to get this far is one bit) */ + if (huff !== 0) { + //table.op[next + huff] = 64; /* invalid code marker */ + //table.bits[next + huff] = len - drop; + //table.val[next + huff] = 0; + table[next + huff] = ((len - drop) << 24) | (64 << 16) | 0; + } + + /* set return parameters */ + //opts.table_index += used; + opts.bits = root; + return 0; +} diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/messages.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/messages.js new file mode 100644 index 000000000..242cc43b9 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/messages.js @@ -0,0 +1,11 @@ +export default { + 2: 'need dictionary' /* Z_NEED_DICT 2 */, + 1: 'stream end' /* Z_STREAM_END 1 */, + 0: '' /* Z_OK 0 */, + '-1': 'file error' /* Z_ERRNO (-1) */, + '-2': 'stream error' /* Z_STREAM_ERROR (-2) */, + '-3': 'data error' /* Z_DATA_ERROR (-3) */, + '-4': 'insufficient memory' /* Z_MEM_ERROR (-4) */, + '-5': 'buffer error' /* Z_BUF_ERROR (-5) */, + '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */, +}; diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/trees.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/trees.js new file mode 100644 index 000000000..c1b9dc978 --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/trees.js @@ -0,0 +1,1162 @@ +import * as utils from '../utils/common.js'; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + +//var Z_FILTERED = 1; +//var Z_HUFFMAN_ONLY = 2; +//var Z_RLE = 3; +var Z_FIXED = 4; +//var Z_DEFAULT_STRATEGY = 0; + +/* Possible values of the data_type field (though see inflate()) */ +var Z_BINARY = 0; +var Z_TEXT = 1; +//var Z_ASCII = 1; // = Z_TEXT +var Z_UNKNOWN = 2; + +/*============================================================================*/ + +function zero(buf) { + var len = buf.length; + while (--len >= 0) { + buf[len] = 0; + } +} + +// From zutil.h + +var STORED_BLOCK = 0; +var STATIC_TREES = 1; +var DYN_TREES = 2; +/* The three kinds of block type */ + +var MIN_MATCH = 3; +var MAX_MATCH = 258; +/* The minimum and maximum match lengths */ + +// From deflate.h +/* =========================================================================== + * Internal compression state. + */ + +var LENGTH_CODES = 29; +/* number of length codes, not counting the special END_BLOCK code */ + +var LITERALS = 256; +/* number of literal bytes 0..255 */ + +var L_CODES = LITERALS + 1 + LENGTH_CODES; +/* number of Literal or Length codes, including the END_BLOCK code */ + +var D_CODES = 30; +/* number of distance codes */ + +var BL_CODES = 19; +/* number of codes used to transfer the bit lengths */ + +var HEAP_SIZE = 2 * L_CODES + 1; +/* maximum heap size */ + +var MAX_BITS = 15; +/* All codes must not exceed MAX_BITS bits */ + +var Buf_size = 16; +/* size of bit buffer in bi_buf */ + +/* =========================================================================== + * Constants + */ + +var MAX_BL_BITS = 7; +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +var END_BLOCK = 256; +/* end of block literal code */ + +var REP_3_6 = 16; +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +var REPZ_3_10 = 17; +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +var REPZ_11_138 = 18; +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +/* eslint-disable comma-spacing,array-bracket-spacing */ +var extra_lbits = + /* extra bits for each length code */ + [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]; + +var extra_dbits = + /* extra bits for each distance code */ + [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]; + +var extra_blbits = /* extra bits for each bit length code */ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]; + +var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; +/* eslint-enable comma-spacing,array-bracket-spacing */ + +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +// We pre-fill arrays with 0 to avoid uninitialized gaps + +var DIST_CODE_LEN = 512; /* see definition of array dist_code below */ + +// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1 +var static_ltree = new Array((L_CODES + 2) * 2); +zero(static_ltree); +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +var static_dtree = new Array(D_CODES * 2); +zero(static_dtree); +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +var _dist_code = new Array(DIST_CODE_LEN); +zero(_dist_code); +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1); +zero(_length_code); +/* length code for each normalized match length (0 == MIN_MATCH) */ + +var base_length = new Array(LENGTH_CODES); +zero(base_length); +/* First normalized length for each code (0 = MIN_MATCH) */ + +var base_dist = new Array(D_CODES); +zero(base_dist); +/* First normalized distance for each code (0 = distance of 1) */ + +function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) { + this.static_tree = static_tree; /* static tree or NULL */ + this.extra_bits = extra_bits; /* extra bits for each code or NULL */ + this.extra_base = extra_base; /* base index for extra_bits */ + this.elems = elems; /* max number of elements in the tree */ + this.max_length = max_length; /* max bit length for the codes */ + + // show if `static_tree` has data or dummy - needed for monomorphic objects + this.has_stree = static_tree && static_tree.length; +} + +var static_l_desc; +var static_d_desc; +var static_bl_desc; + +function TreeDesc(dyn_tree, stat_desc) { + this.dyn_tree = dyn_tree; /* the dynamic tree */ + this.max_code = 0; /* largest code with non zero frequency */ + this.stat_desc = stat_desc; /* the corresponding static tree */ +} + +function d_code(dist) { + return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)]; +} + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +function put_short(s, w) { + // put_byte(s, (uch)((w) & 0xff)); + // put_byte(s, (uch)((ush)(w) >> 8)); + s.pending_buf[s.pending++] = w & 0xff; + s.pending_buf[s.pending++] = (w >>> 8) & 0xff; +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +function send_bits(s, value, length) { + if (s.bi_valid > Buf_size - length) { + s.bi_buf |= (value << s.bi_valid) & 0xffff; + put_short(s, s.bi_buf); + s.bi_buf = value >> (Buf_size - s.bi_valid); + s.bi_valid += length - Buf_size; + } else { + s.bi_buf |= (value << s.bi_valid) & 0xffff; + s.bi_valid += length; + } +} + +function send_code(s, c, tree) { + send_bits(s, tree[c * 2] /*.Code*/, tree[c * 2 + 1] /*.Len*/); +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +function bi_reverse(code, len) { + var res = 0; + do { + res |= code & 1; + code >>>= 1; + res <<= 1; + } while (--len > 0); + return res >>> 1; +} + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +function bi_flush(s) { + if (s.bi_valid === 16) { + put_short(s, s.bi_buf); + s.bi_buf = 0; + s.bi_valid = 0; + } else if (s.bi_valid >= 8) { + s.pending_buf[s.pending++] = s.bi_buf & 0xff; + s.bi_buf >>= 8; + s.bi_valid -= 8; + } +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +function gen_bitlen(s, desc) { + // deflate_state *s; + // tree_desc *desc; /* the tree descriptor */ + var tree = desc.dyn_tree; + var max_code = desc.max_code; + var stree = desc.stat_desc.static_tree; + var has_stree = desc.stat_desc.has_stree; + var extra = desc.stat_desc.extra_bits; + var base = desc.stat_desc.extra_base; + var max_length = desc.stat_desc.max_length; + var h; /* heap index */ + var n, m; /* iterate over the tree elements */ + var bits; /* bit length */ + var xbits; /* extra bits */ + var f; /* frequency */ + var overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) { + s.bl_count[bits] = 0; + } + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s.heap[s.heap_max] * 2 + 1] /*.Len*/ = 0; /* root of the heap */ + + for (h = s.heap_max + 1; h < HEAP_SIZE; h++) { + n = s.heap[h]; + bits = tree[tree[n * 2 + 1] /*.Dad*/ * 2 + 1] /*.Len*/ + 1; + if (bits > max_length) { + bits = max_length; + overflow++; + } + tree[n * 2 + 1] /*.Len*/ = bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) { + continue; + } /* not a leaf node */ + + s.bl_count[bits]++; + xbits = 0; + if (n >= base) { + xbits = extra[n - base]; + } + f = tree[n * 2] /*.Freq*/; + s.opt_len += f * (bits + xbits); + if (has_stree) { + s.static_len += f * (stree[n * 2 + 1] /*.Len*/ + xbits); + } + } + if (overflow === 0) { + return; + } + + // Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length - 1; + while (s.bl_count[bits] === 0) { + bits--; + } + s.bl_count[bits]--; /* move one leaf down the tree */ + s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ + s.bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits !== 0; bits--) { + n = s.bl_count[bits]; + while (n !== 0) { + m = s.heap[--h]; + if (m > max_code) { + continue; + } + if (tree[m * 2 + 1] /*.Len*/ !== bits) { + // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s.opt_len += (bits - tree[m * 2 + 1]) /*.Len*/ * tree[m * 2] /*.Freq*/; + tree[m * 2 + 1] /*.Len*/ = bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +function gen_codes(tree, max_code, bl_count) { + // ct_data *tree; /* the tree to decorate */ + // int max_code; /* largest code with non zero frequency */ + // ushf *bl_count; /* number of codes at each bit length */ + var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */ + var code = 0; /* running code value */ + var bits; /* bit index */ + var n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits - 1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + //Assert (code + bl_count[MAX_BITS]-1 == (1< length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES - 1; code++) { + base_length[code] = length; + for (n = 0; n < 1 << extra_lbits[code]; n++) { + _length_code[length++] = code; + } + } + //Assert (length == 256, "tr_static_init: length != 256"); + /* Note that the length 255 (match length 258) can be represented + * in two different ways: code 284 + 5 bits or code 285, so we + * overwrite length_code[255] to use the best encoding: + */ + _length_code[length - 1] = code; + + /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ + dist = 0; + for (code = 0; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < 1 << extra_dbits[code]; n++) { + _dist_code[dist++] = code; + } + } + //Assert (dist == 256, "tr_static_init: dist != 256"); + dist >>= 7; /* from now on, all distances are divided by 128 */ + for (; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < 1 << (extra_dbits[code] - 7); n++) { + _dist_code[256 + dist++] = code; + } + } + //Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) { + bl_count[bits] = 0; + } + + n = 0; + while (n <= 143) { + static_ltree[n * 2 + 1] /*.Len*/ = 8; + n++; + bl_count[8]++; + } + while (n <= 255) { + static_ltree[n * 2 + 1] /*.Len*/ = 9; + n++; + bl_count[9]++; + } + while (n <= 279) { + static_ltree[n * 2 + 1] /*.Len*/ = 7; + n++; + bl_count[7]++; + } + while (n <= 287) { + static_ltree[n * 2 + 1] /*.Len*/ = 8; + n++; + bl_count[8]++; + } + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes(static_ltree, L_CODES + 1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n * 2 + 1] /*.Len*/ = 5; + static_dtree[n * 2] /*.Code*/ = bi_reverse(n, 5); + } + + // Now data ready and we can init static trees + static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS); + static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS); + static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); + + //static_init_done = true; +} + +/* =========================================================================== + * Initialize a new block. + */ +function init_block(s) { + var n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) { + s.dyn_ltree[n * 2] /*.Freq*/ = 0; + } + for (n = 0; n < D_CODES; n++) { + s.dyn_dtree[n * 2] /*.Freq*/ = 0; + } + for (n = 0; n < BL_CODES; n++) { + s.bl_tree[n * 2] /*.Freq*/ = 0; + } + + s.dyn_ltree[END_BLOCK * 2] /*.Freq*/ = 1; + s.opt_len = s.static_len = 0; + s.last_lit = s.matches = 0; +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +function bi_windup(s) { + if (s.bi_valid > 8) { + put_short(s, s.bi_buf); + } else if (s.bi_valid > 0) { + //put_byte(s, (Byte)s->bi_buf); + s.pending_buf[s.pending++] = s.bi_buf; + } + s.bi_buf = 0; + s.bi_valid = 0; +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +function copy_block(s, buf, len, header) { + //DeflateState *s; + //charf *buf; /* the input data */ + //unsigned len; /* its length */ + //int header; /* true if block header must be written */ + bi_windup(s); /* align on byte boundary */ + + if (header) { + put_short(s, len); + put_short(s, ~len); + } + // while (len--) { + // put_byte(s, *buf++); + // } + utils.arraySet(s.pending_buf, s.window, buf, len, s.pending); + s.pending += len; +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +function smaller(tree, n, m, depth) { + var _n2 = n * 2; + var _m2 = m * 2; + return ( + tree[_n2] /*.Freq*/ < tree[_m2] /*.Freq*/ || (tree[_n2] /*.Freq*/ === tree[_m2] /*.Freq*/ && depth[n] <= depth[m]) + ); +} + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +function pqdownheap(s, tree, k) { + // deflate_state *s; + // ct_data *tree; /* the tree to restore */ + // int k; /* node to move down */ + var v = s.heap[k]; + var j = k << 1; /* left son of k */ + while (j <= s.heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s.heap[j], s.depth)) { + break; + } + + /* Exchange v with the smallest son */ + s.heap[k] = s.heap[j]; + k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s.heap[k] = v; +} + +// inlined manually +// var SMALLEST = 1; + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +function compress_block(s, ltree, dtree) { + // deflate_state *s; + // const ct_data *ltree; /* literal tree */ + // const ct_data *dtree; /* distance tree */ + var dist; /* distance of matched string */ + var lc; /* match length or unmatched char (if dist == 0) */ + var lx = 0; /* running index in l_buf */ + var code; /* the code to send */ + var extra; /* number of extra bits to send */ + + if (s.last_lit !== 0) { + do { + dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | s.pending_buf[s.d_buf + lx * 2 + 1]; + lc = s.pending_buf[s.l_buf + lx]; + lx++; + + if (dist === 0) { + send_code(s, lc, ltree); /* send a literal byte */ + //Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra !== 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + //Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra !== 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + // "pendingBuf overflow"); + } while (lx < s.last_lit); + } + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Construct one Huffman tree and assigns the code bit strings and lengths. + * Update the total bit length for the current block. + * IN assertion: the field freq is set for all tree elements. + * OUT assertions: the fields len and code are set to the optimal bit length + * and corresponding code. The length opt_len is updated; static_len is + * also updated if stree is not null. The field max_code is set. + */ +function build_tree(s, desc) { + // deflate_state *s; + // tree_desc *desc; /* the tree descriptor */ + var tree = desc.dyn_tree; + var stree = desc.stat_desc.static_tree; + var has_stree = desc.stat_desc.has_stree; + var elems = desc.stat_desc.elems; + var n, m; /* iterate over heap elements */ + var max_code = -1; /* largest code with non zero frequency */ + var node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s.heap_len = 0; + s.heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n * 2] /*.Freq*/ !== 0) { + s.heap[++s.heap_len] = max_code = n; + s.depth[n] = 0; + } else { + tree[n * 2 + 1] /*.Len*/ = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s.heap_len < 2) { + node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0; + tree[node * 2] /*.Freq*/ = 1; + s.depth[node] = 0; + s.opt_len--; + + if (has_stree) { + s.static_len -= stree[node * 2 + 1] /*.Len*/; + } + /* node is 0 or 1 so it does not have extra bits */ + } + desc.max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = s.heap_len >> 1 /*int /2*/; n >= 1; n--) { + pqdownheap(s, tree, n); + } + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + //pqremove(s, tree, n); /* n = node of least frequency */ + /*** pqremove ***/ + n = s.heap[1 /*SMALLEST*/]; + s.heap[1 /*SMALLEST*/] = s.heap[s.heap_len--]; + pqdownheap(s, tree, 1 /*SMALLEST*/); + /***/ + + m = s.heap[1 /*SMALLEST*/]; /* m = node of next least frequency */ + + s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */ + s.heap[--s.heap_max] = m; + + /* Create a new node father of n and m */ + tree[node * 2] /*.Freq*/ = tree[n * 2] /*.Freq*/ + tree[m * 2] /*.Freq*/; + s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1; + tree[n * 2 + 1] /*.Dad*/ = tree[m * 2 + 1] /*.Dad*/ = node; + + /* and insert the new node in the heap */ + s.heap[1 /*SMALLEST*/] = node++; + pqdownheap(s, tree, 1 /*SMALLEST*/); + } while (s.heap_len >= 2); + + s.heap[--s.heap_max] = s.heap[1 /*SMALLEST*/]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes(tree, max_code, s.bl_count); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +function scan_tree(s, tree, max_code) { + // deflate_state *s; + // ct_data *tree; /* the tree to be scanned */ + // int max_code; /* and its largest code of non zero frequency */ + var n; /* iterates over all tree elements */ + var prevlen = -1; /* last emitted length */ + var curlen; /* length of current code */ + + var nextlen = tree[0 * 2 + 1]; /*.Len*/ /* length of next code */ + + var count = 0; /* repeat count of the current code */ + var max_count = 7; /* max repeat count */ + var min_count = 4; /* min repeat count */ + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + tree[(max_code + 1) * 2 + 1] /*.Len*/ = 0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n + 1) * 2 + 1] /*.Len*/; + + if (++count < max_count && curlen === nextlen) { + continue; + } else if (count < min_count) { + s.bl_tree[curlen * 2] /*.Freq*/ += count; + } else if (curlen !== 0) { + if (curlen !== prevlen) { + s.bl_tree[curlen * 2] /*.Freq*/++; + } + s.bl_tree[REP_3_6 * 2] /*.Freq*/++; + } else if (count <= 10) { + s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++; + } else { + s.bl_tree[REPZ_11_138 * 2] /*.Freq*/++; + } + + count = 0; + prevlen = curlen; + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + } else { + max_count = 7; + min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +function send_tree(s, tree, max_code) { + // deflate_state *s; + // ct_data *tree; /* the tree to be scanned */ + // int max_code; /* and its largest code of non zero frequency */ + var n; /* iterates over all tree elements */ + var prevlen = -1; /* last emitted length */ + var curlen; /* length of current code */ + + var nextlen = tree[0 * 2 + 1]; /*.Len*/ /* length of next code */ + + var count = 0; /* repeat count of the current code */ + var max_count = 7; /* max repeat count */ + var min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n + 1) * 2 + 1] /*.Len*/; + + if (++count < max_count && curlen === nextlen) { + continue; + } else if (count < min_count) { + do { + send_code(s, curlen, s.bl_tree); + } while (--count !== 0); + } else if (curlen !== 0) { + if (curlen !== prevlen) { + send_code(s, curlen, s.bl_tree); + count--; + } + //Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s.bl_tree); + send_bits(s, count - 3, 2); + } else if (count <= 10) { + send_code(s, REPZ_3_10, s.bl_tree); + send_bits(s, count - 3, 3); + } else { + send_code(s, REPZ_11_138, s.bl_tree); + send_bits(s, count - 11, 7); + } + + count = 0; + prevlen = curlen; + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + } else { + max_count = 7; + min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +function build_bl_tree(s) { + var max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, s.dyn_ltree, s.l_desc.max_code); + scan_tree(s, s.dyn_dtree, s.d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, s.bl_desc); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) { + if (s.bl_tree[bl_order[max_blindex] * 2 + 1] /*.Len*/ !== 0) { + break; + } + } + /* Update opt_len to include the bit length tree and counts */ + s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; + //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + // s->opt_len, s->static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +function send_all_trees(s, lcodes, dcodes, blcodes) { + // deflate_state *s; + // int lcodes, dcodes, blcodes; /* number of codes for each tree */ + var rank; /* index in bl_order */ + + //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + // "too many codes"); + //Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes - 1, 5); + send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + //Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] /*.Len*/, 3); + } + //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */ + //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */ + //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +function detect_data_type(s) { + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + var black_mask = 0xf3ffc07f; + var n; + + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>>= 1) { + if (black_mask & 1 && s.dyn_ltree[n * 2] /*.Freq*/ !== 0) { + return Z_BINARY; + } + } + + /* Check for textual ("white-listed") bytes. */ + if ( + s.dyn_ltree[9 * 2] /*.Freq*/ !== 0 || + s.dyn_ltree[10 * 2] /*.Freq*/ !== 0 || + s.dyn_ltree[13 * 2] /*.Freq*/ !== 0 + ) { + return Z_TEXT; + } + for (n = 32; n < LITERALS; n++) { + if (s.dyn_ltree[n * 2] /*.Freq*/ !== 0) { + return Z_TEXT; + } + } + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +var static_init_done = false; + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +function _tr_init(s) { + if (!static_init_done) { + tr_static_init(); + static_init_done = true; + } + + s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc); + s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc); + s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc); + + s.bi_buf = 0; + s.bi_valid = 0; + + /* Initialize the first block of the first file: */ + init_block(s); +} + +/* =========================================================================== + * Send a stored block + */ +function _tr_stored_block(s, buf, stored_len, last) { + //DeflateState *s; + //charf *buf; /* input block */ + //ulg stored_len; /* length of input block */ + //int last; /* one if this is the last block for a file */ + send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */ + copy_block(s, buf, stored_len, true); /* with header */ +} + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + */ +function _tr_align(s) { + send_bits(s, STATIC_TREES << 1, 3); + send_code(s, END_BLOCK, static_ltree); + bi_flush(s); +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +function _tr_flush_block(s, buf, stored_len, last) { + //DeflateState *s; + //charf *buf; /* input block, or NULL if too old */ + //ulg stored_len; /* length of input block */ + //int last; /* one if this is the last block for a file */ + var opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + var max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s.level > 0) { + /* Check if the file is binary or text */ + if (s.strm.data_type === Z_UNKNOWN) { + s.strm.data_type = detect_data_type(s); + } + + /* Construct the literal and distance trees */ + build_tree(s, s.l_desc); + // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + // s->static_len)); + + build_tree(s, s.d_desc); + // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + // s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s.opt_len + 3 + 7) >>> 3; + static_lenb = (s.static_len + 3 + 7) >>> 3; + + // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + // s->last_lit)); + + if (static_lenb <= opt_lenb) { + opt_lenb = static_lenb; + } + } else { + // Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + + if (stored_len + 4 <= opt_lenb && buf !== -1) { + /* 4: two words for the lengths */ + + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, last); + } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) { + send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3); + compress_block(s, static_ltree, static_dtree); + } else { + send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3); + send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1); + compress_block(s, s.dyn_ltree, s.dyn_dtree); + } + // Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (last) { + bi_windup(s); + } + // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + // s->compressed_len-7*last)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +function _tr_tally(s, dist, lc) { + // deflate_state *s; + // unsigned dist; /* distance of matched string */ + // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ + //var out_length, in_length, dcode; + + s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff; + s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; + + s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff; + s.last_lit++; + + if (dist === 0) { + /* lc is the unmatched char */ + s.dyn_ltree[lc * 2] /*.Freq*/++; + } else { + s.matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + //Assert((ush)dist < (ush)MAX_DIST(s) && + // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2] /*.Freq*/++; + s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++; + } + + // (!) This block is disabled in zlib defailts, + // don't enable it for binary compatibility + + //#ifdef TRUNCATE_BLOCK + // /* Try to guess if it is profitable to stop the current block here */ + // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) { + // /* Compute an upper bound for the compressed length */ + // out_length = s.last_lit*8; + // in_length = s.strstart - s.block_start; + // + // for (dcode = 0; dcode < D_CODES; dcode++) { + // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]); + // } + // out_length >>>= 3; + // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", + // // s->last_lit, in_length, out_length, + // // 100L - out_length*100L/in_length)); + // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) { + // return true; + // } + // } + //#endif + + return s.last_lit === s.lit_bufsize - 1; + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +export { _tr_init, _tr_stored_block, _tr_flush_block, _tr_tally, _tr_align }; diff --git a/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/zstream.js b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/zstream.js new file mode 100644 index 000000000..f331d7f8b --- /dev/null +++ b/gns3server/static/web-ui/assets/vnc-console/novnc/vendor/pako/lib/zlib/zstream.js @@ -0,0 +1,24 @@ +export default function ZStream() { + /* next input byte */ + this.input = null; // JS specific, because we have no pointers + this.next_in = 0; + /* number of bytes available at input */ + this.avail_in = 0; + /* total number of input bytes read so far */ + this.total_in = 0; + /* next output byte should be put there */ + this.output = null; // JS specific, because we have no pointers + this.next_out = 0; + /* remaining free space at output */ + this.avail_out = 0; + /* total number of bytes output so far */ + this.total_out = 0; + /* last error message, NULL if no error */ + this.msg = '' /*Z_NULL*/; + /* not visible by applications */ + this.state = null; + /* best guess about the data type: binary or text */ + this.data_type = 2 /*Z_UNKNOWN*/; + /* adler32 value of the uncompressed data */ + this.adler = 0; +} diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/FileSaver.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/FileSaver.js new file mode 100644 index 000000000..5d204aee1 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/FileSaver.js @@ -0,0 +1,171 @@ +/* +* FileSaver.js +* A saveAs() FileSaver implementation. +* +* By Eli Grey, http://eligrey.com +* +* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT) +* source : http://purl.eligrey.com/github/FileSaver.js +*/ + +// The one and only way of getting global scope in all environments +// https://stackoverflow.com/q/3277182/1008999 +var _global = typeof window === 'object' && window.window === window + ? window : typeof self === 'object' && self.self === self + ? self : typeof global === 'object' && global.global === global + ? global + : this + +function bom (blob, opts) { + if (typeof opts === 'undefined') opts = { autoBom: false } + else if (typeof opts !== 'object') { + console.warn('Deprecated: Expected third argument to be a object') + opts = { autoBom: !opts } + } + + // prepend BOM for UTF-8 XML and text/* types (including HTML) + // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF + if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { + return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type }) + } + return blob +} + +function download (url, name, opts) { + var xhr = new XMLHttpRequest() + xhr.open('GET', url) + xhr.responseType = 'blob' + xhr.onload = function () { + saveAs(xhr.response, name, opts) + } + xhr.onerror = function () { + console.error('could not download file') + } + xhr.send() +} + +function corsEnabled (url) { + var xhr = new XMLHttpRequest() + // use sync to avoid popup blocker + xhr.open('HEAD', url, false) + try { + xhr.send() + } catch (e) {} + return xhr.status >= 200 && xhr.status <= 299 +} + +// `a.click()` doesn't work for all browsers (#465) +function click (node) { + try { + node.dispatchEvent(new MouseEvent('click')) + } catch (e) { + var evt = document.createEvent('MouseEvents') + evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, + 20, false, false, false, false, 0, null) + node.dispatchEvent(evt) + } +} + +// Detect WebView inside a native macOS app by ruling out all browsers +// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too +// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos +var isMacOSWebView = _global.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent) + +var saveAs = _global.saveAs || ( + // probably in some web worker + (typeof window !== 'object' || window !== _global) + ? function saveAs () { /* noop */ } + + // Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView + : ('download' in HTMLAnchorElement.prototype && !isMacOSWebView) + ? function saveAs (blob, name, opts) { + var URL = _global.URL || _global.webkitURL + var a = document.createElement('a') + name = name || blob.name || 'download' + + a.download = name + a.rel = 'noopener' // tabnabbing + + // TODO: detect chrome extensions & packaged apps + // a.target = '_blank' + + if (typeof blob === 'string') { + // Support regular links + a.href = blob + if (a.origin !== location.origin) { + corsEnabled(a.href) + ? download(blob, name, opts) + : click(a, a.target = '_blank') + } else { + click(a) + } + } else { + // Support blobs + a.href = URL.createObjectURL(blob) + setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s + setTimeout(function () { click(a) }, 0) + } + } + + // Use msSaveOrOpenBlob as a second approach + : 'msSaveOrOpenBlob' in navigator + ? function saveAs (blob, name, opts) { + name = name || blob.name || 'download' + + if (typeof blob === 'string') { + if (corsEnabled(blob)) { + download(blob, name, opts) + } else { + var a = document.createElement('a') + a.href = blob + a.target = '_blank' + setTimeout(function () { click(a) }) + } + } else { + navigator.msSaveOrOpenBlob(bom(blob, opts), name) + } + } + + // Fallback to using FileReader and a popup + : function saveAs (blob, name, opts, popup) { + // Open a popup immediately do go around popup blocker + // Mostly only available on user interaction and the fileReader is async so... + popup = popup || open('', '_blank') + if (popup) { + popup.document.title = + popup.document.body.innerText = 'downloading...' + } + + if (typeof blob === 'string') return download(blob, name, opts) + + var force = blob.type === 'application/octet-stream' + var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari + var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent) + + if ((isChromeIOS || (force && isSafari) || isMacOSWebView) && typeof FileReader !== 'undefined') { + // Safari doesn't allow downloading of blob URLs + var reader = new FileReader() + reader.onloadend = function () { + var url = reader.result + url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;') + if (popup) popup.location.href = url + else location = url + popup = null // reverse-tabnabbing #460 + } + reader.readAsDataURL(blob) + } else { + var URL = _global.URL || _global.webkitURL + var url = URL.createObjectURL(blob) + if (popup) popup.location = url + else location.href = url + popup = null // reverse-tabnabbing #460 + setTimeout(function () { URL.revokeObjectURL(url) }, 4E4) // 40s + } + } +) + +_global.saveAs = saveAs.saveAs = saveAs + +if (typeof module !== 'undefined') { + module.exports = saveAs; +} diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/StreamSaver.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/StreamSaver.js new file mode 100644 index 000000000..797c42c38 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/StreamSaver.js @@ -0,0 +1,317 @@ +/*! streamsaver. MIT License. Jimmy Wärting */ + +/* global chrome location ReadableStream define MessageChannel TransformStream */ + +;((name, definition) => { + typeof module !== 'undefined' + ? module.exports = definition() + : typeof define === 'function' && typeof define.amd === 'object' + ? define(definition) + : this[name] = definition() +})('streamSaver', () => { + 'use strict' + + const global = typeof window === 'object' ? window : this + if (!global.HTMLElement) console.warn('streamsaver is meant to run on browsers main thread') + + let mitmTransporter = null + let supportsTransferable = false + const test = fn => { try { fn() } catch (e) {} } + const ponyfill = global.WebStreamsPolyfill || {} + const isSecureContext = global.isSecureContext + // TODO: Must come up with a real detection test (#69) + let useBlobFallback = /constructor/i.test(global.HTMLElement) || !!global.safari || !!global.WebKitPoint + const downloadStrategy = isSecureContext || 'MozAppearance' in document.documentElement.style + ? 'iframe' + : 'navigate' + + const streamSaver = { + createWriteStream, + WritableStream: global.WritableStream || ponyfill.WritableStream, + supported: true, + version: { full: '2.0.5', major: 2, minor: 0, dot: 5 }, + mitm: './mitm.html' + } + + /** + * create a hidden iframe and append it to the DOM (body) + * + * @param {string} src page to load + * @return {HTMLIFrameElement} page to load + */ + function makeIframe (src) { + if (!src) throw new Error('meh') + const iframe = document.createElement('iframe') + iframe.hidden = true + iframe.src = src + iframe.loaded = false + iframe.name = 'iframe' + iframe.isIframe = true + iframe.postMessage = (...args) => iframe.contentWindow.postMessage(...args) + iframe.addEventListener('load', () => { + iframe.loaded = true + }, { once: true }) + document.body.appendChild(iframe) + return iframe + } + + /** + * create a popup that simulates the basic things + * of what a iframe can do + * + * @param {string} src page to load + * @return {object} iframe like object + */ + function makePopup (src) { + const options = 'width=200,height=100' + const delegate = document.createDocumentFragment() + const popup = { + frame: global.open(src, 'popup', options), + loaded: false, + isIframe: false, + isPopup: true, + remove () { popup.frame.close() }, + addEventListener (...args) { delegate.addEventListener(...args) }, + dispatchEvent (...args) { delegate.dispatchEvent(...args) }, + removeEventListener (...args) { delegate.removeEventListener(...args) }, + postMessage (...args) { popup.frame.postMessage(...args) } + } + + const onReady = evt => { + if (evt.source === popup.frame) { + popup.loaded = true + global.removeEventListener('message', onReady) + popup.dispatchEvent(new Event('load')) + } + } + + global.addEventListener('message', onReady) + + return popup + } + + try { + // We can't look for service worker since it may still work on http + new Response(new ReadableStream()) + if (isSecureContext && !('serviceWorker' in navigator)) { + useBlobFallback = true + } + } catch (err) { + useBlobFallback = true + } + + test(() => { + // Transferable stream was first enabled in chrome v73 behind a flag + const { readable } = new TransformStream() + const mc = new MessageChannel() + mc.port1.postMessage(readable, [readable]) + mc.port1.close() + mc.port2.close() + supportsTransferable = true + // Freeze TransformStream object (can only work with native) + Object.defineProperty(streamSaver, 'TransformStream', { + configurable: false, + writable: false, + value: TransformStream + }) + }) + + function loadTransporter () { + if (!mitmTransporter) { + mitmTransporter = isSecureContext + ? makeIframe(streamSaver.mitm) + : makePopup(streamSaver.mitm) + } + } + + /** + * @param {string} filename filename that should be used + * @param {object} options [description] + * @param {number} size deprecated + * @return {WritableStream} + */ + function createWriteStream (filename, options, size) { + let opts = { + size: null, + pathname: null, + writableStrategy: undefined, + readableStrategy: undefined + } + + let bytesWritten = 0 // by StreamSaver.js (not the service worker) + let downloadUrl = null + let channel = null + let ts = null + + // normalize arguments + if (Number.isFinite(options)) { + [ size, options ] = [ options, size ] + console.warn('[StreamSaver] Deprecated pass an object as 2nd argument when creating a write stream') + opts.size = size + opts.writableStrategy = options + } else if (options && options.highWaterMark) { + console.warn('[StreamSaver] Deprecated pass an object as 2nd argument when creating a write stream') + opts.size = size + opts.writableStrategy = options + } else { + opts = options || {} + } + if (!useBlobFallback) { + loadTransporter() + + channel = new MessageChannel() + + // Make filename RFC5987 compatible + filename = encodeURIComponent(filename.replace(/\//g, ':')) + .replace(/['()]/g, escape) + .replace(/\*/g, '%2A') + + const response = { + transferringReadable: supportsTransferable, + pathname: opts.pathname || Math.random().toString().slice(-6) + '/' + filename, + headers: { + 'Content-Type': 'application/octet-stream; charset=utf-8', + 'Content-Disposition': "attachment; filename*=UTF-8''" + filename + } + } + + if (opts.size) { + response.headers['Content-Length'] = opts.size + } + + const args = [ response, '*', [ channel.port2 ] ] + + if (supportsTransferable) { + const transformer = downloadStrategy === 'iframe' ? undefined : { + // This transformer & flush method is only used by insecure context. + transform (chunk, controller) { + if (!(chunk instanceof Uint8Array)) { + throw new TypeError('Can only write Uint8Arrays') + } + bytesWritten += chunk.length + controller.enqueue(chunk) + + if (downloadUrl) { + location.href = downloadUrl + downloadUrl = null + } + }, + flush () { + if (downloadUrl) { + location.href = downloadUrl + } + } + } + ts = new streamSaver.TransformStream( + transformer, + opts.writableStrategy, + opts.readableStrategy + ) + const readableStream = ts.readable + + channel.port1.postMessage({ readableStream }, [ readableStream ]) + } + + channel.port1.onmessage = evt => { + // Service worker sent us a link that we should open. + if (evt.data.download) { + // Special treatment for popup... + if (downloadStrategy === 'navigate') { + mitmTransporter.remove() + mitmTransporter = null + if (bytesWritten) { + location.href = evt.data.download + } else { + downloadUrl = evt.data.download + } + } else { + if (mitmTransporter.isPopup) { + mitmTransporter.remove() + mitmTransporter = null + // Special case for firefox, they can keep sw alive with fetch + if (downloadStrategy === 'iframe') { + makeIframe(streamSaver.mitm) + } + } + + // We never remove this iframes b/c it can interrupt saving + makeIframe(evt.data.download) + } + } else if (evt.data.abort) { + chunks = [] + channel.port1.postMessage('abort') //send back so controller is aborted + channel.port1.onmessage = null + channel.port1.close() + channel.port2.close() + channel = null + } + } + + if (mitmTransporter.loaded) { + mitmTransporter.postMessage(...args) + } else { + mitmTransporter.addEventListener('load', () => { + mitmTransporter.postMessage(...args) + }, { once: true }) + } + } + + let chunks = [] + + return (!useBlobFallback && ts && ts.writable) || new streamSaver.WritableStream({ + write (chunk) { + if (!(chunk instanceof Uint8Array)) { + throw new TypeError('Can only write Uint8Arrays') + } + if (useBlobFallback) { + // Safari... The new IE6 + // https://github.com/jimmywarting/StreamSaver.js/issues/69 + // + // even though it has everything it fails to download anything + // that comes from the service worker..! + chunks.push(chunk) + return + } + + // is called when a new chunk of data is ready to be written + // to the underlying sink. It can return a promise to signal + // success or failure of the write operation. The stream + // implementation guarantees that this method will be called + // only after previous writes have succeeded, and never after + // close or abort is called. + + // TODO: Kind of important that service worker respond back when + // it has been written. Otherwise we can't handle backpressure + // EDIT: Transferable streams solves this... + channel.port1.postMessage(chunk) + bytesWritten += chunk.length + + if (downloadUrl) { + location.href = downloadUrl + downloadUrl = null + } + }, + close () { + if (useBlobFallback) { + const blob = new Blob(chunks, { type: 'application/octet-stream; charset=utf-8' }) + const link = document.createElement('a') + link.href = URL.createObjectURL(blob) + link.download = filename + link.click() + } else { + channel.port1.postMessage('end') + } + }, + abort () { + chunks = [] + channel.port1.postMessage('abort') + channel.port1.onmessage = null + channel.port1.close() + channel.port2.close() + channel = null + } + }, opts.writableStrategy) + } + + return streamSaver +}) diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aac.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aac.js new file mode 100644 index 000000000..1cbada4ad --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aac.js @@ -0,0 +1,4655 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o> 1) & 7); + cookie[1] = ((header.samplingIndex & 1) << 7) | (header.chanConfig << 3); + this.emit('cookie', new AV.Buffer(cookie)); + + this.stream.seek(offset); + this.sentHeader = true; + } + + while (this.stream.available(1)) { + var buffer = this.stream.readSingleBuffer(this.stream.remainingBytes()); + this.emit('data', buffer); + } + }; +}); + +module.exports = ADTSDemuxer; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./tables":11}],2:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var ICStream = require('./ics'); +var Huffman = require('./huffman'); + +// Channel Coupling Element +function CCEElement(config) { + this.ics = new ICStream(config); + this.channelPair = new Array(8); + this.idSelect = new Int32Array(8); + this.chSelect = new Int32Array(8); + this.gain = new Array(16); +} + +CCEElement.BEFORE_TNS = 0; +CCEElement.AFTER_TNS = 1; +CCEElement.AFTER_IMDCT = 2; + +const CCE_SCALE = new Float32Array([ + 1.09050773266525765921, + 1.18920711500272106672, + 1.4142135623730950488016887, + 2.0 +]); + +CCEElement.prototype = { + decode: function(stream, config) { + var channelPair = this.channelPair, + idSelect = this.idSelect, + chSelect = this.chSelect; + + this.couplingPoint = 2 * stream.read(1); + this.coupledCount = stream.read(3); + + var gainCount = 0; + for (var i = 0; i <= this.coupledCount; i++) { + gainCount++; + channelPair[i] = stream.read(1); + idSelect[i] = stream.read(4); + + if (channelPair[i]) { + chSelect[i] = stream.read(2); + if (chSelect[i] === 3) + gainCount++; + + } else { + chSelect[i] = 2; + } + } + + this.couplingPoint += stream.read(1); + this.couplingPoint |= (this.couplingPoint >>> 1); + + var sign = stream.read(1), + scale = CCE_SCALE[stream.read(2)]; + + this.ics.decode(stream, config, false); + + var groupCount = this.ics.info.groupCount, + maxSFB = this.ics.info.maxSFB, + bandTypes = this.ics.bandTypes; + + for (var i = 0; i < gainCount; i++) { + var idx = 0, + cge = 1, + gain = 0, + gainCache = 1; + + if (i > 0) { + cge = this.couplingPoint === CCEElement.AFTER_IMDCT ? 1 : stream.read(1); + gain = cge ? Huffman.decodeScaleFactor(stream) - 60 : 0; + gainCache = Math.pow(scale, -gain); + } + + var gain_i = this.gain[i] = new Float32Array(120); + + if (this.couplingPoint === CCEElement.AFTER_IMDCT) { + gain_i[0] = gainCache; + } else { + for (var g = 0; g < groupCount; g++) { + for (var sfb = 0; sfb < maxSFB; sfb++) { + if (bandTypes[idx] !== ICStream.ZERO_BT) { + if (cge === 0) { + var t = Huffman.decodeScaleFactor(stream) - 60; + if (t !== 0) { + var s = 1; + t = gain += t; + if (!sign) { + s -= 2 * (t & 0x1); + t >>>= 1; + } + gainCache = Math.pow(scale, -t) * s; + } + } + gain_i[idx++] = gainCache; + } + } + } + } + } + }, + + applyIndependentCoupling: function(index, data) { + var gain = this.gain[index][0], + iqData = this.ics.data; + + for (var i = 0; i < data.length; i++) { + data[i] += gain * iqData[i]; + } + }, + + applyDependentCoupling: function(index, data) { + var info = this.ics.info, + swbOffsets = info.swbOffsets, + groupCount = info.groupCount, + maxSFB = info.maxSFB, + bandTypes = this.ics.bandTypes, + iqData = this.ics.data; + + var idx = 0, + offset = 0, + gains = this.gain[index]; + + for (var g = 0; g < groupCount; g++) { + var len = info.groupLength[g]; + + for (var sfb = 0; sfb < maxSFB; sfb++, idx++) { + if (bandTypes[idx] !== ICStream.ZERO_BT) { + var gain = gains[idx]; + for (var group = 0; group < len; group++) { + for (var k = swbOffsets[sfb]; k < swbOffsets[swb + 1]; k++) { + data[offset + group * 128 + k] += gain * iqData[offset + group * 128 + k]; + } + } + } + } + + offset += len * 128; + } + } +}; + +module.exports = CCEElement; + +},{"./huffman":7,"./ics":8}],3:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var ICStream = require('./ics'); + +// Channel Pair Element +function CPEElement(config) { + this.ms_used = []; + this.left = new ICStream(config); + this.right = new ICStream(config); +} + +const MAX_MS_MASK = 128; + +const MASK_TYPE_ALL_0 = 0, + MASK_TYPE_USED = 1, + MASK_TYPE_ALL_1 = 2, + MASK_TYPE_RESERVED = 3; + +CPEElement.prototype.decode = function(stream, config) { + var left = this.left, + right = this.right, + ms_used = this.ms_used; + + if (this.commonWindow = !!stream.read(1)) { + left.info.decode(stream, config, true); + right.info = left.info; + + var mask = stream.read(2); + this.maskPresent = !!mask; + + switch (mask) { + case MASK_TYPE_USED: + var len = left.info.groupCount * left.info.maxSFB; + for (var i = 0; i < len; i++) { + ms_used[i] = !!stream.read(1); + } + break; + + case MASK_TYPE_ALL_0: + case MASK_TYPE_ALL_1: + var val = !!mask; + for (var i = 0; i < MAX_MS_MASK; i++) { + ms_used[i] = val; + } + break; + + default: + throw new Error("Reserved ms mask type: " + mask); + } + } else { + for (var i = 0; i < MAX_MS_MASK; i++) + ms_used[i] = false; + } + + left.decode(stream, config, this.commonWindow); + right.decode(stream, config, this.commonWindow); +}; + +module.exports = CPEElement; + +},{"./ics":8}],4:[function(require,module,exports){ +(function (global){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); +var ADTSDemuxer = require('./adts_demuxer'); +var ICStream = require('./ics'); +var CPEElement = require('./cpe'); +var CCEElement = require('./cce'); +var FilterBank = require('./filter_bank'); +var tables = require('./tables'); + +var AACDecoder = AV.Decoder.extend(function() { + AV.Decoder.register('mp4a', this); + AV.Decoder.register('aac ', this); + + // AAC profiles + const AOT_AAC_MAIN = 1, // no + AOT_AAC_LC = 2, // yes + AOT_AAC_LTP = 4, // no + AOT_ESCAPE = 31; + + // Channel configurations + const CHANNEL_CONFIG_NONE = 0, + CHANNEL_CONFIG_MONO = 1, + CHANNEL_CONFIG_STEREO = 2, + CHANNEL_CONFIG_STEREO_PLUS_CENTER = 3, + CHANNEL_CONFIG_STEREO_PLUS_CENTER_PLUS_REAR_MONO = 4, + CHANNEL_CONFIG_FIVE = 5, + CHANNEL_CONFIG_FIVE_PLUS_ONE = 6, + CHANNEL_CONFIG_SEVEN_PLUS_ONE = 8; + + this.prototype.init = function() { + this.format.floatingPoint = true; + } + + this.prototype.setCookie = function(buffer) { + var data = AV.Stream.fromBuffer(buffer), + stream = new AV.Bitstream(data); + + this.config = {}; + + this.config.profile = stream.read(5); + if (this.config.profile === AOT_ESCAPE) + this.config.profile = 32 + stream.read(6); + + this.config.sampleIndex = stream.read(4); + if (this.config.sampleIndex === 0x0f) { + this.config.sampleRate = stream.read(24); + for (var i = 0; i < tables.SAMPLE_RATES.length; i++) { + if (tables.SAMPLE_RATES[i] === this.config.sampleRate) { + this.config.sampleIndex = i; + break; + } + } + } else { + this.config.sampleRate = tables.SAMPLE_RATES[this.config.sampleIndex]; + } + + this.config.chanConfig = stream.read(4); + this.format.channelsPerFrame = this.config.chanConfig; // sometimes m4a files encode this wrong + + switch (this.config.profile) { + case AOT_AAC_MAIN: + case AOT_AAC_LC: + case AOT_AAC_LTP: + if (stream.read(1)) // frameLengthFlag + throw new Error('frameLengthFlag not supported'); + + this.config.frameLength = 1024; + + if (stream.read(1)) // dependsOnCoreCoder + stream.advance(14); // coreCoderDelay + + if (stream.read(1)) { // extensionFlag + if (this.config.profile > 16) { // error resiliant profile + this.config.sectionDataResilience = stream.read(1); + this.config.scalefactorResilience = stream.read(1); + this.config.spectralDataResilience = stream.read(1); + } + + stream.advance(1); + } + + if (this.config.chanConfig === CHANNEL_CONFIG_NONE) { + stream.advance(4) // element_instance_tag + throw new Error('PCE unimplemented'); + } + + break; + + default: + throw new Error('AAC profile ' + this.config.profile + ' not supported.'); + } + + this.filter_bank = new FilterBank(false, this.config.chanConfig); + }; + + const SCE_ELEMENT = 0, + CPE_ELEMENT = 1, + CCE_ELEMENT = 2, + LFE_ELEMENT = 3, + DSE_ELEMENT = 4, + PCE_ELEMENT = 5, + FIL_ELEMENT = 6, + END_ELEMENT = 7; + + // The main decoding function. + this.prototype.readChunk = function() { + var stream = this.bitstream; + + // check if there is an ADTS header, and read it if so + if (stream.peek(12) === 0xfff) + ADTSDemuxer.readHeader(stream); + + this.cces = []; + var elements = [], + config = this.config, + frameLength = config.frameLength, + elementType = null; + + while ((elementType = stream.read(3)) !== END_ELEMENT) { + var id = stream.read(4); + + switch (elementType) { + // single channel and low frequency elements + case SCE_ELEMENT: + case LFE_ELEMENT: + var ics = new ICStream(this.config); + ics.id = id; + elements.push(ics); + ics.decode(stream, config, false); + break; + + // channel pair element + case CPE_ELEMENT: + var cpe = new CPEElement(this.config); + cpe.id = id; + elements.push(cpe); + cpe.decode(stream, config); + break; + + // channel coupling element + case CCE_ELEMENT: + var cce = new CCEElement(this.config); + this.cces.push(cce); + cce.decode(stream, config); + break; + + // data-stream element + case DSE_ELEMENT: + var align = stream.read(1), + count = stream.read(8); + + if (count === 255) + count += stream.read(8); + + if (align) + stream.align(); + + // skip for now... + stream.advance(count * 8); + break; + + // program configuration element + case PCE_ELEMENT: + throw new Error("TODO: PCE_ELEMENT") + break; + + // filler element + case FIL_ELEMENT: + if (id === 15) + id += stream.read(8) - 1; + + // skip for now... + stream.advance(id * 8); + break; + + default: + throw new Error('Unknown element') + } + } + + stream.align(); + this.process(elements); + + // Interleave channels + var data = this.data, + channels = data.length, + output = new Float32Array(frameLength * channels), + j = 0; + + for (var k = 0; k < frameLength; k++) { + for (var i = 0; i < channels; i++) { + output[j++] = data[i][k] / 32768; + } + } + + return output; + }; + + this.prototype.process = function(elements) { + var channels = this.config.chanConfig; + + // if (channels === 1 && psPresent) + // TODO: sbrPresent (2) + var mult = 1; + + var len = mult * this.config.frameLength; + var data = this.data = []; + + // Initialize channels + for (var i = 0; i < channels; i++) { + data[i] = new Float32Array(len); + } + + var channel = 0; + for (var i = 0; i < elements.length && channel < channels; i++) { + var e = elements[i]; + + if (e instanceof ICStream) { // SCE or LFE element + channel += this.processSingle(e, channel); + } else if (e instanceof CPEElement) { + this.processPair(e, channel); + channel += 2; + } else if (e instanceof CCEElement) { + channel++; + } else { + throw new Error("Unknown element found.") + } + } + }; + + this.prototype.processSingle = function(element, channel) { + var profile = this.config.profile, + info = element.info, + data = element.data; + + if (profile === AOT_AAC_MAIN) + throw new Error("Main prediction unimplemented"); + + if (profile === AOT_AAC_LTP) + throw new Error("LTP prediction unimplemented"); + + this.applyChannelCoupling(element, CCEElement.BEFORE_TNS, data, null); + + if (element.tnsPresent) + element.tns.process(element, data, false); + + this.applyChannelCoupling(element, CCEElement.AFTER_TNS, data, null); + + // filterbank + this.filter_bank.process(info, data, this.data[channel], channel); + + if (profile === AOT_AAC_LTP) + throw new Error("LTP prediction unimplemented"); + + this.applyChannelCoupling(element, CCEElement.AFTER_IMDCT, this.data[channel], null); + + if (element.gainPresent) + throw new Error("Gain control not implemented"); + + if (this.sbrPresent) + throw new Error("SBR not implemented"); + + return 1; + }; + + this.prototype.processPair = function(element, channel) { + var profile = this.config.profile, + left = element.left, + right = element.right, + l_info = left.info, + r_info = right.info, + l_data = left.data, + r_data = right.data; + + // Mid-side stereo + if (element.commonWindow && element.maskPresent) + this.processMS(element, l_data, r_data); + + if (profile === AOT_AAC_MAIN) + throw new Error("Main prediction unimplemented"); + + // Intensity stereo + this.processIS(element, l_data, r_data); + + if (profile === AOT_AAC_LTP) + throw new Error("LTP prediction unimplemented"); + + this.applyChannelCoupling(element, CCEElement.BEFORE_TNS, l_data, r_data); + + if (left.tnsPresent) + left.tns.process(left, l_data, false); + + if (right.tnsPresent) + right.tns.process(right, r_data, false); + + this.applyChannelCoupling(element, CCEElement.AFTER_TNS, l_data, r_data); + + // filterbank + this.filter_bank.process(l_info, l_data, this.data[channel], channel); + this.filter_bank.process(r_info, r_data, this.data[channel + 1], channel + 1); + + if (profile === AOT_AAC_LTP) + throw new Error("LTP prediction unimplemented"); + + this.applyChannelCoupling(element, CCEElement.AFTER_IMDCT, this.data[channel], this.data[channel + 1]); + + if (left.gainPresent) + throw new Error("Gain control not implemented"); + + if (right.gainPresent) + throw new Error("Gain control not implemented"); + + if (this.sbrPresent) + throw new Error("SBR not implemented"); + }; + + // Intensity stereo + this.prototype.processIS = function(element, left, right) { + var ics = element.right, + info = ics.info, + offsets = info.swbOffsets, + windowGroups = info.groupCount, + maxSFB = info.maxSFB, + bandTypes = ics.bandTypes, + sectEnd = ics.sectEnd, + scaleFactors = ics.scaleFactors; + + var idx = 0, groupOff = 0; + for (var g = 0; g < windowGroups; g++) { + for (var i = 0; i < maxSFB;) { + var end = sectEnd[idx]; + + if (bandTypes[idx] === ICStream.INTENSITY_BT || bandTypes[idx] === ICStream.INTENSITY_BT2) { + for (; i < end; i++, idx++) { + var c = bandTypes[idx] === ICStream.INTENSITY_BT ? 1 : -1; + if (element.maskPresent) + c *= element.ms_used[idx] ? -1 : 1; + + var scale = c * scaleFactors[idx]; + for (var w = 0; w < info.groupLength[g]; w++) { + var off = groupOff + w * 128 + offsets[i], + len = offsets[i + 1] - offsets[i]; + + for (var j = 0; j < len; j++) { + right[off + j] = left[off + j] * scale; + } + } + } + } else { + idx += end - i; + i = end; + } + } + + groupOff += info.groupLength[g] * 128; + } + }; + + // Mid-side stereo + this.prototype.processMS = function(element, left, right) { + var ics = element.left, + info = ics.info, + offsets = info.swbOffsets, + windowGroups = info.groupCount, + maxSFB = info.maxSFB, + sfbCBl = ics.bandTypes, + sfbCBr = element.right.bandTypes; + + var groupOff = 0, idx = 0; + for (var g = 0; g < windowGroups; g++) { + for (var i = 0; i < maxSFB; i++, idx++) { + if (element.ms_used[idx] && sfbCBl[idx] < ICStream.NOISE_BT && sfbCBr[idx] < ICStream.NOISE_BT) { + for (var w = 0; w < info.groupLength[g]; w++) { + var off = groupOff + w * 128 + offsets[i]; + for (var j = 0; j < offsets[i + 1] - offsets[i]; j++) { + var t = left[off + j] - right[off + j]; + left[off + j] += right[off + j]; + right[off + j] = t; + } + } + } + } + groupOff += info.groupLength[g] * 128; + } + }; + + this.prototype.applyChannelCoupling = function(element, couplingPoint, data1, data2) { + var cces = this.cces, + isChannelPair = element instanceof CPEElement, + applyCoupling = couplingPoint === CCEElement.AFTER_IMDCT ? 'applyIndependentCoupling' : 'applyDependentCoupling'; + + for (var i = 0; i < cces.length; i++) { + var cce = cces[i], + index = 0; + + if (cce.couplingPoint === couplingPoint) { + for (var c = 0; c < cce.coupledCount; c++) { + var chSelect = cce.chSelect[c]; + if (cce.channelPair[c] === isChannelPair && cce.idSelect[c] === element.id) { + if (chSelect !== 1) { + cce[applyCoupling](index, data1); + if (chSelect) index++; + } + + if (chSelect !== 2) + cce[applyCoupling](index++, data2); + + } else { + index += 1 + (chSelect === 3 ? 1 : 0); + } + } + } + } + }; + +}); + +module.exports = AACDecoder; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./adts_demuxer":1,"./cce":2,"./cpe":3,"./filter_bank":6,"./ics":8,"./tables":11}],5:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +function FFT(length) { + this.length = length; + + switch (length) { + case 64: + this.roots = generateFFTTableShort(64); + break; + + case 512: + this.roots = generateFFTTableLong(512); + break; + + case 60: + this.roots = generateFFTTableShort(60); + break; + + case 480: + this.roots = generateFFTTableLong(480); + break; + + default: + throw new Error("unexpected FFT length: " + length); + } + + // processing buffers + this.rev = new Array(length); + for (var i = 0; i < length; i++) { + this.rev[i] = new Float32Array(2); + } + + this.a = new Float32Array(2); + this.b = new Float32Array(2); + this.c = new Float32Array(2); + this.d = new Float32Array(2); + this.e1 = new Float32Array(2); + this.e2 = new Float32Array(2); +} + +function generateFFTTableShort(len) { + var t = 2 * Math.PI / len, + cosT = Math.cos(t), + sinT = Math.sin(t), + f = new Array(len); + + for (var i = 0; i < len; i++) { + f[i] = new Float32Array(2); + } + + f[0][0] = 1; + f[0][1] = 0; + var lastImag = 0; + + for (var i = 1; i < len; i++) { + f[i][0] = f[i - 1][0] * cosT + lastImag * sinT; + lastImag = lastImag * cosT - f[i - 1][0] * sinT; + f[i][1] = -lastImag; + } + + return f; +} + +function generateFFTTableLong(len) { + var t = 2 * Math.PI / len, + cosT = Math.cos(t), + sinT = Math.sin(t), + f = new Array(len); + + for (var i = 0; i < len; i++) { + f[i] = new Float32Array(3); + } + + f[0][0] = 1; + f[0][1] = 0; + f[0][2] = 0; + + for (var i = 1; i < len; i++) { + f[i][0] = f[i - 1][0] * cosT + f[i - 1][2] * sinT; + f[i][2] = f[i - 1][2] * cosT - f[i - 1][0] * sinT; + f[i][1] = -f[i][2]; + } + + return f; +} + +FFT.prototype.process = function(input, forward) { + var length = this.length, + imOffset = (forward ? 2 : 1), + scale = (forward ? length : 1), + rev = this.rev, + roots = this.roots; + + // bit-reversal + var ii = 0; + for (var i = 0; i < length; i++) { + rev[i][0] = input[ii][0]; + rev[i][1] = input[ii][1]; + + var k = length >>> 1; + while (ii >= k && k > 0) { + ii -= k; + k >>= 1; + } + + ii += k; + } + + var a = this.a, + b = this.b, + c = this.c, + d = this.d, + e1 = this.e1, + e2 = this.e2; + + for (var i = 0; i < length; i++) { + input[i][0] = rev[i][0]; + input[i][1] = rev[i][1]; + } + + // bottom base-4 round + for (var i = 0; i < length; i += 4) { + a[0] = input[i][0] + input[i + 1][0]; + a[1] = input[i][1] + input[i + 1][1]; + b[0] = input[i + 2][0] + input[i + 3][0]; + b[1] = input[i + 2][1] + input[i + 3][1]; + c[0] = input[i][0] - input[i + 1][0]; + c[1] = input[i][1] - input[i + 1][1]; + d[0] = input[i + 2][0] - input[i + 3][0]; + d[1] = input[i + 2][1] - input[i + 3][1]; + input[i][0] = a[0] + b[0]; + input[i][1] = a[1] + b[1]; + input[i + 2][0] = a[0] - b[0]; + input[i + 2][1] = a[1] - b[1]; + + e1[0] = c[0] - d[1]; + e1[1] = c[1] + d[0]; + e2[0] = c[0] + d[1]; + e2[1] = c[1] - d[0]; + + if (forward) { + input[i + 1][0] = e2[0]; + input[i + 1][1] = e2[1]; + input[i + 3][0] = e1[0]; + input[i + 3][1] = e1[1]; + } else { + input[i + 1][0] = e1[0]; + input[i + 1][1] = e1[1]; + input[i + 3][0] = e2[0]; + input[i + 3][1] = e2[1]; + } + } + + // iterations from bottom to top + for (var i = 4; i < length; i <<= 1) { + var shift = i << 1, + m = length / shift; + + for(var j = 0; j < length; j += shift) { + for(var k = 0; k < i; k++) { + var km = k * m, + rootRe = roots[km][0], + rootIm = roots[km][imOffset], + zRe = input[i + j + k][0] * rootRe - input[i + j + k][1] * rootIm, + zIm = input[i + j + k][0] * rootIm + input[i + j + k][1] * rootRe; + + input[i + j + k][0] = (input[j + k][0] - zRe) * scale; + input[i + j + k][1] = (input[j + k][1] - zIm) * scale; + input[j + k][0] = (input[j + k][0] + zRe) * scale; + input[j + k][1] = (input[j + k][1] + zIm) * scale; + } + } + } +}; + +module.exports = FFT; + +},{}],6:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var ICStream = require('./ics'); +var MDCT = require('./mdct'); + +function FilterBank(smallFrames, channels) { + if (smallFrames) { + throw new Error("WHA?? No small frames allowed."); + } + + this.length = 1024; + this.shortLength = 128; + + this.mid = (this.length - this.shortLength) / 2; + this.trans = this.shortLength / 2; + + this.mdctShort = new MDCT(this.shortLength * 2); + this.mdctLong = new MDCT(this.length * 2); + + this.overlaps = new Array(channels); + for (var i = 0; i < channels; i++) { + this.overlaps[i] = new Float32Array(this.length); + } + + this.buf = new Float32Array(2 * this.length); +} + +function generateSineWindow(len) { + var d = new Float32Array(len); + for (var i = 0; i < len; i++) { + d[i] = Math.sin((i + 0.5) * (Math.PI / (2.0 * len))) + } + return d; +} + +function generateKBDWindow(alpha, len) { + var PIN = Math.PI / len, + out = new Float32Array(len), + sum = 0, + f = new Float32Array(len), + alpha2 = (alpha * PIN) * (alpha * PIN); + + for (var n = 0; n < len; n++) { + var tmp = n * (len - n) * alpha2, + bessel = 1; + + for (var j = 50; j > 0; j--) { + bessel = bessel * tmp / (j * j) + 1; + } + + sum += bessel; + f[n] = sum; + } + + sum++; + for (var n = 0; n < len; n++) { + out[n] = Math.sqrt(f[n] / sum); + } + + return out; +} + +const SINE_1024 = generateSineWindow(1024), + SINE_128 = generateSineWindow(128), + KBD_1024 = generateKBDWindow(4, 1024), + KBD_128 = generateKBDWindow(6, 128), + LONG_WINDOWS = [SINE_1024, KBD_1024], + SHORT_WINDOWS = [SINE_128, KBD_128]; + +FilterBank.prototype.process = function(info, input, output, channel) { + var overlap = this.overlaps[channel], + windowShape = info.windowShape[1], + windowShapePrev = info.windowShape[0], + longWindows = LONG_WINDOWS[windowShape], + shortWindows = SHORT_WINDOWS[windowShape], + longWindowsPrev = LONG_WINDOWS[windowShapePrev], + shortWindowsPrev = SHORT_WINDOWS[windowShapePrev], + length = this.length, + shortLen = this.shortLength, + mid = this.mid, + trans = this.trans, + buf = this.buf, + mdctLong = this.mdctLong, + mdctShort = this.mdctShort; + + switch (info.windowSequence) { + case ICStream.ONLY_LONG_SEQUENCE: + mdctLong.process(input, 0, buf, 0); + + // add second half output of previous frame to windowed output of current frame + for (var i = 0; i < length; i++) { + output[i] = overlap[i] + (buf[i] * longWindowsPrev[i]); + } + + // window the second half and save as overlap for next frame + for (var i = 0; i < length; i++) { + overlap[i] = buf[length + i] * longWindows[length - 1 - i]; + } + + break; + + case ICStream.LONG_START_SEQUENCE: + mdctLong.process(input, 0, buf, 0); + + // add second half output of previous frame to windowed output of current frame + for (var i = 0; i < length; i++) { + output[i] = overlap[i] + (buf[i] * longWindowsPrev[i]); + } + + // window the second half and save as overlap for next frame + for (var i = 0; i < mid; i++) { + overlap[i] = buf[length + i]; + } + + for (var i = 0; i < shortLen; i++) { + overlap[mid + i] = buf[length + mid + i] * shortWindows[shortLen - i - 1]; + } + + for (var i = 0; i < mid; i++) { + overlap[mid + shortLen + i] = 0; + } + + break; + + case ICStream.EIGHT_SHORT_SEQUENCE: + for (var i = 0; i < 8; i++) { + mdctShort.process(input, i * shortLen, buf, 2 * i * shortLen); + } + + // add second half output of previous frame to windowed output of current frame + for (var i = 0; i < mid; i++) { + output[i] = overlap[i]; + } + + for (var i = 0; i < shortLen; i++) { + output[mid + i] = overlap[mid + i] + buf[i] * shortWindowsPrev[i]; + output[mid + 1 * shortLen + i] = overlap[mid + shortLen * 1 + i] + (buf[shortLen * 1 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 2 + i] * shortWindows[i]); + output[mid + 2 * shortLen + i] = overlap[mid + shortLen * 2 + i] + (buf[shortLen * 3 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 4 + i] * shortWindows[i]); + output[mid + 3 * shortLen + i] = overlap[mid + shortLen * 3 + i] + (buf[shortLen * 5 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 6 + i] * shortWindows[i]); + + if (i < trans) + output[mid + 4 * shortLen + i] = overlap[mid + shortLen * 4 + i] + (buf[shortLen * 7 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 8 + i] * shortWindows[i]); + } + + // window the second half and save as overlap for next frame + for (var i = 0; i < shortLen; i++) { + if(i >= trans) + overlap[mid + 4 * shortLen + i - length] = (buf[shortLen * 7 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 8 + i] * shortWindows[i]); + + overlap[mid + 5 * shortLen + i - length] = (buf[shortLen * 9 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 10 + i] * shortWindows[i]); + overlap[mid + 6 * shortLen + i - length] = (buf[shortLen * 11 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 12 + i]*shortWindows[i]); + overlap[mid + 7 * shortLen + i - length] = (buf[shortLen * 13 + i] * shortWindows[shortLen - 1 - i]) + (buf[shortLen * 14 + i]*shortWindows[i]); + overlap[mid + 8 * shortLen + i - length] = (buf[shortLen * 15 + i] * shortWindows[shortLen - 1 - i]); + } + + for (var i = 0; i < mid; i++) { + overlap[mid + shortLen + i] = 0; + } + + break; + + case ICStream.LONG_STOP_SEQUENCE: + mdctLong.process(input, 0, buf, 0); + + // add second half output of previous frame to windowed output of current frame + // construct first half window using padding with 1's and 0's + for (var i = 0; i < mid; i++) { + output[i] = overlap[i]; + } + + for (var i = 0; i < shortLen; i++) { + output[mid + i] = overlap[mid + i] + (buf[mid + i] * shortWindowsPrev[i]); + } + + for (var i = 0; i < mid; i++) { + output[mid + shortLen + i] = overlap[mid + shortLen + i] + buf[mid + shortLen + i]; + } + + // window the second half and save as overlap for next frame + for (var i = 0; i < length; i++) { + overlap[i] = buf[length + i] * longWindows[length - 1 - i]; + } + + break; + } +}; + +module.exports = FilterBank; + +},{"./ics":8,"./mdct":9}],7:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +// [bit length, codeword, values...] +const HCB1 = [ + [1, 0, 0, 0, 0, 0], + [5, 16, 1, 0, 0, 0], + [5, 17, -1, 0, 0, 0], + [5, 18, 0, 0, 0, -1], + [5, 19, 0, 1, 0, 0], + [5, 20, 0, 0, 0, 1], + [5, 21, 0, 0, -1, 0], + [5, 22, 0, 0, 1, 0], + [5, 23, 0, -1, 0, 0], + [7, 96, 1, -1, 0, 0], + [7, 97, -1, 1, 0, 0], + [7, 98, 0, 0, -1, 1], + [7, 99, 0, 1, -1, 0], + [7, 100, 0, -1, 1, 0], + [7, 101, 0, 0, 1, -1], + [7, 102, 1, 1, 0, 0], + [7, 103, 0, 0, -1, -1], + [7, 104, -1, -1, 0, 0], + [7, 105, 0, -1, -1, 0], + [7, 106, 1, 0, -1, 0], + [7, 107, 0, 1, 0, -1], + [7, 108, -1, 0, 1, 0], + [7, 109, 0, 0, 1, 1], + [7, 110, 1, 0, 1, 0], + [7, 111, 0, -1, 0, 1], + [7, 112, 0, 1, 1, 0], + [7, 113, 0, 1, 0, 1], + [7, 114, -1, 0, -1, 0], + [7, 115, 1, 0, 0, 1], + [7, 116, -1, 0, 0, -1], + [7, 117, 1, 0, 0, -1], + [7, 118, -1, 0, 0, 1], + [7, 119, 0, -1, 0, -1], + [9, 480, 1, 1, -1, 0], + [9, 481, -1, 1, -1, 0], + [9, 482, 1, -1, 1, 0], + [9, 483, 0, 1, 1, -1], + [9, 484, 0, 1, -1, 1], + [9, 485, 0, -1, 1, 1], + [9, 486, 0, -1, 1, -1], + [9, 487, 1, -1, -1, 0], + [9, 488, 1, 0, -1, 1], + [9, 489, 0, 1, -1, -1], + [9, 490, -1, 1, 1, 0], + [9, 491, -1, 0, 1, -1], + [9, 492, -1, -1, 1, 0], + [9, 493, 0, -1, -1, 1], + [9, 494, 1, -1, 0, 1], + [9, 495, 1, -1, 0, -1], + [9, 496, -1, 1, 0, -1], + [9, 497, -1, -1, -1, 0], + [9, 498, 0, -1, -1, -1], + [9, 499, 0, 1, 1, 1], + [9, 500, 1, 0, 1, -1], + [9, 501, 1, 1, 0, 1], + [9, 502, -1, 1, 0, 1], + [9, 503, 1, 1, 1, 0], + [10, 1008, -1, -1, 0, 1], + [10, 1009, -1, 0, -1, -1], + [10, 1010, 1, 1, 0, -1], + [10, 1011, 1, 0, -1, -1], + [10, 1012, -1, 0, -1, 1], + [10, 1013, -1, -1, 0, -1], + [10, 1014, -1, 0, 1, 1], + [10, 1015, 1, 0, 1, 1], + [11, 2032, 1, -1, 1, -1], + [11, 2033, -1, 1, -1, 1], + [11, 2034, -1, 1, 1, -1], + [11, 2035, 1, -1, -1, 1], + [11, 2036, 1, 1, 1, 1], + [11, 2037, -1, -1, 1, 1], + [11, 2038, 1, 1, -1, -1], + [11, 2039, -1, -1, 1, -1], + [11, 2040, -1, -1, -1, -1], + [11, 2041, 1, 1, -1, 1], + [11, 2042, 1, -1, 1, 1], + [11, 2043, -1, 1, 1, 1], + [11, 2044, -1, 1, -1, -1], + [11, 2045, -1, -1, -1, 1], + [11, 2046, 1, -1, -1, -1], + [11, 2047, 1, 1, 1, -1] +]; + +const HCB2 = [ + [3, 0, 0, 0, 0, 0], + [4, 2, 1, 0, 0, 0], + [5, 6, -1, 0, 0, 0], + [5, 7, 0, 0, 0, 1], + [5, 8, 0, 0, -1, 0], + [5, 9, 0, 0, 0, -1], + [5, 10, 0, -1, 0, 0], + [5, 11, 0, 0, 1, 0], + [5, 12, 0, 1, 0, 0], + [6, 26, 0, -1, 1, 0], + [6, 27, -1, 1, 0, 0], + [6, 28, 0, 1, -1, 0], + [6, 29, 0, 0, 1, -1], + [6, 30, 0, 1, 0, -1], + [6, 31, 0, 0, -1, 1], + [6, 32, -1, 0, 0, -1], + [6, 33, 1, -1, 0, 0], + [6, 34, 1, 0, -1, 0], + [6, 35, -1, -1, 0, 0], + [6, 36, 0, 0, -1, -1], + [6, 37, 1, 0, 1, 0], + [6, 38, 1, 0, 0, 1], + [6, 39, 0, -1, 0, 1], + [6, 40, -1, 0, 1, 0], + [6, 41, 0, 1, 0, 1], + [6, 42, 0, -1, -1, 0], + [6, 43, -1, 0, 0, 1], + [6, 44, 0, -1, 0, -1], + [6, 45, -1, 0, -1, 0], + [6, 46, 1, 1, 0, 0], + [6, 47, 0, 1, 1, 0], + [6, 48, 0, 0, 1, 1], + [6, 49, 1, 0, 0, -1], + [7, 100, 0, 1, -1, 1], + [7, 101, 1, 0, -1, 1], + [7, 102, -1, 1, -1, 0], + [7, 103, 0, -1, 1, -1], + [7, 104, 1, -1, 1, 0], + [7, 105, 1, 1, 0, -1], + [7, 106, 1, 0, 1, 1], + [7, 107, -1, 1, 1, 0], + [7, 108, 0, -1, -1, 1], + [7, 109, 1, 1, 1, 0], + [7, 110, -1, 0, 1, -1], + [7, 111, -1, -1, -1, 0], + [7, 112, -1, 0, -1, 1], + [7, 113, 1, -1, -1, 0], + [7, 114, 1, 1, -1, 0], + [8, 230, 1, -1, 0, 1], + [8, 231, -1, 1, 0, -1], + [8, 232, -1, -1, 1, 0], + [8, 233, -1, 0, 1, 1], + [8, 234, -1, -1, 0, 1], + [8, 235, -1, -1, 0, -1], + [8, 236, 0, -1, -1, -1], + [8, 237, 1, 0, 1, -1], + [8, 238, 1, 0, -1, -1], + [8, 239, 0, 1, -1, -1], + [8, 240, 0, 1, 1, 1], + [8, 241, -1, 1, 0, 1], + [8, 242, -1, 0, -1, -1], + [8, 243, 0, 1, 1, -1], + [8, 244, 1, -1, 0, -1], + [8, 245, 0, -1, 1, 1], + [8, 246, 1, 1, 0, 1], + [8, 247, 1, -1, 1, -1], + [8, 248, -1, 1, -1, 1], + [9, 498, 1, -1, -1, 1], + [9, 499, -1, -1, -1, -1], + [9, 500, -1, 1, 1, -1], + [9, 501, -1, 1, 1, 1], + [9, 502, 1, 1, 1, 1], + [9, 503, -1, -1, 1, -1], + [9, 504, 1, -1, 1, 1], + [9, 505, -1, 1, -1, -1], + [9, 506, -1, -1, 1, 1], + [9, 507, 1, 1, -1, -1], + [9, 508, 1, -1, -1, -1], + [9, 509, -1, -1, -1, 1], + [9, 510, 1, 1, -1, 1], + [9, 511, 1, 1, 1, -1] +]; + +const HCB3 = [ + [1, 0, 0, 0, 0, 0], + [4, 8, 1, 0, 0, 0], + [4, 9, 0, 0, 0, 1], + [4, 10, 0, 1, 0, 0], + [4, 11, 0, 0, 1, 0], + [5, 24, 1, 1, 0, 0], + [5, 25, 0, 0, 1, 1], + [6, 52, 0, 1, 1, 0], + [6, 53, 0, 1, 0, 1], + [6, 54, 1, 0, 1, 0], + [6, 55, 0, 1, 1, 1], + [6, 56, 1, 0, 0, 1], + [6, 57, 1, 1, 1, 0], + [7, 116, 1, 1, 1, 1], + [7, 117, 1, 0, 1, 1], + [7, 118, 1, 1, 0, 1], + [8, 238, 2, 0, 0, 0], + [8, 239, 0, 0, 0, 2], + [8, 240, 0, 0, 1, 2], + [8, 241, 2, 1, 0, 0], + [8, 242, 1, 2, 1, 0], + [9, 486, 0, 0, 2, 1], + [9, 487, 0, 1, 2, 1], + [9, 488, 1, 2, 0, 0], + [9, 489, 0, 1, 1, 2], + [9, 490, 2, 1, 1, 0], + [9, 491, 0, 0, 2, 0], + [9, 492, 0, 2, 1, 0], + [9, 493, 0, 1, 2, 0], + [9, 494, 0, 2, 0, 0], + [9, 495, 0, 1, 0, 2], + [9, 496, 2, 0, 1, 0], + [9, 497, 1, 2, 1, 1], + [9, 498, 0, 2, 1, 1], + [9, 499, 1, 1, 2, 0], + [9, 500, 1, 1, 2, 1], + [10, 1002, 1, 2, 0, 1], + [10, 1003, 1, 0, 2, 0], + [10, 1004, 1, 0, 2, 1], + [10, 1005, 0, 2, 0, 1], + [10, 1006, 2, 1, 1, 1], + [10, 1007, 1, 1, 1, 2], + [10, 1008, 2, 1, 0, 1], + [10, 1009, 1, 0, 1, 2], + [10, 1010, 0, 0, 2, 2], + [10, 1011, 0, 1, 2, 2], + [10, 1012, 2, 2, 1, 0], + [10, 1013, 1, 2, 2, 0], + [10, 1014, 1, 0, 0, 2], + [10, 1015, 2, 0, 0, 1], + [10, 1016, 0, 2, 2, 1], + [11, 2034, 2, 2, 0, 0], + [11, 2035, 1, 2, 2, 1], + [11, 2036, 1, 1, 0, 2], + [11, 2037, 2, 0, 1, 1], + [11, 2038, 1, 1, 2, 2], + [11, 2039, 2, 2, 1, 1], + [11, 2040, 0, 2, 2, 0], + [11, 2041, 0, 2, 1, 2], + [12, 4084, 1, 0, 2, 2], + [12, 4085, 2, 2, 0, 1], + [12, 4086, 2, 1, 2, 0], + [12, 4087, 2, 2, 2, 0], + [12, 4088, 0, 2, 2, 2], + [12, 4089, 2, 2, 2, 1], + [12, 4090, 2, 1, 2, 1], + [12, 4091, 1, 2, 1, 2], + [12, 4092, 1, 2, 2, 2], + [13, 8186, 0, 2, 0, 2], + [13, 8187, 2, 0, 2, 0], + [13, 8188, 1, 2, 0, 2], + [14, 16378, 2, 0, 2, 1], + [14, 16379, 2, 1, 1, 2], + [14, 16380, 2, 1, 0, 2], + [15, 32762, 2, 2, 2, 2], + [15, 32763, 2, 2, 1, 2], + [15, 32764, 2, 1, 2, 2], + [15, 32765, 2, 0, 1, 2], + [15, 32766, 2, 0, 0, 2], + [16, 65534, 2, 2, 0, 2], + [16, 65535, 2, 0, 2, 2] +]; + +const HCB4 = [ + [4, 0, 1, 1, 1, 1], + [4, 1, 0, 1, 1, 1], + [4, 2, 1, 1, 0, 1], + [4, 3, 1, 1, 1, 0], + [4, 4, 1, 0, 1, 1], + [4, 5, 1, 0, 0, 0], + [4, 6, 1, 1, 0, 0], + [4, 7, 0, 0, 0, 0], + [4, 8, 0, 0, 1, 1], + [4, 9, 1, 0, 1, 0], + [5, 20, 1, 0, 0, 1], + [5, 21, 0, 1, 1, 0], + [5, 22, 0, 0, 0, 1], + [5, 23, 0, 1, 0, 1], + [5, 24, 0, 0, 1, 0], + [5, 25, 0, 1, 0, 0], + [7, 104, 2, 1, 1, 1], + [7, 105, 1, 1, 2, 1], + [7, 106, 1, 2, 1, 1], + [7, 107, 1, 1, 1, 2], + [7, 108, 2, 1, 1, 0], + [7, 109, 2, 1, 0, 1], + [7, 110, 1, 2, 1, 0], + [7, 111, 2, 0, 1, 1], + [7, 112, 0, 1, 2, 1], + [8, 226, 0, 1, 1, 2], + [8, 227, 1, 1, 2, 0], + [8, 228, 0, 2, 1, 1], + [8, 229, 1, 0, 1, 2], + [8, 230, 1, 2, 0, 1], + [8, 231, 1, 1, 0, 2], + [8, 232, 1, 0, 2, 1], + [8, 233, 2, 1, 0, 0], + [8, 234, 2, 0, 1, 0], + [8, 235, 1, 2, 0, 0], + [8, 236, 2, 0, 0, 1], + [8, 237, 0, 1, 0, 2], + [8, 238, 0, 2, 1, 0], + [8, 239, 0, 0, 1, 2], + [8, 240, 0, 1, 2, 0], + [8, 241, 0, 2, 0, 1], + [8, 242, 1, 0, 0, 2], + [8, 243, 0, 0, 2, 1], + [8, 244, 1, 0, 2, 0], + [8, 245, 2, 0, 0, 0], + [8, 246, 0, 0, 0, 2], + [9, 494, 0, 2, 0, 0], + [9, 495, 0, 0, 2, 0], + [9, 496, 1, 2, 2, 1], + [9, 497, 2, 2, 1, 1], + [9, 498, 2, 1, 2, 1], + [9, 499, 1, 1, 2, 2], + [9, 500, 1, 2, 1, 2], + [9, 501, 2, 1, 1, 2], + [10, 1004, 1, 2, 2, 0], + [10, 1005, 2, 2, 1, 0], + [10, 1006, 2, 1, 2, 0], + [10, 1007, 0, 2, 2, 1], + [10, 1008, 0, 1, 2, 2], + [10, 1009, 2, 2, 0, 1], + [10, 1010, 0, 2, 1, 2], + [10, 1011, 2, 0, 2, 1], + [10, 1012, 1, 0, 2, 2], + [10, 1013, 2, 2, 2, 1], + [10, 1014, 1, 2, 0, 2], + [10, 1015, 2, 0, 1, 2], + [10, 1016, 2, 1, 0, 2], + [10, 1017, 1, 2, 2, 2], + [11, 2036, 2, 1, 2, 2], + [11, 2037, 2, 2, 1, 2], + [11, 2038, 0, 2, 2, 0], + [11, 2039, 2, 2, 0, 0], + [11, 2040, 0, 0, 2, 2], + [11, 2041, 2, 0, 2, 0], + [11, 2042, 0, 2, 0, 2], + [11, 2043, 2, 0, 0, 2], + [11, 2044, 2, 2, 2, 2], + [11, 2045, 0, 2, 2, 2], + [11, 2046, 2, 2, 2, 0], + [12, 4094, 2, 2, 0, 2], + [12, 4095, 2, 0, 2, 2] +]; + +const HCB5 = [ + [1, 0, 0, 0], + [4, 8, -1, 0], + [4, 9, 1, 0], + [4, 10, 0, 1], + [4, 11, 0, -1], + [5, 24, 1, -1], + [5, 25, -1, 1], + [5, 26, -1, -1], + [5, 27, 1, 1], + [7, 112, -2, 0], + [7, 113, 0, 2], + [7, 114, 2, 0], + [7, 115, 0, -2], + [8, 232, -2, -1], + [8, 233, 2, 1], + [8, 234, -1, -2], + [8, 235, 1, 2], + [8, 236, -2, 1], + [8, 237, 2, -1], + [8, 238, -1, 2], + [8, 239, 1, -2], + [8, 240, -3, 0], + [8, 241, 3, 0], + [8, 242, 0, -3], + [8, 243, 0, 3], + [9, 488, -3, -1], + [9, 489, 1, 3], + [9, 490, 3, 1], + [9, 491, -1, -3], + [9, 492, -3, 1], + [9, 493, 3, -1], + [9, 494, 1, -3], + [9, 495, -1, 3], + [9, 496, -2, 2], + [9, 497, 2, 2], + [9, 498, -2, -2], + [9, 499, 2, -2], + [10, 1000, -3, -2], + [10, 1001, 3, -2], + [10, 1002, -2, 3], + [10, 1003, 2, -3], + [10, 1004, 3, 2], + [10, 1005, 2, 3], + [10, 1006, -3, 2], + [10, 1007, -2, -3], + [10, 1008, 0, -4], + [10, 1009, -4, 0], + [10, 1010, 4, 1], + [10, 1011, 4, 0], + [11, 2024, -4, -1], + [11, 2025, 0, 4], + [11, 2026, 4, -1], + [11, 2027, -1, -4], + [11, 2028, 1, 4], + [11, 2029, -1, 4], + [11, 2030, -4, 1], + [11, 2031, 1, -4], + [11, 2032, 3, -3], + [11, 2033, -3, -3], + [11, 2034, -3, 3], + [11, 2035, -2, 4], + [11, 2036, -4, -2], + [11, 2037, 4, 2], + [11, 2038, 2, -4], + [11, 2039, 2, 4], + [11, 2040, 3, 3], + [11, 2041, -4, 2], + [12, 4084, -2, -4], + [12, 4085, 4, -2], + [12, 4086, 3, -4], + [12, 4087, -4, -3], + [12, 4088, -4, 3], + [12, 4089, 3, 4], + [12, 4090, -3, 4], + [12, 4091, 4, 3], + [12, 4092, 4, -3], + [12, 4093, -3, -4], + [13, 8188, 4, -4], + [13, 8189, -4, 4], + [13, 8190, 4, 4], + [13, 8191, -4, -4] +]; + +const HCB6 = [ + [4, 0, 0, 0], + [4, 1, 1, 0], + [4, 2, 0, -1], + [4, 3, 0, 1], + [4, 4, -1, 0], + [4, 5, 1, 1], + [4, 6, -1, 1], + [4, 7, 1, -1], + [4, 8, -1, -1], + [6, 36, 2, -1], + [6, 37, 2, 1], + [6, 38, -2, 1], + [6, 39, -2, -1], + [6, 40, -2, 0], + [6, 41, -1, 2], + [6, 42, 2, 0], + [6, 43, 1, -2], + [6, 44, 1, 2], + [6, 45, 0, -2], + [6, 46, -1, -2], + [6, 47, 0, 2], + [6, 48, 2, -2], + [6, 49, -2, 2], + [6, 50, -2, -2], + [6, 51, 2, 2], + [7, 104, -3, 1], + [7, 105, 3, 1], + [7, 106, 3, -1], + [7, 107, -1, 3], + [7, 108, -3, -1], + [7, 109, 1, 3], + [7, 110, 1, -3], + [7, 111, -1, -3], + [7, 112, 3, 0], + [7, 113, -3, 0], + [7, 114, 0, -3], + [7, 115, 0, 3], + [7, 116, 3, 2], + [8, 234, -3, -2], + [8, 235, -2, 3], + [8, 236, 2, 3], + [8, 237, 3, -2], + [8, 238, 2, -3], + [8, 239, -2, -3], + [8, 240, -3, 2], + [8, 241, 3, 3], + [9, 484, 3, -3], + [9, 485, -3, -3], + [9, 486, -3, 3], + [9, 487, 1, -4], + [9, 488, -1, -4], + [9, 489, 4, 1], + [9, 490, -4, 1], + [9, 491, -4, -1], + [9, 492, 1, 4], + [9, 493, 4, -1], + [9, 494, -1, 4], + [9, 495, 0, -4], + [9, 496, -4, 2], + [9, 497, -4, -2], + [9, 498, 2, 4], + [9, 499, -2, -4], + [9, 500, -4, 0], + [9, 501, 4, 2], + [9, 502, 4, -2], + [9, 503, -2, 4], + [9, 504, 4, 0], + [9, 505, 2, -4], + [9, 506, 0, 4], + [10, 1014, -3, -4], + [10, 1015, -3, 4], + [10, 1016, 3, -4], + [10, 1017, 4, -3], + [10, 1018, 3, 4], + [10, 1019, 4, 3], + [10, 1020, -4, 3], + [10, 1021, -4, -3], + [11, 2044, 4, 4], + [11, 2045, -4, 4], + [11, 2046, -4, -4], + [11, 2047, 4, -4] +]; + +const HCB7 = [ + [1, 0, 0, 0], + [3, 4, 1, 0], + [3, 5, 0, 1], + [4, 12, 1, 1], + [6, 52, 2, 1], + [6, 53, 1, 2], + [6, 54, 2, 0], + [6, 55, 0, 2], + [7, 112, 3, 1], + [7, 113, 1, 3], + [7, 114, 2, 2], + [7, 115, 3, 0], + [7, 116, 0, 3], + [8, 234, 2, 3], + [8, 235, 3, 2], + [8, 236, 1, 4], + [8, 237, 4, 1], + [8, 238, 1, 5], + [8, 239, 5, 1], + [8, 240, 3, 3], + [8, 241, 2, 4], + [8, 242, 0, 4], + [8, 243, 4, 0], + [9, 488, 4, 2], + [9, 489, 2, 5], + [9, 490, 5, 2], + [9, 491, 0, 5], + [9, 492, 6, 1], + [9, 493, 5, 0], + [9, 494, 1, 6], + [9, 495, 4, 3], + [9, 496, 3, 5], + [9, 497, 3, 4], + [9, 498, 5, 3], + [9, 499, 2, 6], + [9, 500, 6, 2], + [9, 501, 1, 7], + [10, 1004, 3, 6], + [10, 1005, 0, 6], + [10, 1006, 6, 0], + [10, 1007, 4, 4], + [10, 1008, 7, 1], + [10, 1009, 4, 5], + [10, 1010, 7, 2], + [10, 1011, 5, 4], + [10, 1012, 6, 3], + [10, 1013, 2, 7], + [10, 1014, 7, 3], + [10, 1015, 6, 4], + [10, 1016, 5, 5], + [10, 1017, 4, 6], + [10, 1018, 3, 7], + [11, 2038, 7, 0], + [11, 2039, 0, 7], + [11, 2040, 6, 5], + [11, 2041, 5, 6], + [11, 2042, 7, 4], + [11, 2043, 4, 7], + [11, 2044, 5, 7], + [11, 2045, 7, 5], + [12, 4092, 7, 6], + [12, 4093, 6, 6], + [12, 4094, 6, 7], + [12, 4095, 7, 7] +]; + +const HCB8 = [ + [3, 0, 1, 1], + [4, 2, 2, 1], + [4, 3, 1, 0], + [4, 4, 1, 2], + [4, 5, 0, 1], + [4, 6, 2, 2], + [5, 14, 0, 0], + [5, 15, 2, 0], + [5, 16, 0, 2], + [5, 17, 3, 1], + [5, 18, 1, 3], + [5, 19, 3, 2], + [5, 20, 2, 3], + [6, 42, 3, 3], + [6, 43, 4, 1], + [6, 44, 1, 4], + [6, 45, 4, 2], + [6, 46, 2, 4], + [6, 47, 3, 0], + [6, 48, 0, 3], + [6, 49, 4, 3], + [6, 50, 3, 4], + [6, 51, 5, 2], + [7, 104, 5, 1], + [7, 105, 2, 5], + [7, 106, 1, 5], + [7, 107, 5, 3], + [7, 108, 3, 5], + [7, 109, 4, 4], + [7, 110, 5, 4], + [7, 111, 0, 4], + [7, 112, 4, 5], + [7, 113, 4, 0], + [7, 114, 2, 6], + [7, 115, 6, 2], + [7, 116, 6, 1], + [7, 117, 1, 6], + [8, 236, 3, 6], + [8, 237, 6, 3], + [8, 238, 5, 5], + [8, 239, 5, 0], + [8, 240, 6, 4], + [8, 241, 0, 5], + [8, 242, 4, 6], + [8, 243, 7, 1], + [8, 244, 7, 2], + [8, 245, 2, 7], + [8, 246, 6, 5], + [8, 247, 7, 3], + [8, 248, 1, 7], + [8, 249, 5, 6], + [8, 250, 3, 7], + [9, 502, 6, 6], + [9, 503, 7, 4], + [9, 504, 6, 0], + [9, 505, 4, 7], + [9, 506, 0, 6], + [9, 507, 7, 5], + [9, 508, 7, 6], + [9, 509, 6, 7], + [10, 1020, 5, 7], + [10, 1021, 7, 0], + [10, 1022, 0, 7], + [10, 1023, 7, 7] +]; + +const HCB9 = [ + [1, 0, 0, 0], + [3, 4, 1, 0], + [3, 5, 0, 1], + [4, 12, 1, 1], + [6, 52, 2, 1], + [6, 53, 1, 2], + [6, 54, 2, 0], + [6, 55, 0, 2], + [7, 112, 3, 1], + [7, 113, 2, 2], + [7, 114, 1, 3], + [8, 230, 3, 0], + [8, 231, 0, 3], + [8, 232, 2, 3], + [8, 233, 3, 2], + [8, 234, 1, 4], + [8, 235, 4, 1], + [8, 236, 2, 4], + [8, 237, 1, 5], + [9, 476, 4, 2], + [9, 477, 3, 3], + [9, 478, 0, 4], + [9, 479, 4, 0], + [9, 480, 5, 1], + [9, 481, 2, 5], + [9, 482, 1, 6], + [9, 483, 3, 4], + [9, 484, 5, 2], + [9, 485, 6, 1], + [9, 486, 4, 3], + [10, 974, 0, 5], + [10, 975, 2, 6], + [10, 976, 5, 0], + [10, 977, 1, 7], + [10, 978, 3, 5], + [10, 979, 1, 8], + [10, 980, 8, 1], + [10, 981, 4, 4], + [10, 982, 5, 3], + [10, 983, 6, 2], + [10, 984, 7, 1], + [10, 985, 0, 6], + [10, 986, 8, 2], + [10, 987, 2, 8], + [10, 988, 3, 6], + [10, 989, 2, 7], + [10, 990, 4, 5], + [10, 991, 9, 1], + [10, 992, 1, 9], + [10, 993, 7, 2], + [11, 1988, 6, 0], + [11, 1989, 5, 4], + [11, 1990, 6, 3], + [11, 1991, 8, 3], + [11, 1992, 0, 7], + [11, 1993, 9, 2], + [11, 1994, 3, 8], + [11, 1995, 4, 6], + [11, 1996, 3, 7], + [11, 1997, 0, 8], + [11, 1998, 10, 1], + [11, 1999, 6, 4], + [11, 2000, 2, 9], + [11, 2001, 5, 5], + [11, 2002, 8, 0], + [11, 2003, 7, 0], + [11, 2004, 7, 3], + [11, 2005, 10, 2], + [11, 2006, 9, 3], + [11, 2007, 8, 4], + [11, 2008, 1, 10], + [11, 2009, 7, 4], + [11, 2010, 6, 5], + [11, 2011, 5, 6], + [11, 2012, 4, 8], + [11, 2013, 4, 7], + [11, 2014, 3, 9], + [11, 2015, 11, 1], + [11, 2016, 5, 8], + [11, 2017, 9, 0], + [11, 2018, 8, 5], + [12, 4038, 10, 3], + [12, 4039, 2, 10], + [12, 4040, 0, 9], + [12, 4041, 11, 2], + [12, 4042, 9, 4], + [12, 4043, 6, 6], + [12, 4044, 12, 1], + [12, 4045, 4, 9], + [12, 4046, 8, 6], + [12, 4047, 1, 11], + [12, 4048, 9, 5], + [12, 4049, 10, 4], + [12, 4050, 5, 7], + [12, 4051, 7, 5], + [12, 4052, 2, 11], + [12, 4053, 1, 12], + [12, 4054, 12, 2], + [12, 4055, 11, 3], + [12, 4056, 3, 10], + [12, 4057, 5, 9], + [12, 4058, 6, 7], + [12, 4059, 8, 7], + [12, 4060, 11, 4], + [12, 4061, 0, 10], + [12, 4062, 7, 6], + [12, 4063, 12, 3], + [12, 4064, 10, 0], + [12, 4065, 10, 5], + [12, 4066, 4, 10], + [12, 4067, 6, 8], + [12, 4068, 2, 12], + [12, 4069, 9, 6], + [12, 4070, 9, 7], + [12, 4071, 4, 11], + [12, 4072, 11, 0], + [12, 4073, 6, 9], + [12, 4074, 3, 11], + [12, 4075, 5, 10], + [13, 8152, 8, 8], + [13, 8153, 7, 8], + [13, 8154, 12, 5], + [13, 8155, 3, 12], + [13, 8156, 11, 5], + [13, 8157, 7, 7], + [13, 8158, 12, 4], + [13, 8159, 11, 6], + [13, 8160, 10, 6], + [13, 8161, 4, 12], + [13, 8162, 7, 9], + [13, 8163, 5, 11], + [13, 8164, 0, 11], + [13, 8165, 12, 6], + [13, 8166, 6, 10], + [13, 8167, 12, 0], + [13, 8168, 10, 7], + [13, 8169, 5, 12], + [13, 8170, 7, 10], + [13, 8171, 9, 8], + [13, 8172, 0, 12], + [13, 8173, 11, 7], + [13, 8174, 8, 9], + [13, 8175, 9, 9], + [13, 8176, 10, 8], + [13, 8177, 7, 11], + [13, 8178, 12, 7], + [13, 8179, 6, 11], + [13, 8180, 8, 11], + [13, 8181, 11, 8], + [13, 8182, 7, 12], + [13, 8183, 6, 12], + [14, 16368, 8, 10], + [14, 16369, 10, 9], + [14, 16370, 8, 12], + [14, 16371, 9, 10], + [14, 16372, 9, 11], + [14, 16373, 9, 12], + [14, 16374, 10, 11], + [14, 16375, 12, 9], + [14, 16376, 10, 10], + [14, 16377, 11, 9], + [14, 16378, 12, 8], + [14, 16379, 11, 10], + [14, 16380, 12, 10], + [14, 16381, 12, 11], + [15, 32764, 10, 12], + [15, 32765, 11, 11], + [15, 32766, 11, 12], + [15, 32767, 12, 12] +]; + +const HCB10 = [ + [4, 0, 1, 1], + [4, 1, 1, 2], + [4, 2, 2, 1], + [5, 6, 2, 2], + [5, 7, 1, 0], + [5, 8, 0, 1], + [5, 9, 1, 3], + [5, 10, 3, 2], + [5, 11, 3, 1], + [5, 12, 2, 3], + [5, 13, 3, 3], + [6, 28, 2, 0], + [6, 29, 0, 2], + [6, 30, 2, 4], + [6, 31, 4, 2], + [6, 32, 1, 4], + [6, 33, 4, 1], + [6, 34, 0, 0], + [6, 35, 4, 3], + [6, 36, 3, 4], + [6, 37, 3, 0], + [6, 38, 0, 3], + [6, 39, 4, 4], + [6, 40, 2, 5], + [6, 41, 5, 2], + [7, 84, 1, 5], + [7, 85, 5, 1], + [7, 86, 5, 3], + [7, 87, 3, 5], + [7, 88, 5, 4], + [7, 89, 4, 5], + [7, 90, 6, 2], + [7, 91, 2, 6], + [7, 92, 6, 3], + [7, 93, 4, 0], + [7, 94, 6, 1], + [7, 95, 0, 4], + [7, 96, 1, 6], + [7, 97, 3, 6], + [7, 98, 5, 5], + [7, 99, 6, 4], + [7, 100, 4, 6], + [8, 202, 6, 5], + [8, 203, 7, 2], + [8, 204, 3, 7], + [8, 205, 2, 7], + [8, 206, 5, 6], + [8, 207, 8, 2], + [8, 208, 7, 3], + [8, 209, 5, 0], + [8, 210, 7, 1], + [8, 211, 0, 5], + [8, 212, 8, 1], + [8, 213, 1, 7], + [8, 214, 8, 3], + [8, 215, 7, 4], + [8, 216, 4, 7], + [8, 217, 2, 8], + [8, 218, 6, 6], + [8, 219, 7, 5], + [8, 220, 1, 8], + [8, 221, 3, 8], + [8, 222, 8, 4], + [8, 223, 4, 8], + [8, 224, 5, 7], + [8, 225, 8, 5], + [8, 226, 5, 8], + [9, 454, 7, 6], + [9, 455, 6, 7], + [9, 456, 9, 2], + [9, 457, 6, 0], + [9, 458, 6, 8], + [9, 459, 9, 3], + [9, 460, 3, 9], + [9, 461, 9, 1], + [9, 462, 2, 9], + [9, 463, 0, 6], + [9, 464, 8, 6], + [9, 465, 9, 4], + [9, 466, 4, 9], + [9, 467, 10, 2], + [9, 468, 1, 9], + [9, 469, 7, 7], + [9, 470, 8, 7], + [9, 471, 9, 5], + [9, 472, 7, 8], + [9, 473, 10, 3], + [9, 474, 5, 9], + [9, 475, 10, 4], + [9, 476, 2, 10], + [9, 477, 10, 1], + [9, 478, 3, 10], + [9, 479, 9, 6], + [9, 480, 6, 9], + [9, 481, 8, 0], + [9, 482, 4, 10], + [9, 483, 7, 0], + [9, 484, 11, 2], + [10, 970, 7, 9], + [10, 971, 11, 3], + [10, 972, 10, 6], + [10, 973, 1, 10], + [10, 974, 11, 1], + [10, 975, 9, 7], + [10, 976, 0, 7], + [10, 977, 8, 8], + [10, 978, 10, 5], + [10, 979, 3, 11], + [10, 980, 5, 10], + [10, 981, 8, 9], + [10, 982, 11, 5], + [10, 983, 0, 8], + [10, 984, 11, 4], + [10, 985, 2, 11], + [10, 986, 7, 10], + [10, 987, 6, 10], + [10, 988, 10, 7], + [10, 989, 4, 11], + [10, 990, 1, 11], + [10, 991, 12, 2], + [10, 992, 9, 8], + [10, 993, 12, 3], + [10, 994, 11, 6], + [10, 995, 5, 11], + [10, 996, 12, 4], + [10, 997, 11, 7], + [10, 998, 12, 5], + [10, 999, 3, 12], + [10, 1000, 6, 11], + [10, 1001, 9, 0], + [10, 1002, 10, 8], + [10, 1003, 10, 0], + [10, 1004, 12, 1], + [10, 1005, 0, 9], + [10, 1006, 4, 12], + [10, 1007, 9, 9], + [10, 1008, 12, 6], + [10, 1009, 2, 12], + [10, 1010, 8, 10], + [11, 2022, 9, 10], + [11, 2023, 1, 12], + [11, 2024, 11, 8], + [11, 2025, 12, 7], + [11, 2026, 7, 11], + [11, 2027, 5, 12], + [11, 2028, 6, 12], + [11, 2029, 10, 9], + [11, 2030, 8, 11], + [11, 2031, 12, 8], + [11, 2032, 0, 10], + [11, 2033, 7, 12], + [11, 2034, 11, 0], + [11, 2035, 10, 10], + [11, 2036, 11, 9], + [11, 2037, 11, 10], + [11, 2038, 0, 11], + [11, 2039, 11, 11], + [11, 2040, 9, 11], + [11, 2041, 10, 11], + [11, 2042, 12, 0], + [11, 2043, 8, 12], + [12, 4088, 12, 9], + [12, 4089, 10, 12], + [12, 4090, 9, 12], + [12, 4091, 11, 12], + [12, 4092, 12, 11], + [12, 4093, 0, 12], + [12, 4094, 12, 10], + [12, 4095, 12, 12] +]; + +const HCB11 = [ + [4, 0, 0, 0], + [4, 1, 1, 1], + [5, 4, 16, 16], + [5, 5, 1, 0], + [5, 6, 0, 1], + [5, 7, 2, 1], + [5, 8, 1, 2], + [5, 9, 2, 2], + [6, 20, 1, 3], + [6, 21, 3, 1], + [6, 22, 3, 2], + [6, 23, 2, 0], + [6, 24, 2, 3], + [6, 25, 0, 2], + [6, 26, 3, 3], + [7, 54, 4, 1], + [7, 55, 1, 4], + [7, 56, 4, 2], + [7, 57, 2, 4], + [7, 58, 4, 3], + [7, 59, 3, 4], + [7, 60, 3, 0], + [7, 61, 0, 3], + [7, 62, 5, 1], + [7, 63, 5, 2], + [7, 64, 2, 5], + [7, 65, 4, 4], + [7, 66, 1, 5], + [7, 67, 5, 3], + [7, 68, 3, 5], + [7, 69, 5, 4], + [8, 140, 4, 5], + [8, 141, 6, 2], + [8, 142, 2, 6], + [8, 143, 6, 1], + [8, 144, 6, 3], + [8, 145, 3, 6], + [8, 146, 1, 6], + [8, 147, 4, 16], + [8, 148, 3, 16], + [8, 149, 16, 5], + [8, 150, 16, 3], + [8, 151, 16, 4], + [8, 152, 6, 4], + [8, 153, 16, 6], + [8, 154, 4, 0], + [8, 155, 4, 6], + [8, 156, 0, 4], + [8, 157, 2, 16], + [8, 158, 5, 5], + [8, 159, 5, 16], + [8, 160, 16, 7], + [8, 161, 16, 2], + [8, 162, 16, 8], + [8, 163, 2, 7], + [8, 164, 7, 2], + [8, 165, 3, 7], + [8, 166, 6, 5], + [8, 167, 5, 6], + [8, 168, 6, 16], + [8, 169, 16, 10], + [8, 170, 7, 3], + [8, 171, 7, 1], + [8, 172, 16, 9], + [8, 173, 7, 16], + [8, 174, 1, 16], + [8, 175, 1, 7], + [8, 176, 4, 7], + [8, 177, 16, 11], + [8, 178, 7, 4], + [8, 179, 16, 12], + [8, 180, 8, 16], + [8, 181, 16, 1], + [8, 182, 6, 6], + [8, 183, 9, 16], + [8, 184, 2, 8], + [8, 185, 5, 7], + [8, 186, 10, 16], + [8, 187, 16, 13], + [8, 188, 8, 3], + [8, 189, 8, 2], + [8, 190, 3, 8], + [8, 191, 5, 0], + [8, 192, 16, 14], + [8, 193, 11, 16], + [8, 194, 7, 5], + [8, 195, 4, 8], + [8, 196, 6, 7], + [8, 197, 7, 6], + [8, 198, 0, 5], + [9, 398, 8, 4], + [9, 399, 16, 15], + [9, 400, 12, 16], + [9, 401, 1, 8], + [9, 402, 8, 1], + [9, 403, 14, 16], + [9, 404, 5, 8], + [9, 405, 13, 16], + [9, 406, 3, 9], + [9, 407, 8, 5], + [9, 408, 7, 7], + [9, 409, 2, 9], + [9, 410, 8, 6], + [9, 411, 9, 2], + [9, 412, 9, 3], + [9, 413, 15, 16], + [9, 414, 4, 9], + [9, 415, 6, 8], + [9, 416, 6, 0], + [9, 417, 9, 4], + [9, 418, 5, 9], + [9, 419, 8, 7], + [9, 420, 7, 8], + [9, 421, 1, 9], + [9, 422, 10, 3], + [9, 423, 0, 6], + [9, 424, 10, 2], + [9, 425, 9, 1], + [9, 426, 9, 5], + [9, 427, 4, 10], + [9, 428, 2, 10], + [9, 429, 9, 6], + [9, 430, 3, 10], + [9, 431, 6, 9], + [9, 432, 10, 4], + [9, 433, 8, 8], + [9, 434, 10, 5], + [9, 435, 9, 7], + [9, 436, 11, 3], + [9, 437, 1, 10], + [9, 438, 7, 0], + [9, 439, 10, 6], + [9, 440, 7, 9], + [9, 441, 3, 11], + [9, 442, 5, 10], + [9, 443, 10, 1], + [9, 444, 4, 11], + [9, 445, 11, 2], + [9, 446, 13, 2], + [9, 447, 6, 10], + [9, 448, 13, 3], + [9, 449, 2, 11], + [9, 450, 16, 0], + [9, 451, 5, 11], + [9, 452, 11, 5], + [10, 906, 11, 4], + [10, 907, 9, 8], + [10, 908, 7, 10], + [10, 909, 8, 9], + [10, 910, 0, 16], + [10, 911, 4, 13], + [10, 912, 0, 7], + [10, 913, 3, 13], + [10, 914, 11, 6], + [10, 915, 13, 1], + [10, 916, 13, 4], + [10, 917, 12, 3], + [10, 918, 2, 13], + [10, 919, 13, 5], + [10, 920, 8, 10], + [10, 921, 6, 11], + [10, 922, 10, 8], + [10, 923, 10, 7], + [10, 924, 14, 2], + [10, 925, 12, 4], + [10, 926, 1, 11], + [10, 927, 4, 12], + [10, 928, 11, 1], + [10, 929, 3, 12], + [10, 930, 1, 13], + [10, 931, 12, 2], + [10, 932, 7, 11], + [10, 933, 3, 14], + [10, 934, 5, 12], + [10, 935, 5, 13], + [10, 936, 14, 4], + [10, 937, 4, 14], + [10, 938, 11, 7], + [10, 939, 14, 3], + [10, 940, 12, 5], + [10, 941, 13, 6], + [10, 942, 12, 6], + [10, 943, 8, 0], + [10, 944, 11, 8], + [10, 945, 2, 12], + [10, 946, 9, 9], + [10, 947, 14, 5], + [10, 948, 6, 13], + [10, 949, 10, 10], + [10, 950, 15, 2], + [10, 951, 8, 11], + [10, 952, 9, 10], + [10, 953, 14, 6], + [10, 954, 10, 9], + [10, 955, 5, 14], + [10, 956, 11, 9], + [10, 957, 14, 1], + [10, 958, 2, 14], + [10, 959, 6, 12], + [10, 960, 1, 12], + [10, 961, 13, 8], + [10, 962, 0, 8], + [10, 963, 13, 7], + [10, 964, 7, 12], + [10, 965, 12, 7], + [10, 966, 7, 13], + [10, 967, 15, 3], + [10, 968, 12, 1], + [10, 969, 6, 14], + [10, 970, 2, 15], + [10, 971, 15, 5], + [10, 972, 15, 4], + [10, 973, 1, 14], + [10, 974, 9, 11], + [10, 975, 4, 15], + [10, 976, 14, 7], + [10, 977, 8, 13], + [10, 978, 13, 9], + [10, 979, 8, 12], + [10, 980, 5, 15], + [10, 981, 3, 15], + [10, 982, 10, 11], + [10, 983, 11, 10], + [10, 984, 12, 8], + [10, 985, 15, 6], + [10, 986, 15, 7], + [10, 987, 8, 14], + [10, 988, 15, 1], + [10, 989, 7, 14], + [10, 990, 9, 0], + [10, 991, 0, 9], + [10, 992, 9, 13], + [10, 993, 9, 12], + [10, 994, 12, 9], + [10, 995, 14, 8], + [10, 996, 10, 13], + [10, 997, 14, 9], + [10, 998, 12, 10], + [10, 999, 6, 15], + [10, 1000, 7, 15], + [11, 2002, 9, 14], + [11, 2003, 15, 8], + [11, 2004, 11, 11], + [11, 2005, 11, 14], + [11, 2006, 1, 15], + [11, 2007, 10, 12], + [11, 2008, 10, 14], + [11, 2009, 13, 11], + [11, 2010, 13, 10], + [11, 2011, 11, 13], + [11, 2012, 11, 12], + [11, 2013, 8, 15], + [11, 2014, 14, 11], + [11, 2015, 13, 12], + [11, 2016, 12, 13], + [11, 2017, 15, 9], + [11, 2018, 14, 10], + [11, 2019, 10, 0], + [11, 2020, 12, 11], + [11, 2021, 9, 15], + [11, 2022, 0, 10], + [11, 2023, 12, 12], + [11, 2024, 11, 0], + [11, 2025, 12, 14], + [11, 2026, 10, 15], + [11, 2027, 13, 13], + [11, 2028, 0, 13], + [11, 2029, 14, 12], + [11, 2030, 15, 10], + [11, 2031, 15, 11], + [11, 2032, 11, 15], + [11, 2033, 14, 13], + [11, 2034, 13, 0], + [11, 2035, 0, 11], + [11, 2036, 13, 14], + [11, 2037, 15, 12], + [11, 2038, 15, 13], + [11, 2039, 12, 15], + [11, 2040, 14, 0], + [11, 2041, 14, 14], + [11, 2042, 13, 15], + [11, 2043, 12, 0], + [11, 2044, 14, 15], + [12, 4090, 0, 14], + [12, 4091, 0, 12], + [12, 4092, 15, 14], + [12, 4093, 15, 0], + [12, 4094, 0, 15], + [12, 4095, 15, 15] +]; + +const HCB_SF = [ + [1, 0, 60], + [3, 4, 59], + [4, 10, 61], + [4, 11, 58], + [4, 12, 62], + [5, 26, 57], + [5, 27, 63], + [6, 56, 56], + [6, 57, 64], + [6, 58, 55], + [6, 59, 65], + [7, 120, 66], + [7, 121, 54], + [7, 122, 67], + [8, 246, 53], + [8, 247, 68], + [8, 248, 52], + [8, 249, 69], + [8, 250, 51], + [9, 502, 70], + [9, 503, 50], + [9, 504, 49], + [9, 505, 71], + [10, 1012, 72], + [10, 1013, 48], + [10, 1014, 73], + [10, 1015, 47], + [10, 1016, 74], + [10, 1017, 46], + [11, 2036, 76], + [11, 2037, 75], + [11, 2038, 77], + [11, 2039, 78], + [11, 2040, 45], + [11, 2041, 43], + [12, 4084, 44], + [12, 4085, 79], + [12, 4086, 42], + [12, 4087, 41], + [12, 4088, 80], + [12, 4089, 40], + [13, 8180, 81], + [13, 8181, 39], + [13, 8182, 82], + [13, 8183, 38], + [13, 8184, 83], + [14, 16370, 37], + [14, 16371, 35], + [14, 16372, 85], + [14, 16373, 33], + [14, 16374, 36], + [14, 16375, 34], + [14, 16376, 84], + [14, 16377, 32], + [15, 32756, 87], + [15, 32757, 89], + [15, 32758, 30], + [15, 32759, 31], + [16, 65520, 86], + [16, 65521, 29], + [16, 65522, 26], + [16, 65523, 27], + [16, 65524, 28], + [16, 65525, 24], + [16, 65526, 88], + [17, 131054, 25], + [17, 131055, 22], + [17, 131056, 23], + [18, 262114, 90], + [18, 262115, 21], + [18, 262116, 19], + [18, 262117, 3], + [18, 262118, 1], + [18, 262119, 2], + [18, 262120, 0], + [19, 524242, 98], + [19, 524243, 99], + [19, 524244, 100], + [19, 524245, 101], + [19, 524246, 102], + [19, 524247, 117], + [19, 524248, 97], + [19, 524249, 91], + [19, 524250, 92], + [19, 524251, 93], + [19, 524252, 94], + [19, 524253, 95], + [19, 524254, 96], + [19, 524255, 104], + [19, 524256, 111], + [19, 524257, 112], + [19, 524258, 113], + [19, 524259, 114], + [19, 524260, 115], + [19, 524261, 116], + [19, 524262, 110], + [19, 524263, 105], + [19, 524264, 106], + [19, 524265, 107], + [19, 524266, 108], + [19, 524267, 109], + [19, 524268, 118], + [19, 524269, 6], + [19, 524270, 8], + [19, 524271, 9], + [19, 524272, 10], + [19, 524273, 5], + [19, 524274, 103], + [19, 524275, 120], + [19, 524276, 119], + [19, 524277, 4], + [19, 524278, 7], + [19, 524279, 15], + [19, 524280, 16], + [19, 524281, 18], + [19, 524282, 20], + [19, 524283, 17], + [19, 524284, 11], + [19, 524285, 12], + [19, 524286, 14], + [19, 524287, 13] +]; + +const CODEBOOKS = [HCB1, HCB2, HCB3, HCB4, HCB5, HCB6, HCB7, HCB8, HCB9, HCB10, HCB11]; +const UNSIGNED = [false, false, true, true, false, false, true, true, true, true, true], + QUAD_LEN = 4, + PAIR_LEN = 2; + +var Huffman = { + findOffset: function(stream, table) { + var off = 0, + len = table[off][0], + cw = stream.read(len); + + while (cw !== table[off][1]) { + var j = table[++off][0] - len; + len = table[off][0]; + cw <<= j; + cw |= stream.read(j); + } + + return off; + }, + + signValues: function(stream, data, off, len) { + for (var i = off; i < off + len; i++) { + if (data[i] && stream.read(1)) + data[i] = -data[i]; + } + }, + + getEscape: function(stream, s) { + var i = 4; + while (stream.read(1)) + i++; + + var j = stream.read(i) | (1 << i); + return s < 0 ? -j : j; + }, + + decodeScaleFactor: function(stream) { + var offset = this.findOffset(stream, HCB_SF); + return HCB_SF[offset][2]; + }, + + decodeSpectralData: function(stream, cb, data, off) { + var HCB = CODEBOOKS[cb - 1], + offset = this.findOffset(stream, HCB); + + data[off] = HCB[offset][2]; + data[off + 1] = HCB[offset][3]; + + if (cb < 5) { + data[off + 2] = HCB[offset][4]; + data[off + 3] = HCB[offset][5]; + } + + // sign and escape + if (cb < 11) { + if (UNSIGNED[cb - 1]) + this.signValues(stream, data, off, cb < 5 ? QUAD_LEN : PAIR_LEN); + + } else if (cb === 11 || cb > 15) { + this.signValues(stream, data, off, cb < 5 ? QUAD_LEN : PAIR_LEN); + + if (Math.abs(data[off]) === 16) + data[off] = this.getEscape(stream, data[off]); + + if (Math.abs(data[off + 1]) === 16) + data[off + 1] = this.getEscape(stream, data[off + 1]); + } else { + throw new Error("Huffman: unknown spectral codebook: " + cb); + } + } +}; + +module.exports = Huffman; + +},{}],8:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var tables = require('./tables'); +var Huffman = require('./huffman'); +var TNS = require('./tns'); + +// Individual Channel Stream +function ICStream(config) { + this.info = new ICSInfo(); + this.bandTypes = new Int32Array(MAX_SECTIONS); + this.sectEnd = new Int32Array(MAX_SECTIONS); + this.data = new Float32Array(config.frameLength); + this.scaleFactors = new Float32Array(MAX_SECTIONS); + this.randomState = 0x1F2E3D4C; + this.tns = new TNS(config); + this.specBuf = new Int32Array(4); +} + +ICStream.ZERO_BT = 0; // Scalefactors and spectral data are all zero. +ICStream.FIRST_PAIR_BT = 5; // This and later band types encode two values (rather than four) with one code word. +ICStream.ESC_BT = 11; // Spectral data are coded with an escape sequence. +ICStream.NOISE_BT = 13; // Spectral data are scaled white noise not coded in the bitstream. +ICStream.INTENSITY_BT2 = 14; // Scalefactor data are intensity stereo positions. +ICStream.INTENSITY_BT = 15; // Scalefactor data are intensity stereo positions. + +ICStream.ONLY_LONG_SEQUENCE = 0; +ICStream.LONG_START_SEQUENCE = 1; +ICStream.EIGHT_SHORT_SEQUENCE = 2; +ICStream.LONG_STOP_SEQUENCE = 3; + +const MAX_SECTIONS = 120, + MAX_WINDOW_GROUP_COUNT = 8; + +const SF_DELTA = 60, + SF_OFFSET = 200; + +ICStream.prototype = { + decode: function(stream, config, commonWindow) { + this.globalGain = stream.read(8); + + if (!commonWindow) + this.info.decode(stream, config, commonWindow); + + this.decodeBandTypes(stream, config); + this.decodeScaleFactors(stream); + + if (this.pulsePresent = stream.read(1)) { + if (this.info.windowSequence === ICStream.EIGHT_SHORT_SEQUENCE) + throw new Error("Pulse tool not allowed in eight short sequence."); + + this.decodePulseData(stream); + } + + if (this.tnsPresent = stream.read(1)) { + this.tns.decode(stream, this.info); + } + + if (this.gainPresent = stream.read(1)) { + throw new Error("TODO: decode gain control/SSR"); + } + + this.decodeSpectralData(stream); + }, + + decodeBandTypes: function(stream, config) { + var bits = this.info.windowSequence === ICStream.EIGHT_SHORT_SEQUENCE ? 3 : 5, + groupCount = this.info.groupCount, + maxSFB = this.info.maxSFB, + bandTypes = this.bandTypes, + sectEnd = this.sectEnd, + idx = 0, + escape = (1 << bits) - 1; + + for (var g = 0; g < groupCount; g++) { + var k = 0; + while (k < maxSFB) { + var end = k, + bandType = stream.read(4); + + if (bandType === 12) + throw new Error("Invalid band type: 12"); + + var incr; + while ((incr = stream.read(bits)) === escape) + end += incr; + + end += incr; + + if (end > maxSFB) + throw new Error("Too many bands (" + end + " > " + maxSFB + ")"); + + for (; k < end; k++) { + bandTypes[idx] = bandType; + sectEnd[idx++] = end; + } + } + } + }, + + decodeScaleFactors: function(stream) { + var groupCount = this.info.groupCount, + maxSFB = this.info.maxSFB, + offset = [this.globalGain, this.globalGain - 90, 0], // spectrum, noise, intensity + idx = 0, + noiseFlag = true, + scaleFactors = this.scaleFactors, + sectEnd = this.sectEnd, + bandTypes = this.bandTypes; + + for (var g = 0; g < groupCount; g++) { + for (var i = 0; i < maxSFB;) { + var runEnd = sectEnd[idx]; + + switch (bandTypes[idx]) { + case ICStream.ZERO_BT: + for (; i < runEnd; i++, idx++) { + scaleFactors[idx] = 0; + } + break; + + case ICStream.INTENSITY_BT: + case ICStream.INTENSITY_BT2: + for(; i < runEnd; i++, idx++) { + offset[2] += Huffman.decodeScaleFactor(stream) - SF_DELTA; + var tmp = Math.min(Math.max(offset[2], -155), 100); + scaleFactors[idx] = tables.SCALEFACTOR_TABLE[-tmp + SF_OFFSET]; + } + break; + + case ICStream.NOISE_BT: + for(; i < runEnd; i++, idx++) { + if (noiseFlag) { + offset[1] += stream.read(9) - 256; + noiseFlag = false; + } else { + offset[1] += Huffman.decodeScaleFactor(stream) - SF_DELTA; + } + var tmp = Math.min(Math.max(offset[1], -100), 155); + scaleFactors[idx] = -tables.SCALEFACTOR_TABLE[tmp + SF_OFFSET]; + } + break; + + default: + for(; i < runEnd; i++, idx++) { + offset[0] += Huffman.decodeScaleFactor(stream) - SF_DELTA; + if(offset[0] > 255) + throw new Error("Scalefactor out of range: " + offset[0]); + + scaleFactors[idx] = tables.SCALEFACTOR_TABLE[offset[0] - 100 + SF_OFFSET]; + } + break; + } + } + } + }, + + decodePulseData: function(stream) { + var pulseCount = stream.read(2) + 1, + pulseSWB = stream.read(6); + + if (pulseSWB >= this.info.swbCount) + throw new Error("Pulse SWB out of range: " + pulseSWB); + + if (!this.pulseOffset || this.pulseOffset.length !== pulseCount) { + // only reallocate if needed + this.pulseOffset = new Int32Array(pulseCount); + this.pulseAmp = new Int32Array(pulseCount); + } + + this.pulseOffset[0] = this.info.swbOffsets[pulseSWB] + stream.read(5); + this.pulseAmp[0] = stream.read(4); + + if (this.pulseOffset[0] > 1023) + throw new Error("Pulse offset out of range: " + this.pulseOffset[0]); + + for (var i = 1; i < pulseCount; i++) { + this.pulseOffset[i] = stream.read(5) + this.pulseOffset[i - 1]; + if (this.pulseOffset[i] > 1023) + throw new Error("Pulse offset out of range: " + this.pulseOffset[i]); + + this.pulseAmp[i] = stream.read(4); + } + }, + + decodeSpectralData: function(stream) { + var data = this.data, + info = this.info, + maxSFB = info.maxSFB, + windowGroups = info.groupCount, + offsets = info.swbOffsets, + bandTypes = this.bandTypes, + scaleFactors = this.scaleFactors, + buf = this.specBuf; + + var groupOff = 0, idx = 0; + for (var g = 0; g < windowGroups; g++) { + var groupLen = info.groupLength[g]; + + for (var sfb = 0; sfb < maxSFB; sfb++, idx++) { + var hcb = bandTypes[idx], + off = groupOff + offsets[sfb], + width = offsets[sfb + 1] - offsets[sfb]; + + if (hcb === ICStream.ZERO_BT || hcb === ICStream.INTENSITY_BT || hcb === ICStream.INTENSITY_BT2) { + for (var group = 0; group < groupLen; group++, off += 128) { + for (var i = off; i < off + width; i++) { + data[i] = 0; + } + } + } else if (hcb === ICStream.NOISE_BT) { + // fill with random values + for (var group = 0; group < groupLen; group++, off += 128) { + var energy = 0; + + for (var k = 0; k < width; k++) { + this.randomState = (this.randomState * (1664525 + 1013904223))|0; + data[off + k] = this.randomState; + energy += data[off + k] * data[off + k]; + } + + var scale = scaleFactors[idx] / Math.sqrt(energy); + for (var k = 0; k < width; k++) { + data[off + k] *= scale; + } + } + } else { + for (var group = 0; group < groupLen; group++, off += 128) { + var num = (hcb >= ICStream.FIRST_PAIR_BT) ? 2 : 4; + for (var k = 0; k < width; k += num) { + Huffman.decodeSpectralData(stream, hcb, buf, 0); + + // inverse quantization & scaling + for (var j = 0; j < num; j++) { + data[off + k + j] = (buf[j] > 0) ? tables.IQ_TABLE[buf[j]] : -tables.IQ_TABLE[-buf[j]]; + data[off + k + j] *= scaleFactors[idx]; + } + } + } + } + } + groupOff += groupLen << 7; + } + + // add pulse data, if present + if (this.pulsePresent) { + throw new Error('TODO: add pulse data'); + } + } +} + +// Individual Channel Stream Info +function ICSInfo() { + this.windowShape = new Int32Array(2); + this.windowSequence = ICStream.ONLY_LONG_SEQUENCE; + this.groupLength = new Int32Array(MAX_WINDOW_GROUP_COUNT); + this.ltpData1Present = false; + this.ltpData2Present = false; +} + +ICSInfo.prototype = { + decode: function(stream, config, commonWindow) { + stream.advance(1); // reserved + + this.windowSequence = stream.read(2); + this.windowShape[0] = this.windowShape[1]; + this.windowShape[1] = stream.read(1); + + this.groupCount = 1; + this.groupLength[0] = 1; + + if (this.windowSequence === ICStream.EIGHT_SHORT_SEQUENCE) { + this.maxSFB = stream.read(4); + for (var i = 0; i < 7; i++) { + if (stream.read(1)) { + this.groupLength[this.groupCount - 1]++; + } else { + this.groupCount++; + this.groupLength[this.groupCount - 1] = 1; + } + } + + this.windowCount = 8; + this.swbOffsets = tables.SWB_OFFSET_128[config.sampleIndex]; + this.swbCount = tables.SWB_SHORT_WINDOW_COUNT[config.sampleIndex]; + this.predictorPresent = false; + } else { + this.maxSFB = stream.read(6); + this.windowCount = 1; + this.swbOffsets = tables.SWB_OFFSET_1024[config.sampleIndex]; + this.swbCount = tables.SWB_LONG_WINDOW_COUNT[config.sampleIndex]; + this.predictorPresent = !!stream.read(1); + + if (this.predictorPresent) + this.decodePrediction(stream, config, commonWindow); + } + }, + + decodePrediction: function(stream, config, commonWindow) { + throw new Error('Prediction not implemented.'); + + switch (config.profile) { + case AOT_AAC_MAIN: + throw new Error('Prediction not implemented.'); + break; + + case AOT_AAC_LTP: + throw new Error('LTP prediction not implemented.'); + break; + + default: + throw new Error('Unsupported profile for prediction ' + config.profile); + } + } +}; + +module.exports = ICStream; + +},{"./huffman":7,"./tables":11,"./tns":12}],9:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +var tables = require('./mdct_tables'); +var FFT = require('./fft'); + +// Modified Discrete Cosine Transform +function MDCT(length) { + this.N = length; + this.N2 = length >>> 1; + this.N4 = length >>> 2; + this.N8 = length >>> 3; + + switch (length) { + case 2048: + this.sincos = tables.MDCT_TABLE_2048; + break; + + case 256: + this.sincos = tables.MDCT_TABLE_256; + break; + + case 1920: + this.sincos = tables.MDCT_TABLE_1920; + break; + + case 240: + this.sincos = tables.MDCT_TABLE_240; + break; + + default: + throw new Error("unsupported MDCT length: " + length); + } + + this.fft = new FFT(this.N4); + + this.buf = new Array(this.N4); + for (var i = 0; i < this.N4; i++) { + this.buf[i] = new Float32Array(2); + } + + this.tmp = new Float32Array(2); +} + +MDCT.prototype.process = function(input, inOffset, output, outOffset) { + // local access + var N2 = this.N2, + N4 = this.N4, + N8 = this.N8, + buf = this.buf, + tmp = this.tmp, + sincos = this.sincos, + fft = this.fft; + + // pre-IFFT complex multiplication + for (var k = 0; k < N4; k++) { + buf[k][1] = (input[inOffset + 2 * k] * sincos[k][0]) + (input[inOffset + N2 - 1 - 2 * k] * sincos[k][1]); + buf[k][0] = (input[inOffset + N2 - 1 - 2 * k] * sincos[k][0]) - (input[inOffset + 2 * k] * sincos[k][1]); + } + + // complex IFFT, non-scaling + fft.process(buf, false); + + // post-IFFT complex multiplication + for (var k = 0; k < N4; k++) { + tmp[0] = buf[k][0]; + tmp[1] = buf[k][1]; + buf[k][1] = (tmp[1] * sincos[k][0]) + (tmp[0] * sincos[k][1]); + buf[k][0] = (tmp[0] * sincos[k][0]) - (tmp[1] * sincos[k][1]); + } + + // reordering + for (var k = 0; k < N8; k += 2) { + output[outOffset + 2 * k] = buf[N8 + k][1]; + output[outOffset + 2 + 2 * k] = buf[N8 + 1 + k][1]; + + output[outOffset + 1 + 2 * k] = -buf[N8 - 1 - k][0]; + output[outOffset + 3 + 2 * k] = -buf[N8 - 2 - k][0]; + + output[outOffset + N4 + 2 * k] = buf[k][0]; + output[outOffset + N4 + 2 + 2 * k] = buf[1 + k][0]; + + output[outOffset + N4 + 1 + 2 * k] = -buf[N4 - 1 - k][1]; + output[outOffset + N4 + 3 + 2 * k] = -buf[N4 - 2 - k][1]; + + output[outOffset + N2 + 2 * k] = buf[N8 + k][0]; + output[outOffset + N2 + 2 + 2 * k] = buf[N8 + 1 + k][0]; + + output[outOffset + N2 + 1 + 2 * k] = -buf[N8 - 1 - k][1]; + output[outOffset + N2 + 3 + 2 * k] = -buf[N8 - 2 - k][1]; + + output[outOffset + N2 + N4 + 2 * k] = -buf[k][1]; + output[outOffset + N2 + N4 + 2 + 2 * k] = -buf[1 + k][1]; + + output[outOffset + N2 + N4 + 1 + 2 * k] = buf[N4 - 1 - k][0]; + output[outOffset + N2 + N4 + 3 + 2 * k] = buf[N4 - 2 - k][0]; + } +}; + +module.exports = MDCT; + +},{"./fft":5,"./mdct_tables":10}],10:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +exports.MDCT_TABLE_2048 = [ + [0.031249997702054, 0.000011984224612], + [0.031249813866531, 0.000107857810004], + [0.031249335895858, 0.000203730380198], + [0.031248563794535, 0.000299601032804], + [0.031247497569829, 0.000395468865451], + [0.031246137231775, 0.000491332975794], + [0.031244482793177, 0.000587192461525], + [0.031242534269608, 0.000683046420376], + [0.031240291679407, 0.000778893950134], + [0.031237755043684, 0.000874734148645], + [0.031234924386313, 0.000970566113826], + [0.031231799733938, 0.001066388943669], + [0.031228381115970, 0.001162201736253], + [0.031224668564585, 0.001258003589751], + [0.031220662114728, 0.001353793602441], + [0.031216361804108, 0.001449570872710], + [0.031211767673203, 0.001545334499065], + [0.031206879765253, 0.001641083580144], + [0.031201698126266, 0.001736817214719], + [0.031196222805014, 0.001832534501709], + [0.031190453853031, 0.001928234540186], + [0.031184391324617, 0.002023916429386], + [0.031178035276836, 0.002119579268713], + [0.031171385769513, 0.002215222157753], + [0.031164442865236, 0.002310844196278], + [0.031157206629353, 0.002406444484258], + [0.031149677129975, 0.002502022121865], + [0.031141854437973, 0.002597576209488], + [0.031133738626977, 0.002693105847734], + [0.031125329773375, 0.002788610137442], + [0.031116627956316, 0.002884088179689], + [0.031107633257703, 0.002979539075801], + [0.031098345762200, 0.003074961927355], + [0.031088765557222, 0.003170355836197], + [0.031078892732942, 0.003265719904442], + [0.031068727382288, 0.003361053234488], + [0.031058269600939, 0.003456354929021], + [0.031047519487329, 0.003551624091024], + [0.031036477142640, 0.003646859823790], + [0.031025142670809, 0.003742061230921], + [0.031013516178519, 0.003837227416347], + [0.031001597775203, 0.003932357484328], + [0.030989387573042, 0.004027450539462], + [0.030976885686963, 0.004122505686697], + [0.030964092234638, 0.004217522031340], + [0.030951007336485, 0.004312498679058], + [0.030937631115663, 0.004407434735897], + [0.030923963698074, 0.004502329308281], + [0.030910005212362, 0.004597181503027], + [0.030895755789908, 0.004691990427350], + [0.030881215564835, 0.004786755188872], + [0.030866384674000, 0.004881474895632], + [0.030851263256996, 0.004976148656090], + [0.030835851456154, 0.005070775579142], + [0.030820149416533, 0.005165354774124], + [0.030804157285929, 0.005259885350819], + [0.030787875214864, 0.005354366419469], + [0.030771303356593, 0.005448797090784], + [0.030754441867095, 0.005543176475946], + [0.030737290905077, 0.005637503686619], + [0.030719850631972, 0.005731777834961], + [0.030702121211932, 0.005825998033626], + [0.030684102811835, 0.005920163395780], + [0.030665795601276, 0.006014273035101], + [0.030647199752570, 0.006108326065793], + [0.030628315440748, 0.006202321602594], + [0.030609142843557, 0.006296258760782], + [0.030589682141455, 0.006390136656185], + [0.030569933517616, 0.006483954405188], + [0.030549897157919, 0.006577711124743], + [0.030529573250956, 0.006671405932375], + [0.030508961988022, 0.006765037946194], + [0.030488063563118, 0.006858606284900], + [0.030466878172949, 0.006952110067791], + [0.030445406016919, 0.007045548414774], + [0.030423647297133, 0.007138920446372], + [0.030401602218392, 0.007232225283733], + [0.030379270988192, 0.007325462048634], + [0.030356653816724, 0.007418629863497], + [0.030333750916869, 0.007511727851390], + [0.030310562504198, 0.007604755136040], + [0.030287088796968, 0.007697710841838], + [0.030263330016124, 0.007790594093851], + [0.030239286385293, 0.007883404017824], + [0.030214958130781, 0.007976139740197], + [0.030190345481576, 0.008068800388104], + [0.030165448669342, 0.008161385089390], + [0.030140267928416, 0.008253892972610], + [0.030114803495809, 0.008346323167047], + [0.030089055611203, 0.008438674802711], + [0.030063024516947, 0.008530947010354], + [0.030036710458054, 0.008623138921475], + [0.030010113682202, 0.008715249668328], + [0.029983234439732, 0.008807278383932], + [0.029956072983640, 0.008899224202078], + [0.029928629569580, 0.008991086257336], + [0.029900904455860, 0.009082863685067], + [0.029872897903441, 0.009174555621425], + [0.029844610175929, 0.009266161203371], + [0.029816041539579, 0.009357679568679], + [0.029787192263292, 0.009449109855944], + [0.029758062618606, 0.009540451204587], + [0.029728652879702, 0.009631702754871], + [0.029698963323395, 0.009722863647900], + [0.029668994229134, 0.009813933025633], + [0.029638745879000, 0.009904910030891], + [0.029608218557702, 0.009995793807363], + [0.029577412552575, 0.010086583499618], + [0.029546328153577, 0.010177278253107], + [0.029514965653285, 0.010267877214177], + [0.029483325346896, 0.010358379530076], + [0.029451407532220, 0.010448784348962], + [0.029419212509679, 0.010539090819911], + [0.029386740582307, 0.010629298092923], + [0.029353992055740, 0.010719405318933], + [0.029320967238220, 0.010809411649818], + [0.029287666440590, 0.010899316238403], + [0.029254089976290, 0.010989118238474], + [0.029220238161353, 0.011078816804778], + [0.029186111314406, 0.011168411093039], + [0.029151709756664, 0.011257900259961], + [0.029117033811927, 0.011347283463239], + [0.029082083806579, 0.011436559861563], + [0.029046860069582, 0.011525728614630], + [0.029011362932476, 0.011614788883150], + [0.028975592729373, 0.011703739828853], + [0.028939549796957, 0.011792580614500], + [0.028903234474475, 0.011881310403886], + [0.028866647103744, 0.011969928361855], + [0.028829788029135, 0.012058433654299], + [0.028792657597583, 0.012146825448172], + [0.028755256158571, 0.012235102911499], + [0.028717584064137, 0.012323265213377], + [0.028679641668864, 0.012411311523990], + [0.028641429329882, 0.012499241014612], + [0.028602947406859, 0.012587052857618], + [0.028564196262001, 0.012674746226488], + [0.028525176260050, 0.012762320295819], + [0.028485887768276, 0.012849774241331], + [0.028446331156478, 0.012937107239875], + [0.028406506796976, 0.013024318469437], + [0.028366415064615, 0.013111407109155], + [0.028326056336751, 0.013198372339315], + [0.028285430993258, 0.013285213341368], + [0.028244539416515, 0.013371929297933], + [0.028203381991411, 0.013458519392807], + [0.028161959105334, 0.013544982810971], + [0.028120271148172, 0.013631318738598], + [0.028078318512309, 0.013717526363062], + [0.028036101592619, 0.013803604872943], + [0.027993620786463, 0.013889553458039], + [0.027950876493687, 0.013975371309367], + [0.027907869116616, 0.014061057619178], + [0.027864599060052, 0.014146611580959], + [0.027821066731270, 0.014232032389445], + [0.027777272540012, 0.014317319240622], + [0.027733216898487, 0.014402471331737], + [0.027688900221361, 0.014487487861307], + [0.027644322925762, 0.014572368029123], + [0.027599485431266, 0.014657111036262], + [0.027554388159903, 0.014741716085090], + [0.027509031536144, 0.014826182379271], + [0.027463415986904, 0.014910509123778], + [0.027417541941533, 0.014994695524894], + [0.027371409831816, 0.015078740790225], + [0.027325020091965, 0.015162644128704], + [0.027278373158618, 0.015246404750603], + [0.027231469470833, 0.015330021867534], + [0.027184309470088, 0.015413494692460], + [0.027136893600268, 0.015496822439704], + [0.027089222307671, 0.015580004324954], + [0.027041296040997, 0.015663039565269], + [0.026993115251345, 0.015745927379091], + [0.026944680392213, 0.015828666986247], + [0.026895991919487, 0.015911257607961], + [0.026847050291442, 0.015993698466859], + [0.026797855968734, 0.016075988786976], + [0.026748409414401, 0.016158127793763], + [0.026698711093851, 0.016240114714099], + [0.026648761474864, 0.016321948776289], + [0.026598561027585, 0.016403629210082], + [0.026548110224519, 0.016485155246669], + [0.026497409540530, 0.016566526118696], + [0.026446459452830, 0.016647741060271], + [0.026395260440982, 0.016728799306966], + [0.026343812986890, 0.016809700095831], + [0.026292117574797, 0.016890442665397], + [0.026240174691280, 0.016971026255683], + [0.026187984825246, 0.017051450108208], + [0.026135548467924, 0.017131713465990], + [0.026082866112867, 0.017211815573560], + [0.026029938255941, 0.017291755676967], + [0.025976765395322, 0.017371533023784], + [0.025923348031494, 0.017451146863116], + [0.025869686667242, 0.017530596445607], + [0.025815781807646, 0.017609881023449], + [0.025761633960080, 0.017688999850383], + [0.025707243634204, 0.017767952181715], + [0.025652611341960, 0.017846737274313], + [0.025597737597568, 0.017925354386623], + [0.025542622917522, 0.018003802778671], + [0.025487267820581, 0.018082081712071], + [0.025431672827768, 0.018160190450031], + [0.025375838462365, 0.018238128257362], + [0.025319765249906, 0.018315894400484], + [0.025263453718173, 0.018393488147432], + [0.025206904397193, 0.018470908767865], + [0.025150117819228, 0.018548155533070], + [0.025093094518776, 0.018625227715971], + [0.025035835032562, 0.018702124591135], + [0.024978339899534, 0.018778845434780], + [0.024920609660858, 0.018855389524780], + [0.024862644859912, 0.018931756140672], + [0.024804446042284, 0.019007944563666], + [0.024746013755764, 0.019083954076646], + [0.024687348550337, 0.019159783964183], + [0.024628450978184, 0.019235433512536], + [0.024569321593670, 0.019310902009663], + [0.024509960953345, 0.019386188745225], + [0.024450369615932, 0.019461293010596], + [0.024390548142329, 0.019536214098866], + [0.024330497095598, 0.019610951304848], + [0.024270217040961, 0.019685503925087], + [0.024209708545799, 0.019759871257867], + [0.024148972179639, 0.019834052603212], + [0.024088008514157, 0.019908047262901], + [0.024026818123164, 0.019981854540467], + [0.023965401582609, 0.020055473741208], + [0.023903759470567, 0.020128904172192], + [0.023841892367236, 0.020202145142264], + [0.023779800854935, 0.020275195962052], + [0.023717485518092, 0.020348055943974], + [0.023654946943242, 0.020420724402244], + [0.023592185719023, 0.020493200652878], + [0.023529202436167, 0.020565484013703], + [0.023465997687496, 0.020637573804361], + [0.023402572067918, 0.020709469346314], + [0.023338926174419, 0.020781169962854], + [0.023275060606058, 0.020852674979108], + [0.023210975963963, 0.020923983722044], + [0.023146672851322, 0.020995095520475], + [0.023082151873380, 0.021066009705072], + [0.023017413637435, 0.021136725608363], + [0.022952458752826, 0.021207242564742], + [0.022887287830934, 0.021277559910478], + [0.022821901485173, 0.021347676983716], + [0.022756300330983, 0.021417593124488], + [0.022690484985827, 0.021487307674717], + [0.022624456069185, 0.021556819978223], + [0.022558214202547, 0.021626129380729], + [0.022491760009405, 0.021695235229869], + [0.022425094115252, 0.021764136875192], + [0.022358217147572, 0.021832833668171], + [0.022291129735838, 0.021901324962204], + [0.022223832511501, 0.021969610112625], + [0.022156326107988, 0.022037688476709], + [0.022088611160696, 0.022105559413676], + [0.022020688306983, 0.022173222284699], + [0.021952558186166, 0.022240676452909], + [0.021884221439510, 0.022307921283403], + [0.021815678710228, 0.022374956143245], + [0.021746930643469, 0.022441780401478], + [0.021677977886316, 0.022508393429127], + [0.021608821087780, 0.022574794599206], + [0.021539460898790, 0.022640983286719], + [0.021469897972190, 0.022706958868676], + [0.021400132962735, 0.022772720724087], + [0.021330166527077, 0.022838268233979], + [0.021259999323769, 0.022903600781391], + [0.021189632013250, 0.022968717751391], + [0.021119065257845, 0.023033618531071], + [0.021048299721754, 0.023098302509561], + [0.020977336071050, 0.023162769078031], + [0.020906174973670, 0.023227017629698], + [0.020834817099409, 0.023291047559828], + [0.020763263119915, 0.023354858265748], + [0.020691513708680, 0.023418449146848], + [0.020619569541038, 0.023481819604585], + [0.020547431294155, 0.023544969042494], + [0.020475099647023, 0.023607896866186], + [0.020402575280455, 0.023670602483363], + [0.020329858877078, 0.023733085303813], + [0.020256951121327, 0.023795344739427], + [0.020183852699437, 0.023857380204193], + [0.020110564299439, 0.023919191114211], + [0.020037086611150, 0.023980776887692], + [0.019963420326171, 0.024042136944968], + [0.019889566137877, 0.024103270708495], + [0.019815524741412, 0.024164177602859], + [0.019741296833681, 0.024224857054779], + [0.019666883113346, 0.024285308493120], + [0.019592284280817, 0.024345531348888], + [0.019517501038246, 0.024405525055242], + [0.019442534089523, 0.024465289047500], + [0.019367384140264, 0.024524822763141], + [0.019292051897809, 0.024584125641809], + [0.019216538071215, 0.024643197125323], + [0.019140843371246, 0.024702036657681], + [0.019064968510369, 0.024760643685063], + [0.018988914202748, 0.024819017655836], + [0.018912681164234, 0.024877158020562], + [0.018836270112363, 0.024935064232003], + [0.018759681766343, 0.024992735745123], + [0.018682916847054, 0.025050172017095], + [0.018605976077037, 0.025107372507308], + [0.018528860180486, 0.025164336677369], + [0.018451569883247, 0.025221063991110], + [0.018374105912805, 0.025277553914591], + [0.018296468998280, 0.025333805916107], + [0.018218659870421, 0.025389819466194], + [0.018140679261596, 0.025445594037630], + [0.018062527905790, 0.025501129105445], + [0.017984206538592, 0.025556424146920], + [0.017905715897192, 0.025611478641598], + [0.017827056720375, 0.025666292071285], + [0.017748229748511, 0.025720863920056], + [0.017669235723550, 0.025775193674260], + [0.017590075389012, 0.025829280822525], + [0.017510749489986, 0.025883124855762], + [0.017431258773116, 0.025936725267170], + [0.017351603986600, 0.025990081552242], + [0.017271785880180, 0.026043193208768], + [0.017191805205132, 0.026096059736841], + [0.017111662714267, 0.026148680638861], + [0.017031359161915, 0.026201055419541], + [0.016950895303924, 0.026253183585908], + [0.016870271897651, 0.026305064647313], + [0.016789489701954, 0.026356698115431], + [0.016708549477186, 0.026408083504269], + [0.016627451985187, 0.026459220330167], + [0.016546197989277, 0.026510108111806], + [0.016464788254250, 0.026560746370212], + [0.016383223546365, 0.026611134628757], + [0.016301504633341, 0.026661272413168], + [0.016219632284346, 0.026711159251530], + [0.016137607269996, 0.026760794674288], + [0.016055430362340, 0.026810178214254], + [0.015973102334858, 0.026859309406613], + [0.015890623962454, 0.026908187788922], + [0.015807996021446, 0.026956812901119], + [0.015725219289558, 0.027005184285527], + [0.015642294545918, 0.027053301486856], + [0.015559222571044, 0.027101164052208], + [0.015476004146842, 0.027148771531083], + [0.015392640056594, 0.027196123475380], + [0.015309131084956, 0.027243219439406], + [0.015225478017946, 0.027290058979875], + [0.015141681642938, 0.027336641655915], + [0.015057742748656, 0.027382967029073], + [0.014973662125164, 0.027429034663317], + [0.014889440563862, 0.027474844125040], + [0.014805078857474, 0.027520394983066], + [0.014720577800046, 0.027565686808654], + [0.014635938186934, 0.027610719175499], + [0.014551160814797, 0.027655491659740], + [0.014466246481592, 0.027700003839960], + [0.014381195986567, 0.027744255297195], + [0.014296010130247, 0.027788245614933], + [0.014210689714436, 0.027831974379120], + [0.014125235542201, 0.027875441178165], + [0.014039648417870, 0.027918645602941], + [0.013953929147020, 0.027961587246792], + [0.013868078536476, 0.028004265705534], + [0.013782097394294, 0.028046680577462], + [0.013695986529763, 0.028088831463351], + [0.013609746753390, 0.028130717966461], + [0.013523378876898, 0.028172339692540], + [0.013436883713214, 0.028213696249828], + [0.013350262076462, 0.028254787249062], + [0.013263514781960, 0.028295612303478], + [0.013176642646205, 0.028336171028814], + [0.013089646486871, 0.028376463043317], + [0.013002527122799, 0.028416487967743], + [0.012915285373990, 0.028456245425361], + [0.012827922061597, 0.028495735041960], + [0.012740438007915, 0.028534956445849], + [0.012652834036379, 0.028573909267859], + [0.012565110971550, 0.028612593141354], + [0.012477269639111, 0.028651007702224], + [0.012389310865858, 0.028689152588899], + [0.012301235479693, 0.028727027442343], + [0.012213044309615, 0.028764631906065], + [0.012124738185712, 0.028801965626115], + [0.012036317939156, 0.028839028251097], + [0.011947784402191, 0.028875819432161], + [0.011859138408130, 0.028912338823015], + [0.011770380791341, 0.028948586079925], + [0.011681512387245, 0.028984560861718], + [0.011592534032306, 0.029020262829785], + [0.011503446564022, 0.029055691648087], + [0.011414250820918, 0.029090846983152], + [0.011324947642537, 0.029125728504087], + [0.011235537869437, 0.029160335882573], + [0.011146022343175, 0.029194668792871], + [0.011056401906305, 0.029228726911828], + [0.010966677402371, 0.029262509918876], + [0.010876849675891, 0.029296017496036], + [0.010786919572361, 0.029329249327922], + [0.010696887938235, 0.029362205101743], + [0.010606755620926, 0.029394884507308], + [0.010516523468793, 0.029427287237024], + [0.010426192331137, 0.029459412985906], + [0.010335763058187, 0.029491261451573], + [0.010245236501099, 0.029522832334255], + [0.010154613511943, 0.029554125336796], + [0.010063894943698, 0.029585140164654], + [0.009973081650240, 0.029615876525905], + [0.009882174486340, 0.029646334131247], + [0.009791174307650, 0.029676512694001], + [0.009700081970699, 0.029706411930116], + [0.009608898332881, 0.029736031558168], + [0.009517624252453, 0.029765371299366], + [0.009426260588521, 0.029794430877553], + [0.009334808201034, 0.029823210019210], + [0.009243267950778, 0.029851708453456], + [0.009151640699363, 0.029879925912053], + [0.009059927309220, 0.029907862129408], + [0.008968128643591, 0.029935516842573], + [0.008876245566520, 0.029962889791254], + [0.008784278942845, 0.029989980717805], + [0.008692229638191, 0.030016789367235], + [0.008600098518961, 0.030043315487212], + [0.008507886452329, 0.030069558828062], + [0.008415594306230, 0.030095519142772], + [0.008323222949351, 0.030121196186994], + [0.008230773251129, 0.030146589719046], + [0.008138246081733, 0.030171699499915], + [0.008045642312067, 0.030196525293257], + [0.007952962813750, 0.030221066865402], + [0.007860208459119, 0.030245323985357], + [0.007767380121212, 0.030269296424803], + [0.007674478673766, 0.030292983958103], + [0.007581504991203, 0.030316386362302], + [0.007488459948628, 0.030339503417126], + [0.007395344421816, 0.030362334904989], + [0.007302159287206, 0.030384880610993], + [0.007208905421891, 0.030407140322928], + [0.007115583703613, 0.030429113831278], + [0.007022195010752, 0.030450800929220], + [0.006928740222316, 0.030472201412626], + [0.006835220217939, 0.030493315080068], + [0.006741635877866, 0.030514141732814], + [0.006647988082948, 0.030534681174838], + [0.006554277714635, 0.030554933212813], + [0.006460505654964, 0.030574897656119], + [0.006366672786553, 0.030594574316845], + [0.006272779992593, 0.030613963009786], + [0.006178828156839, 0.030633063552447], + [0.006084818163601, 0.030651875765048], + [0.005990750897737, 0.030670399470520], + [0.005896627244644, 0.030688634494512], + [0.005802448090250, 0.030706580665388], + [0.005708214321004, 0.030724237814232], + [0.005613926823871, 0.030741605774849], + [0.005519586486321, 0.030758684383764], + [0.005425194196321, 0.030775473480228], + [0.005330750842327, 0.030791972906214], + [0.005236257313276, 0.030808182506425], + [0.005141714498576, 0.030824102128288], + [0.005047123288102, 0.030839731621963], + [0.004952484572181, 0.030855070840339], + [0.004857799241589, 0.030870119639036], + [0.004763068187541, 0.030884877876411], + [0.004668292301681, 0.030899345413553], + [0.004573472476075, 0.030913522114288], + [0.004478609603205, 0.030927407845180], + [0.004383704575956, 0.030941002475530], + [0.004288758287610, 0.030954305877381], + [0.004193771631837, 0.030967317925516], + [0.004098745502689, 0.030980038497461], + [0.004003680794587, 0.030992467473486], + [0.003908578402316, 0.031004604736602], + [0.003813439221017, 0.031016450172571], + [0.003718264146176, 0.031028003669899], + [0.003623054073616, 0.031039265119839], + [0.003527809899492, 0.031050234416394], + [0.003432532520278, 0.031060911456318], + [0.003337222832760, 0.031071296139114], + [0.003241881734029, 0.031081388367037], + [0.003146510121474, 0.031091188045095], + [0.003051108892766, 0.031100695081051], + [0.002955678945860, 0.031109909385419], + [0.002860221178978, 0.031118830871473], + [0.002764736490604, 0.031127459455239], + [0.002669225779478, 0.031135795055501], + [0.002573689944583, 0.031143837593803], + [0.002478129885137, 0.031151586994444], + [0.002382546500589, 0.031159043184484], + [0.002286940690606, 0.031166206093743], + [0.002191313355067, 0.031173075654800], + [0.002095665394051, 0.031179651802998], + [0.001999997707835, 0.031185934476438], + [0.001904311196878, 0.031191923615985], + [0.001808606761820, 0.031197619165268], + [0.001712885303465, 0.031203021070678], + [0.001617147722782, 0.031208129281370], + [0.001521394920889, 0.031212943749264], + [0.001425627799047, 0.031217464429043], + [0.001329847258653, 0.031221691278159], + [0.001234054201231, 0.031225624256825], + [0.001138249528420, 0.031229263328024], + [0.001042434141971, 0.031232608457502], + [0.000946608943736, 0.031235659613775], + [0.000850774835656, 0.031238416768124], + [0.000754932719759, 0.031240879894597], + [0.000659083498149, 0.031243048970010], + [0.000563228072993, 0.031244923973948], + [0.000467367346520, 0.031246504888762], + [0.000371502221008, 0.031247791699571], + [0.000275633598775, 0.031248784394264], + [0.000179762382174, 0.031249482963498], + [0.000083889473581, 0.031249887400697] +]; + +exports.MDCT_TABLE_256 = [ + [0.088387931675923, 0.000271171628935], + [0.088354655998507, 0.002440238387037], + [0.088268158780110, 0.004607835236780], + [0.088128492123423, 0.006772656498875], + [0.087935740158418, 0.008933398165942], + [0.087690018991670, 0.011088758687994], + [0.087391476636423, 0.013237439756448], + [0.087040292923427, 0.015378147086172], + [0.086636679392621, 0.017509591195118], + [0.086180879165703, 0.019630488181053], + [0.085673166799686, 0.021739560494940], + [0.085113848121515, 0.023835537710479], + [0.084503260043847, 0.025917157289369], + [0.083841770362110, 0.027983165341813], + [0.083129777532952, 0.030032317381813], + [0.082367710434230, 0.032063379076803], + [0.081556028106671, 0.034075126991164], + [0.080695219477356, 0.036066349323177], + [0.079785803065216, 0.038035846634965], + [0.078828326668693, 0.039982432574992], + [0.077823367035766, 0.041904934592675], + [0.076771529516540, 0.043802194644686], + [0.075673447698606, 0.045673069892513], + [0.074529783025390, 0.047516433390863], + [0.073341224397728, 0.049331174766491], + [0.072108487758894, 0.051116200887052], + [0.070832315663343, 0.052870436519557], + [0.069513476829429, 0.054592824978055], + [0.068152765676348, 0.056282328760143], + [0.066751001845620, 0.057937930171918], + [0.065309029707361, 0.059558631940996], + [0.063827717851668, 0.061143457817234], + [0.062307958565413, 0.062691453160784], + [0.060750667294763, 0.064201685517134], + [0.059156782093749, 0.065673245178784], + [0.057527263059216, 0.067105245733220], + [0.055863091752499, 0.068496824596852], + [0.054165270608165, 0.069847143534609], + [0.052434822330188, 0.071155389164853], + [0.050672789275903, 0.072420773449336], + [0.048880232828135, 0.073642534167879], + [0.047058232755862, 0.074819935377512], + [0.045207886563797, 0.075952267855771], + [0.043330308831298, 0.077038849527912], + [0.041426630540984, 0.078079025877766], + [0.039497998397473, 0.079072170341994], + [0.037545574136653, 0.080017684687506], + [0.035570533825892, 0.080914999371817], + [0.033574067155622, 0.081763573886112], + [0.031557376722714, 0.082562897080836], + [0.029521677306074, 0.083312487473584], + [0.027468195134911, 0.084011893539132], + [0.025398167150101, 0.084660693981419], + [0.023312840259098, 0.085258497987320], + [0.021213470584847, 0.085804945462053], + [0.019101322709138, 0.086299707246093], + [0.016977668910873, 0.086742485313442], + [0.014843788399692, 0.087133012951149], + [0.012700966545425, 0.087471054919968], + [0.010550494103830, 0.087756407596056], + [0.008393666439096, 0.087988899093631], + [0.006231782743558, 0.088168389368510], + [0.004066145255116, 0.088294770302461], + [0.001898058472816, 0.088367965768336] +]; + +exports.MDCT_TABLE_1920 = [ + [0.032274858518097, 0.000013202404176], + [0.032274642494505, 0.000118821372483], + [0.032274080835421, 0.000224439068308], + [0.032273173546860, 0.000330054360572], + [0.032271920638538, 0.000435666118218], + [0.032270322123873, 0.000541273210231], + [0.032268378019984, 0.000646874505642], + [0.032266088347691, 0.000752468873546], + [0.032263453131514, 0.000858055183114], + [0.032260472399674, 0.000963632303600], + [0.032257146184092, 0.001069199104358], + [0.032253474520390, 0.001174754454853], + [0.032249457447888, 0.001280297224671], + [0.032245095009606, 0.001385826283535], + [0.032240387252262, 0.001491340501313], + [0.032235334226272, 0.001596838748031], + [0.032229935985750, 0.001702319893890], + [0.032224192588507, 0.001807782809271], + [0.032218104096050, 0.001913226364749], + [0.032211670573582, 0.002018649431111], + [0.032204892090000, 0.002124050879359], + [0.032197768717898, 0.002229429580728], + [0.032190300533560, 0.002334784406698], + [0.032182487616965, 0.002440114229003], + [0.032174330051782, 0.002545417919644], + [0.032165827925374, 0.002650694350905], + [0.032156981328790, 0.002755942395358], + [0.032147790356771, 0.002861160925883], + [0.032138255107744, 0.002966348815672], + [0.032128375683825, 0.003071504938250], + [0.032118152190814, 0.003176628167476], + [0.032107584738196, 0.003281717377568], + [0.032096673439141, 0.003386771443102], + [0.032085418410500, 0.003491789239036], + [0.032073819772804, 0.003596769640711], + [0.032061877650267, 0.003701711523874], + [0.032049592170778, 0.003806613764680], + [0.032036963465906, 0.003911475239711], + [0.032023991670893, 0.004016294825985], + [0.032010676924657, 0.004121071400967], + [0.031997019369789, 0.004225803842586], + [0.031983019152549, 0.004330491029241], + [0.031968676422869, 0.004435131839816], + [0.031953991334348, 0.004539725153692], + [0.031938964044252, 0.004644269850758], + [0.031923594713510, 0.004748764811426], + [0.031907883506716, 0.004853208916638], + [0.031891830592124, 0.004957601047881], + [0.031875436141648, 0.005061940087200], + [0.031858700330859, 0.005166224917208], + [0.031841623338985, 0.005270454421097], + [0.031824205348907, 0.005374627482653], + [0.031806446547156, 0.005478742986267], + [0.031788347123916, 0.005582799816945], + [0.031769907273017, 0.005686796860323], + [0.031751127191935, 0.005790733002674], + [0.031732007081789, 0.005894607130928], + [0.031712547147340, 0.005998418132675], + [0.031692747596989, 0.006102164896182], + [0.031672608642773, 0.006205846310406], + [0.031652130500364, 0.006309461265002], + [0.031631313389067, 0.006413008650337], + [0.031610157531816, 0.006516487357501], + [0.031588663155172, 0.006619896278321], + [0.031566830489325, 0.006723234305370], + [0.031544659768083, 0.006826500331981], + [0.031522151228878, 0.006929693252258], + [0.031499305112758, 0.007032811961088], + [0.031476121664387, 0.007135855354151], + [0.031452601132040, 0.007238822327937], + [0.031428743767604, 0.007341711779751], + [0.031404549826572, 0.007444522607730], + [0.031380019568042, 0.007547253710853], + [0.031355153254712, 0.007649903988952], + [0.031329951152882, 0.007752472342725], + [0.031304413532445, 0.007854957673748], + [0.031278540666888, 0.007957358884484], + [0.031252332833290, 0.008059674878300], + [0.031225790312316, 0.008161904559473], + [0.031198913388214, 0.008264046833205], + [0.031171702348814, 0.008366100605636], + [0.031144157485525, 0.008468064783849], + [0.031116279093331, 0.008569938275893], + [0.031088067470786, 0.008671719990782], + [0.031059522920014, 0.008773408838517], + [0.031030645746705, 0.008875003730092], + [0.031001436260110, 0.008976503577507], + [0.030971894773039, 0.009077907293780], + [0.030942021601857, 0.009179213792959], + [0.030911817066483, 0.009280421990133], + [0.030881281490382, 0.009381530801444], + [0.030850415200566, 0.009482539144097], + [0.030819218527589, 0.009583445936373], + [0.030787691805541, 0.009684250097643], + [0.030755835372048, 0.009784950548375], + [0.030723649568268, 0.009885546210147], + [0.030691134738883, 0.009986036005661], + [0.030658291232103, 0.010086418858753], + [0.030625119399655, 0.010186693694402], + [0.030591619596781, 0.010286859438745], + [0.030557792182239, 0.010386915019088], + [0.030523637518292, 0.010486859363916], + [0.030489155970710, 0.010586691402906], + [0.030454347908763, 0.010686410066936], + [0.030419213705216, 0.010786014288099], + [0.030383753736329, 0.010885502999714], + [0.030347968381849, 0.010984875136338], + [0.030311858025010, 0.011084129633775], + [0.030275423052523, 0.011183265429088], + [0.030238663854579, 0.011282281460612], + [0.030201580824838, 0.011381176667967], + [0.030164174360430, 0.011479949992062], + [0.030126444861948, 0.011578600375117], + [0.030088392733446, 0.011677126760663], + [0.030050018382430, 0.011775528093563], + [0.030011322219859, 0.011873803320018], + [0.029972304660138, 0.011971951387578], + [0.029932966121114, 0.012069971245157], + [0.029893307024070, 0.012167861843041], + [0.029853327793724, 0.012265622132901], + [0.029813028858222, 0.012363251067801], + [0.029772410649132, 0.012460747602215], + [0.029731473601443, 0.012558110692033], + [0.029690218153558, 0.012655339294575], + [0.029648644747289, 0.012752432368600], + [0.029606753827855, 0.012849388874320], + [0.029564545843872, 0.012946207773407], + [0.029522021247356, 0.013042888029011], + [0.029479180493710, 0.013139428605762], + [0.029436024041725, 0.013235828469789], + [0.029392552353570, 0.013332086588727], + [0.029348765894794, 0.013428201931728], + [0.029304665134313, 0.013524173469475], + [0.029260250544412, 0.013620000174189], + [0.029215522600735, 0.013715681019643], + [0.029170481782283, 0.013811214981173], + [0.029125128571406, 0.013906601035686], + [0.029079463453801, 0.014001838161674], + [0.029033486918505, 0.014096925339225], + [0.028987199457889, 0.014191861550031], + [0.028940601567655, 0.014286645777401], + [0.028893693746829, 0.014381277006273], + [0.028846476497755, 0.014475754223221], + [0.028798950326094, 0.014570076416472], + [0.028751115740811, 0.014664242575910], + [0.028702973254178, 0.014758251693091], + [0.028654523381760, 0.014852102761253], + [0.028605766642418, 0.014945794775326], + [0.028556703558297, 0.015039326731945], + [0.028507334654823, 0.015132697629457], + [0.028457660460698, 0.015225906467935], + [0.028407681507891, 0.015318952249187], + [0.028357398331639, 0.015411833976768], + [0.028306811470432, 0.015504550655988], + [0.028255921466016, 0.015597101293927], + [0.028204728863381, 0.015689484899442], + [0.028153234210760, 0.015781700483179], + [0.028101438059619, 0.015873747057582], + [0.028049340964652, 0.015965623636907], + [0.027996943483779, 0.016057329237229], + [0.027944246178133, 0.016148862876456], + [0.027891249612061, 0.016240223574335], + [0.027837954353113, 0.016331410352467], + [0.027784360972039, 0.016422422234315], + [0.027730470042780, 0.016513258245214], + [0.027676282142466, 0.016603917412384], + [0.027621797851405, 0.016694398764938], + [0.027567017753080, 0.016784701333894], + [0.027511942434143, 0.016874824152183], + [0.027456572484404, 0.016964766254662], + [0.027400908496833, 0.017054526678124], + [0.027344951067546, 0.017144104461307], + [0.027288700795801, 0.017233498644904], + [0.027232158283994, 0.017322708271577], + [0.027175324137651, 0.017411732385960], + [0.027118198965418, 0.017500570034678], + [0.027060783379060, 0.017589220266351], + [0.027003077993454, 0.017677682131607], + [0.026945083426576, 0.017765954683088], + [0.026886800299502, 0.017854036975468], + [0.026828229236397, 0.017941928065456], + [0.026769370864511, 0.018029627011808], + [0.026710225814170, 0.018117132875340], + [0.026650794718768, 0.018204444718934], + [0.026591078214767, 0.018291561607551], + [0.026531076941680, 0.018378482608238], + [0.026470791542075, 0.018465206790142], + [0.026410222661558, 0.018551733224515], + [0.026349370948775, 0.018638060984730], + [0.026288237055398, 0.018724189146286], + [0.026226821636121, 0.018810116786819], + [0.026165125348656, 0.018895842986112], + [0.026103148853718, 0.018981366826109], + [0.026040892815028, 0.019066687390916], + [0.025978357899296, 0.019151803766819], + [0.025915544776223, 0.019236715042290], + [0.025852454118485, 0.019321420307998], + [0.025789086601733, 0.019405918656817], + [0.025725442904582, 0.019490209183837], + [0.025661523708606, 0.019574290986376], + [0.025597329698327, 0.019658163163984], + [0.025532861561211, 0.019741824818458], + [0.025468119987662, 0.019825275053848], + [0.025403105671008, 0.019908512976470], + [0.025337819307501, 0.019991537694913], + [0.025272261596305, 0.020074348320047], + [0.025206433239491, 0.020156943965039], + [0.025140334942028, 0.020239323745355], + [0.025073967411776, 0.020321486778774], + [0.025007331359476, 0.020403432185395], + [0.024940427498748, 0.020485159087650], + [0.024873256546079, 0.020566666610309], + [0.024805819220816, 0.020647953880491], + [0.024738116245157, 0.020729020027676], + [0.024670148344147, 0.020809864183709], + [0.024601916245669, 0.020890485482816], + [0.024533420680433, 0.020970883061607], + [0.024464662381971, 0.021051056059087], + [0.024395642086630, 0.021131003616670], + [0.024326360533561, 0.021210724878181], + [0.024256818464715, 0.021290218989868], + [0.024187016624830, 0.021369485100415], + [0.024116955761430, 0.021448522360944], + [0.024046636624808, 0.021527329925030], + [0.023976059968027, 0.021605906948708], + [0.023905226546906, 0.021684252590480], + [0.023834137120014, 0.021762366011328], + [0.023762792448662, 0.021840246374720], + [0.023691193296893, 0.021917892846620], + [0.023619340431478, 0.021995304595495], + [0.023547234621902, 0.022072480792330], + [0.023474876640361, 0.022149420610628], + [0.023402267261751, 0.022226123226426], + [0.023329407263659, 0.022302587818300], + [0.023256297426359, 0.022378813567377], + [0.023182938532797, 0.022454799657339], + [0.023109331368588, 0.022530545274437], + [0.023035476722006, 0.022606049607496], + [0.022961375383975, 0.022681311847926], + [0.022887028148061, 0.022756331189727], + [0.022812435810462, 0.022831106829504], + [0.022737599170003, 0.022905637966469], + [0.022662519028125, 0.022979923802453], + [0.022587196188874, 0.023053963541915], + [0.022511631458899, 0.023127756391950], + [0.022435825647437, 0.023201301562294], + [0.022359779566306, 0.023274598265338], + [0.022283494029900, 0.023347645716133], + [0.022206969855176, 0.023420443132400], + [0.022130207861645, 0.023492989734537], + [0.022053208871367, 0.023565284745628], + [0.021975973708940, 0.023637327391451], + [0.021898503201489, 0.023709116900488], + [0.021820798178663, 0.023780652503931], + [0.021742859472618, 0.023851933435691], + [0.021664687918017, 0.023922958932406], + [0.021586284352013, 0.023993728233451], + [0.021507649614247, 0.024064240580942], + [0.021428784546832, 0.024134495219750], + [0.021349689994350, 0.024204491397504], + [0.021270366803840, 0.024274228364600], + [0.021190815824791, 0.024343705374213], + [0.021111037909128, 0.024412921682298], + [0.021031033911210, 0.024481876547605], + [0.020950804687815, 0.024550569231683], + [0.020870351098134, 0.024618998998889], + [0.020789674003759, 0.024687165116394], + [0.020708774268678, 0.024755066854194], + [0.020627652759262, 0.024822703485116], + [0.020546310344257, 0.024890074284826], + [0.020464747894775, 0.024957178531837], + [0.020382966284284, 0.025024015507516], + [0.020300966388600, 0.025090584496093], + [0.020218749085876, 0.025156884784668], + [0.020136315256592, 0.025222915663218], + [0.020053665783549, 0.025288676424605], + [0.019970801551857, 0.025354166364584], + [0.019887723448925, 0.025419384781811], + [0.019804432364452, 0.025484330977848], + [0.019720929190419, 0.025549004257175], + [0.019637214821078, 0.025613403927192], + [0.019553290152943, 0.025677529298230], + [0.019469156084779, 0.025741379683559], + [0.019384813517595, 0.025804954399392], + [0.019300263354632, 0.025868252764895], + [0.019215506501354, 0.025931274102193], + [0.019130543865439, 0.025994017736379], + [0.019045376356769, 0.026056482995518], + [0.018960004887419, 0.026118669210657], + [0.018874430371648, 0.026180575715833], + [0.018788653725892, 0.026242201848076], + [0.018702675868750, 0.026303546947421], + [0.018616497720974, 0.026364610356909], + [0.018530120205464, 0.026425391422602], + [0.018443544247254, 0.026485889493583], + [0.018356770773502, 0.026546103921965], + [0.018269800713483, 0.026606034062902], + [0.018182634998576, 0.026665679274589], + [0.018095274562256, 0.026725038918274], + [0.018007720340083, 0.026784112358263], + [0.017919973269692, 0.026842898961926], + [0.017832034290785, 0.026901398099707], + [0.017743904345116, 0.026959609145127], + [0.017655584376488, 0.027017531474792], + [0.017567075330734, 0.027075164468401], + [0.017478378155718, 0.027132507508750], + [0.017389493801313, 0.027189559981742], + [0.017300423219401, 0.027246321276391], + [0.017211167363854, 0.027302790784828], + [0.017121727190533, 0.027358967902310], + [0.017032103657269, 0.027414852027226], + [0.016942297723858, 0.027470442561102], + [0.016852310352050, 0.027525738908608], + [0.016762142505537, 0.027580740477564], + [0.016671795149944, 0.027635446678948], + [0.016581269252819, 0.027689856926900], + [0.016490565783622, 0.027743970638730], + [0.016399685713714, 0.027797787234924], + [0.016308630016347, 0.027851306139149], + [0.016217399666655, 0.027904526778260], + [0.016125995641641, 0.027957448582309], + [0.016034418920170, 0.028010070984544], + [0.015942670482954, 0.028062393421421], + [0.015850751312545, 0.028114415332610], + [0.015758662393324, 0.028166136160998], + [0.015666404711489, 0.028217555352697], + [0.015573979255046, 0.028268672357047], + [0.015481387013797, 0.028319486626627], + [0.015388628979331, 0.028369997617257], + [0.015295706145012, 0.028420204788004], + [0.015202619505968, 0.028470107601191], + [0.015109370059084, 0.028519705522399], + [0.015015958802984, 0.028568998020472], + [0.014922386738030, 0.028617984567529], + [0.014828654866302, 0.028666664638963], + [0.014734764191593, 0.028715037713449], + [0.014640715719398, 0.028763103272951], + [0.014546510456900, 0.028810860802724], + [0.014452149412962, 0.028858309791325], + [0.014357633598114, 0.028905449730613], + [0.014262964024545, 0.028952280115756], + [0.014168141706090, 0.028998800445240], + [0.014073167658220, 0.029045010220868], + [0.013978042898030, 0.029090908947771], + [0.013882768444231, 0.029136496134411], + [0.013787345317136, 0.029181771292585], + [0.013691774538648, 0.029226733937433], + [0.013596057132255, 0.029271383587441], + [0.013500194123014, 0.029315719764447], + [0.013404186537539, 0.029359741993647], + [0.013308035403995, 0.029403449803598], + [0.013211741752084, 0.029446842726223], + [0.013115306613032, 0.029489920296820], + [0.013018731019584, 0.029532682054063], + [0.012922016005985, 0.029575127540008], + [0.012825162607977, 0.029617256300097], + [0.012728171862781, 0.029659067883165], + [0.012631044809089, 0.029700561841444], + [0.012533782487056, 0.029741737730567], + [0.012436385938281, 0.029782595109573], + [0.012338856205805, 0.029823133540913], + [0.012241194334091, 0.029863352590452], + [0.012143401369021, 0.029903251827477], + [0.012045478357878, 0.029942830824699], + [0.011947426349339, 0.029982089158259], + [0.011849246393462, 0.030021026407731], + [0.011750939541676, 0.030059642156129], + [0.011652506846768, 0.030097935989909], + [0.011553949362874, 0.030135907498976], + [0.011455268145464, 0.030173556276684], + [0.011356464251335, 0.030210881919845], + [0.011257538738598, 0.030247884028732], + [0.011158492666665, 0.030284562207083], + [0.011059327096240, 0.030320916062102], + [0.010960043089307, 0.030356945204470], + [0.010860641709118, 0.030392649248343], + [0.010761124020182, 0.030428027811361], + [0.010661491088253, 0.030463080514646], + [0.010561743980319, 0.030497806982812], + [0.010461883764593, 0.030532206843968], + [0.010361911510496, 0.030566279729717], + [0.010261828288652, 0.030600025275167], + [0.010161635170872, 0.030633443118931], + [0.010061333230142, 0.030666532903129], + [0.009960923540617, 0.030699294273397], + [0.009860407177603, 0.030731726878888], + [0.009759785217550, 0.030763830372273], + [0.009659058738038, 0.030795604409750], + [0.009558228817767, 0.030827048651045], + [0.009457296536545, 0.030858162759415], + [0.009356262975275, 0.030888946401653], + [0.009255129215945, 0.030919399248091], + [0.009153896341616, 0.030949520972603], + [0.009052565436412, 0.030979311252611], + [0.008951137585505, 0.031008769769084], + [0.008849613875105, 0.031037896206544], + [0.008747995392451, 0.031066690253072], + [0.008646283225794, 0.031095151600306], + [0.008544478464390, 0.031123279943448], + [0.008442582198486, 0.031151074981266], + [0.008340595519310, 0.031178536416098], + [0.008238519519057, 0.031205663953853], + [0.008136355290878, 0.031232457304017], + [0.008034103928871, 0.031258916179656], + [0.007931766528065, 0.031285040297416], + [0.007829344184412, 0.031310829377528], + [0.007726837994772, 0.031336283143813], + [0.007624249056906, 0.031361401323680], + [0.007521578469457, 0.031386183648135], + [0.007418827331946, 0.031410629851778], + [0.007315996744755, 0.031434739672811], + [0.007213087809115, 0.031458512853036], + [0.007110101627101, 0.031481949137863], + [0.007007039301610, 0.031505048276306], + [0.006903901936357, 0.031527810020993], + [0.006800690635862, 0.031550234128164], + [0.006697406505433, 0.031572320357675], + [0.006594050651161, 0.031594068473000], + [0.006490624179905, 0.031615478241233], + [0.006387128199278, 0.031636549433095], + [0.006283563817639, 0.031657281822929], + [0.006179932144080, 0.031677675188707], + [0.006076234288412, 0.031697729312034], + [0.005972471361157, 0.031717443978146], + [0.005868644473532, 0.031736818975914], + [0.005764754737440, 0.031755854097848], + [0.005660803265456, 0.031774549140098], + [0.005556791170816, 0.031792903902453], + [0.005452719567407, 0.031810918188350], + [0.005348589569753, 0.031828591804869], + [0.005244402293001, 0.031845924562742], + [0.005140158852914, 0.031862916276347], + [0.005035860365855, 0.031879566763717], + [0.004931507948778, 0.031895875846539], + [0.004827102719212, 0.031911843350155], + [0.004722645795254, 0.031927469103567], + [0.004618138295554, 0.031942752939435], + [0.004513581339303, 0.031957694694082], + [0.004408976046222, 0.031972294207493], + [0.004304323536549, 0.031986551323320], + [0.004199624931030, 0.032000465888879], + [0.004094881350902, 0.032014037755158], + [0.003990093917884, 0.032027266776813], + [0.003885263754166, 0.032040152812170], + [0.003780391982394, 0.032052695723232], + [0.003675479725661, 0.032064895375674], + [0.003570528107494, 0.032076751638847], + [0.003465538251839, 0.032088264385780], + [0.003360511283053, 0.032099433493181], + [0.003255448325892, 0.032110258841438], + [0.003150350505494, 0.032120740314619], + [0.003045218947373, 0.032130877800478], + [0.002940054777404, 0.032140671190449], + [0.002834859121810, 0.032150120379653], + [0.002729633107153, 0.032159225266897], + [0.002624377860318, 0.032167985754674], + [0.002519094508504, 0.032176401749168], + [0.002413784179212, 0.032184473160250], + [0.002308448000231, 0.032192199901481], + [0.002203087099626, 0.032199581890114], + [0.002097702605728, 0.032206619047093], + [0.001992295647121, 0.032213311297057], + [0.001886867352628, 0.032219658568338], + [0.001781418851302, 0.032225660792960], + [0.001675951272410, 0.032231317906644], + [0.001570465745428, 0.032236629848809], + [0.001464963400018, 0.032241596562566], + [0.001359445366028, 0.032246217994727], + [0.001253912773470, 0.032250494095799], + [0.001148366752513, 0.032254424819990], + [0.001042808433471, 0.032258010125204], + [0.000937238946789, 0.032261249973045], + [0.000831659423030, 0.032264144328817], + [0.000726070992868, 0.032266693161525], + [0.000620474787068, 0.032268896443871], + [0.000514871936481, 0.032270754152261], + [0.000409263572030, 0.032272266266801], + [0.000303650824695, 0.032273432771295], + [0.000198034825504, 0.032274253653254], + [0.000092416705518, 0.032274728903884] +]; + +exports.MDCT_TABLE_240 = [ + [0.091286604111815, 0.000298735779793], + [0.091247502481454, 0.002688238127538], + [0.091145864370807, 0.005075898091152], + [0.090981759437558, 0.007460079287760], + [0.090755300151030, 0.009839147718664], + [0.090466641715108, 0.012211472889198], + [0.090115981961863, 0.014575428926191], + [0.089703561215976, 0.016929395692256], + [0.089229662130024, 0.019271759896156], + [0.088694609490769, 0.021600916198470], + [0.088098769996564, 0.023915268311810], + [0.087442552006035, 0.026213230094844], + [0.086726405258214, 0.028493226639351], + [0.085950820564309, 0.030753695349588], + [0.085116329471329, 0.032993087013213], + [0.084223503897785, 0.035209866863042], + [0.083272955741727, 0.037402515628894], + [0.082265336461381, 0.039569530578832], + [0.081201336628670, 0.041709426549053], + [0.080081685455930, 0.043820736961749], + [0.078907150296148, 0.045902014830227], + [0.077678536117054, 0.047951833750597], + [0.076396684949434, 0.049968788879362], + [0.075062475310050, 0.051951497896226], + [0.073676821599542, 0.053898601951466], + [0.072240673475749, 0.055808766597225], + [0.070755015202858, 0.057680682702068], + [0.069220864976840, 0.059513067348201], + [0.067639274227625, 0.061304664710718], + [0.066011326898512, 0.063054246918278], + [0.064338138703282, 0.064760614894630], + [0.062620856361546, 0.066422599180399], + [0.060860656812842, 0.068039060734572], + [0.059058746410016, 0.069608891715145], + [0.057216360092450, 0.071131016238378], + [0.055334760539699, 0.072604391116154], + [0.053415237306106, 0.074028006570930], + [0.051459105937014, 0.075400886927784], + [0.049467707067153, 0.076722091283096], + [0.047442405501835, 0.077990714149396], + [0.045384589281588, 0.079205886075941], + [0.043295668730857, 0.080366774244592], + [0.041177075491445, 0.081472583040586], + [0.039030261541332, 0.082522554597810], + [0.036856698199564, 0.083515969318206], + [0.034657875117883, 0.084452146364948], + [0.032435299259796, 0.085330444129049], + [0.030190493867775, 0.086150260669096], + [0.027924997419306, 0.086911034123781], + [0.025640362572491, 0.087612243096981], + [0.023338155101933, 0.088253407015092], + [0.021019952825636, 0.088834086456390], + [0.018687344523641, 0.089353883452193], + [0.016341928849164, 0.089812441759604], + [0.013985313232951, 0.090209447105664], + [0.011619112781631, 0.090544627402740], + [0.009244949170797, 0.090817752935000], + [0.006864449533597, 0.091028636515846], + [0.004479245345574, 0.091177133616206], + [0.002090971306534, 0.091263142463585] +]; +},{}],11:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +/******************************************************************************** + * Sample offset into the window indicating the beginning of a scalefactor + * window band + * + * scalefactor window band - term for scalefactor bands within a window, + * given in Table 4.110 to Table 4.128. + * + * scalefactor band - a set of spectral coefficients which are scaled by one + * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band + * may contain several scalefactor window bands of corresponding frequency. For + * all other window_sequences scalefactor bands and scalefactor window bands are + * identical. + *******************************************************************************/ +const SWB_OFFSET_1024_96 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 96, 108, 120, 132, 144, + 156, 172, 188, 212, 240, 276, 320, 384, + 448, 512, 576, 640, 704, 768, 832, 896, + 960, 1024 +]); + +const SWB_OFFSET_128_96 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 +]); + +const SWB_OFFSET_1024_64 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 100, 112, 124, 140, 156, + 172, 192, 216, 240, 268, 304, 344, 384, + 424, 464, 504, 544, 584, 624, 664, 704, + 744, 784, 824, 864, 904, 944, 984, 1024 +]); + +const SWB_OFFSET_128_64 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 +]); + +const SWB_OFFSET_1024_48 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 1024 +]); + +const SWB_OFFSET_128_48 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 28, 36, + 44, 56, 68, 80, 96, 112, 128 +]); + +const SWB_OFFSET_1024_32 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 960, 992, 1024 +]); + +const SWB_OFFSET_1024_24 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 52, 60, 68, 76, + 84, 92, 100, 108, 116, 124, 136, 148, + 160, 172, 188, 204, 220, 240, 260, 284, + 308, 336, 364, 396, 432, 468, 508, 552, + 600, 652, 704, 768, 832, 896, 960, 1024 +]); + +const SWB_OFFSET_128_24 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 64, 76, 92, 108, 128 +]); + +const SWB_OFFSET_1024_16 = new Uint16Array([ + 0, 8, 16, 24, 32, 40, 48, 56, + 64, 72, 80, 88, 100, 112, 124, 136, + 148, 160, 172, 184, 196, 212, 228, 244, + 260, 280, 300, 320, 344, 368, 396, 424, + 456, 492, 532, 572, 616, 664, 716, 772, + 832, 896, 960, 1024 +]); + +const SWB_OFFSET_128_16 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 40, 48, 60, 72, 88, 108, 128 +]); + +const SWB_OFFSET_1024_8 = new Uint16Array([ + 0, 12, 24, 36, 48, 60, 72, 84, + 96, 108, 120, 132, 144, 156, 172, 188, + 204, 220, 236, 252, 268, 288, 308, 328, + 348, 372, 396, 420, 448, 476, 508, 544, + 580, 620, 664, 712, 764, 820, 880, 944, + 1024 +]); + +const SWB_OFFSET_128_8 = new Uint16Array([ + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 60, 72, 88, 108, 128 +]); + +exports.SWB_OFFSET_1024 = [ + SWB_OFFSET_1024_96, + SWB_OFFSET_1024_96, + SWB_OFFSET_1024_64, + SWB_OFFSET_1024_48, + SWB_OFFSET_1024_48, + SWB_OFFSET_1024_32, + SWB_OFFSET_1024_24, + SWB_OFFSET_1024_24, + SWB_OFFSET_1024_16, + SWB_OFFSET_1024_16, + SWB_OFFSET_1024_16, + SWB_OFFSET_1024_8 +]; + +exports.SWB_OFFSET_128 = [ + SWB_OFFSET_128_96, + SWB_OFFSET_128_96, + SWB_OFFSET_128_64, + SWB_OFFSET_128_48, + SWB_OFFSET_128_48, + SWB_OFFSET_128_48, + SWB_OFFSET_128_24, + SWB_OFFSET_128_24, + SWB_OFFSET_128_16, + SWB_OFFSET_128_16, + SWB_OFFSET_128_16, + SWB_OFFSET_128_8 +]; + +exports.SWB_SHORT_WINDOW_COUNT = new Uint8Array([ + 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15 +]); + +exports.SWB_LONG_WINDOW_COUNT = new Uint8Array([ + 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40 +]); + +/* + * Scalefactor lookup table + */ +exports.SCALEFACTOR_TABLE = (function() { + var table = new Float32Array(428); + + for (var i = 0; i < 428; i++) { + table[i] = Math.pow(2, (i - 200) / 4); + } + + return table; +})(); + + +/** + * Inverse quantization lookup table + */ +exports.IQ_TABLE = (function() { + var table = new Float32Array(8191), + four_thirds = 4/3; + + for (var i = 0; i < 8191; i++) { + table[i] = Math.pow(i, four_thirds); + } + + return table; +})(); + +exports.SAMPLE_RATES = new Int32Array([ + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, 7350 +]); + +},{}],12:[function(require,module,exports){ +/* + * AAC.js - Advanced Audio Coding decoder in JavaScript + * Created by Devon Govett + * Copyright (c) 2012, Official.fm Labs + * + * AAC.js is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * AAC.js is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * If not, see . + */ + +// Temporal Noise Shaping +function TNS(config) { + this.maxBands = TNS_MAX_BANDS_1024[config.sampleIndex] + this.nFilt = new Int32Array(8); + this.length = new Array(8); + this.direction = new Array(8); + this.order = new Array(8); + this.coef = new Array(8); + + // Probably could allocate these as needed + for (var w = 0; w < 8; w++) { + this.length[w] = new Int32Array(4); + this.direction[w] = new Array(4); + this.order[w] = new Int32Array(4); + this.coef[w] = new Array(4); + + for (var filt = 0; filt < 4; filt++) { + this.coef[w][filt] = new Float32Array(TNS_MAX_ORDER); + } + } + + this.lpc = new Float32Array(TNS_MAX_ORDER); + this.tmp = new Float32Array(TNS_MAX_ORDER); +} + +const TNS_MAX_ORDER = 20, + SHORT_BITS = [1, 4, 3], + LONG_BITS = [2, 6, 5]; + +const TNS_COEF_1_3 = [0.00000000, -0.43388373, 0.64278758, 0.34202015], + + TNS_COEF_0_3 = [0.00000000, -0.43388373, -0.78183150, -0.97492790, + 0.98480773, 0.86602539, 0.64278758, 0.34202015], + + TNS_COEF_1_4 = [0.00000000, -0.20791170, -0.40673664, -0.58778524, + 0.67369562, 0.52643216, 0.36124167, 0.18374951], + + TNS_COEF_0_4 = [0.00000000, -0.20791170, -0.40673664, -0.58778524, + -0.74314481, -0.86602539, -0.95105654, -0.99452192, + 0.99573416, 0.96182561, 0.89516330, 0.79801720, + 0.67369562, 0.52643216, 0.36124167, 0.18374951], + + TNS_TABLES = [TNS_COEF_0_3, TNS_COEF_0_4, TNS_COEF_1_3, TNS_COEF_1_4]; + +const TNS_MAX_BANDS_1024 = [31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39, 39], + TNS_MAX_BANDS_128 = [9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14]; + +TNS.prototype.decode = function(stream, info) { + var windowCount = info.windowCount, + bits = info.windowSequence === 2 ? SHORT_BITS : LONG_BITS; + + for (var w = 0; w < windowCount; w++) { + if (this.nFilt[w] = stream.read(bits[0])) { + var coefRes = stream.read(1), + nFilt_w = this.nFilt[w], + length_w = this.length[w], + order_w = this.order[w], + direction_w = this.direction[w], + coef_w = this.coef[w]; + + for (var filt = 0; filt < nFilt_w; filt++) { + length_w[filt] = stream.read(bits[1]); + + if ((order_w[filt] = stream.read(bits[2])) > 20) + throw new Error("TNS filter out of range: " + order_w[filt]); + + if (order_w[filt]) { + direction_w[filt] = !!stream.read(1); + var coefCompress = stream.read(1), + coefLen = coefRes + 3 - coefCompress, + tmp = 2 * coefCompress + coefRes, + table = TNS_TABLES[tmp], + order_w_filt = order_w[filt], + coef_w_filt = coef_w[filt]; + + for (var i = 0; i < order_w_filt; i++) + coef_w_filt[i] = table[stream.read(coefLen)]; + } + + } + } + } +}; + +TNS.prototype.process = function(ics, data, decode) { + var mmm = Math.min(this.maxBands, ics.maxSFB), + lpc = this.lpc, + tmp = this.tmp, + info = ics.info, + windowCount = info.windowCount; + + for (var w = 0; w < windowCount; w++) { + var bottom = info.swbCount, + nFilt_w = this.nFilt[w], + length_w = this.length[w], + order_w = this.order[w], + coef_w = this.coef[w], + direction_w = this.direction[w]; + + for (var filt = 0; filt < nFilt_w; filt++) { + var top = bottom, + bottom = Math.max(0, tmp - length_w[filt]), + order = order_w[filt]; + + if (order === 0) continue; + + // calculate lpc coefficients + var autoc = coef_w[filt]; + for (var i = 0; i < order; i++) { + var r = -autoc[i]; + lpc[i] = r; + + for (var j = 0, len = (i + 1) >> 1; j < len; j++) { + var f = lpc[j], + b = lpc[i - 1 - j]; + + lpc[j] = f + r * b; + lpc[i - 1 - j] = b + r * f; + } + } + + var start = info.swbOffsets[Math.min(bottom, mmm)], + end = info.swbOffsets[Math.min(top, mmm)], + size, + inc = 1; + + if ((size = end - start) <= 0) continue; + + if (direction_w[filt]) { + inc = -1; + start = end - 1; + } + + start += w * 128; + + if (decode) { + // ar filter + for (var m = 0; m < size; m++, start += inc) { + for (var i = 1; i <= Math.min(m, order); i++) { + data[start] -= data[start - i * inc] * lpc[i - 1]; + } + } + } else { + // ma filter + for (var m = 0; m < size; m++, start += inc) { + tmp[0] = data[start]; + + for (var i = 1; i <= Math.min(m, order); i++) + data[start] += tmp[i] * lpc[i - 1]; + + for (var i = order; i > 0; i--) + tmp[i] = tmp[i - 1]; + } + } + } + } +}; + +module.exports = TNS; + +},{}]},{},[4]) + + +//# sourceMappingURL=aac.js.map \ No newline at end of file diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora-xpra.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora-xpra.js new file mode 100644 index 000000000..ffe997505 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora-xpra.js @@ -0,0 +1,48 @@ +// based on aurora-websocket.js https://github.com/fsbdev/aurora-websocket +// MIT licensed + +(function() { + var __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + AV.XpraSource = (function(_super) { + __extends(XpraSource, _super); + + function XpraSource() { + // constructor + } + + XpraSource.prototype.start = function() { + return true; + }; + + XpraSource.prototype.pause = function() { + return true; + }; + + XpraSource.prototype.reset = function() { + return true; + }; + + XpraSource.prototype._on_data = function(data) { + var buf = new AV.Buffer(data); + return this.emit('data', buf); + }; + + return XpraSource; + + })(AV.EventEmitter); + + AV.Asset.fromXpraSource = function() { + var source; + source = new AV.XpraSource(); + return new AV.Asset(source); + }; + + AV.Player.fromXpraSource = function() { + var asset; + asset = AV.Asset.fromXpraSource(); + return new AV.Player(asset); + }; + +}).call(this); \ No newline at end of file diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora.js new file mode 100644 index 000000000..18b3f1eb3 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/aurora.js @@ -0,0 +1,4003 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AV = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o> 3); + return this.bitPosition = pos & 7; + }; + + Bitstream.prototype.rewind = function(bits) { + var pos; + pos = this.bitPosition - bits; + this.stream.rewind(Math.abs(pos >> 3)); + return this.bitPosition = pos & 7; + }; + + Bitstream.prototype.seek = function(offset) { + var curOffset; + curOffset = this.offset(); + if (offset > curOffset) { + return this.advance(offset - curOffset); + } else if (offset < curOffset) { + return this.rewind(curOffset - offset); + } + }; + + Bitstream.prototype.align = function() { + if (this.bitPosition !== 0) { + this.bitPosition = 0; + return this.stream.advance(1); + } + }; + + Bitstream.prototype.read = function(bits, signed) { + var a, a0, a1, a2, a3, a4, mBits; + if (bits === 0) { + return 0; + } + mBits = bits + this.bitPosition; + if (mBits <= 8) { + a = ((this.stream.peekUInt8() << this.bitPosition) & 0xff) >>> (8 - bits); + } else if (mBits <= 16) { + a = ((this.stream.peekUInt16() << this.bitPosition) & 0xffff) >>> (16 - bits); + } else if (mBits <= 24) { + a = ((this.stream.peekUInt24() << this.bitPosition) & 0xffffff) >>> (24 - bits); + } else if (mBits <= 32) { + a = (this.stream.peekUInt32() << this.bitPosition) >>> (32 - bits); + } else if (mBits <= 40) { + a0 = this.stream.peekUInt8(0) * 0x0100000000; + a1 = this.stream.peekUInt8(1) << 24 >>> 0; + a2 = this.stream.peekUInt8(2) << 16; + a3 = this.stream.peekUInt8(3) << 8; + a4 = this.stream.peekUInt8(4); + a = a0 + a1 + a2 + a3 + a4; + a %= Math.pow(2, 40 - this.bitPosition); + a = Math.floor(a / Math.pow(2, 40 - this.bitPosition - bits)); + } else { + throw new Error("Too many bits!"); + } + if (signed) { + if (mBits < 32) { + if (a >>> (bits - 1)) { + a = ((1 << bits >>> 0) - a) * -1; + } + } else { + if (a / Math.pow(2, bits - 1) | 0) { + a = (Math.pow(2, bits) - a) * -1; + } + } + } + this.advance(bits); + return a; + }; + + Bitstream.prototype.peek = function(bits, signed) { + var a, a0, a1, a2, a3, a4, mBits; + if (bits === 0) { + return 0; + } + mBits = bits + this.bitPosition; + if (mBits <= 8) { + a = ((this.stream.peekUInt8() << this.bitPosition) & 0xff) >>> (8 - bits); + } else if (mBits <= 16) { + a = ((this.stream.peekUInt16() << this.bitPosition) & 0xffff) >>> (16 - bits); + } else if (mBits <= 24) { + a = ((this.stream.peekUInt24() << this.bitPosition) & 0xffffff) >>> (24 - bits); + } else if (mBits <= 32) { + a = (this.stream.peekUInt32() << this.bitPosition) >>> (32 - bits); + } else if (mBits <= 40) { + a0 = this.stream.peekUInt8(0) * 0x0100000000; + a1 = this.stream.peekUInt8(1) << 24 >>> 0; + a2 = this.stream.peekUInt8(2) << 16; + a3 = this.stream.peekUInt8(3) << 8; + a4 = this.stream.peekUInt8(4); + a = a0 + a1 + a2 + a3 + a4; + a %= Math.pow(2, 40 - this.bitPosition); + a = Math.floor(a / Math.pow(2, 40 - this.bitPosition - bits)); + } else { + throw new Error("Too many bits!"); + } + if (signed) { + if (mBits < 32) { + if (a >>> (bits - 1)) { + a = ((1 << bits >>> 0) - a) * -1; + } + } else { + if (a / Math.pow(2, bits - 1) | 0) { + a = (Math.pow(2, bits) - a) * -1; + } + } + } + return a; + }; + + Bitstream.prototype.readLSB = function(bits, signed) { + var a, mBits; + if (bits === 0) { + return 0; + } + if (bits > 40) { + throw new Error("Too many bits!"); + } + mBits = bits + this.bitPosition; + a = (this.stream.peekUInt8(0)) >>> this.bitPosition; + if (mBits > 8) { + a |= (this.stream.peekUInt8(1)) << (8 - this.bitPosition); + } + if (mBits > 16) { + a |= (this.stream.peekUInt8(2)) << (16 - this.bitPosition); + } + if (mBits > 24) { + a += (this.stream.peekUInt8(3)) << (24 - this.bitPosition) >>> 0; + } + if (mBits > 32) { + a += (this.stream.peekUInt8(4)) * Math.pow(2, 32 - this.bitPosition); + } + if (mBits >= 32) { + a %= Math.pow(2, bits); + } else { + a &= (1 << bits) - 1; + } + if (signed) { + if (mBits < 32) { + if (a >>> (bits - 1)) { + a = ((1 << bits >>> 0) - a) * -1; + } + } else { + if (a / Math.pow(2, bits - 1) | 0) { + a = (Math.pow(2, bits) - a) * -1; + } + } + } + this.advance(bits); + return a; + }; + + Bitstream.prototype.peekLSB = function(bits, signed) { + var a, mBits; + if (bits === 0) { + return 0; + } + if (bits > 40) { + throw new Error("Too many bits!"); + } + mBits = bits + this.bitPosition; + a = (this.stream.peekUInt8(0)) >>> this.bitPosition; + if (mBits > 8) { + a |= (this.stream.peekUInt8(1)) << (8 - this.bitPosition); + } + if (mBits > 16) { + a |= (this.stream.peekUInt8(2)) << (16 - this.bitPosition); + } + if (mBits > 24) { + a += (this.stream.peekUInt8(3)) << (24 - this.bitPosition) >>> 0; + } + if (mBits > 32) { + a += (this.stream.peekUInt8(4)) * Math.pow(2, 32 - this.bitPosition); + } + if (mBits >= 32) { + a %= Math.pow(2, bits); + } else { + a &= (1 << bits) - 1; + } + if (signed) { + if (mBits < 32) { + if (a >>> (bits - 1)) { + a = ((1 << bits >>> 0) - a) * -1; + } + } else { + if (a / Math.pow(2, bits - 1) | 0) { + a = (Math.pow(2, bits) - a) * -1; + } + } + } + return a; + }; + + return Bitstream; + + })(); + + module.exports = Bitstream; + +}).call(this); + +},{}],6:[function(require,module,exports){ +(function (global){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AVBuffer; + + AVBuffer = (function() { + var BlobBuilder, URL; + + function AVBuffer(input) { + var ref; + if (input instanceof Uint8Array) { + this.data = input; + } else if (input instanceof ArrayBuffer || Array.isArray(input) || typeof input === 'number' || ((ref = global.Buffer) != null ? ref.isBuffer(input) : void 0)) { + this.data = new Uint8Array(input); + } else if (input.buffer instanceof ArrayBuffer) { + this.data = new Uint8Array(input.buffer, input.byteOffset, input.length * input.BYTES_PER_ELEMENT); + } else if (input instanceof AVBuffer) { + this.data = input.data; + } else { + throw new Error("Constructing buffer with unknown type."); + } + this.length = this.data.length; + this.next = null; + this.prev = null; + } + + AVBuffer.allocate = function(size) { + return new AVBuffer(size); + }; + + AVBuffer.prototype.copy = function() { + return new AVBuffer(new Uint8Array(this.data)); + }; + + AVBuffer.prototype.slice = function(position, length) { + if (length == null) { + length = this.length; + } + if (position === 0 && length >= this.length) { + return new AVBuffer(this.data); + } else { + return new AVBuffer(this.data.subarray(position, position + length)); + } + }; + + BlobBuilder = global.BlobBuilder || global.MozBlobBuilder || global.WebKitBlobBuilder; + + URL = global.URL || global.webkitURL || global.mozURL; + + AVBuffer.makeBlob = function(data, type) { + var bb; + if (type == null) { + type = 'application/octet-stream'; + } + try { + return new Blob([data], { + type: type + }); + } catch (error) {} + if (BlobBuilder != null) { + bb = new BlobBuilder; + bb.append(data); + return bb.getBlob(type); + } + return null; + }; + + AVBuffer.makeBlobURL = function(data, type) { + return URL != null ? URL.createObjectURL(this.makeBlob(data, type)) : void 0; + }; + + AVBuffer.revokeBlobURL = function(url) { + return URL != null ? URL.revokeObjectURL(url) : void 0; + }; + + AVBuffer.prototype.toBlob = function() { + return AVBuffer.makeBlob(this.data.buffer); + }; + + AVBuffer.prototype.toBlobURL = function() { + return AVBuffer.makeBlobURL(this.data.buffer); + }; + + return AVBuffer; + + })(); + + module.exports = AVBuffer; + +}).call(this); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{}],7:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var BufferList; + + BufferList = (function() { + function BufferList() { + this.first = null; + this.last = null; + this.numBuffers = 0; + this.availableBytes = 0; + this.availableBuffers = 0; + } + + BufferList.prototype.copy = function() { + var result; + result = new BufferList; + result.first = this.first; + result.last = this.last; + result.numBuffers = this.numBuffers; + result.availableBytes = this.availableBytes; + result.availableBuffers = this.availableBuffers; + return result; + }; + + BufferList.prototype.append = function(buffer) { + var ref; + buffer.prev = this.last; + if ((ref = this.last) != null) { + ref.next = buffer; + } + this.last = buffer; + if (this.first == null) { + this.first = buffer; + } + this.availableBytes += buffer.length; + this.availableBuffers++; + return this.numBuffers++; + }; + + BufferList.prototype.advance = function() { + if (this.first) { + this.availableBytes -= this.first.length; + this.availableBuffers--; + this.first = this.first.next; + return this.first != null; + } + return false; + }; + + BufferList.prototype.rewind = function() { + var ref; + if (this.first && !this.first.prev) { + return false; + } + this.first = ((ref = this.first) != null ? ref.prev : void 0) || this.last; + if (this.first) { + this.availableBytes += this.first.length; + this.availableBuffers++; + } + return this.first != null; + }; + + BufferList.prototype.reset = function() { + var results; + results = []; + while (this.rewind()) { + continue; + } + return results; + }; + + return BufferList; + + })(); + + module.exports = BufferList; + +}).call(this); + +},{}],8:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Base, EventEmitter, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty, + slice = [].slice; + + Base = require('./base'); + + EventEmitter = (function(superClass) { + extend(EventEmitter, superClass); + + function EventEmitter() { + return EventEmitter.__super__.constructor.apply(this, arguments); + } + + EventEmitter.prototype.on = function(event, fn) { + var base; + if (this.events == null) { + this.events = {}; + } + if ((base = this.events)[event] == null) { + base[event] = []; + } + return this.events[event].push(fn); + }; + + EventEmitter.prototype.off = function(event, fn) { + var events, index, ref; + if (this.events == null) { + return; + } + if ((ref = this.events) != null ? ref[event] : void 0) { + if (fn != null) { + index = this.events[event].indexOf(fn); + if (~index) { + return this.events[event].splice(index, 1); + } + } else { + return this.events[event]; + } + } else if (event == null) { + return events = {}; + } + }; + + EventEmitter.prototype.once = function(event, fn) { + var cb; + return this.on(event, cb = function() { + this.off(event, cb); + return fn.apply(this, arguments); + }); + }; + + EventEmitter.prototype.emit = function() { + var args, event, fn, i, len, ref, ref1; + event = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; + if (!((ref = this.events) != null ? ref[event] : void 0)) { + return; + } + ref1 = this.events[event].slice(); + for (i = 0, len = ref1.length; i < len; i++) { + fn = ref1[i]; + fn.apply(this, args); + } + }; + + return EventEmitter; + + })(Base); + + module.exports = EventEmitter; + +}).call(this); + +},{"./base":4}],9:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AVBuffer, BufferList, Stream, UnderflowError; + + BufferList = require('./bufferlist'); + + AVBuffer = require('./buffer'); + + UnderflowError = require('./underflow'); + + Stream = (function() { + var buf, decodeString, float32, float64, float64Fallback, float80, int16, int32, int8, nativeEndian, uint16, uint32, uint8; + + buf = new ArrayBuffer(16); + + uint8 = new Uint8Array(buf); + + int8 = new Int8Array(buf); + + uint16 = new Uint16Array(buf); + + int16 = new Int16Array(buf); + + uint32 = new Uint32Array(buf); + + int32 = new Int32Array(buf); + + float32 = new Float32Array(buf); + + if (typeof Float64Array !== "undefined" && Float64Array !== null) { + float64 = new Float64Array(buf); + } + + nativeEndian = new Uint16Array(new Uint8Array([0x12, 0x34]).buffer)[0] === 0x3412; + + function Stream(list1) { + this.list = list1; + this.localOffset = 0; + this.offset = 0; + } + + Stream.fromBuffer = function(buffer) { + var list; + list = new BufferList; + list.append(buffer); + return new Stream(list); + }; + + Stream.prototype.copy = function() { + var result; + result = new Stream(this.list.copy()); + result.localOffset = this.localOffset; + result.offset = this.offset; + return result; + }; + + Stream.prototype.available = function(bytes) { + return bytes <= this.list.availableBytes - this.localOffset; + }; + + Stream.prototype.remainingBytes = function() { + return this.list.availableBytes - this.localOffset; + }; + + Stream.prototype.advance = function(bytes) { + if (!this.available(bytes)) { + throw new UnderflowError(); + } + this.localOffset += bytes; + this.offset += bytes; + while (this.list.first && this.localOffset >= this.list.first.length) { + this.localOffset -= this.list.first.length; + this.list.advance(); + } + return this; + }; + + Stream.prototype.rewind = function(bytes) { + if (bytes > this.offset) { + throw new UnderflowError(); + } + if (!this.list.first) { + this.list.rewind(); + this.localOffset = this.list.first.length; + } + this.localOffset -= bytes; + this.offset -= bytes; + while (this.list.first.prev && this.localOffset < 0) { + this.list.rewind(); + this.localOffset += this.list.first.length; + } + return this; + }; + + Stream.prototype.seek = function(position) { + if (position > this.offset) { + return this.advance(position - this.offset); + } else if (position < this.offset) { + return this.rewind(this.offset - position); + } + }; + + Stream.prototype.readUInt8 = function() { + var a; + if (!this.available(1)) { + throw new UnderflowError(); + } + a = this.list.first.data[this.localOffset]; + this.localOffset += 1; + this.offset += 1; + if (this.localOffset === this.list.first.length) { + this.localOffset = 0; + this.list.advance(); + } + return a; + }; + + Stream.prototype.peekUInt8 = function(offset) { + var buffer; + if (offset == null) { + offset = 0; + } + if (!this.available(offset + 1)) { + throw new UnderflowError(); + } + offset = this.localOffset + offset; + buffer = this.list.first; + while (buffer) { + if (buffer.length > offset) { + return buffer.data[offset]; + } + offset -= buffer.length; + buffer = buffer.next; + } + return 0; + }; + + Stream.prototype.read = function(bytes, littleEndian) { + var i, j, k, ref, ref1; + if (littleEndian == null) { + littleEndian = false; + } + if (littleEndian === nativeEndian) { + for (i = j = 0, ref = bytes; j < ref; i = j += 1) { + uint8[i] = this.readUInt8(); + } + } else { + for (i = k = ref1 = bytes - 1; k >= 0; i = k += -1) { + uint8[i] = this.readUInt8(); + } + } + }; + + Stream.prototype.peek = function(bytes, offset, littleEndian) { + var i, j, k, ref, ref1; + if (littleEndian == null) { + littleEndian = false; + } + if (littleEndian === nativeEndian) { + for (i = j = 0, ref = bytes; j < ref; i = j += 1) { + uint8[i] = this.peekUInt8(offset + i); + } + } else { + for (i = k = 0, ref1 = bytes; k < ref1; i = k += 1) { + uint8[bytes - i - 1] = this.peekUInt8(offset + i); + } + } + }; + + Stream.prototype.readInt8 = function() { + this.read(1); + return int8[0]; + }; + + Stream.prototype.peekInt8 = function(offset) { + if (offset == null) { + offset = 0; + } + this.peek(1, offset); + return int8[0]; + }; + + Stream.prototype.readUInt16 = function(littleEndian) { + this.read(2, littleEndian); + return uint16[0]; + }; + + Stream.prototype.peekUInt16 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(2, offset, littleEndian); + return uint16[0]; + }; + + Stream.prototype.readInt16 = function(littleEndian) { + this.read(2, littleEndian); + return int16[0]; + }; + + Stream.prototype.peekInt16 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(2, offset, littleEndian); + return int16[0]; + }; + + Stream.prototype.readUInt24 = function(littleEndian) { + if (littleEndian) { + return this.readUInt16(true) + (this.readUInt8() << 16); + } else { + return (this.readUInt16() << 8) + this.readUInt8(); + } + }; + + Stream.prototype.peekUInt24 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + if (littleEndian) { + return this.peekUInt16(offset, true) + (this.peekUInt8(offset + 2) << 16); + } else { + return (this.peekUInt16(offset) << 8) + this.peekUInt8(offset + 2); + } + }; + + Stream.prototype.readInt24 = function(littleEndian) { + if (littleEndian) { + return this.readUInt16(true) + (this.readInt8() << 16); + } else { + return (this.readInt16() << 8) + this.readUInt8(); + } + }; + + Stream.prototype.peekInt24 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + if (littleEndian) { + return this.peekUInt16(offset, true) + (this.peekInt8(offset + 2) << 16); + } else { + return (this.peekInt16(offset) << 8) + this.peekUInt8(offset + 2); + } + }; + + Stream.prototype.readUInt32 = function(littleEndian) { + this.read(4, littleEndian); + return uint32[0]; + }; + + Stream.prototype.peekUInt32 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(4, offset, littleEndian); + return uint32[0]; + }; + + Stream.prototype.readInt32 = function(littleEndian) { + this.read(4, littleEndian); + return int32[0]; + }; + + Stream.prototype.peekInt32 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(4, offset, littleEndian); + return int32[0]; + }; + + Stream.prototype.readFloat32 = function(littleEndian) { + this.read(4, littleEndian); + return float32[0]; + }; + + Stream.prototype.peekFloat32 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(4, offset, littleEndian); + return float32[0]; + }; + + Stream.prototype.readFloat64 = function(littleEndian) { + this.read(8, littleEndian); + if (float64) { + return float64[0]; + } else { + return float64Fallback(); + } + }; + + float64Fallback = function() { + var exp, frac, high, low, out, sign; + low = uint32[0], high = uint32[1]; + if (!high || high === 0x80000000) { + return 0.0; + } + sign = 1 - (high >>> 31) * 2; + exp = (high >>> 20) & 0x7ff; + frac = high & 0xfffff; + if (exp === 0x7ff) { + if (frac) { + return 0/0; + } + return sign * 2e308; + } + exp -= 1023; + out = (frac | 0x100000) * Math.pow(2, exp - 20); + out += low * Math.pow(2, exp - 52); + return sign * out; + }; + + Stream.prototype.peekFloat64 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(8, offset, littleEndian); + if (float64) { + return float64[0]; + } else { + return float64Fallback(); + } + }; + + Stream.prototype.readFloat80 = function(littleEndian) { + this.read(10, littleEndian); + return float80(); + }; + + float80 = function() { + var a0, a1, exp, high, low, out, sign; + high = uint32[0], low = uint32[1]; + a0 = uint8[9]; + a1 = uint8[8]; + sign = 1 - (a0 >>> 7) * 2; + exp = ((a0 & 0x7F) << 8) | a1; + if (exp === 0 && low === 0 && high === 0) { + return 0; + } + if (exp === 0x7fff) { + if (low === 0 && high === 0) { + return sign * 2e308; + } + return 0/0; + } + exp -= 16383; + out = low * Math.pow(2, exp - 31); + out += high * Math.pow(2, exp - 63); + return sign * out; + }; + + Stream.prototype.peekFloat80 = function(offset, littleEndian) { + if (offset == null) { + offset = 0; + } + this.peek(10, offset, littleEndian); + return float80(); + }; + + Stream.prototype.readBuffer = function(length) { + var i, j, ref, result, to; + result = AVBuffer.allocate(length); + to = result.data; + for (i = j = 0, ref = length; j < ref; i = j += 1) { + to[i] = this.readUInt8(); + } + return result; + }; + + Stream.prototype.peekBuffer = function(offset, length) { + var i, j, ref, result, to; + if (offset == null) { + offset = 0; + } + result = AVBuffer.allocate(length); + to = result.data; + for (i = j = 0, ref = length; j < ref; i = j += 1) { + to[i] = this.peekUInt8(offset + i); + } + return result; + }; + + Stream.prototype.readSingleBuffer = function(length) { + var result; + result = this.list.first.slice(this.localOffset, length); + this.advance(result.length); + return result; + }; + + Stream.prototype.peekSingleBuffer = function(offset, length) { + var result; + result = this.list.first.slice(this.localOffset + offset, length); + return result; + }; + + Stream.prototype.readString = function(length, encoding) { + if (encoding == null) { + encoding = 'ascii'; + } + return decodeString.call(this, 0, length, encoding, true); + }; + + Stream.prototype.peekString = function(offset, length, encoding) { + if (offset == null) { + offset = 0; + } + if (encoding == null) { + encoding = 'ascii'; + } + return decodeString.call(this, offset, length, encoding, false); + }; + + decodeString = function(offset, length, encoding, advance) { + var b1, b2, b3, b4, bom, c, end, littleEndian, nullEnd, pt, result, w1, w2; + encoding = encoding.toLowerCase(); + nullEnd = length === null ? 0 : -1; + if (length == null) { + length = 2e308; + } + end = offset + length; + result = ''; + switch (encoding) { + case 'ascii': + case 'latin1': + while (offset < end && (c = this.peekUInt8(offset++)) !== nullEnd) { + result += String.fromCharCode(c); + } + break; + case 'utf8': + case 'utf-8': + while (offset < end && (b1 = this.peekUInt8(offset++)) !== nullEnd) { + if ((b1 & 0x80) === 0) { + result += String.fromCharCode(b1); + } else if ((b1 & 0xe0) === 0xc0) { + b2 = this.peekUInt8(offset++) & 0x3f; + result += String.fromCharCode(((b1 & 0x1f) << 6) | b2); + } else if ((b1 & 0xf0) === 0xe0) { + b2 = this.peekUInt8(offset++) & 0x3f; + b3 = this.peekUInt8(offset++) & 0x3f; + result += String.fromCharCode(((b1 & 0x0f) << 12) | (b2 << 6) | b3); + } else if ((b1 & 0xf8) === 0xf0) { + b2 = this.peekUInt8(offset++) & 0x3f; + b3 = this.peekUInt8(offset++) & 0x3f; + b4 = this.peekUInt8(offset++) & 0x3f; + pt = (((b1 & 0x0f) << 18) | (b2 << 12) | (b3 << 6) | b4) - 0x10000; + result += String.fromCharCode(0xd800 + (pt >> 10), 0xdc00 + (pt & 0x3ff)); + } + } + break; + case 'utf16-be': + case 'utf16be': + case 'utf16le': + case 'utf16-le': + case 'utf16bom': + case 'utf16-bom': + switch (encoding) { + case 'utf16be': + case 'utf16-be': + littleEndian = false; + break; + case 'utf16le': + case 'utf16-le': + littleEndian = true; + break; + case 'utf16bom': + case 'utf16-bom': + if (length < 2 || (bom = this.peekUInt16(offset)) === nullEnd) { + if (advance) { + this.advance(offset += 2); + } + return result; + } + littleEndian = bom === 0xfffe; + offset += 2; + } + while (offset < end && (w1 = this.peekUInt16(offset, littleEndian)) !== nullEnd) { + offset += 2; + if (w1 < 0xd800 || w1 > 0xdfff) { + result += String.fromCharCode(w1); + } else { + if (w1 > 0xdbff) { + throw new Error("Invalid utf16 sequence."); + } + w2 = this.peekUInt16(offset, littleEndian); + if (w2 < 0xdc00 || w2 > 0xdfff) { + throw new Error("Invalid utf16 sequence."); + } + result += String.fromCharCode(w1, w2); + offset += 2; + } + } + if (w1 === nullEnd) { + offset += 2; + } + break; + default: + throw new Error("Unknown encoding: " + encoding); + } + if (advance) { + this.advance(offset); + } + return result; + }; + + return Stream; + + })(); + + module.exports = Stream; + +}).call(this); + +},{"./buffer":6,"./bufferlist":7,"./underflow":10}],10:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var UnderflowError, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + UnderflowError = (function(superClass) { + extend(UnderflowError, superClass); + + function UnderflowError() { + UnderflowError.__super__.constructor.apply(this, arguments); + this.name = 'UnderflowError'; + this.stack = new Error().stack; + } + + return UnderflowError; + + })(Error); + + module.exports = UnderflowError; + +}).call(this); + +},{}],11:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Bitstream, BufferList, Decoder, EventEmitter, Stream, UnderflowError, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('./core/events'); + + BufferList = require('./core/bufferlist'); + + Stream = require('./core/stream'); + + Bitstream = require('./core/bitstream'); + + UnderflowError = require('./core/underflow'); + + Decoder = (function(superClass) { + var codecs; + + extend(Decoder, superClass); + + function Decoder(demuxer, format) { + var list; + this.demuxer = demuxer; + this.format = format; + list = new BufferList; + this.stream = new Stream(list); + this.bitstream = new Bitstream(this.stream); + this.receivedFinalBuffer = false; + this.waiting = false; + this.demuxer.on('cookie', (function(_this) { + return function(cookie) { + var error; + try { + return _this.setCookie(cookie); + } catch (error1) { + error = error1; + return _this.emit('error', error); + } + }; + })(this)); + this.demuxer.on('data', (function(_this) { + return function(chunk) { + list.append(chunk); + if (_this.waiting) { + return _this.decode(); + } + }; + })(this)); + this.demuxer.on('end', (function(_this) { + return function() { + _this.receivedFinalBuffer = true; + if (_this.waiting) { + return _this.decode(); + } + }; + })(this)); + this.init(); + } + + Decoder.prototype.init = function() {}; + + Decoder.prototype.setCookie = function(cookie) {}; + + Decoder.prototype.readChunk = function() {}; + + Decoder.prototype.decode = function() { + var error, offset, packet; + this.waiting = !this.receivedFinalBuffer; + offset = this.bitstream.offset(); + try { + packet = this.readChunk(); + } catch (error1) { + error = error1; + if (!(error instanceof UnderflowError)) { + this.emit('error', error); + return false; + } + } + if (packet) { + this.emit('data', packet); + if (this.receivedFinalBuffer) { + this.emit('end'); + } + return true; + } else if (!this.receivedFinalBuffer) { + this.bitstream.seek(offset); + this.waiting = true; + } else { + this.emit('end'); + } + return false; + }; + + Decoder.prototype.seek = function(timestamp) { + var seekPoint; + seekPoint = this.demuxer.seek(timestamp); + this.stream.seek(seekPoint.offset); + return seekPoint.timestamp; + }; + + codecs = {}; + + Decoder.register = function(id, decoder) { + return codecs[id] = decoder; + }; + + Decoder.find = function(id) { + return codecs[id] || null; + }; + + return Decoder; + + })(EventEmitter); + + module.exports = Decoder; + +}).call(this); + +},{"./core/bitstream":5,"./core/bufferlist":7,"./core/events":8,"./core/stream":9,"./core/underflow":10}],12:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Decoder, LPCMDecoder, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Decoder = require('../decoder'); + + LPCMDecoder = (function(superClass) { + extend(LPCMDecoder, superClass); + + function LPCMDecoder() { + this.readChunk = bind(this.readChunk, this); + return LPCMDecoder.__super__.constructor.apply(this, arguments); + } + + Decoder.register('lpcm', LPCMDecoder); + + LPCMDecoder.prototype.readChunk = function() { + var chunkSize, i, j, k, l, littleEndian, m, n, o, output, ref, ref1, ref2, ref3, ref4, ref5, samples, stream; + stream = this.stream; + littleEndian = this.format.littleEndian; + chunkSize = Math.min(4096, stream.remainingBytes()); + samples = chunkSize / (this.format.bitsPerChannel / 8) | 0; + if (chunkSize < this.format.bitsPerChannel / 8) { + return null; + } + if (this.format.floatingPoint) { + switch (this.format.bitsPerChannel) { + case 32: + output = new Float32Array(samples); + for (i = j = 0, ref = samples; j < ref; i = j += 1) { + output[i] = stream.readFloat32(littleEndian); + } + break; + case 64: + output = new Float64Array(samples); + for (i = k = 0, ref1 = samples; k < ref1; i = k += 1) { + output[i] = stream.readFloat64(littleEndian); + } + break; + default: + throw new Error('Unsupported bit depth.'); + } + } else { + switch (this.format.bitsPerChannel) { + case 8: + output = new Int8Array(samples); + for (i = l = 0, ref2 = samples; l < ref2; i = l += 1) { + output[i] = stream.readInt8(); + } + break; + case 16: + output = new Int16Array(samples); + for (i = m = 0, ref3 = samples; m < ref3; i = m += 1) { + output[i] = stream.readInt16(littleEndian); + } + break; + case 24: + output = new Int32Array(samples); + for (i = n = 0, ref4 = samples; n < ref4; i = n += 1) { + output[i] = stream.readInt24(littleEndian); + } + break; + case 32: + output = new Int32Array(samples); + for (i = o = 0, ref5 = samples; o < ref5; i = o += 1) { + output[i] = stream.readInt32(littleEndian); + } + break; + default: + throw new Error('Unsupported bit depth.'); + } + } + return output; + }; + + return LPCMDecoder; + + })(Decoder); + +}).call(this); + +},{"../decoder":11}],13:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Decoder, XLAWDecoder, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Decoder = require('../decoder'); + + XLAWDecoder = (function(superClass) { + var BIAS, QUANT_MASK, SEG_MASK, SEG_SHIFT, SIGN_BIT; + + extend(XLAWDecoder, superClass); + + function XLAWDecoder() { + this.readChunk = bind(this.readChunk, this); + return XLAWDecoder.__super__.constructor.apply(this, arguments); + } + + Decoder.register('ulaw', XLAWDecoder); + + Decoder.register('alaw', XLAWDecoder); + + SIGN_BIT = 0x80; + + QUANT_MASK = 0xf; + + SEG_SHIFT = 4; + + SEG_MASK = 0x70; + + BIAS = 0x84; + + XLAWDecoder.prototype.init = function() { + var i, j, k, seg, t, table, val; + this.format.bitsPerChannel = 16; + this.table = table = new Int16Array(256); + if (this.format.formatID === 'ulaw') { + for (i = j = 0; j < 256; i = ++j) { + val = ~i; + t = ((val & QUANT_MASK) << 3) + BIAS; + t <<= (val & SEG_MASK) >>> SEG_SHIFT; + table[i] = val & SIGN_BIT ? BIAS - t : t - BIAS; + } + } else { + for (i = k = 0; k < 256; i = ++k) { + val = i ^ 0x55; + t = val & QUANT_MASK; + seg = (val & SEG_MASK) >>> SEG_SHIFT; + if (seg) { + t = (t + t + 1 + 32) << (seg + 2); + } else { + t = (t + t + 1) << 3; + } + table[i] = val & SIGN_BIT ? t : -t; + } + } + }; + + XLAWDecoder.prototype.readChunk = function() { + var i, j, output, ref, ref1, samples, stream, table; + ref = this, stream = ref.stream, table = ref.table; + samples = Math.min(4096, this.stream.remainingBytes()); + if (samples === 0) { + return; + } + output = new Int16Array(samples); + for (i = j = 0, ref1 = samples; j < ref1; i = j += 1) { + output[i] = table[stream.readUInt8()]; + } + return output; + }; + + return XLAWDecoder; + + })(Decoder); + +}).call(this); + +},{"../decoder":11}],14:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var BufferList, Demuxer, EventEmitter, Stream, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('./core/events'); + + BufferList = require('./core/bufferlist'); + + Stream = require('./core/stream'); + + Demuxer = (function(superClass) { + var formats; + + extend(Demuxer, superClass); + + Demuxer.probe = function(buffer) { + return false; + }; + + function Demuxer(source, chunk) { + var list, received; + list = new BufferList; + list.append(chunk); + this.stream = new Stream(list); + received = false; + source.on('data', (function(_this) { + return function(chunk) { + var e; + received = true; + list.append(chunk); + try { + return _this.readChunk(chunk); + } catch (error) { + e = error; + return _this.emit('error', e); + } + }; + })(this)); + source.on('error', (function(_this) { + return function(err) { + return _this.emit('error', err); + }; + })(this)); + source.on('end', (function(_this) { + return function() { + if (!received) { + _this.readChunk(chunk); + } + return _this.emit('end'); + }; + })(this)); + this.seekPoints = []; + this.init(); + } + + Demuxer.prototype.init = function() {}; + + Demuxer.prototype.readChunk = function(chunk) {}; + + Demuxer.prototype.addSeekPoint = function(offset, timestamp) { + var index; + index = this.searchTimestamp(timestamp); + return this.seekPoints.splice(index, 0, { + offset: offset, + timestamp: timestamp + }); + }; + + Demuxer.prototype.searchTimestamp = function(timestamp, backward) { + var high, low, mid, time; + low = 0; + high = this.seekPoints.length; + if (high > 0 && this.seekPoints[high - 1].timestamp < timestamp) { + return high; + } + while (low < high) { + mid = (low + high) >> 1; + time = this.seekPoints[mid].timestamp; + if (time < timestamp) { + low = mid + 1; + } else if (time >= timestamp) { + high = mid; + } + } + if (high > this.seekPoints.length) { + high = this.seekPoints.length; + } + return high; + }; + + Demuxer.prototype.seek = function(timestamp) { + var index, seekPoint; + if (this.format && this.format.framesPerPacket > 0 && this.format.bytesPerPacket > 0) { + seekPoint = { + timestamp: timestamp, + offset: this.format.bytesPerPacket * timestamp / this.format.framesPerPacket + }; + return seekPoint; + } else { + index = this.searchTimestamp(timestamp); + return this.seekPoints[index]; + } + }; + + formats = []; + + Demuxer.register = function(demuxer) { + return formats.push(demuxer); + }; + + Demuxer.find = function(buffer) { + var e, format, i, len, offset, stream; + stream = Stream.fromBuffer(buffer); + for (i = 0, len = formats.length; i < len; i++) { + format = formats[i]; + offset = stream.offset; + try { + if (format.probe(stream)) { + return format; + } + } catch (error) { + e = error; + } + stream.seek(offset); + } + return null; + }; + + return Demuxer; + + })(EventEmitter); + + module.exports = Demuxer; + +}).call(this); + +},{"./core/bufferlist":7,"./core/events":8,"./core/stream":9}],15:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AIFFDemuxer, Demuxer, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Demuxer = require('../demuxer'); + + AIFFDemuxer = (function(superClass) { + extend(AIFFDemuxer, superClass); + + function AIFFDemuxer() { + return AIFFDemuxer.__super__.constructor.apply(this, arguments); + } + + Demuxer.register(AIFFDemuxer); + + AIFFDemuxer.probe = function(buffer) { + var ref; + return buffer.peekString(0, 4) === 'FORM' && ((ref = buffer.peekString(8, 4)) === 'AIFF' || ref === 'AIFC'); + }; + + AIFFDemuxer.prototype.readChunk = function() { + var buffer, format, offset, ref; + if (!this.readStart && this.stream.available(12)) { + if (this.stream.readString(4) !== 'FORM') { + return this.emit('error', 'Invalid AIFF.'); + } + this.fileSize = this.stream.readUInt32(); + this.fileType = this.stream.readString(4); + this.readStart = true; + if ((ref = this.fileType) !== 'AIFF' && ref !== 'AIFC') { + return this.emit('error', 'Invalid AIFF.'); + } + } + while (this.stream.available(1)) { + if (!this.readHeaders && this.stream.available(8)) { + this.type = this.stream.readString(4); + this.len = this.stream.readUInt32(); + } + switch (this.type) { + case 'COMM': + if (!this.stream.available(this.len)) { + return; + } + this.format = { + formatID: 'lpcm', + channelsPerFrame: this.stream.readUInt16(), + sampleCount: this.stream.readUInt32(), + bitsPerChannel: this.stream.readUInt16(), + sampleRate: this.stream.readFloat80(), + framesPerPacket: 1, + littleEndian: false, + floatingPoint: false + }; + this.format.bytesPerPacket = (this.format.bitsPerChannel / 8) * this.format.channelsPerFrame; + if (this.fileType === 'AIFC') { + format = this.stream.readString(4); + this.format.littleEndian = format === 'sowt' && this.format.bitsPerChannel > 8; + this.format.floatingPoint = format === 'fl32' || format === 'fl64'; + if (format === 'twos' || format === 'sowt' || format === 'fl32' || format === 'fl64' || format === 'NONE') { + format = 'lpcm'; + } + this.format.formatID = format; + this.len -= 4; + } + this.stream.advance(this.len - 18); + this.emit('format', this.format); + this.emit('duration', this.format.sampleCount / this.format.sampleRate * 1000 | 0); + break; + case 'SSND': + if (!(this.readSSNDHeader && this.stream.available(4))) { + offset = this.stream.readUInt32(); + this.stream.advance(4); + this.stream.advance(offset); + this.readSSNDHeader = true; + } + buffer = this.stream.readSingleBuffer(this.len); + this.len -= buffer.length; + this.readHeaders = this.len > 0; + this.emit('data', buffer); + break; + default: + if (!this.stream.available(this.len)) { + return; + } + this.stream.advance(this.len); + } + if (this.type !== 'SSND') { + this.readHeaders = false; + } + } + }; + + return AIFFDemuxer; + + })(Demuxer); + +}).call(this); + +},{"../demuxer":14}],16:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AUDemuxer, Demuxer, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Demuxer = require('../demuxer'); + + AUDemuxer = (function(superClass) { + var bps, formats; + + extend(AUDemuxer, superClass); + + function AUDemuxer() { + return AUDemuxer.__super__.constructor.apply(this, arguments); + } + + Demuxer.register(AUDemuxer); + + AUDemuxer.probe = function(buffer) { + return buffer.peekString(0, 4) === '.snd'; + }; + + bps = [8, 8, 16, 24, 32, 32, 64]; + + bps[26] = 8; + + formats = { + 1: 'ulaw', + 27: 'alaw' + }; + + AUDemuxer.prototype.readChunk = function() { + var bytes, dataSize, encoding, size; + if (!this.readHeader && this.stream.available(24)) { + if (this.stream.readString(4) !== '.snd') { + return this.emit('error', 'Invalid AU file.'); + } + size = this.stream.readUInt32(); + dataSize = this.stream.readUInt32(); + encoding = this.stream.readUInt32(); + this.format = { + formatID: formats[encoding] || 'lpcm', + littleEndian: false, + floatingPoint: encoding === 6 || encoding === 7, + bitsPerChannel: bps[encoding - 1], + sampleRate: this.stream.readUInt32(), + channelsPerFrame: this.stream.readUInt32(), + framesPerPacket: 1 + }; + if (this.format.bitsPerChannel == null) { + return this.emit('error', 'Unsupported encoding in AU file.'); + } + this.format.bytesPerPacket = (this.format.bitsPerChannel / 8) * this.format.channelsPerFrame; + if (dataSize !== 0xffffffff) { + bytes = this.format.bitsPerChannel / 8; + this.emit('duration', dataSize / bytes / this.format.channelsPerFrame / this.format.sampleRate * 1000 | 0); + } + this.emit('format', this.format); + this.readHeader = true; + } + if (this.readHeader) { + while (this.stream.available(1)) { + this.emit('data', this.stream.readSingleBuffer(this.stream.remainingBytes())); + } + } + }; + + return AUDemuxer; + + })(Demuxer); + +}).call(this); + +},{"../demuxer":14}],17:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var CAFDemuxer, Demuxer, M4ADemuxer, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Demuxer = require('../demuxer'); + + M4ADemuxer = require('./m4a'); + + CAFDemuxer = (function(superClass) { + extend(CAFDemuxer, superClass); + + function CAFDemuxer() { + return CAFDemuxer.__super__.constructor.apply(this, arguments); + } + + Demuxer.register(CAFDemuxer); + + CAFDemuxer.probe = function(buffer) { + return buffer.peekString(0, 4) === 'caff'; + }; + + CAFDemuxer.prototype.readChunk = function() { + var buffer, byteOffset, cookie, entries, flags, i, j, k, key, metadata, offset, ref, ref1, sampleOffset, value; + if (!this.format && this.stream.available(64)) { + if (this.stream.readString(4) !== 'caff') { + return this.emit('error', "Invalid CAF, does not begin with 'caff'"); + } + this.stream.advance(4); + if (this.stream.readString(4) !== 'desc') { + return this.emit('error', "Invalid CAF, 'caff' is not followed by 'desc'"); + } + if (!(this.stream.readUInt32() === 0 && this.stream.readUInt32() === 32)) { + return this.emit('error', "Invalid 'desc' size, should be 32"); + } + this.format = {}; + this.format.sampleRate = this.stream.readFloat64(); + this.format.formatID = this.stream.readString(4); + flags = this.stream.readUInt32(); + if (this.format.formatID === 'lpcm') { + this.format.floatingPoint = Boolean(flags & 1); + this.format.littleEndian = Boolean(flags & 2); + } + this.format.bytesPerPacket = this.stream.readUInt32(); + this.format.framesPerPacket = this.stream.readUInt32(); + this.format.channelsPerFrame = this.stream.readUInt32(); + this.format.bitsPerChannel = this.stream.readUInt32(); + this.emit('format', this.format); + } + while (this.stream.available(1)) { + if (!this.headerCache) { + this.headerCache = { + type: this.stream.readString(4), + oversize: this.stream.readUInt32() !== 0, + size: this.stream.readUInt32() + }; + if (this.headerCache.oversize) { + return this.emit('error', "Holy Shit, an oversized file, not supported in JS"); + } + } + switch (this.headerCache.type) { + case 'kuki': + if (this.stream.available(this.headerCache.size)) { + if (this.format.formatID === 'aac ') { + offset = this.stream.offset + this.headerCache.size; + if (cookie = M4ADemuxer.readEsds(this.stream)) { + this.emit('cookie', cookie); + } + this.stream.seek(offset); + } else { + buffer = this.stream.readBuffer(this.headerCache.size); + this.emit('cookie', buffer); + } + this.headerCache = null; + } + break; + case 'pakt': + if (this.stream.available(this.headerCache.size)) { + if (this.stream.readUInt32() !== 0) { + return this.emit('error', 'Sizes greater than 32 bits are not supported.'); + } + this.numPackets = this.stream.readUInt32(); + if (this.stream.readUInt32() !== 0) { + return this.emit('error', 'Sizes greater than 32 bits are not supported.'); + } + this.numFrames = this.stream.readUInt32(); + this.primingFrames = this.stream.readUInt32(); + this.remainderFrames = this.stream.readUInt32(); + this.emit('duration', this.numFrames / this.format.sampleRate * 1000 | 0); + this.sentDuration = true; + byteOffset = 0; + sampleOffset = 0; + for (i = j = 0, ref = this.numPackets; j < ref; i = j += 1) { + this.addSeekPoint(byteOffset, sampleOffset); + byteOffset += this.format.bytesPerPacket || M4ADemuxer.readDescrLen(this.stream); + sampleOffset += this.format.framesPerPacket || M4ADemuxer.readDescrLen(this.stream); + } + this.headerCache = null; + } + break; + case 'info': + entries = this.stream.readUInt32(); + metadata = {}; + for (i = k = 0, ref1 = entries; 0 <= ref1 ? k < ref1 : k > ref1; i = 0 <= ref1 ? ++k : --k) { + key = this.stream.readString(null); + value = this.stream.readString(null); + metadata[key] = value; + } + this.emit('metadata', metadata); + this.headerCache = null; + break; + case 'data': + if (!this.sentFirstDataChunk) { + this.stream.advance(4); + this.headerCache.size -= 4; + if (this.format.bytesPerPacket !== 0 && !this.sentDuration) { + this.numFrames = this.headerCache.size / this.format.bytesPerPacket; + this.emit('duration', this.numFrames / this.format.sampleRate * 1000 | 0); + } + this.sentFirstDataChunk = true; + } + buffer = this.stream.readSingleBuffer(this.headerCache.size); + this.headerCache.size -= buffer.length; + this.emit('data', buffer); + if (this.headerCache.size <= 0) { + this.headerCache = null; + } + break; + default: + if (this.stream.available(this.headerCache.size)) { + this.stream.advance(this.headerCache.size); + this.headerCache = null; + } + } + } + }; + + return CAFDemuxer; + + })(Demuxer); + +}).call(this); + +},{"../demuxer":14,"./m4a":18}],18:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Demuxer, M4ADemuxer, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty, + indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Demuxer = require('../demuxer'); + + M4ADemuxer = (function(superClass) { + var BITS_PER_CHANNEL, TYPES, after, atom, atoms, bool, containers, diskTrack, genres, meta, string; + + extend(M4ADemuxer, superClass); + + function M4ADemuxer() { + return M4ADemuxer.__super__.constructor.apply(this, arguments); + } + + Demuxer.register(M4ADemuxer); + + TYPES = ['M4A ', 'M4P ', 'M4B ', 'M4V ', 'isom', 'mp42', 'qt ']; + + M4ADemuxer.probe = function(buffer) { + var ref; + return buffer.peekString(4, 4) === 'ftyp' && (ref = buffer.peekString(8, 4), indexOf.call(TYPES, ref) >= 0); + }; + + M4ADemuxer.prototype.init = function() { + this.atoms = []; + this.offsets = []; + this.track = null; + return this.tracks = []; + }; + + atoms = {}; + + containers = {}; + + atom = function(name, fn) { + var c, container, k, len1, ref; + c = []; + ref = name.split('.').slice(0, -1); + for (k = 0, len1 = ref.length; k < len1; k++) { + container = ref[k]; + c.push(container); + containers[c.join('.')] = true; + } + if (atoms[name] == null) { + atoms[name] = {}; + } + return atoms[name].fn = fn; + }; + + after = function(name, fn) { + if (atoms[name] == null) { + atoms[name] = {}; + } + return atoms[name].after = fn; + }; + + M4ADemuxer.prototype.readChunk = function() { + var handler, path, type; + this["break"] = false; + while (this.stream.available(1) && !this["break"]) { + if (!this.readHeaders) { + if (!this.stream.available(8)) { + return; + } + this.len = this.stream.readUInt32() - 8; + this.type = this.stream.readString(4); + if (this.len === 0) { + continue; + } + this.atoms.push(this.type); + this.offsets.push(this.stream.offset + this.len); + this.readHeaders = true; + } + path = this.atoms.join('.'); + handler = atoms[path]; + if (handler != null ? handler.fn : void 0) { + if (!(this.stream.available(this.len) || path === 'mdat')) { + return; + } + handler.fn.call(this); + if (path in containers) { + this.readHeaders = false; + } + } else if (path in containers) { + this.readHeaders = false; + } else { + if (!this.stream.available(this.len)) { + return; + } + this.stream.advance(this.len); + } + while (this.stream.offset >= this.offsets[this.offsets.length - 1]) { + handler = atoms[this.atoms.join('.')]; + if (handler != null ? handler.after : void 0) { + handler.after.call(this); + } + type = this.atoms.pop(); + this.offsets.pop(); + this.readHeaders = false; + } + } + }; + + atom('ftyp', function() { + var ref; + if (ref = this.stream.readString(4), indexOf.call(TYPES, ref) < 0) { + return this.emit('error', 'Not a valid M4A file.'); + } + return this.stream.advance(this.len - 4); + }); + + atom('moov.trak', function() { + this.track = {}; + return this.tracks.push(this.track); + }); + + atom('moov.trak.tkhd', function() { + this.stream.advance(4); + this.stream.advance(8); + this.track.id = this.stream.readUInt32(); + return this.stream.advance(this.len - 16); + }); + + atom('moov.trak.mdia.hdlr', function() { + this.stream.advance(4); + this.stream.advance(4); + this.track.type = this.stream.readString(4); + this.stream.advance(12); + return this.stream.advance(this.len - 24); + }); + + atom('moov.trak.mdia.mdhd', function() { + this.stream.advance(4); + this.stream.advance(8); + this.track.timeScale = this.stream.readUInt32(); + this.track.duration = this.stream.readUInt32(); + return this.stream.advance(4); + }); + + BITS_PER_CHANNEL = { + ulaw: 8, + alaw: 8, + in24: 24, + in32: 32, + fl32: 32, + fl64: 64 + }; + + atom('moov.trak.mdia.minf.stbl.stsd', function() { + var format, numEntries, ref, ref1, version; + this.stream.advance(4); + numEntries = this.stream.readUInt32(); + if (this.track.type !== 'soun') { + return this.stream.advance(this.len - 8); + } + if (numEntries !== 1) { + return this.emit('error', "Only expecting one entry in sample description atom!"); + } + this.stream.advance(4); + format = this.track.format = {}; + format.formatID = this.stream.readString(4); + this.stream.advance(6); + this.stream.advance(2); + version = this.stream.readUInt16(); + this.stream.advance(6); + format.channelsPerFrame = this.stream.readUInt16(); + format.bitsPerChannel = this.stream.readUInt16(); + this.stream.advance(4); + format.sampleRate = this.stream.readUInt16(); + this.stream.advance(2); + if (version === 1) { + format.framesPerPacket = this.stream.readUInt32(); + this.stream.advance(4); + format.bytesPerFrame = this.stream.readUInt32(); + this.stream.advance(4); + } else if (version !== 0) { + this.emit('error', 'Unknown version in stsd atom'); + } + if (BITS_PER_CHANNEL[format.formatID] != null) { + format.bitsPerChannel = BITS_PER_CHANNEL[format.formatID]; + } + format.floatingPoint = (ref = format.formatID) === 'fl32' || ref === 'fl64'; + format.littleEndian = format.formatID === 'sowt' && format.bitsPerChannel > 8; + if ((ref1 = format.formatID) === 'twos' || ref1 === 'sowt' || ref1 === 'in24' || ref1 === 'in32' || ref1 === 'fl32' || ref1 === 'fl64' || ref1 === 'raw ' || ref1 === 'NONE') { + return format.formatID = 'lpcm'; + } + }); + + atom('moov.trak.mdia.minf.stbl.stsd.alac', function() { + this.stream.advance(4); + return this.track.cookie = this.stream.readBuffer(this.len - 4); + }); + + atom('moov.trak.mdia.minf.stbl.stsd.esds', function() { + var offset; + offset = this.stream.offset + this.len; + this.track.cookie = M4ADemuxer.readEsds(this.stream); + return this.stream.seek(offset); + }); + + atom('moov.trak.mdia.minf.stbl.stsd.wave.enda', function() { + return this.track.format.littleEndian = !!this.stream.readUInt16(); + }); + + M4ADemuxer.readDescrLen = function(stream) { + var c, count, len; + len = 0; + count = 4; + while (count--) { + c = stream.readUInt8(); + len = (len << 7) | (c & 0x7f); + if (!(c & 0x80)) { + break; + } + } + return len; + }; + + M4ADemuxer.readEsds = function(stream) { + var codec_id, flags, len, tag; + stream.advance(4); + tag = stream.readUInt8(); + len = M4ADemuxer.readDescrLen(stream); + if (tag === 0x03) { + stream.advance(2); + flags = stream.readUInt8(); + if (flags & 0x80) { + stream.advance(2); + } + if (flags & 0x40) { + stream.advance(stream.readUInt8()); + } + if (flags & 0x20) { + stream.advance(2); + } + } else { + stream.advance(2); + } + tag = stream.readUInt8(); + len = M4ADemuxer.readDescrLen(stream); + if (tag === 0x04) { + codec_id = stream.readUInt8(); + stream.advance(1); + stream.advance(3); + stream.advance(4); + stream.advance(4); + tag = stream.readUInt8(); + len = M4ADemuxer.readDescrLen(stream); + if (tag === 0x05) { + return stream.readBuffer(len); + } + } + return null; + }; + + atom('moov.trak.mdia.minf.stbl.stts', function() { + var entries, i, k, ref; + this.stream.advance(4); + entries = this.stream.readUInt32(); + this.track.stts = []; + for (i = k = 0, ref = entries; k < ref; i = k += 1) { + this.track.stts[i] = { + count: this.stream.readUInt32(), + duration: this.stream.readUInt32() + }; + } + return this.setupSeekPoints(); + }); + + atom('moov.trak.mdia.minf.stbl.stsc', function() { + var entries, i, k, ref; + this.stream.advance(4); + entries = this.stream.readUInt32(); + this.track.stsc = []; + for (i = k = 0, ref = entries; k < ref; i = k += 1) { + this.track.stsc[i] = { + first: this.stream.readUInt32(), + count: this.stream.readUInt32(), + id: this.stream.readUInt32() + }; + } + return this.setupSeekPoints(); + }); + + atom('moov.trak.mdia.minf.stbl.stsz', function() { + var entries, i, k, ref; + this.stream.advance(4); + this.track.sampleSize = this.stream.readUInt32(); + entries = this.stream.readUInt32(); + if (this.track.sampleSize === 0 && entries > 0) { + this.track.sampleSizes = []; + for (i = k = 0, ref = entries; k < ref; i = k += 1) { + this.track.sampleSizes[i] = this.stream.readUInt32(); + } + } + return this.setupSeekPoints(); + }); + + atom('moov.trak.mdia.minf.stbl.stco', function() { + var entries, i, k, ref; + this.stream.advance(4); + entries = this.stream.readUInt32(); + this.track.chunkOffsets = []; + for (i = k = 0, ref = entries; k < ref; i = k += 1) { + this.track.chunkOffsets[i] = this.stream.readUInt32(); + } + return this.setupSeekPoints(); + }); + + atom('moov.trak.tref.chap', function() { + var entries, i, k, ref; + entries = this.len >> 2; + this.track.chapterTracks = []; + for (i = k = 0, ref = entries; k < ref; i = k += 1) { + this.track.chapterTracks[i] = this.stream.readUInt32(); + } + }); + + M4ADemuxer.prototype.setupSeekPoints = function() { + var i, j, k, l, len1, offset, position, ref, ref1, results, sampleIndex, size, stscIndex, sttsIndex, sttsSample, timestamp; + if (!((this.track.chunkOffsets != null) && (this.track.stsc != null) && (this.track.sampleSize != null) && (this.track.stts != null))) { + return; + } + stscIndex = 0; + sttsIndex = 0; + sttsIndex = 0; + sttsSample = 0; + sampleIndex = 0; + offset = 0; + timestamp = 0; + this.track.seekPoints = []; + ref = this.track.chunkOffsets; + results = []; + for (i = k = 0, len1 = ref.length; k < len1; i = ++k) { + position = ref[i]; + for (j = l = 0, ref1 = this.track.stsc[stscIndex].count; l < ref1; j = l += 1) { + this.track.seekPoints.push({ + offset: offset, + position: position, + timestamp: timestamp + }); + size = this.track.sampleSize || this.track.sampleSizes[sampleIndex++]; + offset += size; + position += size; + timestamp += this.track.stts[sttsIndex].duration; + if (sttsIndex + 1 < this.track.stts.length && ++sttsSample === this.track.stts[sttsIndex].count) { + sttsSample = 0; + sttsIndex++; + } + } + if (stscIndex + 1 < this.track.stsc.length && i + 1 === this.track.stsc[stscIndex + 1].first) { + results.push(stscIndex++); + } else { + results.push(void 0); + } + } + return results; + }; + + after('moov', function() { + var k, len1, ref, track; + if (this.mdatOffset != null) { + this.stream.seek(this.mdatOffset - 8); + } + ref = this.tracks; + for (k = 0, len1 = ref.length; k < len1; k++) { + track = ref[k]; + if (!(track.type === 'soun')) { + continue; + } + this.track = track; + break; + } + if (this.track.type !== 'soun') { + this.track = null; + return this.emit('error', 'No audio tracks in m4a file.'); + } + this.emit('format', this.track.format); + this.emit('duration', this.track.duration / this.track.timeScale * 1000 | 0); + if (this.track.cookie) { + this.emit('cookie', this.track.cookie); + } + return this.seekPoints = this.track.seekPoints; + }); + + atom('mdat', function() { + var bytes, chunkSize, k, length, numSamples, offset, ref, sample, size; + if (!this.startedData) { + if (this.mdatOffset == null) { + this.mdatOffset = this.stream.offset; + } + if (this.tracks.length === 0) { + bytes = Math.min(this.stream.remainingBytes(), this.len); + this.stream.advance(bytes); + this.len -= bytes; + return; + } + this.chunkIndex = 0; + this.stscIndex = 0; + this.sampleIndex = 0; + this.tailOffset = 0; + this.tailSamples = 0; + this.startedData = true; + } + if (!this.readChapters) { + this.readChapters = this.parseChapters(); + if (this["break"] = !this.readChapters) { + return; + } + this.stream.seek(this.mdatOffset); + } + offset = this.track.chunkOffsets[this.chunkIndex] + this.tailOffset; + length = 0; + if (!this.stream.available(offset - this.stream.offset)) { + this["break"] = true; + return; + } + this.stream.seek(offset); + while (this.chunkIndex < this.track.chunkOffsets.length) { + numSamples = this.track.stsc[this.stscIndex].count - this.tailSamples; + chunkSize = 0; + for (sample = k = 0, ref = numSamples; k < ref; sample = k += 1) { + size = this.track.sampleSize || this.track.sampleSizes[this.sampleIndex]; + if (!this.stream.available(length + size)) { + break; + } + length += size; + chunkSize += size; + this.sampleIndex++; + } + if (sample < numSamples) { + this.tailOffset += chunkSize; + this.tailSamples += sample; + break; + } else { + this.chunkIndex++; + this.tailOffset = 0; + this.tailSamples = 0; + if (this.stscIndex + 1 < this.track.stsc.length && this.chunkIndex + 1 === this.track.stsc[this.stscIndex + 1].first) { + this.stscIndex++; + } + if (offset + length !== this.track.chunkOffsets[this.chunkIndex]) { + break; + } + } + } + if (length > 0) { + this.emit('data', this.stream.readBuffer(length)); + return this["break"] = this.chunkIndex === this.track.chunkOffsets.length; + } else { + return this["break"] = true; + } + }); + + M4ADemuxer.prototype.parseChapters = function() { + var bom, id, k, len, len1, nextTimestamp, point, ref, ref1, ref2, ref3, title, track; + if (!(((ref = this.track.chapterTracks) != null ? ref.length : void 0) > 0)) { + return true; + } + id = this.track.chapterTracks[0]; + ref1 = this.tracks; + for (k = 0, len1 = ref1.length; k < len1; k++) { + track = ref1[k]; + if (track.id === id) { + break; + } + } + if (track.id !== id) { + this.emit('error', 'Chapter track does not exist.'); + } + if (this.chapters == null) { + this.chapters = []; + } + while (this.chapters.length < track.seekPoints.length) { + point = track.seekPoints[this.chapters.length]; + if (!this.stream.available(point.position - this.stream.offset + 32)) { + return false; + } + this.stream.seek(point.position); + len = this.stream.readUInt16(); + title = null; + if (!this.stream.available(len)) { + return false; + } + if (len > 2) { + bom = this.stream.peekUInt16(); + if (bom === 0xfeff || bom === 0xfffe) { + title = this.stream.readString(len, 'utf16-bom'); + } + } + if (title == null) { + title = this.stream.readString(len, 'utf8'); + } + nextTimestamp = (ref2 = (ref3 = track.seekPoints[this.chapters.length + 1]) != null ? ref3.timestamp : void 0) != null ? ref2 : track.duration; + this.chapters.push({ + title: title, + timestamp: point.timestamp / track.timeScale * 1000 | 0, + duration: (nextTimestamp - point.timestamp) / track.timeScale * 1000 | 0 + }); + } + this.emit('chapters', this.chapters); + return true; + }; + + atom('moov.udta.meta', function() { + this.metadata = {}; + return this.stream.advance(4); + }); + + after('moov.udta.meta', function() { + return this.emit('metadata', this.metadata); + }); + + meta = function(field, name, fn) { + return atom("moov.udta.meta.ilst." + field + ".data", function() { + this.stream.advance(8); + this.len -= 8; + return fn.call(this, name); + }); + }; + + string = function(field) { + return this.metadata[field] = this.stream.readString(this.len, 'utf8'); + }; + + meta('©alb', 'album', string); + + meta('©arg', 'arranger', string); + + meta('©art', 'artist', string); + + meta('©ART', 'artist', string); + + meta('aART', 'albumArtist', string); + + meta('catg', 'category', string); + + meta('©com', 'composer', string); + + meta('©cpy', 'copyright', string); + + meta('cprt', 'copyright', string); + + meta('©cmt', 'comments', string); + + meta('©day', 'releaseDate', string); + + meta('desc', 'description', string); + + meta('©gen', 'genre', string); + + meta('©grp', 'grouping', string); + + meta('©isr', 'ISRC', string); + + meta('keyw', 'keywords', string); + + meta('©lab', 'recordLabel', string); + + meta('ldes', 'longDescription', string); + + meta('©lyr', 'lyrics', string); + + meta('©nam', 'title', string); + + meta('©phg', 'recordingCopyright', string); + + meta('©prd', 'producer', string); + + meta('©prf', 'performers', string); + + meta('purd', 'purchaseDate', string); + + meta('purl', 'podcastURL', string); + + meta('©swf', 'songwriter', string); + + meta('©too', 'encoder', string); + + meta('©wrt', 'composer', string); + + meta('covr', 'coverArt', function(field) { + return this.metadata[field] = this.stream.readBuffer(this.len); + }); + + genres = ["Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A Capella", "Euro-House", "Dance Hall"]; + + meta('gnre', 'genre', function(field) { + return this.metadata[field] = genres[this.stream.readUInt16() - 1]; + }); + + meta('tmpo', 'tempo', function(field) { + return this.metadata[field] = this.stream.readUInt16(); + }); + + meta('rtng', 'rating', function(field) { + var rating; + rating = this.stream.readUInt8(); + return this.metadata[field] = rating === 2 ? 'Clean' : rating !== 0 ? 'Explicit' : 'None'; + }); + + diskTrack = function(field) { + this.stream.advance(2); + this.metadata[field] = this.stream.readUInt16() + ' of ' + this.stream.readUInt16(); + return this.stream.advance(this.len - 6); + }; + + meta('disk', 'diskNumber', diskTrack); + + meta('trkn', 'trackNumber', diskTrack); + + bool = function(field) { + return this.metadata[field] = this.stream.readUInt8() === 1; + }; + + meta('cpil', 'compilation', bool); + + meta('pcst', 'podcast', bool); + + meta('pgap', 'gapless', bool); + + return M4ADemuxer; + + })(Demuxer); + + module.exports = M4ADemuxer; + +}).call(this); + +},{"../demuxer":14}],19:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Demuxer, WAVEDemuxer, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Demuxer = require('../demuxer'); + + WAVEDemuxer = (function(superClass) { + var formats; + + extend(WAVEDemuxer, superClass); + + function WAVEDemuxer() { + return WAVEDemuxer.__super__.constructor.apply(this, arguments); + } + + Demuxer.register(WAVEDemuxer); + + WAVEDemuxer.probe = function(buffer) { + return buffer.peekString(0, 4) === 'RIFF' && buffer.peekString(8, 4) === 'WAVE'; + }; + + formats = { + 0x0001: 'lpcm', + 0x0003: 'lpcm', + 0x0006: 'alaw', + 0x0007: 'ulaw' + }; + + WAVEDemuxer.prototype.readChunk = function() { + var buffer, bytes, encoding; + if (!this.readStart && this.stream.available(12)) { + if (this.stream.readString(4) !== 'RIFF') { + return this.emit('error', 'Invalid WAV file.'); + } + this.fileSize = this.stream.readUInt32(true); + this.readStart = true; + if (this.stream.readString(4) !== 'WAVE') { + return this.emit('error', 'Invalid WAV file.'); + } + } + while (this.stream.available(1)) { + if (!this.readHeaders && this.stream.available(8)) { + this.type = this.stream.readString(4); + this.len = this.stream.readUInt32(true); + } + switch (this.type) { + case 'fmt ': + encoding = this.stream.readUInt16(true); + if (!(encoding in formats)) { + return this.emit('error', 'Unsupported format in WAV file.'); + } + this.format = { + formatID: formats[encoding], + floatingPoint: encoding === 0x0003, + littleEndian: formats[encoding] === 'lpcm', + channelsPerFrame: this.stream.readUInt16(true), + sampleRate: this.stream.readUInt32(true), + framesPerPacket: 1 + }; + this.stream.advance(4); + this.stream.advance(2); + this.format.bitsPerChannel = this.stream.readUInt16(true); + this.format.bytesPerPacket = (this.format.bitsPerChannel / 8) * this.format.channelsPerFrame; + this.emit('format', this.format); + this.stream.advance(this.len - 16); + break; + case 'data': + if (!this.sentDuration) { + bytes = this.format.bitsPerChannel / 8; + this.emit('duration', this.len / bytes / this.format.channelsPerFrame / this.format.sampleRate * 1000 | 0); + this.sentDuration = true; + } + buffer = this.stream.readSingleBuffer(this.len); + this.len -= buffer.length; + this.readHeaders = this.len > 0; + this.emit('data', buffer); + break; + default: + if (!this.stream.available(this.len)) { + return; + } + this.stream.advance(this.len); + } + if (this.type !== 'data') { + this.readHeaders = false; + } + } + }; + + return WAVEDemuxer; + + })(Demuxer); + +}).call(this); + +},{"../demuxer":14}],20:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AudioDevice, EventEmitter, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('./core/events'); + + AudioDevice = (function(superClass) { + var devices; + + extend(AudioDevice, superClass); + + function AudioDevice(sampleRate1, channels1) { + this.sampleRate = sampleRate1; + this.channels = channels1; + this.updateTime = bind(this.updateTime, this); + this.playing = false; + this.currentTime = 0; + this._lastTime = 0; + } + + AudioDevice.prototype.start = function() { + if (this.playing) { + return; + } + this.playing = true; + if (this.device == null) { + this.device = AudioDevice.create(this.sampleRate, this.channels); + } + if (!this.device) { + throw new Error("No supported audio device found."); + } + this._lastTime = this.device.getDeviceTime(); + this._timer = setInterval(this.updateTime, 200); + return this.device.on('refill', this.refill = (function(_this) { + return function(buffer) { + return _this.emit('refill', buffer); + }; + })(this)); + }; + + AudioDevice.prototype.stop = function() { + if (!this.playing) { + return; + } + this.playing = false; + this.device.off('refill', this.refill); + return clearInterval(this._timer); + }; + + AudioDevice.prototype.destroy = function() { + var ref; + this.stop(); + return (ref = this.device) != null ? ref.destroy() : void 0; + }; + + AudioDevice.prototype.seek = function(currentTime) { + this.currentTime = currentTime; + if (this.playing) { + this._lastTime = this.device.getDeviceTime(); + } + return this.emit('timeUpdate', this.currentTime); + }; + + AudioDevice.prototype.updateTime = function() { + var time; + time = this.device.getDeviceTime(); + this.currentTime += (time - this._lastTime) / this.device.sampleRate * 1000 | 0; + this._lastTime = time; + return this.emit('timeUpdate', this.currentTime); + }; + + devices = []; + + AudioDevice.register = function(device) { + return devices.push(device); + }; + + AudioDevice.create = function(sampleRate, channels) { + var device, i, len; + for (i = 0, len = devices.length; i < len; i++) { + device = devices[i]; + if (device.supported) { + return new device(sampleRate, channels); + } + } + return null; + }; + + return AudioDevice; + + })(EventEmitter); + + module.exports = AudioDevice; + +}).call(this); + +},{"./core/events":8}],21:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AVBuffer, AudioDevice, EventEmitter, MozillaAudioDevice, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('../core/events'); + + AudioDevice = require('../device'); + + AVBuffer = require('../core/buffer'); + + MozillaAudioDevice = (function(superClass) { + var createTimer, destroyTimer; + + extend(MozillaAudioDevice, superClass); + + AudioDevice.register(MozillaAudioDevice); + + MozillaAudioDevice.supported = (typeof Audio !== "undefined" && Audio !== null) && 'mozWriteAudio' in new Audio; + + function MozillaAudioDevice(sampleRate, channels) { + this.sampleRate = sampleRate; + this.channels = channels; + this.refill = bind(this.refill, this); + this.audio = new Audio; + this.audio.mozSetup(this.channels, this.sampleRate); + this.writePosition = 0; + this.prebufferSize = this.sampleRate / 2; + this.tail = null; + this.timer = createTimer(this.refill, 100); + } + + MozillaAudioDevice.prototype.refill = function() { + var available, buffer, currentPosition, written; + if (this.tail) { + written = this.audio.mozWriteAudio(this.tail); + this.writePosition += written; + if (this.writePosition < this.tail.length) { + this.tail = this.tail.subarray(written); + } else { + this.tail = null; + } + } + currentPosition = this.audio.mozCurrentSampleOffset(); + available = currentPosition + this.prebufferSize - this.writePosition; + if (available > 0) { + buffer = new Float32Array(available); + this.emit('refill', buffer); + written = this.audio.mozWriteAudio(buffer); + if (written < buffer.length) { + this.tail = buffer.subarray(written); + } + this.writePosition += written; + } + }; + + MozillaAudioDevice.prototype.destroy = function() { + return destroyTimer(this.timer); + }; + + MozillaAudioDevice.prototype.getDeviceTime = function() { + return this.audio.mozCurrentSampleOffset() / this.channels; + }; + + createTimer = function(fn, interval) { + var url, worker; + url = AVBuffer.makeBlobURL("setInterval(function() { postMessage('ping'); }, " + interval + ");"); + if (url == null) { + return setInterval(fn, interval); + } + worker = new Worker(url); + worker.onmessage = fn; + worker.url = url; + return worker; + }; + + destroyTimer = function(timer) { + if (timer.terminate) { + timer.terminate(); + return URL.revokeObjectURL(timer.url); + } else { + return clearInterval(timer); + } + }; + + return MozillaAudioDevice; + + })(EventEmitter); + +}).call(this); + +},{"../core/buffer":6,"../core/events":8,"../device":20}],22:[function(require,module,exports){ +//JavaScript Audio Resampler +//Copyright (C) 2011-2015 Grant Galitz +//Released to Public Domain +function Resampler(fromSampleRate, toSampleRate, channels, inputBufferLength) { + this.fromSampleRate = +fromSampleRate; + this.toSampleRate = +toSampleRate; + this.channels = channels | 0; + this.inputBufferLength = inputBufferLength; + this.initialize(); +} + +Resampler.prototype.initialize = function () { + //Perform some checks: + if (this.fromSampleRate > 0 && this.toSampleRate > 0 && this.channels > 0) { + if (this.fromSampleRate == this.toSampleRate) { + //Setup a resampler bypass: + this.resampler = this.bypassResampler; //Resampler just returns what was passed through. + this.ratioWeight = 1; + } else { + this.ratioWeight = this.fromSampleRate / this.toSampleRate; + if (this.fromSampleRate < this.toSampleRate) { + /* + Use generic linear interpolation if upsampling, + as linear interpolation produces a gradient that we want + and works fine with two input sample points per output in this case. + */ + this.compileLinearInterpolationFunction(); + this.lastWeight = 1; + } else { + /* + Custom resampler I wrote that doesn't skip samples + like standard linear interpolation in high downsampling. + This is more accurate than linear interpolation on downsampling. + */ + this.compileMultiTapFunction(); + this.tailExists = false; + this.lastWeight = 0; + } + + var outputBufferSize = (Math.ceil(this.inputBufferLength * this.toSampleRate / this.fromSampleRate / this.channels * 1.01) * this.channels) + this.channels; + this.outputBuffer = new Float32Array(outputBufferSize); + this.lastOutput = new Float32Array(this.channels); + } + } else { + throw(new Error("Invalid settings specified for the resampler.")); + } +}; + +Resampler.prototype.compileLinearInterpolationFunction = function () { + var toCompile = "var outputOffset = 0;\ + var bufferLength = buffer.length;\ + if (bufferLength > 0) {\ + var weight = this.lastWeight;\ + var firstWeight = 0;\ + var secondWeight = 0;\ + var sourceOffset = 0;\ + var outputOffset = 0;\ + var outputBuffer = this.outputBuffer;\ + for (; weight < 1; weight += " + this.ratioWeight + ") {\ + secondWeight = weight % 1;\ + firstWeight = 1 - secondWeight;"; + for (var channel = 0; channel < this.channels; ++channel) { + toCompile += "outputBuffer[outputOffset++] = (this.lastOutput[" + channel + "] * firstWeight) + (buffer[" + channel + "] * secondWeight);"; + } + toCompile += "}\ + weight -= 1;\ + for (bufferLength -= " + this.channels + ", sourceOffset = Math.floor(weight) * " + this.channels + "; sourceOffset < bufferLength;) {\ + secondWeight = weight % 1;\ + firstWeight = 1 - secondWeight;"; + for (var channel = 0; channel < this.channels; ++channel) { + toCompile += "outputBuffer[outputOffset++] = (buffer[sourceOffset" + ((channel > 0) ? (" + " + channel) : "") + "] * firstWeight) + (buffer[sourceOffset + " + (this.channels + channel) + "] * secondWeight);"; + } + toCompile += "weight += " + this.ratioWeight + ";\ + sourceOffset = Math.floor(weight) * " + this.channels + ";\ + }"; + for (var channel = 0; channel < this.channels; ++channel) { + toCompile += "this.lastOutput[" + channel + "] = buffer[sourceOffset++];"; + } + toCompile += "this.lastWeight = weight % 1;\ + }\ + return this.outputBuffer;"; + + this.resampler = Function("buffer", toCompile); +}; + +Resampler.prototype.compileMultiTapFunction = function () { + var toCompile = "var outputOffset = 0;\ + var bufferLength = buffer.length;\ + if (bufferLength > 0) {\ + var weight = 0;"; + for (var channel = 0; channel < this.channels; ++channel) { + toCompile += "var output" + channel + " = 0;" + } + toCompile += "var actualPosition = 0;\ + var amountToNext = 0;\ + var alreadyProcessedTail = !this.tailExists;\ + this.tailExists = false;\ + var outputBuffer = this.outputBuffer;\ + var currentPosition = 0;\ + do {\ + if (alreadyProcessedTail) {\ + weight = " + this.ratioWeight + ";"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "output" + channel + " = 0;" + } + toCompile += "}\ + else {\ + weight = this.lastWeight;"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "output" + channel + " = this.lastOutput[" + channel + "];" + } + toCompile += "alreadyProcessedTail = true;\ + }\ + while (weight > 0 && actualPosition < bufferLength) {\ + amountToNext = 1 + actualPosition - currentPosition;\ + if (weight >= amountToNext) {"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "output" + channel + " += buffer[actualPosition++] * amountToNext;" + } + toCompile += "currentPosition = actualPosition;\ + weight -= amountToNext;\ + }\ + else {"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "output" + channel + " += buffer[actualPosition" + ((channel > 0) ? (" + " + channel) : "") + "] * weight;" + } + toCompile += "currentPosition += weight;\ + weight = 0;\ + break;\ + }\ + }\ + if (weight <= 0) {"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "outputBuffer[outputOffset++] = output" + channel + " / " + this.ratioWeight + ";" + } + toCompile += "}\ + else {\ + this.lastWeight = weight;"; + for (channel = 0; channel < this.channels; ++channel) { + toCompile += "this.lastOutput[" + channel + "] = output" + channel + ";" + } + toCompile += "this.tailExists = true;\ + break;\ + }\ + } while (actualPosition < bufferLength);\ + }\ + return this.outputBuffer;"; + + this.resampler = Function("buffer", toCompile); +}; + +Resampler.prototype.bypassResampler = function (inputBuffer) { + return inputBuffer; +}; + +module.exports = Resampler; + +},{}],23:[function(require,module,exports){ +(function (global){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AudioDevice, EventEmitter, Resampler, WebAudioDevice, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('../core/events'); + + AudioDevice = require('../device'); + + Resampler = require('./resampler'); + + WebAudioDevice = (function(superClass) { + var AudioContext, createProcessor, sharedContext; + + extend(WebAudioDevice, superClass); + + AudioDevice.register(WebAudioDevice); + + AudioContext = global.AudioContext || global.webkitAudioContext; + + WebAudioDevice.supported = AudioContext && (typeof AudioContext.prototype[createProcessor = 'createScriptProcessor'] === 'function' || typeof AudioContext.prototype[createProcessor = 'createJavaScriptNode'] === 'function'); + + sharedContext = null; + + function WebAudioDevice(sampleRate, channels1) { + this.sampleRate = sampleRate; + this.channels = channels1; + this.refill = bind(this.refill, this); + this.context = sharedContext != null ? sharedContext : sharedContext = new AudioContext; + this.deviceSampleRate = this.context.sampleRate; + this.bufferSize = Math.ceil(4096 / (this.deviceSampleRate / this.sampleRate) * this.channels); + this.bufferSize += this.bufferSize % this.channels; + if (this.deviceSampleRate !== this.sampleRate) { + this.resampler = new Resampler(this.sampleRate, this.deviceSampleRate, this.channels, this.bufferSize); + } + this.node = this.context[createProcessor](4096, this.channels, this.channels); + this.node.onaudioprocess = this.refill; + this.node.connect(this.context.destination); + } + + WebAudioDevice.prototype.refill = function(event) { + var channelCount, channels, data, i, j, k, l, n, outputBuffer, ref, ref1, ref2; + outputBuffer = event.outputBuffer; + channelCount = outputBuffer.numberOfChannels; + channels = new Array(channelCount); + for (i = j = 0, ref = channelCount; j < ref; i = j += 1) { + channels[i] = outputBuffer.getChannelData(i); + } + data = new Float32Array(this.bufferSize); + this.emit('refill', data); + if (this.resampler) { + data = this.resampler.resampler(data); + } + for (i = k = 0, ref1 = outputBuffer.length; k < ref1; i = k += 1) { + for (n = l = 0, ref2 = channelCount; l < ref2; n = l += 1) { + channels[n][i] = data[i * channelCount + n]; + } + } + }; + + WebAudioDevice.prototype.destroy = function() { + return this.node.disconnect(0); + }; + + WebAudioDevice.prototype.getDeviceTime = function() { + return this.context.currentTime * this.sampleRate; + }; + + return WebAudioDevice; + + })(EventEmitter); + +}).call(this); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"../core/events":8,"../device":20,"./resampler":22}],24:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Filter; + + Filter = (function() { + function Filter(context, key) { + if (context && key) { + Object.defineProperty(this, 'value', { + get: function() { + return context[key]; + } + }); + } + } + + Filter.prototype.process = function(buffer) {}; + + return Filter; + + })(); + + module.exports = Filter; + +}).call(this); + +},{}],25:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var BalanceFilter, Filter, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Filter = require('../filter'); + + BalanceFilter = (function(superClass) { + extend(BalanceFilter, superClass); + + function BalanceFilter() { + return BalanceFilter.__super__.constructor.apply(this, arguments); + } + + BalanceFilter.prototype.process = function(buffer) { + var i, j, pan, ref; + if (this.value === 0) { + return; + } + pan = Math.max(-50, Math.min(50, this.value)); + for (i = j = 0, ref = buffer.length; j < ref; i = j += 2) { + buffer[i] *= Math.min(1, (50 - pan) / 50); + buffer[i + 1] *= Math.min(1, (50 + pan) / 50); + } + }; + + return BalanceFilter; + + })(Filter); + + module.exports = BalanceFilter; + +}).call(this); + +},{"../filter":24}],26:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Filter, VolumeFilter, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + Filter = require('../filter'); + + VolumeFilter = (function(superClass) { + extend(VolumeFilter, superClass); + + function VolumeFilter() { + return VolumeFilter.__super__.constructor.apply(this, arguments); + } + + VolumeFilter.prototype.process = function(buffer) { + var i, j, ref, vol; + if (this.value >= 100) { + return; + } + vol = Math.max(0, Math.min(100, this.value)) / 100; + for (i = j = 0, ref = buffer.length; j < ref; i = j += 1) { + buffer[i] *= vol; + } + }; + + return VolumeFilter; + + })(Filter); + + module.exports = VolumeFilter; + +}).call(this); + +},{"../filter":24}],27:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var Asset, AudioDevice, BalanceFilter, EventEmitter, Player, Queue, VolumeFilter, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('./core/events'); + + Asset = require('./asset'); + + VolumeFilter = require('./filters/volume'); + + BalanceFilter = require('./filters/balance'); + + Queue = require('./queue'); + + AudioDevice = require('./device'); + + Player = (function(superClass) { + extend(Player, superClass); + + function Player(asset) { + this.asset = asset; + this.startPlaying = bind(this.startPlaying, this); + this.playing = false; + this.buffered = 0; + this.currentTime = 0; + this.duration = 0; + this.volume = 100; + this.pan = 0; + this.metadata = {}; + this.filters = [new VolumeFilter(this, 'volume'), new BalanceFilter(this, 'pan')]; + this.asset.on('buffer', (function(_this) { + return function(buffered) { + _this.buffered = buffered; + return _this.emit('buffer', _this.buffered); + }; + })(this)); + this.asset.on('decodeStart', (function(_this) { + return function() { + _this.queue = new Queue(_this.asset); + return _this.queue.once('ready', _this.startPlaying); + }; + })(this)); + this.asset.on('format', (function(_this) { + return function(format) { + _this.format = format; + return _this.emit('format', _this.format); + }; + })(this)); + this.asset.on('metadata', (function(_this) { + return function(metadata) { + _this.metadata = metadata; + return _this.emit('metadata', _this.metadata); + }; + })(this)); + this.asset.on('duration', (function(_this) { + return function(duration) { + _this.duration = duration; + return _this.emit('duration', _this.duration); + }; + })(this)); + this.asset.on('error', (function(_this) { + return function(error) { + return _this.emit('error', error); + }; + })(this)); + } + + Player.fromURL = function(url, opts) { + return new Player(Asset.fromURL(url, opts)); + }; + + Player.fromFile = function(file) { + return new Player(Asset.fromFile(file)); + }; + + Player.fromBuffer = function(buffer) { + return new Player(Asset.fromBuffer(buffer)); + }; + + Player.prototype.preload = function() { + if (!this.asset) { + return; + } + this.startedPreloading = true; + return this.asset.start(false); + }; + + Player.prototype.play = function() { + var ref; + if (this.playing) { + return; + } + if (!this.startedPreloading) { + this.preload(); + } + this.playing = true; + return (ref = this.device) != null ? ref.start() : void 0; + }; + + Player.prototype.pause = function() { + var ref; + if (!this.playing) { + return; + } + this.playing = false; + return (ref = this.device) != null ? ref.stop() : void 0; + }; + + Player.prototype.togglePlayback = function() { + if (this.playing) { + return this.pause(); + } else { + return this.play(); + } + }; + + Player.prototype.stop = function() { + var ref; + this.pause(); + this.asset.stop(); + return (ref = this.device) != null ? ref.destroy() : void 0; + }; + + Player.prototype.seek = function(timestamp) { + var ref; + if ((ref = this.device) != null) { + ref.stop(); + } + this.queue.once('ready', (function(_this) { + return function() { + var ref1, ref2; + if ((ref1 = _this.device) != null) { + ref1.seek(_this.currentTime); + } + if (_this.playing) { + return (ref2 = _this.device) != null ? ref2.start() : void 0; + } + }; + })(this)); + timestamp = (timestamp / 1000) * this.format.sampleRate; + timestamp = this.asset.decoder.seek(timestamp); + this.currentTime = timestamp / this.format.sampleRate * 1000 | 0; + this.queue.reset(); + return this.currentTime; + }; + + Player.prototype.startPlaying = function() { + var frame, frameOffset; + frame = this.queue.read(); + frameOffset = 0; + this.device = new AudioDevice(this.format.sampleRate, this.format.channelsPerFrame); + this.device.on('timeUpdate', (function(_this) { + return function(currentTime) { + _this.currentTime = currentTime; + return _this.emit('progress', _this.currentTime); + }; + })(this)); + this.refill = (function(_this) { + return function(buffer) { + var bufferOffset, filter, i, j, k, len, max, ref, ref1; + if (!_this.playing) { + return; + } + if (!frame) { + frame = _this.queue.read(); + frameOffset = 0; + } + bufferOffset = 0; + while (frame && bufferOffset < buffer.length) { + max = Math.min(frame.length - frameOffset, buffer.length - bufferOffset); + for (i = j = 0, ref = max; j < ref; i = j += 1) { + buffer[bufferOffset++] = frame[frameOffset++]; + } + if (frameOffset === frame.length) { + frame = _this.queue.read(); + frameOffset = 0; + } + } + ref1 = _this.filters; + for (k = 0, len = ref1.length; k < len; k++) { + filter = ref1[k]; + filter.process(buffer); + } + if (!frame) { + if (_this.queue.ended) { + _this.currentTime = _this.duration; + _this.emit('progress', _this.currentTime); + _this.emit('end'); + _this.stop(); + } else { + _this.device.stop(); + } + } + }; + })(this); + this.device.on('refill', this.refill); + if (this.playing) { + this.device.start(); + } + return this.emit('ready'); + }; + + Player.prototype.destroy = function() { + var ref, ref1; + this.stop(); + if ((ref = this.device) != null) { + ref.off(); + } + if ((ref1 = this.asset) != null) { + ref1.destroy(); + } + return this.off(); + }; + + return Player; + + })(EventEmitter); + + module.exports = Player; + +}).call(this); + +},{"./asset":1,"./core/events":8,"./device":20,"./filters/balance":25,"./filters/volume":26,"./queue":28}],28:[function(require,module,exports){ +// Generated by CoffeeScript 1.11.1 +(function() { + var EventEmitter, Queue, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('./core/events'); + + Queue = (function(superClass) { + extend(Queue, superClass); + + function Queue(asset) { + this.asset = asset; + this.write = bind(this.write, this); + this.readyMark = 64; + this.finished = false; + this.buffering = true; + this.ended = false; + this.buffers = []; + this.asset.on('data', this.write); + this.asset.on('end', (function(_this) { + return function() { + return _this.ended = true; + }; + })(this)); + this.asset.decodePacket(); + } + + Queue.prototype.write = function(buffer) { + if (buffer) { + this.buffers.push(buffer); + } + if (this.buffering) { + if (this.buffers.length >= this.readyMark || this.ended) { + this.buffering = false; + return this.emit('ready'); + } else { + return this.asset.decodePacket(); + } + } + }; + + Queue.prototype.read = function() { + if (this.buffers.length === 0) { + return null; + } + this.asset.decodePacket(); + return this.buffers.shift(); + }; + + Queue.prototype.reset = function() { + this.buffers.length = 0; + this.buffering = true; + return this.asset.decodePacket(); + }; + + return Queue; + + })(EventEmitter); + + module.exports = Queue; + +}).call(this); + +},{"./core/events":8}],29:[function(require,module,exports){ +var AVBuffer, EventEmitter, FileSource, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + +EventEmitter = require('../../core/events'); + +AVBuffer = require('../../core/buffer'); + +FileSource = (function(_super) { + __extends(FileSource, _super); + + function FileSource(file) { + this.file = file; + if (typeof FileReader === "undefined" || FileReader === null) { + return this.emit('error', 'This browser does not have FileReader support.'); + } + this.offset = 0; + this.length = this.file.size; + this.chunkSize = 1 << 20; + this.file[this.slice = 'slice'] || this.file[this.slice = 'webkitSlice'] || this.file[this.slice = 'mozSlice']; + } + + FileSource.prototype.start = function() { + if (this.reader) { + if (!this.active) { + return this.loop(); + } + } + this.reader = new FileReader; + this.active = true; + this.reader.onload = (function(_this) { + return function(e) { + var buf; + buf = new AVBuffer(new Uint8Array(e.target.result)); + _this.offset += buf.length; + _this.emit('data', buf); + _this.active = false; + if (_this.offset < _this.length) { + return _this.loop(); + } + }; + })(this); + this.reader.onloadend = (function(_this) { + return function() { + if (_this.offset === _this.length) { + _this.emit('end'); + return _this.reader = null; + } + }; + })(this); + this.reader.onerror = (function(_this) { + return function(e) { + return _this.emit('error', e); + }; + })(this); + this.reader.onprogress = (function(_this) { + return function(e) { + return _this.emit('progress', (_this.offset + e.loaded) / _this.length * 100); + }; + })(this); + return this.loop(); + }; + + FileSource.prototype.loop = function() { + var blob, endPos; + this.active = true; + endPos = Math.min(this.offset + this.chunkSize, this.length); + blob = this.file[this.slice](this.offset, endPos); + return this.reader.readAsArrayBuffer(blob); + }; + + FileSource.prototype.pause = function() { + var _ref; + this.active = false; + try { + return (_ref = this.reader) != null ? _ref.abort() : void 0; + } catch (_error) {} + }; + + FileSource.prototype.reset = function() { + this.pause(); + return this.offset = 0; + }; + + return FileSource; + +})(EventEmitter); + +module.exports = FileSource; + +},{"../../core/buffer":6,"../../core/events":8}],30:[function(require,module,exports){ +var AVBuffer, EventEmitter, HTTPSource, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + +EventEmitter = require('../../core/events'); + +AVBuffer = require('../../core/buffer'); + +HTTPSource = (function(_super) { + __extends(HTTPSource, _super); + + function HTTPSource(url, opts) { + this.url = url; + this.opts = opts != null ? opts : {}; + this.chunkSize = 1 << 20; + this.inflight = false; + if (this.opts.length) { + this.length = this.opts.length; + } + this.reset(); + } + + HTTPSource.prototype.start = function() { + if (this.length) { + if (!this.inflight) { + return this.loop(); + } + } + this.inflight = true; + this.xhr = new XMLHttpRequest(); + this.xhr.onload = (function(_this) { + return function(event) { + _this.length = parseInt(_this.xhr.getResponseHeader("Content-Length")); + _this.inflight = false; + return _this.loop(); + }; + })(this); + this.xhr.onerror = (function(_this) { + return function(err) { + _this.pause(); + return _this.emit('error', err); + }; + })(this); + this.xhr.onabort = (function(_this) { + return function(event) { + return _this.inflight = false; + }; + })(this); + this.xhr.open("HEAD", this.url, true); + return this.xhr.send(null); + }; + + HTTPSource.prototype.loop = function() { + var endPos; + if (this.inflight || !this.length) { + return this.emit('error', 'Something is wrong in HTTPSource.loop'); + } + this.inflight = true; + this.xhr = new XMLHttpRequest(); + this.xhr.onload = (function(_this) { + return function(event) { + var buf, buffer, i, txt, _i, _ref; + if (_this.xhr.response) { + buf = new Uint8Array(_this.xhr.response); + } else { + txt = _this.xhr.responseText; + buf = new Uint8Array(txt.length); + for (i = _i = 0, _ref = txt.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + buf[i] = txt.charCodeAt(i) & 0xff; + } + } + buffer = new AVBuffer(buf); + _this.offset += buffer.length; + _this.emit('data', buffer); + if (_this.offset >= _this.length) { + _this.emit('end'); + } + _this.inflight = false; + if (!(_this.offset >= _this.length)) { + return _this.loop(); + } + }; + })(this); + this.xhr.onprogress = (function(_this) { + return function(event) { + return _this.emit('progress', (_this.offset + event.loaded) / _this.length * 100); + }; + })(this); + this.xhr.onerror = (function(_this) { + return function(err) { + _this.emit('error', err); + return _this.pause(); + }; + })(this); + this.xhr.onabort = (function(_this) { + return function(event) { + return _this.inflight = false; + }; + })(this); + this.xhr.open("GET", this.url, true); + this.xhr.responseType = "arraybuffer"; + endPos = Math.min(this.offset + this.chunkSize, this.length - 1); + this.xhr.setRequestHeader("If-None-Match", "webkit-no-cache"); + this.xhr.setRequestHeader("Range", "bytes=" + this.offset + "-" + endPos); + this.xhr.overrideMimeType('text/plain; charset=x-user-defined'); + return this.xhr.send(null); + }; + + HTTPSource.prototype.pause = function() { + var _ref; + this.inflight = false; + return (_ref = this.xhr) != null ? _ref.abort() : void 0; + }; + + HTTPSource.prototype.reset = function() { + this.pause(); + return this.offset = 0; + }; + + return HTTPSource; + +})(EventEmitter); + +module.exports = HTTPSource; + +},{"../../core/buffer":6,"../../core/events":8}],31:[function(require,module,exports){ +(function (global){ +// Generated by CoffeeScript 1.11.1 +(function() { + var AVBuffer, BufferList, BufferSource, EventEmitter, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + EventEmitter = require('../core/events'); + + BufferList = require('../core/bufferlist'); + + AVBuffer = require('../core/buffer'); + + BufferSource = (function(superClass) { + var clearImmediate, setImmediate; + + extend(BufferSource, superClass); + + function BufferSource(input) { + this.loop = bind(this.loop, this); + if (input instanceof BufferList) { + this.list = input; + } else { + this.list = new BufferList; + this.list.append(new AVBuffer(input)); + } + this.paused = true; + } + + setImmediate = global.setImmediate || function(fn) { + return global.setTimeout(fn, 0); + }; + + clearImmediate = global.clearImmediate || function(timer) { + return global.clearTimeout(timer); + }; + + BufferSource.prototype.start = function() { + this.paused = false; + return this._timer = setImmediate(this.loop); + }; + + BufferSource.prototype.loop = function() { + this.emit('progress', (this.list.numBuffers - this.list.availableBuffers + 1) / this.list.numBuffers * 100 | 0); + this.emit('data', this.list.first); + if (this.list.advance()) { + return setImmediate(this.loop); + } else { + return this.emit('end'); + } + }; + + BufferSource.prototype.pause = function() { + clearImmediate(this._timer); + return this.paused = true; + }; + + BufferSource.prototype.reset = function() { + this.pause(); + return this.list.rewind(); + }; + + return BufferSource; + + })(EventEmitter); + + module.exports = BufferSource; + +}).call(this); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"../core/buffer":6,"../core/bufferlist":7,"../core/events":8}],32:[function(require,module,exports){ +var key, val, _ref; + +_ref = require('./src/aurora'); +for (key in _ref) { + val = _ref[key]; + exports[key] = val; +} + +require('./src/devices/webaudio'); + +require('./src/devices/mozilla'); + +},{"./src/aurora":2,"./src/devices/mozilla":21,"./src/devices/webaudio":23}]},{},[32])(32) +}); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYXNzZXQuanMiLCJzcmMvYXVyb3JhLmpzIiwic3JjL2F1cm9yYV9iYXNlLmpzIiwic3JjL2NvcmUvYmFzZS5qcyIsInNyYy9jb3JlL2JpdHN0cmVhbS5qcyIsInNyYy9jb3JlL2J1ZmZlci5qcyIsInNyYy9jb3JlL2J1ZmZlcmxpc3QuanMiLCJzcmMvY29yZS9ldmVudHMuanMiLCJzcmMvY29yZS9zdHJlYW0uanMiLCJzcmMvY29yZS91bmRlcmZsb3cuanMiLCJzcmMvZGVjb2Rlci5qcyIsInNyYy9kZWNvZGVycy9scGNtLmpzIiwic3JjL2RlY29kZXJzL3hsYXcuanMiLCJzcmMvZGVtdXhlci5qcyIsInNyYy9kZW11eGVycy9haWZmLmpzIiwic3JjL2RlbXV4ZXJzL2F1LmpzIiwic3JjL2RlbXV4ZXJzL2NhZi5qcyIsInNyYy9kZW11eGVycy9tNGEuanMiLCJzcmMvZGVtdXhlcnMvd2F2ZS5qcyIsInNyYy9kZXZpY2UuanMiLCJzcmMvZGV2aWNlcy9tb3ppbGxhLmpzIiwic3JjL2RldmljZXMvcmVzYW1wbGV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gICAgICB9XG5cbiAgICAgICAgcmV0dXJuIENsYXNzO1xuXG4gICAgICB9KSh0aGlzKTtcbiAgICAgIGlmICh0eXBlb2YgcHJvcCA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgICBrZXlzID0gT2JqZWN0LmtleXMoQ2xhc3MucHJvdG90eXBlKTtcbiAgICAgICAgcHJvcC5jYWxsKENsYXNzLCBDbGFzcyk7XG4gICAgICAgIHByb3AgPSB7fTtcbiAgICAgICAgcmVmID0gQ2xhc3MucHJvdG90eXBlO1xuICAgICAgICBmb3IgKGtleSBpbiByZWYpIHtcbiAgICAgICAgICBmbiA9IHJlZltrZXldO1xuICAgICAgICAgIGlmIChpbmRleE9mLmNhbGwoa2V5cywga2V5KSA8IDApIHtcbiAgICAgICAgICAgIHByb3Bba2V5XSA9IGZuO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuICAgICAgX3N1cGVyID0gQ2xhc3MuX19zdXBlcl9fO1xuICAgICAgZm9yIChrZXkgaW4gcHJvcCkge1xuICAgICAgICBmbiA9IHByb3Bba2V5XTtcbiAgICAgICAgaWYgKHR5cGVvZiBmbiA9PT0gJ2Z1bmN0aW9uJyAmJiBmblRlc3QudGVzdChmbikpIHtcbiAgICAgICAgICAoZnVuY3Rpb24oa2V5LCBmbikge1xuICAgICAgICAgICAgcmV0dXJuIENsYXNzLnByb3RvdHlwZVtrZXldID0gZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgIHZhciByZXQsIHRtcDtcbiAgICAgICAgICAgICAgdG1wID0gdGhpcy5fc3VwZXI7XG4gICAgICAgICAgICAgIHRoaXMuX3N1cGVyID0gX3N1cGVyW2tleV07XG4gICAgICAgICAgICAgIHJldCA9IGZuLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7XG4gICAgICAgICAgICAgIHRoaXMuX3N1cGVyID0gdG1wO1xuICAgICAgICAgICAgICByZXR1cm4gcmV0O1xuICAgICAgICAgICAgfTtcbiAgICAgICAgIC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gdGhpcy5zdHJlYW0ucGVla1VJbnQ4KDEpIDw8IDI0ID4+PiAwO1xuICAgICAgICBhMiA9IHRoaXMuc3RyZWFtLnBlZWtVSW50OCgyKSA8PCAxNjtcbiAgICAgICAgYTMgPSB0aGlzLnN0cmVhbS5wZWVrVUludDgoMykgPDwgODtcbiAgICAgICAgYTQgPSB0aGlzLnN0cmVhbS5wZWVrVUludDgoNCk7XG4gICAgICAgIGEgPSBhMCArIGExICsgYTIgKyBhMyArIGE0O1xuICAgICAgICBhICU9IE1hdGgucG93KDIsIDQwIC0gdGhpcy5iaXRQb3NpdGlvbik7XG4gICAgICAgIGEgPSBNYXRoLmZsb29yKGEgLyBNYXRoLnBvdygyLCA0MCAtIHRoaXMuYml0UG9zaXRpb24gLSBiaXRzKSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJUb28gbWFueSBiaXRzIVwiKTtcbiAgICAgIH1cbiAgICAgIGlmIChzaWduZWQpIHtcbiAgICAgICAgaWYgKG1CaXRzIDwgMzIpIHtcbiAgICAgICAgICBpZiAoYSA+Pj4gKGJpdHMgLSAxKSkge1xuICAgICAgICAgICAgYSA9ICgoMSA8PCBiaXRzID4+PiAwKSAtIGEpICogLTE7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGlmIChhIC8gTWF0aC5wb3coMiwgYml0cyAtIDEpIHwgMCkge1xuICAgICAgICAgICAgYSA9IChNYXRoLnBvdygyLCBiaXRzKSAtIGEpICogLTE7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9XG4gICAgICB0aGlzLmFkdmFuY2UoYml0cyk7XG4gICAgICByZXR1cm4gYTtcbiAgICB9O1xuXG4gICAgQml0c3RyZWFtLnByb3RvdHlwZS5wZWVrID0gZnVuY3Rpb24oYml0cywgc2lnbmVkKSB7XG4gICAgICB2YXIgYSwgYTAsIGExLCBhMiwgYTMsIGE0LCBtQml0cztcbiAgICA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2ZW50LCBmbikge1xuICAgICAgdmFyIGJhc2U7XG4gICAgICBpZiAodGhpcy5ldmVudHMgPT0gbnVsbCkge1xuICAgICAgICB0aGlzLmV2ZW50cyA9IHt9O1xuICAgICAgfVxuICAgICAgaWYgKChiYXNlID0gdGhpcy5ldmVudHMpW2V2ZW50XSA9PSBudWxsKSB7XG4gICAgICAgIGJhc2VbZXZlbnRdID0gW107XG4gICAgICB9XG4gICAgICByZXR1cm4gdGhpcy5ldmVudHNbZXZlbnRdLnB1c2goZm4pO1xuICAgIH07XG5cbiAgICBFdmVudEVtaXR0ZXIucHJvdG90eXBlLm9mZiA9IGZ1bmN0aW9uKGV2ZW50LCBmbikge1xuICAgICAgdmFyIGV2ZW50cywgaW5kZXgsIHJlZjtcbiAgICAgIGlmICh0aGlzLmV2ZW50cyA9PSBudWxsKSB7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cbiAgICAgIGlmICgocmVmID0gdGhpcy5ldmVudHMpICE9IG51bGwgPyByZWZbZXZlbnRdIDogdm9pZCAwKSB7XG4gICAgICAgIGlmIChmbiAhPSBudWxsKSB7XG4gICAgICAgICAgaW5kZXggPSB0aGlzLmV2ZW50c1tldmVudF0uaW5kZXhPZihmbik7XG4gICAgICAgICAgaWYgKH5pbmRleCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMuZXZlbnRzW2V2ZW50XS5zcGxpY2UoaW5kZXgsIDEpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICByZXR1cm4gdGhpcy5ldmVudHNbZXZlbnRdO1xuICAgICAgICB9XG4gICAgICB9IGVsc2UgaWYgKGV2ZW50ID09IG51bGwpIHtcbiAgICAgICAgcmV0dXJuIGV2ZW50cyA9IHt9O1xuICAgICAgfVxuICAgIH07XG5cbiAgICBFdmVudEVtaXR0ZXIucHJvdG90eXBlLm9uY2UgPSBmdW5jdGlvbihldmVudCwgZm4pIHtcbiAgICAgIHZhciBjYjtcbiAgICAgIH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HRsZUVuZGlhbiA9IHRydWU7XG4gICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgY2FzZSAndXRmMTZib20nOlxuICAgICAgICAgICAgY2FzZSAndXRmMTYtYm9tJzpcbiAgICAgICAgICAgICAgaWYgKGxlbmd0aCA8IDIgfHwgKGJvbSA9IHRoaXMucGVla1VJbnQxNihvZmZzZXQpKSA9PT0gbnVsbEVuZCkge1xuICAgICAgICAgICAgICAgIGlmIChhZHZhbmNlKSB7XG4gICAgICAgICAgICAgICAgICB0aGlzLmFkdmFuY2Uob2Zmc2V0ICs9IDIpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICByZXR1cm4gcmVzdWx0O1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIGxpdHRsZUVuZGlhbiA9IGJvbSA9PT0gMHhmZmZlO1xuICAgICAgICAgICAgICBvZmZzZXQgKz0gMjtcbiAgICAgICAgICB9XG4gICAgICAgICAgd2hpbGUgKG9mZnNldCA8IGVuZCAmJiAodzEgPSB0aGlzLnBlZWtVSW50MTYob2Zmc2V0LCBsaXR0bGVFbmRpYW4pKSAhPT0gbnVsbEVuZCkge1xuICAgICAgICAgICAgb2Zmc2V0ICs9IDI7XG4gICAgICAgICAgICBpZiAodzEgPCAweGQ4MDAgfHwgdzEgPiAweGRmZmYpIHtcbiAgICAgICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUodzEpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgaWYgKHcxID4gMHhkYmZmKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFwiSW52YWxpZCB1dGYxNiBzZXF1ZW5jZS5cIik7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgdzIgPSB0aGlzLnBlZWtVSW50MTYob2Zmc2V0LCBsaXR0bGVFbmRpYW4pO1xuICAgICAgICAgICAgICBpZiAodzIgPCAweGRjMDA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jb29raWUnLCAoZnVuY3Rpb24oX3RoaXMpIHtcbiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKGNvb2tpZSkge1xuICAgICAgICAgIHZhciBlcnJvcjtcbiAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgcmV0dXJuIF90aGlzLnNldENvb2tpZShjb29raWUpO1xuICAgICAgICAgIH0gY2F0Y2ggKGVycm9yMSkge1xuICAgICAgICAgICAgZXJyb3IgPSBlcnJvcjE7XG4gICAgICAgICAgICByZXR1cm4gX3RoaXMuZW1pdCgnZXJyb3InLCBlcnJvcik7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSkodGhpcykpO1xuICAgICAgdGhpcy5kZW11eGVyLm9uKCdkYXRhJywgKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihjaHVuaykge1xuICAgICAgICAgIGxpc3QuYXBwZW5kKGNodW5rKTtcbiAgICAgICAgICBpZiAoX3RoaXMud2FpdGluZykge1xuICAgICAgICAgICAgcmV0dXJuIF90aGlzLmRlY29kZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpKTtcbiAgICAgIHRoaXMuZGVtdXhlci5vbignZW5kJywgKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbigpIHtcbiAgICAgICAgICBfdGhpcy5yZWNlaXZlZEZpbmFsQnVmZmVyID0gdHJ1ZTtcbiAgICAgICAgICBpZiAoX3RoaXMud2FpdGluZykge1xuICAgICAgICAgICAgcmV0dXJuIF90aGlzLmRlY29kZSgpO1xuICAgICAgICAgIH1cbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpKTtcbiAgICAgIHRoaXMuaW5pdCgpO1xuICAgIH1cblxuICAgIERlY29kZXIucHJvdG90eXBlLmluaXQgPSBmdW5jdGlvbigpIHt9O1xuXG4gICAgRGVjb2Rlci5wcm90b3R5cGUuc2V0Q29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AgICAgIHNhbXBsZXMgPSBjaHVua1NpemUgLyAodGhpcy5mb3JtYXQuYml0c1BlckNoYW5uZWwgLyA4KSB8IDA7XG4gICAgICBpZiAoY2h1bmtTaXplIDwgdGhpcy5mb3JtYXQuYml0c1BlckNoYW5uZWwgLyA4KSB7XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgICAgfVxuICAgICAgaWYgKHRoaXMuZm9ybWF0LmZsb2F0aW5nUG9pbnQpIHtcbiAgICAgICAgc3dpdGNoICh0aGlzLmZvcm1hdC5iaXRzUGVyQ2hhbm5lbCkge1xuICAgICAgICAgIGNhc2UgMzI6XG4gICAgICAgICAgICBvdXRwdXQgPSBuZXcgRmxvYXQzMkFycmF5KHNhbXBsZXMpO1xuICAgICAgICAgICAgZm9yIChpID0gaiA9IDAsIHJlZiA9IHNhbXBsZXM7IGogPCByZWY7IGkgPSBqICs9IDEpIHtcbiAgICAgICAgICAgICAgb3V0cHV0W2ldID0gc3RyZWFtLnJlYWRGbG9hdDMyKGxpdHRsZUVuZGlhbik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlIDY0OlxuICAgICAgICAgICAgb3V0cHV0ID0gbmV3IEZsb2F0NjRBcnJheShzYW1wbGVzKTtcbiAgICAgICAgICAgIGZvciAoaSA9IGsgPSAwLCByZWYxID0gc2FtcGxlczsgayA8IHJlZjE7IGkgPSBrICs9IDEpIHtcbiAgICAgICAgICAgICAgb3V0cHV0W2ldID0gc3RyZWFtLnJlYWRGbG9hdDY0KGxpdHRsZUVuZGlhbik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdVbnN1cHBvcnRlZCBiaXQgZGVwdGguJyk7XG4gICAgICAgIH1cbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHN3aXRjaCAodGhpcy5mb3JtYXQuYml0c1BlckNoYW5uZWwpIHtcbiAgICAgICAgICBjYXNlIDg6XG4gICAgICAgICAgICBvdXRwdXQgPSBuZXcgSW50OEFycmF5KHNhbXBsZXMpO1xuICAgICAgICAgICAgZm9yIChpID0gbCA9IDAsIHJlZjIgPSBzYW1wbGVzOyBsIDwgcmVmMjsgaSA9IGwgKz0gMSkge1xuICAgICAgICAgICAgICBvdXRwdXRbaV0gPSBzdHJlYW0ucmVhZEludDgoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgMTY6XG4gICAgICAgICAgICBvdXRwdXQgPSBuZXcgSW50MTZBcnJheShzYW1wbGVzKTtcbiAgICAgICAgICAgIGZvciAoaSA9IG0gPSAwLCByZWYzID0gc2FtcGxlczsgbSA8IHJlZjM7IGkgPSBtICs9IDEpIHtcbiAgICAgICAgICAgICAgb3V0cHV0W2ldID0gc3RyZWFtLnJlYWRJbnQxNihsaXR0bGVFbmRpYW4pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAyNDpcbiAgICAgICAgICAgIG91dHB1dCA9IG5ldyBJbnQzMkFycmF5KHNhbXBsZXMpO1xuICAgICAgICAgICAgZm9yIChpID0gbiA9IDAsIHJlZjQgPSBzYW1wbGVzOyBuIDwgcmVmNDsgaSA9IG4gKz0gMSkge1xuICAgICAgICAgICAgICBvdXRwdXRbaV0gPSBzdHJlYW0ucmVhZEludDI0KGxpdHRsZUVuZGlhbik7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlIDMyOlxuICAgICAgICAgICAgb3V0cHV0ID0gbmV3IEludDMyQXJyYXkoc2FtcGxlcyk7XG4gICAgICAgICAgICBmb3IgKGkgPSBvID0gMCwgcmVmNSA9IHNhbXBsZXM7IG8gPCByZWY1OyBpID0gbyArPSAxKSB7XG4gICAgICAgICAgICAgIG91dHB1dFtpXSA9IHN0cmVhbS5yZ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4pKSB7XG4gICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHRoaXMuZm9ybWF0ID0ge1xuICAgICAgICAgICAgICBmb3JtYXRJRDogJ2xwY20nLFxuICAgICAgICAgICAgICBjaGFubmVsc1BlckZyYW1lOiB0aGlzLnN0cmVhbS5yZWFkVUludDE2KCksXG4gICAgICAgICAgICAgIHNhbXBsZUNvdW50OiB0aGlzLnN0cmVhbS5yZWFkVUludDMyKCksXG4gICAgICAgICAgICAgIGJpdHNQZXJDaGFubmVsOiB0aGlzLnN0cmVhbS5yZWFkVUludDE2KCksXG4gICAgICAgICAgICAgIHNhbXBsZVJhdGU6IHRoaXMuc3RyZWFtLnJlYWRGbG9hdDgwKCksXG4gICAgICAgICAgICAgIGZyYW1lc1BlclBhY2tldDogMSxcbiAgICAgICAgICAgICAgbGl0dGxlRW5kaWFuOiBmYWxzZSxcbiAgICAgICAgICAgICAgZmxvYXRpbmdQb2ludDogZmFsc2VcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICB0aGlzLmZvcm1hdC5ieXRlc1BlclBhY2tldCA9ICh0aGlzLmZvcm1hdC5iaXRzUGVyQ2hhbm5lbCAvIDgpICogdGhpcy5mb3JtYXQuY2hhbm5lbHNQZXJGcmFtZTtcbiAgICAgICAgICAgIGlmICh0aGlzLmZpbGVUeXBlID09PSAnQUlGQycpIHtcbiAgICAgICAgICAgICAgZm9ybWF0ID0gdGhpcy5zdHJlYW0ucmVhZFN0cmluZyg0KTtcbiAgICAgICAgICAgICAgdGhpcy5mb3JtYXQubGl0dGxlRW5kaWFuID0gZm9ybWF0ID09PSAnc293dCcgJiYgdGhpcy5mb3JtYXQuYml0c1BlckNoYW5uZWwgPiA4O1xuICAgICAgICAgICAgICB0aGlzLmZvcm1hdC5mbG9hdGluZ1BvaW50ID0gZm9ybWF0ID09PSAnZmwzMicgfHwgZm9ybWF0ID09PSAnZmw2NCc7XG4gICAgICAgICAgICAgIGlmIChm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YyAnKSB7XG4gICAgICAgICAgICAgICAgb2Zmc2V0ID0gdGhpcy5zdHJlYW0ub2Zmc2V0ICsgdGhpcy5oZWFkZXJDYWNoZS5zaXplO1xuICAgICAgICAgICAgICAgIGlmIChjb29raWUgPSBNNEFEZW11eGVyLnJlYWRFc2RzKHRoaXMuc3RyZWFtKSkge1xuICAgICAgICAgICAgICAgICAgdGhpcy5lbWl0KCdjb29raWUnLCBjb29raWUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB0aGlzLnN0cmVhbS5zZWVrKG9mZnNldCk7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgYnVmZmVyID0gdGhpcy5zdHJlYW0ucmVhZEJ1ZmZlcih0aGlzLmhlYWRlckNhY2hlLnNpemUpO1xuICAgICAgICAgICAgICAgIHRoaXMuZW1pdCgnY29va2llJywgYnVmZmVyKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLmhlYWRlckNhY2hlID0gbnVsbDtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ3Bha3QnOlxuICAgICAgICAgICAgaWYgKHRoaXMuc3RyZWFtLmF2YWlsYWJsZSh0aGlzLmhlYWRlckNhY2hlLnNpemUpKSB7XG4gICAgICAgICAgICAgIGlmICh0aGlzLnN0cmVhbS5yZWFkVUludDMyKCkgIT09IDApIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdGhpcy5lbWl0KCdlcnJvcicsICdTaXplcyBncmVhdGVyIHRoYW4gMzIgYml0cyBhcmUgbm90IHN1cHBvcnRlZC4nKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLm51bVBhY2tldHMgPSB0aGlzLnN0cmVhbS5yZWFkVUludDMyKCk7XG4gICAgICAgICAgICAgIGlmICh0aGlzLnN0cmVhbS5yZWFkVUludDMyKCkgIT09IDApIHtcbiAgICAgICAgIC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gICAgICAgICAgdGhpcy5oZWFkZXJDYWNoZSA9IG51bGw7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlICdpbmZvJzpcbiAgICAgICAgICAgIGVudHJpZXMgPSB0aGlzLnN0cmVhbS5yZWFkVUludDMyKCk7XG4gICAgICAgICAgICBtZXRhZGF0YSA9IHt9O1xuICAgICAgICAgICAgZm9yIChpID0gayA9IDAsIHJlZjEgPSBlbnRyaWVzOyAwIDw9IHJlZjEgPyBrIDwgcmVmMSA6IGsgPiByZWYxOyBpID0gMCA8PSByZWYxID8gKytrIDogLS1rKSB7XG4gICAgICAgICAgICAgIGtleSA9IHRoaXMuc3RyZWFtLnJlYWRTdHJpbmcobnVsbCk7XG4gICAgICAgICAgICAgIHZhbHVlID0gdGhpcy5zdHJlYW0ucmVhZFN0cmluZyhudWxsKTtcbiAgICAgICAgICAgICAgbWV0YWRhdGFba2V5XSA9IHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5lbWl0KCdtZXRhZGF0YScsIG1ldGFkYXRhKTtcbiAgICAgICAgICAgIHRoaXMuaGVhZGVyQ2FjaGUgPSBudWxsO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnZGF0YSc6XG4gICAgICAgICAgICBpZiAoIXRoaXMuc2VudEZpcnN0RGF0YUNodW5rKSB7XG4gICAgICAgICAgICAgIHRoaXMuc3RyZWFtLmFkdmFuY2UoNCk7XG4gICAgICAgICAgICAgIHRoaXMuaGVhZGVyQ2FjaGUuc2l6ZSAtPSA0O1xuICAgICAgICAgICAgICBpZiAodGhpcy5mb3JtYXQuYnl0ZXNQZXJQYWNrZXQgIT09IDAgJiYgIXRoaXMuc2VudER1cmF0aW9uKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5udW1GcmFtZXMgPSB0aGlzLmhlYWRlckNhY2hlLnNpemUgLyB0aGlzLmZvcm1hdC5ieXRlc1BlclBhY2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G4gICAgICB9XG4gICAgICBzdHNjSW5kZXggPSAwO1xuICAgICAgc3R0c0luZGV4ID0gMDtcbiAgICAgIHN0dHNJbmRleCA9IDA7XG4gICAgICBzdHRzU2FtcGxlID0gMDtcbiAgICAgIHNhbXBsZUluZGV4ID0gMDtcbiAgICAgIG9mZnNldCA9IDA7XG4gICAgICB0aW1lc3RhbXAgPSAwO1xuICAgICAgdGhpcy50cmFjay5zZWVrUG9pbnRzID0gW107XG4gICAgICByZWYgPSB0aGlzLnRyYWNrLmNodW5rT2Zmc2V0cztcbiAgICAgIHJlc3VsdHMgPSBbXTtcbiAgICAgIGZvciAoaSA9IGsgPSAwLCBsZW4xID0gcmVmLmxlbmd0aDsgayA8IGxlbjE7IGkgPSArK2spIHtcbiAgICAgICAgcG9zaXRpb24gPSByZWZbaV07XG4gICAgICAgIGZvciAoaiA9IGwgPSAwLCByZWYxID0gdGhpcy50cmFjay5zdHNjW3N0c2NJbmRleF0uY291bnQ7IGwgPCByZWYxOyBqID0gbCArPSAxKSB7XG4gICAgICAgICAgdGhpcy50cmFjay5zZWVrUG9pbnRzLnB1c2goe1xuICAgICAgICAgICAgb2Zmc2V0OiBvZmZzZXQsXG4gICAgICAgICAgICBwb3NpdGlvbjogcG9zaXRpb24sXG4gICAgICAgICAgICB0aW1lc3RhbXA6IHRpbWVzdGFtcFxuICAgICAgICAgIH0pO1xuICAgICAgICAgIHNpemUgPSB0aGlzLnRyYWNrLnNhbXBsZVNpemUgfHwgdGhpcy50cmFjay5zYW1wbGVTaXplc1tzYW1wbGVJbmRleCsrXTtcbiAgICAgICAgICBvZmZzZXQgKz0gc2l6ZTtcbiAgICAgICAgICBwb3NpdGlvbiArPSBzaXplO1xuICAgICAgICAgIHRpbWVzdGFtcCArPSB0aGlzLnRyYWNrLnN0dHNbc3R0c0luZGV4XS5kdXJhdGlvbjtcbiAgICAgICAgICBpZiAoc3R0c0luZGV4ICsgMSA8IHRoaXMudHJhY2suc3R0cy5sZW5ndGggJiYgKytzdHRzU2FtcGxlID09PSB0aGlzLnRyYWNrLnN0dHNbc3R0c0luZGV4XS5jb3VudCkge1xuICAgICAgICAgICAgc3R0c1NhbXBsZSA9IDA7XG4gICAgICAgICAgICBzdHRzSW5kZXgrKztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHN0c2NJbmRleCArIDEgPCB0aGlzLnRyYWNrLnN0c2MubGVuZ3RoICYmIGkgKyAxID09PSB0aGlzLnRyYWNrLnN0c2Nbc3RzY0luZGV4ICsgMV0uZmlyc3QpIHtcbiAgICAgICAgICByZXN1bHRzLnB1c2goc3RzY0luZGV4KyspO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJlc3VsdHMucHVzaCh2b2lkIDApO1xuICAgICAgICB9XG4gICAgICB9XG4gICAgICByZXR1cm4gcmVzdWx0cztcbiAgICB9O1xuXG4gICAgYWZ0ZXIoJ21vb3YnLCBmdW5jdGlvbigpIHtcbiAgICAgIHZhciBrLCBsZW4xLCByZWYsIHRyYWNrO1xuICAgICAgaWYgKHRoaXMubWRhdE9mZnNldCAhPSBudWxsKSB7XG4gICAgICAgIHRoaXMuc3RyZWFtLnNlZWsodGhpcy5tZGF0T2Zmc2V0IC0gOCk7XG4gICAgICB9XG4gICAgICByZWYgPSB0aGlzLnRyYWNrcztcbiAgICAgIGZvciAoayA9IDAsIGxlbjEgPSByZWYubGVuZ3RoOyBrIDwgbGVuMTsgaysrKSB7XG4gICAgICAgIHRyYWNrID0gcmVmW2tdO1xuICAgICAgICBpZiAoISh0cmFjay50eXBlID09PSAnc291bicpKSB7XG4gICAgICAgICAgY29udGludWU7XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy50cmFjayA9IHRyYWNrO1xuICAgICAgICBicmVhaztcbiAgICAgIH1cbiAgICAgIGlmICh0aGlzLnRyYWNrLnR5cGUgIT09ICdzb3VuJykge1xuICAgICAgICB0aGlzLnRyYWNrID0gbnVsbDtcbiAgICAgICAgcmV0dXJuIHRoaXMuZW1pdCgnZXJyb3InLCAnTm8gYXVkaW8gdHJhY2tzIGluIG00YSBmaWxlLicpO1xuICAgICAgfVxuICAgICAgdGhpcy5lbWl0KCdmb3JtYXQnLCB0aGlzLnRyYWNrLmZvcm1hdCk7XG4gICAgICB0aGlzLmVtaXQoJ2R1cmF0aW9uJywgdGhpcy50cmFjay5kdXJhdGlvbiAvIHRoaXMudHJhY2sudGltZVNjYWxlICogMTAwMCB8IDApO1xuICAgICAgaWYgKHRoaXMudHJhY2suY29va2llKSB7XG4gICAgICAgIHRoaXMuZW1pdCgnY29va2llJywgdGhpcy50cmFjay5jb29raWUpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIHRoaXMuc2Vla1BvaW50cyA9IHRoaXMudHJhY2suc2Vla1BvaW50cztcbiAgICB9KTtcblxuICAgIGF0b20oJ21kYXQnLCBmdW5jdGlvbigpIHtcbiAgICAgIHZhciBieXRlcywgY2h1bmtTaXplLCBrLCBsZW5ndGgsIG51bVNhbXBsZXMsIG9mZnNldCwgcmVmLCBzYW1wbGUsIHNpemU7XG4gICAgICBpZiAoIXRoaXMuc3RhcnRlZERhdGEpIHtcbiAgICAgICAgaWYgKHRoaXMubWRhdE9mZnNldCA9PSBudWxsKSB7XG4gICAgICAgICAgdGhpcy5tZGF0T2Zmc2V0ID0gdGhpcy5zdHJlYW0ub2Zmc2V0O1xuICAgICAgICB9XG4gICAgICAgIGlmICh0aGlzLnRyYWNrcy5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICBieXRlcyA9IE1hdGgubWluKHRoaXMuc3RyZWFtLnJlbWFpbmluZ0J5dGVzKCksIHRoaXMubGVuKTtcbiAgICAgICAgICB0aGlzLnN0cmVhbS5hZHZhbmNlKGJ5dGVzKTtcbiAgICAgICAgICB0aGlzLmxlbiAtPSBieXRlcztcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgdGhpcy5jaHVua0luZGV4ID0gMDtcbiAgICAgICAgdGhpcy5zd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czsgayA8IHJlZjsgc2FtcGxlID0gayArPSAxKSB7XG4gICAgICAgICAgc2l6ZSA9IHRoaXMudHJhY2suc2FtcGxlU2l6ZSB8fCB0aGlzLnRyYWNrLnNhbXBsZVNpemVzW3RoaXMuc2FtcGxlSW5kZXhdO1xuICAgICAgICAgIGlmICghdGhpcy5zdHJlYW0uYXZhaWxhYmxlKGxlbmd0aCArIHNpemUpKSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgICAgbGVuZ3RoICs9IHNpemU7XG4gICAgICAgICAgY2h1bmtTaXplICs9IHNpemU7XG4gICAgICAgICAgdGhpcy5zYW1wbGVJbmRleCsrO1xuICAgICAgICB9XG4gICAgICAgIGlmIChzYW1wbGUgPCBudW1TYW1wbGVzKSB7XG4gICAgICAgICAgdGhpcy50YWlsT2Zmc2V0ICs9IGNodW5rU2l6ZTtcbiAgICAgICAgICB0aGlzLnRhaWxTYW1wbGVzICs9IHNhbXBsZTtcbiAgICAgICAgICBicmVhaztcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICB0aGlzLmNodW5rSW5kZXgrKztcbiAgICAgICAgICB0aGlzLnRhaWxPZmZzZXQgPSAwO1xuICAgICAgICAgIHRoaXMudGFpbFNhbXBsZXMgPSAwO1xuICAgICAgICAgIGlmICh0aGlzLnN0c2NJbmRleCArIDEgPCB0aGlzLnRyYWNrLnN0c2MubGVuZ3RoICYmIHRoaXMuY2h1bmtJbmRleCArIDEgPT09IHRoaXMudHJhY2suc3RzY1t0aGlzLnN0c2NJbmRleCArIDFdLmZpcnN0KSB7XG4gICAgICAgICAgICB0aGlzLnN0c2NJbmRleCsrO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAob2Zmc2V0ICsgbGVuZ3RoICE9PSB0aGlzLnRyYWNrLmNodW5rT2Zmc2V0c1t0aGlzLmNodW5rSW5kZXhdKSB7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG4gICAgICAgIH1cb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zZXQuc3RhcnQoZmFsc2UpO1xuICAgIH07XG5cbiAgICBQbGF5ZXIucHJvdG90eXBlLnBsYXkgPSBmdW5jdGlvbigpIHtcbiAgICAgIHZhciByZWY7XG4gICAgICBpZiAodGhpcy5wbGF5aW5nKSB7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cbiAgICAgIGlmICghdGhpcy5zdGFydGVkUHJlbG9hZGluZykge1xuICAgICAgICB0aGlzLnByZWxvYWQoKTtcbiAgICAgIH1cbiAgICAgIHRoaXMucGxheWluZyA9IHRydWU7XG4gICAgICByZXR1cm4gKHJlZiA9IHRoaXMuZGV2aWNlKSAhPSBudWxsID8gcmVmLnN0YXJ0KCkgOiB2b2lkIDA7XG4gICAgfTtcblxuICAgIFBsYXllci5wcm90b3R5cGUucGF1c2UgPSBmdW5jdGlvbigpIHtcbiAgICAgIHZhciByZWY7XG4gICAgICBpZiAoIXRoaXMucGxheWluZykge1xuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgICB0aGlzLnBsYXlpbmcgPSBmYWxzZTtcbiAgICAgIHJldHVybiAocmVmID0gdGhpcy5kZXZpY2UpICE9IG51bGwgPyByZWYuc3RvcCgpIDogdm9pZCAwO1xuICAgIH07XG5cbiAgICBQbGF5ZXIucHJvdG90eXBlLnRvZ2dsZVBsYXliYWNrID0gZnVuY3Rpb24oKSB7XG4gICAgICBpZiAodGhpcy5wbGF5aW5nKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnBhdXNlKCk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICByZXR1cm4gdGhpcy5wbGF5KCk7XG4gICAgICB9XG4gICAgfTtcblxuICAgIFBsYXllci5wcm90b3R5cGUuc3RvcCA9IGZ1bmN0aW9uKCkge1xuICAgICAgdmFyIHJlZjtcbiAgICAgIHRoaXMucGF1c2UoKTtcbiAgICAgIHRoaXMuYXNzZXQuc3RvcCgpO1xuICAgICAgcmV0dXJuIChyZWYgPSB0aGlzLmRldmljZSkgIT0gbnVs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vbigpIHtcbiAgICAgIHZhciBmcmFtZSwgZnJhbWVPZmZzZXQ7XG4gICAgICBmcmFtZSA9IHRoaXMucXVldWUucmVhZCgpO1xuICAgICAgZnJhbWVPZmZzZXQgPSAwO1xuICAgICAgdGhpcy5kZXZpY2UgPSBuZXcgQXVkaW9EZXZpY2UodGhpcy5mb3JtYXQuc2FtcGxlUmF0ZSwgdGhpcy5mb3JtYXQuY2hhbm5lbHNQZXJGcmFtZSk7XG4gICAgICB0aGlzLmRldmljZS5vbigndGltZVVwZGF0ZScsIChmdW5jdGlvbihfdGhpcykge1xuICAgICAgICByZXR1cm4gZnVuY3Rpb24oY3VycmVudFRpbWUpIHtcbiAgICAgICAgICBfdGhpcy5jdXJyZW50VGltZSA9IGN1cnJlbnRUaW1lO1xuICAgICAgICAgIHJldHVybiBfdGhpcy5lbWl0KCdwcm9ncmVzcycsIF90aGlzLmN1cnJlbnRUaW1lKTtcbiAgICAgICAgfTtcbiAgICAgIH0pKHRoaXMpKTtcbiAgICAgIHRoaXMucmVmaWxsID0gKGZ1bmN0aW9uKF90aGlzKSB7XG4gICAgICAgIHJldHVybiBmdW5jdGlvbihidWZmZXIpIHtcbiAgICAgICAgICB2YXIgYnVmZmVyT2Zmc2V0LCBmaWx0ZXIsIGksIGosIGssIGxlbiwgbWF4LCByZWYsIHJlZjE7XG4gICAgICAgICAgaWYgKCFfdGhpcy5wbGF5aW5nKSB7XG4gICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgfVxuICAgICAgICAgIGlmICghZnJhbWUpIHtcbiAgICAgICAgICAgIGZyYW1lID0gX3RoaXMucXVldWUucmVhZCgpO1xuICAgICAgICAgICAgZnJhbWVPZmZzZXQgPSAwO1xuICAgICAgICAgIH1cbiAgICAgICAgICBidWZmZXJPZmZzZXQgPSAwO1xuICAgICAgICAgIHdoaWxlIChmcmFtZSAmJiBidWZmZXJPZmZzZXQgPCBidWZmZXIubGVuZ3RoKSB7XG4gICAgICAgICAgICBtYXggPSBNYXRoLm1pbihmcmFtZS5sZW5ndGggLSBmcmFtZU9mZnNldCwgYnVmZmVyLmxlbmd0aCAtIGJ1ZmZlck9mZnNldCk7XG4gICAgICAgICAgICBmb3IgKGkgPSBqID0gMCwgcmVmID0gbWF4OyBqIDwgcmVmOyBpID0gaiArPSAxKSB7XG4gICAgICAgICAgICAgIGJ1ZmZlcltidWZmZXJPZmZzZXQrK10gPSBmcmFtZVtmcmFtZU9mZnNldCsrXTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChmcmFtZU9mZnNldCA9PT0gZnJhbWUubGVuZ3RoKSB7XG4gICAgICAgICAgICAgIGZyYW1lID0gX3RoaXMucXVldWUucmVhZCgpO1xuICAgICAgICAgICAgICBmcmFtZU9mZnNldCA9IDA7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICAgIHJlZjEgPSBfdGhpcy5maWx0ZXJzO1xuICAgICAgICAgIGZvciAoayA9IDAsIGxlbiA9IHJlZjEubGVuZ3RoOyBrIDwgbGVuOyBrKyspIHtcbiAgICAgICAgICAgIGZpbHRlciA9IHJlZjFba107XG4gICAgICAgICAgICBmaWx0ZXIucHJvY2VzcyhidWZmZXIpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoIWZyYW1lKSB7XG4gICAgICAgICAgICBpZiAoX3RoaXMucXVldWUuZW5kZWQpIHtcbiAgICAgICAgICAgICAgX3RoaXMuY3VycmVudFRpbWUgPSBfdGhpcy5kdXJhdGlvbjtcbiAgICAgICAgICAgICAgX3RoaXMuZW1pdCgncHJvZ3Jlc3MnLCBfdGhpcy5jdXJyZW50VGltZSk7XG4gICAgICAgICAgICAgIF90aGlzLmVtaXQoJ2VuZCcpO1xuICAgICAgICAgICAgICBfdGhpcy5zdG9wKCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBfdGhpcy5kZXZpY2Uuc3RvcCgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAg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AgIEBsb29wKCkgaWYgQG9mZnNldCA8IEBsZW5ndGhcbiAgICAgICAgXG4gICAgICAgIEByZWFkZXIub25sb2FkZW5kID0gPT5cbiAgICAgICAgICAgIGlmIEBvZmZzZXQgaXMgQGxlbmd0aFxuICAgICAgICAgICAgICAgIEBlbWl0ICdlbmQnXG4gICAgICAgICAgICAgICAgQHJlYWRlciA9IG51bGxcbiAgICAgICAgXG4gICAgICAgIEByZWFkZXIub25lcnJvciA9IChlKSA9PlxuICAgICAgICAgICAgQGVtaXQgJ2Vycm9yJywgZVxuICAgICAgICBcbiAgICAgICAgQHJlYWRlci5vbnByb2dyZXNzID0gKGUpID0+XG4gICAgICAgICAgICBAZW1pdCAncHJvZ3Jlc3MnLCAoQG9mZnNldCArIGUubG9hZGVkKSAvIEBsZW5ndGggKiAxMDBcbiAgICAgICAgXG4gICAgICAgIEBsb29wKClcbiAgICAgICAgXG4gICAgbG9vcDogLT5cbiAgICAgICAgQGFjdGl2ZSA9IHRydWVcbiAgICAgICAgZW5kUG9zID0gTWF0aC5taW4oQG9mZnNldCArIEBjaHVua1NpemUsIEBsZW5ndGgpXG4gICAgICAgIFxuICAgICAgICBibG9iID0gQGZpbGVbQHNsaWNlXShAb2Zmc2V0LCBlbmRQb3MpXG4gICAgICAgIEByZWFkZXIucmVhZEFzQXJyYXlCdWZmZXIoYmxvYilcbiAgICAgICAgXG4gICAgcGF1c2U6IC0+XG4gICAgICAgIEBhY3RpdmUgPSBmYWxzZVxuICAgICAgICB0cnlcbiAgICAgICAgICBAcmVhZGVyPy5hYm9ydCgpXG4gICAgICAgIFxuICAgIHJlc2V0OiAtPlxuICAgICAgICBAcGF1c2UoKVxuICAgICAgICBAb2Zmc2V0ID0gMFxuXG5tb2R1bGUuZXhwb3J0cyA9IEZpbGVTb3VyY2VcbiIsIkV2ZW50RW1pdHRlciA9IHJlcXVpcmUgJy4uLy4uL2NvcmUvZXZlbnRzJ1xuQVZCdWZmZXIgPSByZXF1aXJlICcuLi8uLi9jb3JlL2J1ZmZlcidcblxuY2xhc3MgSFRUUFNvdXJjZSBleHRlbmRzIEV2ZW50RW1pdHRlclxuICAgIGNvbnN0cnVjdG9yOiAoQHVybCwgQG9wdHMgPSB7fSkgLT5cbiAgICAgICAgQGNodW5rU2l6ZSA9IDEgPDwgMjBcbiAgICAgICAgQGluZmxpZ2h0ID0gZmFsc2VcbiAgICAgICAgaWYgQG9wdHMubGVuZ3RoXG4gICAgICAgICAgICBAbGVuZ3RoID0gQG9wdHMubGVuZ3RoXG4gICAgICAgIEByZXNldCgpXG4gICAgICAgIFxuICAgIHN0YXJ0OiAtPlxuICAgICAgICBpZiBAbGVuZ3RoXG4gICAgICAgICAgICByZXR1cm4gQGxvb3AoKSB1bmxlc3MgQGluZmxpZ2h0XG4gICAgICAgIFxuICAgICAgICBAaW5mbGlnaHQgPSB0cnVlXG4gICAgICAgIEB4aHIgPSBuZXcgWE1MSHR0cFJlcXVlc3QoKVxuICAgICAgICBcbiAgICAgICAgQHhoci5vbmxvYWQgPSAoZXZlbnQpID0+XG4gICAgICAgICAgICBAbGVuZ3RoID0gcGFyc2VJbnQgQHhoci5nZXRSZXNwb25zZUhlYWRlcihcIkNvbnRlbnQtTGVuZ3RoXCIpICAgICAgICAgICAgICAgIFxuICAgICAgICAgICAgQGluZmxpZ2h0ID0gZmFsc2VcbiAgICAgICAgICAgIEBsb29wKClcbiAgICAgICAgXG4gICAgICAgIEB4aHIub25lcnJvciA9IChlcnIpID0+XG4gICAgICAgICAgICBAcGF1c2UoKVxuICAgICAgICAgICAgQGVtaXQgJ2Vycm9yJywgZXJyXG4gICAgICAgICAgICBcbiAgICAgICAgQHhoci5vbmFib3J0ID0gKGV2ZW50KSA9PlxuICAgICAgICAgICAgQGluZmxpZ2h0ID0gZmFsc2VcbiAgICAgICAgXG4gICAgICAgIEB4aHIub3BlbihcIkhFQURcIiwgQHVybCwgdHJ1ZSlcbiAgICAgICAgQHhoci5zZW5kKG51bGwpXG4gICAgICAgIFxuICAgIGxvb3A6IC0+XG4gICAgICAgIGlmIEBpbmZsaWdodCBvciBub3QgQGxlbmd0aFxuICAgICAgICAgICAgcmV0dXJuIEBlbWl0ICdlcnJvcicsICdTb21ldGhpbmcgaXMgd3JvbmcgaW4gSFRUUFNvdXJjZS5sb29wJ1xuICAgICAgICAgICAgXG4gICAgICAgIEBpbmZsaWdodCA9IHRydWVcbiAgICAgICAgQHhociA9IG5ldyBYTUxIdHRwUmVxdWVzdCgpXG4gICAgICAgIFxuICAgICAgICBAeGhyLm9ubG9hZCA9IChldmVudCkgPT5cbiAgICAgICAgICAgIGlmIEB4aHIucmVzcG9uc2VcbiAgICAgICAgICAgICAgICBidWYgPSBuZXcgVWludDhBcnJheShAeGhyLnJlc3BvbnNlKVxuICAgICAgICAgICAgZWxzZVxuICAgICAgICAgICAgICAgIHR4dCA9IEB4aHIucmVzcG9uc2VUZXh0XG4gICAgICAgICAgICAgICAgYnVmID0gbmV3IFVpbnQ4QXJyYXkodHh0Lmxlbmd0aClcbiAgICAgICAgICAgICAgICBmb3IgaSBpbiBbMC4uLnR4dC5sZW5ndGhdXG4gICAgICAgICAgICAgICAgICAgIGJ1ZltpXSA9IHR4dC5jaGFyQ29kZUF0KGkpICYgMHhmZlxuXG4gICAgICAgICAgICBidWZmZXIgPSBuZXcgQVZCdWZmZXIoYnVmKVxuICAgICAgICAgICAgQG9mZnNldCArPSBidWZmZXIubGVuZ3RoXG4gICAgICAgICAgICBcbiAgICAgICAgICAgIEBlbWl0ICdkYXRhJywgYnVmZmVyXG4gICAgICAgICAgICBAZW1pdCAnZW5kJyBpZiBAb2Zmc2V0ID49IEBsZW5ndGhcblxuICAgICAgICAgICAgQGluZmxpZ2h0ID0gZmFsc2VcbiAgICAgICAgICAgIEBsb29wKCkgdW5sZXNzIEBvZmZzZXQgPj0gQGxlbmd0aFxuICAgICAgICAgICAgXG4gICAgICAgIEB4aHIub25wcm9ncmVzcyA9IChldmVudCkgPT5cbiAgICAgICAgICAgIEBlb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Lmxpc3QuYWR2YW5jZSgpKSB7XG4gICAgICAgIHJldHVybiBzZXRJbW1lZGlhdGUodGhpcy5sb29wKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHJldHVybiB0aGlzLmVtaXQoJ2VuZCcpO1xuICAgICAgfVxuICAgIH07XG5cbiAgICBCdWZmZXJTb3VyY2UucHJvdG90eXBlLnBhdXNlID0gZnVuY3Rpb24oKSB7XG4gICAgICBjbGVhckltbWVkaWF0ZSh0aGlzLl90aW1lcik7XG4gICAgICByZXR1cm4gdGhpcy5wYXVzZWQgPSB0cnVlO1xuICAgIH07XG5cbiAgICBCdWZmZXJTb3VyY2UucHJvdG90eXBlLnJlc2V0ID0gZnVuY3Rpb24oKSB7XG4gICAgICB0aGlzLnBhdXNlKCk7XG4gICAgICByZXR1cm4gdGhpcy5saXN0LnJld2luZCgpO1xuICAgIH07XG5cbiAgICByZXR1cm4gQnVmZmVyU291cmNlO1xuXG4gIH0pKEV2ZW50RW1pdHRlcik7XG5cbiAgbW9kdWxlLmV4cG9ydHMgPSBCdWZmZXJTb3VyY2U7XG5cbn0pLmNhbGwodGhpcyk7XG4iXX0= diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/flac.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/flac.js new file mode 100644 index 000000000..882a926a4 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/flac.js @@ -0,0 +1,799 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1; ones--) { + stream.advance(2); // == 2 + frame_or_sample_num = (frame_or_sample_num << 6) | stream.read(6); + } + + // block size + if (bsCode === 0) + throw new Error('Reserved blocksize code'); + else if (bsCode === 6) + this.blockSize = stream.read(8) + 1; + else if (bsCode === 7) + this.blockSize = stream.read(16) + 1; + else + this.blockSize = BLOCK_SIZES[bsCode]; + + // sample rate + var sampleRate; + if (srCode < 12) + sampleRate = SAMPLE_RATES[srCode]; + else if (srCode === 12) + sampleRate = stream.read(8) * 1000; + else if (srCode === 13) + sampleRate = stream.read(16); + else if (srCode === 14) + sampleRate = stream.read(16) * 10; + else + throw new Error('Invalid sample rate code'); + + stream.advance(8); // skip CRC check + + // subframes + for (var i = 0; i < channels; i++) + this.decodeSubframe(i); + + stream.align(); + stream.advance(16); // skip CRC frame footer + + var is32 = this.bps > 16, + output = new ArrayBuffer(this.blockSize * channels * (is32 ? 4 : 2)), + buf = is32 ? new Int32Array(output) : new Int16Array(output), + blockSize = this.blockSize, + decoded = this.decoded, + j = 0; + + switch (this.chMode) { + case CHMODE_INDEPENDENT: + for (var k = 0; k < blockSize; k++) { + for (var i = 0; i < channels; i++) { + buf[j++] = decoded[i][k]; + } + } + break; + + case CHMODE_LEFT_SIDE: + for (var i = 0; i < blockSize; i++) { + var left = decoded[0][i], + right = decoded[1][i]; + + buf[j++] = left; + buf[j++] = (left - right); + } + break; + + case CHMODE_RIGHT_SIDE: + for (var i = 0; i < blockSize; i++) { + var left = decoded[0][i], + right = decoded[1][i]; + + buf[j++] = (left + right); + buf[j++] = right; + } + break; + + case CHMODE_MID_SIDE: + for (var i = 0; i < blockSize; i++) { + var left = decoded[0][i], + right = decoded[1][i]; + + left -= right >> 1; + buf[j++] = (left + right); + buf[j++] = left; + } + break; + } + + return buf; + }; + + this.prototype.decodeSubframe = function(channel) { + var wasted = 0, + stream = this.bitstream, + blockSize = this.blockSize, + decoded = this.decoded; + + this.curr_bps = this.bps; + if (channel === 0) { + if (this.chMode === CHMODE_RIGHT_SIDE) + this.curr_bps++; + } else { + if (this.chMode === CHMODE_LEFT_SIDE || this.chMode === CHMODE_MID_SIDE) + this.curr_bps++; + } + + if (stream.read(1)) + throw new Error("Invalid subframe padding"); + + var type = stream.read(6); + + if (stream.read(1)) { + wasted = 1; + while (!stream.read(1)) + wasted++; + + this.curr_bps -= wasted; + } + + if (this.curr_bps > 32) + throw new Error("decorrelated bit depth > 32 (" + this.curr_bps + ")"); + + if (type === 0) { + var tmp = stream.read(this.curr_bps, true); + for (var i = 0; i < blockSize; i++) + decoded[channel][i] = tmp; + + } else if (type === 1) { + var bps = this.curr_bps; + for (var i = 0; i < blockSize; i++) + decoded[channel][i] = stream.read(bps, true); + + } else if ((type >= 8) && (type <= 12)) { + this.decode_subframe_fixed(channel, type & ~0x8); + + } else if (type >= 32) { + this.decode_subframe_lpc(channel, (type & ~0x20) + 1); + + } else { + throw new Error("Invalid coding type"); + } + + if (wasted) { + for (var i = 0; i < blockSize; i++) + decoded[channel][i] <<= wasted; + } + }; + + this.prototype.decode_subframe_fixed = function(channel, predictor_order) { + var decoded = this.decoded[channel], + stream = this.bitstream, + bps = this.curr_bps; + + // warm up samples + for (var i = 0; i < predictor_order; i++) + decoded[i] = stream.read(bps, true); + + this.decode_residuals(channel, predictor_order); + + var a = 0, b = 0, c = 0, d = 0; + + if (predictor_order > 0) + a = decoded[predictor_order - 1]; + + if (predictor_order > 1) + b = a - decoded[predictor_order - 2]; + + if (predictor_order > 2) + c = b - decoded[predictor_order - 2] + decoded[predictor_order - 3]; + + if (predictor_order > 3) + d = c - decoded[predictor_order - 2] + 2 * decoded[predictor_order - 3] - decoded[predictor_order - 4]; + + switch (predictor_order) { + case 0: + break; + + case 1: + case 2: + case 3: + case 4: + var abcd = new Int32Array([a, b, c, d]), + blockSize = this.blockSize; + + for (var i = predictor_order; i < blockSize; i++) { + abcd[predictor_order - 1] += decoded[i]; + + for (var j = predictor_order - 2; j >= 0; j--) { + abcd[j] += abcd[j + 1]; + } + + decoded[i] = abcd[0]; + } + + break; + + default: + throw new Error("Invalid Predictor Order " + predictor_order); + } + }; + + this.prototype.decode_subframe_lpc = function(channel, predictor_order) { + var stream = this.bitstream, + decoded = this.decoded[channel], + bps = this.curr_bps, + blockSize = this.blockSize; + + // warm up samples + for (var i = 0; i < predictor_order; i++) { + decoded[i] = stream.read(bps, true); + } + + var coeff_prec = stream.read(4) + 1; + if (coeff_prec === 16) + throw new Error("Invalid coefficient precision"); + + var qlevel = stream.read(5, true); + if (qlevel < 0) + throw new Error("Negative qlevel, maybe buggy stream"); + + var coeffs = new Int32Array(32); + for (var i = 0; i < predictor_order; i++) { + coeffs[i] = stream.read(coeff_prec, true); + } + + this.decode_residuals(channel, predictor_order); + + if (this.bps <= 16) { + for (var i = predictor_order; i < blockSize - 1; i += 2) { + var d = decoded[i - predictor_order], + s0 = 0, s1 = 0, c = 0; + + for (var j = predictor_order - 1; j > 0; j--) { + c = coeffs[j]; + s0 += c * d; + d = decoded[i - j]; + s1 += c * d; + } + + c = coeffs[0]; + s0 += c * d; + d = decoded[i] += (s0 >> qlevel); + s1 += c * d; + decoded[i + 1] += (s1 >> qlevel); + } + + if (i < blockSize) { + var sum = 0; + for (var j = 0; j < predictor_order; j++) + sum += coeffs[j] * decoded[i - j - 1]; + + decoded[i] += (sum >> qlevel); + } + } else { + // simulate 64 bit integer using an array of two 32 bit ints + var total = this.lpc_total; + for (var i = predictor_order; i < blockSize; i++) { + // reset total to 0 + total[0] = 0; + total[1] = 0; + + for (j = 0; j < predictor_order; j++) { + // simulate `total += coeffs[j] * decoded[i - j - 1]` + multiply_add(total, coeffs[j], decoded[i - j - 1]); + } + + // simulate `decoded[i] += total >> qlevel` + // we know that qlevel < 32 since it is a 5 bit field (see above) + decoded[i] += (total[0] >>> qlevel) | (total[1] << (32 - qlevel)); + } + } + }; + + const TWO_PWR_32_DBL = Math.pow(2, 32); + + // performs `total += a * b` on a simulated 64 bit int + // total is an Int32Array(2) + // a and b are JS numbers (32 bit ints) + function multiply_add(total, a, b) { + // multiply a * b (we can use normal JS multiplication for this) + var r = a * b; + var n = r < 0; + if (n) + r = -r; + + var r_low = (r % TWO_PWR_32_DBL) | 0; + var r_high = (r / TWO_PWR_32_DBL) | 0; + if (n) { + r_low = ~r_low + 1; + r_high = ~r_high; + } + + // add result to total + var a48 = total[1] >>> 16; + var a32 = total[1] & 0xFFFF; + var a16 = total[0] >>> 16; + var a00 = total[0] & 0xFFFF; + + var b48 = r_high >>> 16; + var b32 = r_high & 0xFFFF; + var b16 = r_low >>> 16; + var b00 = r_low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + + // store result back in total + total[0] = (c16 << 16) | c00; + total[1] = (c48 << 16) | c32; + } + + const INT_MAX = 32767; + + this.prototype.decode_residuals = function(channel, predictor_order) { + var stream = this.bitstream, + method_type = stream.read(2); + + if (method_type > 1) + throw new Error('Illegal residual coding method ' + method_type); + + var rice_order = stream.read(4), + samples = (this.blockSize >>> rice_order); + + if (predictor_order > samples) + throw new Error('Invalid predictor order ' + predictor_order + ' > ' + samples); + + var decoded = this.decoded[channel], + sample = predictor_order, + i = predictor_order; + + for (var partition = 0; partition < (1 << rice_order); partition++) { + var tmp = stream.read(method_type === 0 ? 4 : 5); + + if (tmp === (method_type === 0 ? 15 : 31)) { + tmp = stream.read(5); + for (; i < samples; i++) + decoded[sample++] = stream.read(tmp, true); + + } else { + for (; i < samples; i++) + decoded[sample++] = this.golomb(tmp, INT_MAX, 0); + } + + i = 0; + } + }; + + const MIN_CACHE_BITS = 25; + + this.prototype.golomb = function(k, limit, esc_len) { + var data = this.bitstream, + offset = data.bitPosition, + buf = data.peek(32 - offset) << offset, + v = 0; + + var log = 31 - clz(buf | 1); // log2(buf) + + if (log - k >= 32 - MIN_CACHE_BITS && 32 - log < limit) { + buf >>>= log - k; + buf += (30 - log) << k; + + data.advance(32 + k - log); + v = buf; + + } else { + for (var i = 0; data.read(1) === 0; i++) + buf = data.peek(32 - offset) << offset; + + if (i < limit - 1) { + if (k) + buf = data.read(k); + else + buf = 0; + + v = buf + (i << k); + + } else if (i === limit - 1) { + buf = data.read(esc_len); + v = buf + 1; + + } else { + v = -1; + } + } + + return (v >> 1) ^ -(v & 1); + }; + + // Should be in the damned standard library... + function clz(input) { + var output = 0, + curbyte = 0; + + while(true) { // emulate goto in JS using the break statement :D + curbyte = input >>> 24; + if (curbyte) break; + output += 8; + + curbyte = input >>> 16; + if (curbyte & 0xff) break; + output += 8; + + curbyte = input >>> 8; + if (curbyte & 0xff) break; + output += 8; + + curbyte = input; + if (curbyte & 0xff) break; + output += 8; + + return output; + } + + if (!(curbyte & 0xf0)) + output += 4; + else + curbyte >>>= 4; + + if (curbyte & 0x8) + return output; + + if (curbyte & 0x4) + return output + 1; + + if (curbyte & 0x2) + return output + 2; + + if (curbyte & 0x1) + return output + 3; + + // shouldn't get here + return output + 4; + } +}); + +module.exports = FLACDecoder; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],3:[function(require,module,exports){ +(function (global){ +/* + * FLAC.js - Free Lossless Audio Codec decoder in JavaScript + * By Devon Govett and Jens Nockert of Official.fm Labs + * + * FLAC.js is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FLAC.js is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); + +var FLACDemuxer = AV.Demuxer.extend(function() { + AV.Demuxer.register(this); + + this.probe = function(buffer) { + return buffer.peekString(0, 4) === 'fLaC'; + } + + const STREAMINFO = 0, + PADDING = 1, + APPLICATION = 2, + SEEKTABLE = 3, + VORBIS_COMMENT = 4, + CUESHEET = 5, + PICTURE = 6, + INVALID = 127, + STREAMINFO_SIZE = 34; + + this.prototype.readChunk = function() { + var stream = this.stream; + + if (!this.readHeader && stream.available(4)) { + if (stream.readString(4) !== 'fLaC') + return this.emit('error', 'Invalid FLAC file.'); + + this.readHeader = true; + } + + while (stream.available(1) && !this.last) { + if (!this.readBlockHeaders) { + var tmp = stream.readUInt8(); + this.last = (tmp & 0x80) === 0x80, + this.type = tmp & 0x7F, + this.size = stream.readUInt24(); + } + + if (!this.foundStreamInfo && this.type !== STREAMINFO) + return this.emit('error', 'STREAMINFO must be the first block'); + + if (!stream.available(this.size)) + return; + + switch (this.type) { + case STREAMINFO: + if (this.foundStreamInfo) + return this.emit('error', 'STREAMINFO can only occur once.'); + + if (this.size !== STREAMINFO_SIZE) + return this.emit('error', 'STREAMINFO size is wrong.'); + + this.foundStreamInfo = true; + var bitstream = new AV.Bitstream(stream); + + var cookie = { + minBlockSize: bitstream.read(16), + maxBlockSize: bitstream.read(16), + minFrameSize: bitstream.read(24), + maxFrameSize: bitstream.read(24) + }; + + this.format = { + formatID: 'flac', + sampleRate: bitstream.read(20), + channelsPerFrame: bitstream.read(3) + 1, + bitsPerChannel: bitstream.read(5) + 1 + }; + + this.emit('format', this.format); + this.emit('cookie', cookie); + + var sampleCount = bitstream.read(36); + this.emit('duration', sampleCount / this.format.sampleRate * 1000 | 0); + + stream.advance(16); // skip MD5 hashes + this.readBlockHeaders = false; + break; + + /* + I am only looking at the least significant 32 bits of sample number and offset data + This is more than sufficient for the longest flac file I have (~50 mins 2-channel 16-bit 44.1k which uses about 7.5% of the UInt32 space for the largest offset) + Can certainly be improved by storing sample numbers and offests as doubles, but would require additional overriding of the searchTimestamp and seek functions (possibly more?) + Also the flac faq suggests it would be possible to find frame lengths and thus create seek points on the fly via decoding but I assume this would be slow + I may look into these thigns though as my project progresses + */ + case SEEKTABLE: + for(var s=0; s 0) + { + this.emit('error', 'Seek points with sample number >UInt32 not supported'); + } + var samplenum = stream.readUInt32(); + if(stream.readUInt32() > 0) + { + this.emit('error', 'Seek points with stream offset >UInt32 not supported'); + } + var offset = stream.readUInt32(); + + stream.advance(2); + + this.addSeekPoint(offset, samplenum); + } + } + break; + + case VORBIS_COMMENT: + // see http://www.xiph.org/vorbis/doc/v-comment.html + this.metadata || (this.metadata = {}); + var len = stream.readUInt32(true); + + this.metadata.vendor = stream.readString(len); + var length = stream.readUInt32(true); + + for (var i = 0; i < length; i++) { + len = stream.readUInt32(true); + var str = stream.readString(len, 'utf8'), + idx = str.indexOf('='); + + this.metadata[str.slice(0, idx).toLowerCase()] = str.slice(idx + 1); + } + + // TODO: standardize field names across formats + break; + + case PICTURE: + var type = stream.readUInt32(); + if (type !== 3) { // make sure this is album art (type 3) + stream.advance(this.size - 4); + } else { + var mimeLen = stream.readUInt32(), + mime = stream.readString(mimeLen), + descLen = stream.readUInt32(), + description = stream.readString(descLen), + width = stream.readUInt32(), + height = stream.readUInt32(), + depth = stream.readUInt32(), + colors = stream.readUInt32(), + length = stream.readUInt32(), + picture = stream.readBuffer(length); + + this.metadata || (this.metadata = {}); + this.metadata.coverArt = picture; + } + + // does anyone want the rest of the info? + break; + + default: + stream.advance(this.size); + this.readBlockHeaders = false; + } + + if (this.last && this.metadata) + this.emit('metadata', this.metadata); + } + + while (stream.available(1) && this.last) { + var buffer = stream.readSingleBuffer(stream.remainingBytes()); + this.emit('data', buffer); + } + } + +}); + +module.exports = FLACDemuxer; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],4:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); + +// if ogg.js exists, register a plugin +try { + var OggDemuxer = (typeof window !== "undefined" ? window['AV']['OggDemuxer'] : typeof global !== "undefined" ? global['AV']['OggDemuxer'] : null); +} catch (e) {}; +if (!OggDemuxer) return; + +OggDemuxer.plugins.push({ + magic: "\177FLAC", + + init: function() { + this.list = new AV.BufferList(); + this.stream = new AV.Stream(this.list); + }, + + readHeaders: function(packet) { + var stream = this.stream; + this.list.append(new AV.Buffer(packet)); + + stream.advance(5); // magic + if (stream.readUInt8() != 1) + throw new Error('Unsupported FLAC version'); + + stream.advance(3); + if (stream.peekString(0, 4) != 'fLaC') + throw new Error('Not flac'); + + this.flac = AV.Demuxer.find(stream.peekSingleBuffer(0, stream.remainingBytes())); + if (!this.flac) + throw new Error('Flac demuxer not found'); + + this.flac.prototype.readChunk.call(this); + return true; + }, + + readPacket: function(packet) { + this.list.append(new AV.Buffer(packet)); + this.flac.prototype.readChunk.call(this); + } +}); + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}]},{},[1]) + + +//# sourceMappingURL=flac.js.map \ No newline at end of file diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/mp3.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/mp3.js new file mode 100644 index 000000000..85b3be5b7 --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/aurora/mp3.js @@ -0,0 +1,7751 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { + timestamp = this._super(timestamp); + offset = this.stream.offset; + } else { + offset = timestamp * this.format.bitrate / 8 / this.format.sampleRate; + } + + this.mp3_stream.reset(offset); + + // try to find 3 consecutive valid frame headers in a row + for (var i = 0; i < 4096; i++) { + var pos = offset + i; + for (var j = 0; j < 3; j++) { + this.mp3_stream.reset(pos); + + try { + var header = MP3FrameHeader.decode(this.mp3_stream); + } catch (e) { + break; + } + + // skip the rest of the frame + var size = header.framesize(); + if (size == null) + break; + + pos += size; + } + + // check if we're done + if (j === 3) + break; + } + + // if we didn't find 3 frames, just try the first one and hope for the best + if (j !== 3) + i = 0; + + this.mp3_stream.reset(offset + i); + + // if we guesstimated, update the timestamp to another estimate of where we actually seeked to + if (this.demuxer.seekPoints.length === 0) + timestamp = this.stream.offset / (this.format.bitrate / 8) * this.format.sampleRate; + + this.seeking = true; + return timestamp; + }; +}); + +module.exports = MP3Decoder; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./frame":4,"./header":5,"./layer1":9,"./layer2":10,"./layer3":11,"./stream":12,"./synth":13}],3:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); +var ID3v23Stream = require('./id3').ID3v23Stream; +var ID3v22Stream = require('./id3').ID3v22Stream; +var MP3FrameHeader = require('./header'); +var MP3Stream = require('./stream'); + +var MP3Demuxer = AV.Demuxer.extend(function() { + AV.Demuxer.register(this); + + this.probe = function(stream) { + var off = stream.offset; + + // skip id3 metadata if it exists + var id3header = MP3Demuxer.getID3v2Header(stream); + if (id3header) + stream.advance(10 + id3header.length); + + // attempt to read the header of the first audio frame + var s = new MP3Stream(new AV.Bitstream(stream)); + var header = null; + + try { + header = MP3FrameHeader.decode(s); + } catch (e) {}; + + // go back to the beginning, for other probes + stream.seek(off); + + return !!header; + }; + + this.getID3v2Header = function(stream) { + if (stream.peekString(0, 3) == 'ID3') { + stream = AV.Stream.fromBuffer(stream.peekBuffer(0, 10)); + stream.advance(3); // 'ID3' + + var major = stream.readUInt8(); + var minor = stream.readUInt8(); + var flags = stream.readUInt8(); + var bytes = stream.readBuffer(4).data; + var length = (bytes[0] << 21) | (bytes[1] << 14) | (bytes[2] << 7) | bytes[3]; + + return { + version: '2.' + major + '.' + minor, + major: major, + minor: minor, + flags: flags, + length: length + }; + } + + return null; + }; + + const XING_OFFSETS = [[32, 17], [17, 9]]; + this.prototype.parseDuration = function(header, off) { + var stream = this.stream; + var frames; + + if (this.metadata) { + var mllt = this.metadata.MPEGLocationLookupTable; + if (mllt) { + var bitstream = new AV.Bitstream(AV.Stream.fromBuffer(mllt.data)); + var refSize = mllt.bitsForBytesDeviation + mllt.bitsForMillisecondsDev; + var samples = 0; + var bytes = 0; + + while (bitstream.available(refSize)) { + this.addSeekPoint(bytes, samples); + + var bytesDev = bitstream.read(mllt.bitsForBytesDeviation); + bitstream.advance(mllt.bitsForMillisecondsDev); // skip millisecond deviation + + bytes += mllt.bytesBetweenReference + bytesDev; + samples += mllt.framesBetweenReference * header.nbsamples() * 32; + } + + this.addSeekPoint(bytes, samples); + } + + if (this.metadata.length) { + this.emit('duration', parseInt(this.metadata.length, 10)); + return true; + } + } + + var offset = stream.offset; + if (!header || header.layer !== 3) + return false; + + // Check for Xing/Info tag + stream.advance(XING_OFFSETS[header.flags & MP3FrameHeader.FLAGS.LSF_EXT ? 1 : 0][header.nchannels() === 1 ? 1 : 0]); + var tag = stream.readString(4); + if (tag === 'Xing' || tag === 'Info') { + var flags = stream.readUInt32(); + if (flags & 1) + frames = stream.readUInt32(); + + if (flags & 2) + var size = stream.readUInt32(); + + if (flags & 4 && frames && size && this.seekPoints.length === 0) { + for (var i = 0; i < 100; i++) { + var b = stream.readUInt8(); + var pos = b / 256 * size | 0; + var time = i / 100 * (frames * header.nbsamples() * 32) | 0; + this.addSeekPoint(pos, time); + } + } + + if (flags & 8) + stream.advance(4); + + } else { + // Check for VBRI tag (always 32 bytes after end of mpegaudio header) + stream.seek(off + 4 + 32); + tag = stream.readString(4); + if (tag == 'VBRI' && stream.readUInt16() === 1) { // Check tag version + stream.advance(4); // skip delay and quality + stream.advance(4); // skip size + frames = stream.readUInt32(); + + if (this.seekPoints.length === 0) { + var entries = stream.readUInt16(); + var scale = stream.readUInt16(); + var bytesPerEntry = stream.readUInt16(); + var framesPerEntry = stream.readUInt16(); + var fn = 'readUInt' + (bytesPerEntry * 8); + + var pos = 0; + for (var i = 0; i < entries; i++) { + this.addSeekPoint(pos, i * framesPerEntry * header.nbsamples() * 32 | 0); + pos += stream[fn]() * scale; + } + } + } + } + + if (!frames) + return false; + + this.emit('duration', (frames * header.nbsamples() * 32) / header.samplerate * 1000 | 0); + return true; + }; + + this.prototype.readChunk = function() { + var stream = this.stream; + + if (!this.sentInfo) { + // read id3 metadata if it exists + var id3header = MP3Demuxer.getID3v2Header(stream); + if (id3header && !this.metadata) { + stream.advance(10); + + if (id3header.major > 2) { + var id3 = new ID3v23Stream(id3header, stream); + } else { + var id3 = new ID3v22Stream(id3header, stream); + } + + this.metadata = id3.read(); + this.emit('metadata', this.metadata); + stream.seek(10 + id3header.length); + } + + // read the header of the first audio frame + var off = stream.offset; + var s = new MP3Stream(new AV.Bitstream(stream)); + + var header = MP3FrameHeader.decode(s); + if (!header) + return this.emit('error', 'Could not find first frame.'); + + this.emit('format', { + formatID: 'mp3', + sampleRate: header.samplerate, + channelsPerFrame: header.nchannels(), + bitrate: header.bitrate, + floatingPoint: true, + layer: header.layer, + flags: header.flags + }); + + var sentDuration = this.parseDuration(header, off); + stream.advance(off - stream.offset); + + // if there were no Xing/VBRI tags, guesstimate the duration based on data size and bitrate + this.dataSize = 0; + if (!sentDuration) { + this.on('end', function() { + this.emit('duration', this.dataSize * 8 / header.bitrate * 1000 | 0); + }); + } + + this.sentInfo = true; + } + + while (stream.available(1)) { + var buffer = stream.readSingleBuffer(stream.remainingBytes()); + this.dataSize += buffer.length; + this.emit('data', buffer); + } + }; +}); + +module.exports = MP3Demuxer; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./header":5,"./id3":7,"./stream":12}],4:[function(require,module,exports){ +var MP3FrameHeader = require('./header'); +var utils = require('./utils'); + +function MP3Frame() { + this.header = null; // MPEG audio header + this.options = 0; // decoding options (from stream) + this.sbsample = utils.makeArray([2, 36, 32]); // synthesis subband filter samples + this.overlap = utils.makeArray([2, 32, 18]); // Layer III block overlap data + this.decoders = []; +} + +// included layer decoders are registered here +MP3Frame.layers = []; + +MP3Frame.prototype.decode = function(stream) { + if (!this.header || !(this.header.flags & MP3FrameHeader.FLAGS.INCOMPLETE)) + this.header = MP3FrameHeader.decode(stream); + + this.header.flags &= ~MP3FrameHeader.FLAGS.INCOMPLETE; + + // make an instance of the decoder for this layer if needed + var decoder = this.decoders[this.header.layer - 1]; + if (!decoder) { + var Layer = MP3Frame.layers[this.header.layer]; + if (!Layer) + throw new Error("Layer " + this.header.layer + " is not supported."); + + decoder = this.decoders[this.header.layer - 1] = new Layer(); + } + + decoder.decode(stream, this); +}; + +module.exports = MP3Frame; + +},{"./header":5,"./utils":15}],5:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); + +function MP3FrameHeader() { + this.layer = 0; // audio layer (1, 2, or 3) + this.mode = 0; // channel mode (see above) + this.mode_extension = 0; // additional mode info + this.emphasis = 0; // de-emphasis to use (see above) + + this.bitrate = 0; // stream bitrate (bps) + this.samplerate = 0; // sampling frequency (Hz) + + this.crc_check = 0; // frame CRC accumulator + this.crc_target = 0; // final target CRC checksum + + this.flags = 0; // flags (see above) + this.private_bits = 0; // private bits +} + +const BITRATES = [ + // MPEG-1 + [ 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, // Layer I + 256000, 288000, 320000, 352000, 384000, 416000, 448000 ], + [ 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, // Layer II + 128000, 160000, 192000, 224000, 256000, 320000, 384000 ], + [ 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, // Layer III + 112000, 128000, 160000, 192000, 224000, 256000, 320000 ], + + // MPEG-2 LSF + [ 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, // Layer I + 128000, 144000, 160000, 176000, 192000, 224000, 256000 ], + [ 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, // Layers + 64000, 80000, 96000, 112000, 128000, 144000, 160000 ] // II & III +]; + +const SAMPLERATES = [ + 44100, 48000, 32000 +]; + +MP3FrameHeader.FLAGS = { + NPRIVATE_III: 0x0007, // number of Layer III private bits + INCOMPLETE : 0x0008, // header but not data is decoded + + PROTECTION : 0x0010, // frame has CRC protection + COPYRIGHT : 0x0020, // frame is copyright + ORIGINAL : 0x0040, // frame is original (else copy) + PADDING : 0x0080, // frame has additional slot + + I_STEREO : 0x0100, // uses intensity joint stereo + MS_STEREO : 0x0200, // uses middle/side joint stereo + FREEFORMAT : 0x0400, // uses free format bitrate + + LSF_EXT : 0x1000, // lower sampling freq. extension + MC_EXT : 0x2000, // multichannel audio extension + MPEG_2_5_EXT: 0x4000 // MPEG 2.5 (unofficial) extension +}; + +const PRIVATE = { + HEADER : 0x0100, // header private bit + III : 0x001f // Layer III private bits (up to 5) +}; + +MP3FrameHeader.MODE = { + SINGLE_CHANNEL: 0, // single channel + DUAL_CHANNEL : 1, // dual channel + JOINT_STEREO : 2, // joint (MS/intensity) stereo + STEREO : 3 // normal LR stereo +}; + +const EMPHASIS = { + NONE : 0, // no emphasis + _50_15_US : 1, // 50/15 microseconds emphasis + CCITT_J_17: 3, // CCITT J.17 emphasis + RESERVED : 2 // unknown emphasis +}; + +MP3FrameHeader.BUFFER_GUARD = 8; +MP3FrameHeader.BUFFER_MDLEN = (511 + 2048 + MP3FrameHeader.BUFFER_GUARD); + +MP3FrameHeader.prototype.copy = function() { + var clone = new MP3FrameHeader(); + var keys = Object.keys(this); + + for (var key in keys) { + clone[key] = this[key]; + } + + return clone; +} + +MP3FrameHeader.prototype.nchannels = function () { + return this.mode === 0 ? 1 : 2; +}; + +MP3FrameHeader.prototype.nbsamples = function() { + return (this.layer === 1 ? 12 : ((this.layer === 3 && (this.flags & MP3FrameHeader.FLAGS.LSF_EXT)) ? 18 : 36)); +}; + +MP3FrameHeader.prototype.framesize = function() { + if (this.bitrate === 0) + return null; + + var padding = (this.flags & MP3FrameHeader.FLAGS.PADDING ? 1 : 0); + switch (this.layer) { + case 1: + var size = (this.bitrate * 12) / this.samplerate | 0; + return (size + padding) * 4; + + case 2: + var size = (this.bitrate * 144) / this.samplerate | 0; + return size + padding; + + case 3: + default: + var lsf = this.flags & MP3FrameHeader.FLAGS.LSF_EXT ? 1 : 0; + var size = (this.bitrate * 144) / (this.samplerate << lsf) | 0; + return size + padding; + } +}; + +MP3FrameHeader.prototype.decode = function(stream) { + this.flags = 0; + this.private_bits = 0; + + // syncword + stream.advance(11); + + // MPEG 2.5 indicator (really part of syncword) + if (stream.read(1) === 0) + this.flags |= MP3FrameHeader.FLAGS.MPEG_2_5_EXT; + + // ID + if (stream.read(1) === 0) { + this.flags |= MP3FrameHeader.FLAGS.LSF_EXT; + } else if (this.flags & MP3FrameHeader.FLAGS.MPEG_2_5_EXT) { + throw new AV.UnderflowError(); // LOSTSYNC + } + + // layer + this.layer = 4 - stream.read(2); + + if (this.layer === 4) + throw new Error('Invalid layer'); + + // protection_bit + if (stream.read(1) === 0) + this.flags |= MP3FrameHeader.FLAGS.PROTECTION; + + // bitrate_index + var index = stream.read(4); + if (index === 15) + throw new Error('Invalid bitrate'); + + if (this.flags & MP3FrameHeader.FLAGS.LSF_EXT) { + this.bitrate = BITRATES[3 + (this.layer >> 1)][index]; + } else { + this.bitrate = BITRATES[this.layer - 1][index]; + } + + // sampling_frequency + index = stream.read(2); + if (index === 3) + throw new Error('Invalid sampling frequency'); + + this.samplerate = SAMPLERATES[index]; + + if (this.flags & MP3FrameHeader.FLAGS.LSF_EXT) { + this.samplerate /= 2; + + if (this.flags & MP3FrameHeader.FLAGS.MPEG_2_5_EXT) + this.samplerate /= 2; + } + + // padding_bit + if (stream.read(1)) + this.flags |= MP3FrameHeader.FLAGS.PADDING; + + // private_bit + if (stream.read(1)) + this.private_bits |= PRIVATE.HEADER; + + // mode + this.mode = 3 - stream.read(2); + + // mode_extension + this.mode_extension = stream.read(2); + + // copyright + if (stream.read(1)) + this.flags |= MP3FrameHeader.FLAGS.COPYRIGHT; + + // original/copy + if (stream.read(1)) + this.flags |= MP3FrameHeader.FLAGS.ORIGINAL; + + // emphasis + this.emphasis = stream.read(2); + + // crc_check + if (this.flags & MP3FrameHeader.FLAGS.PROTECTION) + this.crc_target = stream.read(16); +}; + +MP3FrameHeader.decode = function(stream) { + // synchronize + var ptr = stream.next_frame; + var syncing = true; + var header = null; + + while (syncing) { + syncing = false; + + if (stream.sync) { + if (!stream.available(MP3FrameHeader.BUFFER_GUARD)) { + stream.next_frame = ptr; + throw new AV.UnderflowError(); + } else if (!(stream.getU8(ptr) === 0xff && (stream.getU8(ptr + 1) & 0xe0) === 0xe0)) { + // mark point where frame sync word was expected + stream.this_frame = ptr; + stream.next_frame = ptr + 1; + throw new AV.UnderflowError(); // LOSTSYNC + } + } else { + stream.seek(ptr * 8); + if (!stream.doSync()) + throw new AV.UnderflowError(); + + ptr = stream.nextByte(); + } + + // begin processing + stream.this_frame = ptr; + stream.next_frame = ptr + 1; // possibly bogus sync word + + stream.seek(stream.this_frame * 8); + + header = new MP3FrameHeader(); + header.decode(stream); + + if (header.bitrate === 0) { + if (stream.freerate === 0 || !stream.sync || (header.layer === 3 && stream.freerate > 640000)) + MP3FrameHeader.free_bitrate(stream, header); + + header.bitrate = stream.freerate; + header.flags |= MP3FrameHeader.FLAGS.FREEFORMAT; + } + + // calculate beginning of next frame + var pad_slot = (header.flags & MP3FrameHeader.FLAGS.PADDING) ? 1 : 0; + + if (header.layer === 1) { + var N = (((12 * header.bitrate / header.samplerate) << 0) + pad_slot) * 4; + } else { + var slots_per_frame = (header.layer === 3 && (header.flags & MP3FrameHeader.FLAGS.LSF_EXT)) ? 72 : 144; + var N = ((slots_per_frame * header.bitrate / header.samplerate) << 0) + pad_slot; + } + + // verify there is enough data left in buffer to decode this frame + if (!stream.available(N + MP3FrameHeader.BUFFER_GUARD)) { + stream.next_frame = stream.this_frame; + throw new AV.UnderflowError(); + } + + stream.next_frame = stream.this_frame + N; + + if (!stream.sync) { + // check that a valid frame header follows this frame + ptr = stream.next_frame; + + if (!(stream.getU8(ptr) === 0xff && (stream.getU8(ptr + 1) & 0xe0) === 0xe0)) { + ptr = stream.next_frame = stream.this_frame + 1; + + // emulating 'goto sync' + syncing = true; + continue; + } + + stream.sync = true; + } + } + + header.flags |= MP3FrameHeader.FLAGS.INCOMPLETE; + return header; +}; + +MP3FrameHeader.free_bitrate = function(stream, header) { + var pad_slot = header.flags & MP3FrameHeader.FLAGS.PADDING ? 1 : 0, + slots_per_frame = header.layer === 3 && header.flags & MP3FrameHeader.FLAGS.LSF_EXT ? 72 : 144; + + var start = stream.offset(); + var rate = 0; + + while (stream.doSync()) { + var peek_header = header.copy(); + var peek_stream = stream.copy(); + + if (peek_header.decode(peek_stream) && peek_header.layer === header.layer && peek_header.samplerate === header.samplerate) { + var N = stream.nextByte() - stream.this_frame; + + if (header.layer === 1) { + rate = header.samplerate * (N - 4 * pad_slot + 4) / 48 / 1000 | 0; + } else { + rate = header.samplerate * (N - pad_slot + 1) / slots_per_frame / 1000 | 0; + } + + if (rate >= 8) + break; + } + + stream.advance(8); + } + + stream.seek(start); + + if (rate < 8 || (header.layer === 3 && rate > 640)) + throw new AV.UnderflowError(); // LOSTSYNC + + stream.freerate = rate * 1000; +}; + +module.exports = MP3FrameHeader; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],6:[function(require,module,exports){ +/* + * These are the Huffman code words for Layer III. + * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3. + * + * These tables support decoding up to 4 Huffman code bits at a time. + */ + +var PTR = function(offs, bits) { + return { + final: 0, + ptr: { + bits: bits, + offset: offs + } + }; +}; + +var huffquad_V = function (v, w, x, y, hlen) { + return { + final: 1, + value: { + v: v, + w: w, + x: x, + y: y, + hlen: hlen + } + }; +}; + +const hufftabA = [ + /* 0000 */ PTR(16, 2), + /* 0001 */ PTR(20, 2), + /* 0010 */ PTR(24, 1), + /* 0011 */ PTR(26, 1), + /* 0100 */ huffquad_V(0, 0, 1, 0, 4), + /* 0101 */ huffquad_V(0, 0, 0, 1, 4), + /* 0110 */ huffquad_V(0, 1, 0, 0, 4), + /* 0111 */ huffquad_V(1, 0, 0, 0, 4), + /* 1000 */ huffquad_V(0, 0, 0, 0, 1), + /* 1001 */ huffquad_V(0, 0, 0, 0, 1), + /* 1010 */ huffquad_V(0, 0, 0, 0, 1), + /* 1011 */ huffquad_V(0, 0, 0, 0, 1), + /* 1100 */ huffquad_V(0, 0, 0, 0, 1), + /* 1101 */ huffquad_V(0, 0, 0, 0, 1), + /* 1110 */ huffquad_V(0, 0, 0, 0, 1), + /* 1111 */ huffquad_V(0, 0, 0, 0, 1), + + /* 0000 ... */ + /* 00 */ huffquad_V(1, 0, 1, 1, 2), /* 16 */ + /* 01 */ huffquad_V(1, 1, 1, 1, 2), + /* 10 */ huffquad_V(1, 1, 0, 1, 2), + /* 11 */ huffquad_V(1, 1, 1, 0, 2), + + /* 0001 ... */ + /* 00 */ huffquad_V(0, 1, 1, 1, 2), /* 20 */ + /* 01 */ huffquad_V(0, 1, 0, 1, 2), + /* 10 */ huffquad_V(1, 0, 0, 1, 1), + /* 11 */ huffquad_V(1, 0, 0, 1, 1), + + /* 0010 ... */ + /* 0 */ huffquad_V(0, 1, 1, 0, 1), /* 24 */ + /* 1 */ huffquad_V(0, 0, 1, 1, 1), + + /* 0011 ... */ + /* 0 */ huffquad_V(1, 0, 1, 0, 1), /* 26 */ + /* 1 */ huffquad_V(1, 1, 0, 0, 1) +]; + +const hufftabB = [ + /* 0000 */ huffquad_V(1, 1, 1, 1, 4), + /* 0001 */ huffquad_V(1, 1, 1, 0, 4), + /* 0010 */ huffquad_V(1, 1, 0, 1, 4), + /* 0011 */ huffquad_V(1, 1, 0, 0, 4), + /* 0100 */ huffquad_V(1, 0, 1, 1, 4), + /* 0101 */ huffquad_V(1, 0, 1, 0, 4), + /* 0110 */ huffquad_V(1, 0, 0, 1, 4), + /* 0111 */ huffquad_V(1, 0, 0, 0, 4), + /* 1000 */ huffquad_V(0, 1, 1, 1, 4), + /* 1001 */ huffquad_V(0, 1, 1, 0, 4), + /* 1010 */ huffquad_V(0, 1, 0, 1, 4), + /* 1011 */ huffquad_V(0, 1, 0, 0, 4), + /* 1100 */ huffquad_V(0, 0, 1, 1, 4), + /* 1101 */ huffquad_V(0, 0, 1, 0, 4), + /* 1110 */ huffquad_V(0, 0, 0, 1, 4), + /* 1111 */ huffquad_V(0, 0, 0, 0, 4) +]; + +var V = function (x, y, hlen) { + return { + final: 1, + value: { + x: x, + y: y, + hlen: hlen + } + }; +}; + +const hufftab0 = [ + /* */ V(0, 0, 0) +]; + +const hufftab1 = [ + /* 000 */ V(1, 1, 3), + /* 001 */ V(0, 1, 3), + /* 010 */ V(1, 0, 2), + /* 011 */ V(1, 0, 2), + /* 100 */ V(0, 0, 1), + /* 101 */ V(0, 0, 1), + /* 110 */ V(0, 0, 1), + /* 111 */ V(0, 0, 1) +]; + +const hufftab2 = [ + /* 000 */ PTR(8, 3), + /* 001 */ V(1, 1, 3), + /* 010 */ V(0, 1, 3), + /* 011 */ V(1, 0, 3), + /* 100 */ V(0, 0, 1), + /* 101 */ V(0, 0, 1), + /* 110 */ V(0, 0, 1), + /* 111 */ V(0, 0, 1), + + /* 000 ... */ + /* 000 */ V(2, 2, 3), /* 8 */ + /* 001 */ V(0, 2, 3), + /* 010 */ V(1, 2, 2), + /* 011 */ V(1, 2, 2), + /* 100 */ V(2, 1, 2), + /* 101 */ V(2, 1, 2), + /* 110 */ V(2, 0, 2), + /* 111 */ V(2, 0, 2) +]; + +const hufftab3 = [ + /* 000 */ PTR(8, 3), + /* 001 */ V(1, 0, 3), + /* 010 */ V(1, 1, 2), + /* 011 */ V(1, 1, 2), + /* 100 */ V(0, 1, 2), + /* 101 */ V(0, 1, 2), + /* 110 */ V(0, 0, 2), + /* 111 */ V(0, 0, 2), + + /* 000 ... */ + /* 000 */ V(2, 2, 3), /* 8 */ + /* 001 */ V(0, 2, 3), + /* 010 */ V(1, 2, 2), + /* 011 */ V(1, 2, 2), + /* 100 */ V(2, 1, 2), + /* 101 */ V(2, 1, 2), + /* 110 */ V(2, 0, 2), + /* 111 */ V(2, 0, 2) +]; + +const hufftab5 = [ + /* 000 */ PTR(8, 4), + /* 001 */ V(1, 1, 3), + /* 010 */ V(0, 1, 3), + /* 011 */ V(1, 0, 3), + /* 100 */ V(0, 0, 1), + /* 101 */ V(0, 0, 1), + /* 110 */ V(0, 0, 1), + /* 111 */ V(0, 0, 1), + + /* 000 ... */ + /* 0000 */ PTR(24, 1), /* 8 */ + /* 0001 */ V(3, 2, 4), + /* 0010 */ V(3, 1, 3), + /* 0011 */ V(3, 1, 3), + /* 0100 */ V(1, 3, 4), + /* 0101 */ V(0, 3, 4), + /* 0110 */ V(3, 0, 4), + /* 0111 */ V(2, 2, 4), + /* 1000 */ V(1, 2, 3), + /* 1001 */ V(1, 2, 3), + /* 1010 */ V(2, 1, 3), + /* 1011 */ V(2, 1, 3), + /* 1100 */ V(0, 2, 3), + /* 1101 */ V(0, 2, 3), + /* 1110 */ V(2, 0, 3), + /* 1111 */ V(2, 0, 3), + + /* 000 0000 ... */ + /* 0 */ V(3, 3, 1), /* 24 */ + /* 1 */ V(2, 3, 1) +]; + +const hufftab6 = [ + /* 0000 */ PTR(16, 3), + /* 0001 */ PTR(24, 1), + /* 0010 */ PTR(26, 1), + /* 0011 */ V(1, 2, 4), + /* 0100 */ V(2, 1, 4), + /* 0101 */ V(2, 0, 4), + /* 0110 */ V(0, 1, 3), + /* 0111 */ V(0, 1, 3), + /* 1000 */ V(1, 1, 2), + /* 1001 */ V(1, 1, 2), + /* 1010 */ V(1, 1, 2), + /* 1011 */ V(1, 1, 2), + /* 1100 */ V(1, 0, 3), + /* 1101 */ V(1, 0, 3), + /* 1110 */ V(0, 0, 3), + /* 1111 */ V(0, 0, 3), + + /* 0000 ... */ + /* 000 */ V(3, 3, 3), /* 16 */ + /* 001 */ V(0, 3, 3), + /* 010 */ V(2, 3, 2), + /* 011 */ V(2, 3, 2), + /* 100 */ V(3, 2, 2), + /* 101 */ V(3, 2, 2), + /* 110 */ V(3, 0, 2), + /* 111 */ V(3, 0, 2), + + /* 0001 ... */ + /* 0 */ V(1, 3, 1), /* 24 */ + /* 1 */ V(3, 1, 1), + + /* 0010 ... */ + /* 0 */ V(2, 2, 1), /* 26 */ + /* 1 */ V(0, 2, 1) +]; + +const hufftab7 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 2), + /* 0011 */ V(1, 1, 4), + /* 0100 */ V(0, 1, 3), + /* 0101 */ V(0, 1, 3), + /* 0110 */ V(1, 0, 3), + /* 0111 */ V(1, 0, 3), + /* 1000 */ V(0, 0, 1), + /* 1001 */ V(0, 0, 1), + /* 1010 */ V(0, 0, 1), + /* 1011 */ V(0, 0, 1), + /* 1100 */ V(0, 0, 1), + /* 1101 */ V(0, 0, 1), + /* 1110 */ V(0, 0, 1), + /* 1111 */ V(0, 0, 1), + + /* 0000 ... */ + /* 0000 */ PTR(52, 2), /* 16 */ + /* 0001 */ PTR(56, 1), + /* 0010 */ PTR(58, 1), + /* 0011 */ V(1, 5, 4), + /* 0100 */ V(5, 1, 4), + /* 0101 */ PTR(60, 1), + /* 0110 */ V(5, 0, 4), + /* 0111 */ PTR(62, 1), + /* 1000 */ V(2, 4, 4), + /* 1001 */ V(4, 2, 4), + /* 1010 */ V(1, 4, 3), + /* 1011 */ V(1, 4, 3), + /* 1100 */ V(4, 1, 3), + /* 1101 */ V(4, 1, 3), + /* 1110 */ V(4, 0, 3), + /* 1111 */ V(4, 0, 3), + + /* 0001 ... */ + /* 0000 */ V(0, 4, 4), /* 32 */ + /* 0001 */ V(2, 3, 4), + /* 0010 */ V(3, 2, 4), + /* 0011 */ V(0, 3, 4), + /* 0100 */ V(1, 3, 3), + /* 0101 */ V(1, 3, 3), + /* 0110 */ V(3, 1, 3), + /* 0111 */ V(3, 1, 3), + /* 1000 */ V(3, 0, 3), + /* 1001 */ V(3, 0, 3), + /* 1010 */ V(2, 2, 3), + /* 1011 */ V(2, 2, 3), + /* 1100 */ V(1, 2, 2), + /* 1101 */ V(1, 2, 2), + /* 1110 */ V(1, 2, 2), + /* 1111 */ V(1, 2, 2), + + /* 0010 ... */ + /* 00 */ V(2, 1, 1), /* 48 */ + /* 01 */ V(2, 1, 1), + /* 10 */ V(0, 2, 2), + /* 11 */ V(2, 0, 2), + + /* 0000 0000 ... */ + /* 00 */ V(5, 5, 2), /* 52 */ + /* 01 */ V(4, 5, 2), + /* 10 */ V(5, 4, 2), + /* 11 */ V(5, 3, 2), + + /* 0000 0001 ... */ + /* 0 */ V(3, 5, 1), /* 56 */ + /* 1 */ V(4, 4, 1), + + /* 0000 0010 ... */ + /* 0 */ V(2, 5, 1), /* 58 */ + /* 1 */ V(5, 2, 1), + + /* 0000 0101 ... */ + /* 0 */ V(0, 5, 1), /* 60 */ + /* 1 */ V(3, 4, 1), + + /* 0000 0111 ... */ + /* 0 */ V(4, 3, 1), /* 62 */ + /* 1 */ V(3, 3, 1) +]; + +const hufftab8 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ V(1, 2, 4), + /* 0011 */ V(2, 1, 4), + /* 0100 */ V(1, 1, 2), + /* 0101 */ V(1, 1, 2), + /* 0110 */ V(1, 1, 2), + /* 0111 */ V(1, 1, 2), + /* 1000 */ V(0, 1, 3), + /* 1001 */ V(0, 1, 3), + /* 1010 */ V(1, 0, 3), + /* 1011 */ V(1, 0, 3), + /* 1100 */ V(0, 0, 2), + /* 1101 */ V(0, 0, 2), + /* 1110 */ V(0, 0, 2), + /* 1111 */ V(0, 0, 2), + + /* 0000 ... */ + /* 0000 */ PTR(48, 3), /* 16 */ + /* 0001 */ PTR(56, 2), + /* 0010 */ PTR(60, 1), + /* 0011 */ V(1, 5, 4), + /* 0100 */ V(5, 1, 4), + /* 0101 */ PTR(62, 1), + /* 0110 */ PTR(64, 1), + /* 0111 */ V(2, 4, 4), + /* 1000 */ V(4, 2, 4), + /* 1001 */ V(1, 4, 4), + /* 1010 */ V(4, 1, 3), + /* 1011 */ V(4, 1, 3), + /* 1100 */ V(0, 4, 4), + /* 1101 */ V(4, 0, 4), + /* 1110 */ V(2, 3, 4), + /* 1111 */ V(3, 2, 4), + + /* 0001 ... */ + /* 0000 */ V(1, 3, 4), /* 32 */ + /* 0001 */ V(3, 1, 4), + /* 0010 */ V(0, 3, 4), + /* 0011 */ V(3, 0, 4), + /* 0100 */ V(2, 2, 2), + /* 0101 */ V(2, 2, 2), + /* 0110 */ V(2, 2, 2), + /* 0111 */ V(2, 2, 2), + /* 1000 */ V(0, 2, 2), + /* 1001 */ V(0, 2, 2), + /* 1010 */ V(0, 2, 2), + /* 1011 */ V(0, 2, 2), + /* 1100 */ V(2, 0, 2), + /* 1101 */ V(2, 0, 2), + /* 1110 */ V(2, 0, 2), + /* 1111 */ V(2, 0, 2), + + /* 0000 0000 ... */ + /* 000 */ V(5, 5, 3), /* 48 */ + /* 001 */ V(5, 4, 3), + /* 010 */ V(4, 5, 2), + /* 011 */ V(4, 5, 2), + /* 100 */ V(5, 3, 1), + /* 101 */ V(5, 3, 1), + /* 110 */ V(5, 3, 1), + /* 111 */ V(5, 3, 1), + + /* 0000 0001 ... */ + /* 00 */ V(3, 5, 2), /* 56 */ + /* 01 */ V(4, 4, 2), + /* 10 */ V(2, 5, 1), + /* 11 */ V(2, 5, 1), + + /* 0000 0010 ... */ + /* 0 */ V(5, 2, 1), /* 60 */ + /* 1 */ V(0, 5, 1), + + /* 0000 0101 ... */ + /* 0 */ V(3, 4, 1), /* 62 */ + /* 1 */ V(4, 3, 1), + + /* 0000 0110 ... */ + /* 0 */ V(5, 0, 1), /* 64 */ + /* 1 */ V(3, 3, 1) +]; + +const hufftab9 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 3), + /* 0010 */ PTR(40, 2), + /* 0011 */ PTR(44, 2), + /* 0100 */ PTR(48, 1), + /* 0101 */ V(1, 2, 4), + /* 0110 */ V(2, 1, 4), + /* 0111 */ V(2, 0, 4), + /* 1000 */ V(1, 1, 3), + /* 1001 */ V(1, 1, 3), + /* 1010 */ V(0, 1, 3), + /* 1011 */ V(0, 1, 3), + /* 1100 */ V(1, 0, 3), + /* 1101 */ V(1, 0, 3), + /* 1110 */ V(0, 0, 3), + /* 1111 */ V(0, 0, 3), + + /* 0000 ... */ + /* 0000 */ PTR(50, 1), /* 16 */ + /* 0001 */ V(3, 5, 4), + /* 0010 */ V(5, 3, 4), + /* 0011 */ PTR(52, 1), + /* 0100 */ V(4, 4, 4), + /* 0101 */ V(2, 5, 4), + /* 0110 */ V(5, 2, 4), + /* 0111 */ V(1, 5, 4), + /* 1000 */ V(5, 1, 3), + /* 1001 */ V(5, 1, 3), + /* 1010 */ V(3, 4, 3), + /* 1011 */ V(3, 4, 3), + /* 1100 */ V(4, 3, 3), + /* 1101 */ V(4, 3, 3), + /* 1110 */ V(5, 0, 4), + /* 1111 */ V(0, 4, 4), + + /* 0001 ... */ + /* 000 */ V(2, 4, 3), /* 32 */ + /* 001 */ V(4, 2, 3), + /* 010 */ V(3, 3, 3), + /* 011 */ V(4, 0, 3), + /* 100 */ V(1, 4, 2), + /* 101 */ V(1, 4, 2), + /* 110 */ V(4, 1, 2), + /* 111 */ V(4, 1, 2), + + /* 0010 ... */ + /* 00 */ V(2, 3, 2), /* 40 */ + /* 01 */ V(3, 2, 2), + /* 10 */ V(1, 3, 1), + /* 11 */ V(1, 3, 1), + + /* 0011 ... */ + /* 00 */ V(3, 1, 1), /* 44 */ + /* 01 */ V(3, 1, 1), + /* 10 */ V(0, 3, 2), + /* 11 */ V(3, 0, 2), + + /* 0100 ... */ + /* 0 */ V(2, 2, 1), /* 48 */ + /* 1 */ V(0, 2, 1), + + /* 0000 0000 ... */ + /* 0 */ V(5, 5, 1), /* 50 */ + /* 1 */ V(4, 5, 1), + + /* 0000 0011 ... */ + /* 0 */ V(5, 4, 1), /* 52 */ + /* 1 */ V(0, 5, 1) +]; + +const hufftab10 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 2), + /* 0011 */ V(1, 1, 4), + /* 0100 */ V(0, 1, 3), + /* 0101 */ V(0, 1, 3), + /* 0110 */ V(1, 0, 3), + /* 0111 */ V(1, 0, 3), + /* 1000 */ V(0, 0, 1), + /* 1001 */ V(0, 0, 1), + /* 1010 */ V(0, 0, 1), + /* 1011 */ V(0, 0, 1), + /* 1100 */ V(0, 0, 1), + /* 1101 */ V(0, 0, 1), + /* 1110 */ V(0, 0, 1), + /* 1111 */ V(0, 0, 1), + + /* 0000 ... */ + /* 0000 */ PTR(52, 3), /* 16 */ + /* 0001 */ PTR(60, 2), + /* 0010 */ PTR(64, 3), + /* 0011 */ PTR(72, 1), + /* 0100 */ PTR(74, 2), + /* 0101 */ PTR(78, 2), + /* 0110 */ PTR(82, 2), + /* 0111 */ V(1, 7, 4), + /* 1000 */ V(7, 1, 4), + /* 1001 */ PTR(86, 1), + /* 1010 */ PTR(88, 2), + /* 1011 */ PTR(92, 2), + /* 1100 */ V(1, 6, 4), + /* 1101 */ V(6, 1, 4), + /* 1110 */ V(6, 0, 4), + /* 1111 */ PTR(96, 1), + + /* 0001 ... */ + /* 0000 */ PTR(98, 1), /* 32 */ + /* 0001 */ PTR(100, 1), + /* 0010 */ V(1, 4, 4), + /* 0011 */ V(4, 1, 4), + /* 0100 */ V(4, 0, 4), + /* 0101 */ V(2, 3, 4), + /* 0110 */ V(3, 2, 4), + /* 0111 */ V(0, 3, 4), + /* 1000 */ V(1, 3, 3), + /* 1001 */ V(1, 3, 3), + /* 1010 */ V(3, 1, 3), + /* 1011 */ V(3, 1, 3), + /* 1100 */ V(3, 0, 3), + /* 1101 */ V(3, 0, 3), + /* 1110 */ V(2, 2, 3), + /* 1111 */ V(2, 2, 3), + + /* 0010 ... */ + /* 00 */ V(1, 2, 2), /* 48 */ + /* 01 */ V(2, 1, 2), + /* 10 */ V(0, 2, 2), + /* 11 */ V(2, 0, 2), + + /* 0000 0000 ... */ + /* 000 */ V(7, 7, 3), /* 52 */ + /* 001 */ V(6, 7, 3), + /* 010 */ V(7, 6, 3), + /* 011 */ V(5, 7, 3), + /* 100 */ V(7, 5, 3), + /* 101 */ V(6, 6, 3), + /* 110 */ V(4, 7, 2), + /* 111 */ V(4, 7, 2), + + /* 0000 0001 ... */ + /* 00 */ V(7, 4, 2), /* 60 */ + /* 01 */ V(5, 6, 2), + /* 10 */ V(6, 5, 2), + /* 11 */ V(3, 7, 2), + + /* 0000 0010 ... */ + /* 000 */ V(7, 3, 2), /* 64 */ + /* 001 */ V(7, 3, 2), + /* 010 */ V(4, 6, 2), + /* 011 */ V(4, 6, 2), + /* 100 */ V(5, 5, 3), + /* 101 */ V(5, 4, 3), + /* 110 */ V(6, 3, 2), + /* 111 */ V(6, 3, 2), + + /* 0000 0011 ... */ + /* 0 */ V(2, 7, 1), /* 72 */ + /* 1 */ V(7, 2, 1), + + /* 0000 0100 ... */ + /* 00 */ V(6, 4, 2), /* 74 */ + /* 01 */ V(0, 7, 2), + /* 10 */ V(7, 0, 1), + /* 11 */ V(7, 0, 1), + + /* 0000 0101 ... */ + /* 00 */ V(6, 2, 1), /* 78 */ + /* 01 */ V(6, 2, 1), + /* 10 */ V(4, 5, 2), + /* 11 */ V(3, 5, 2), + + /* 0000 0110 ... */ + /* 00 */ V(0, 6, 1), /* 82 */ + /* 01 */ V(0, 6, 1), + /* 10 */ V(5, 3, 2), + /* 11 */ V(4, 4, 2), + + /* 0000 1001 ... */ + /* 0 */ V(3, 6, 1), /* 86 */ + /* 1 */ V(2, 6, 1), + + /* 0000 1010 ... */ + /* 00 */ V(2, 5, 2), /* 88 */ + /* 01 */ V(5, 2, 2), + /* 10 */ V(1, 5, 1), + /* 11 */ V(1, 5, 1), + + /* 0000 1011 ... */ + /* 00 */ V(5, 1, 1), /* 92 */ + /* 01 */ V(5, 1, 1), + /* 10 */ V(3, 4, 2), + /* 11 */ V(4, 3, 2), + + /* 0000 1111 ... */ + /* 0 */ V(0, 5, 1), /* 96 */ + /* 1 */ V(5, 0, 1), + + /* 0001 0000 ... */ + /* 0 */ V(2, 4, 1), /* 98 */ + /* 1 */ V(4, 2, 1), + + /* 0001 0001 ... */ + /* 0 */ V(3, 3, 1), /* 100 */ + /* 1 */ V(0, 4, 1) +]; + +const hufftab11 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ PTR(64, 3), + /* 0100 */ V(1, 2, 4), + /* 0101 */ PTR(72, 1), + /* 0110 */ V(1, 1, 3), + /* 0111 */ V(1, 1, 3), + /* 1000 */ V(0, 1, 3), + /* 1001 */ V(0, 1, 3), + /* 1010 */ V(1, 0, 3), + /* 1011 */ V(1, 0, 3), + /* 1100 */ V(0, 0, 2), + /* 1101 */ V(0, 0, 2), + /* 1110 */ V(0, 0, 2), + /* 1111 */ V(0, 0, 2), + + /* 0000 ... */ + /* 0000 */ PTR(74, 2), /* 16 */ + /* 0001 */ PTR(78, 3), + /* 0010 */ PTR(86, 2), + /* 0011 */ PTR(90, 1), + /* 0100 */ PTR(92, 2), + /* 0101 */ V(2, 7, 4), + /* 0110 */ V(7, 2, 4), + /* 0111 */ PTR(96, 1), + /* 1000 */ V(7, 1, 3), + /* 1001 */ V(7, 1, 3), + /* 1010 */ V(1, 7, 4), + /* 1011 */ V(7, 0, 4), + /* 1100 */ V(3, 6, 4), + /* 1101 */ V(6, 3, 4), + /* 1110 */ V(6, 0, 4), + /* 1111 */ PTR(98, 1), + + /* 0001 ... */ + /* 0000 */ PTR(100, 1), /* 32 */ + /* 0001 */ V(1, 5, 4), + /* 0010 */ V(6, 2, 3), + /* 0011 */ V(6, 2, 3), + /* 0100 */ V(2, 6, 4), + /* 0101 */ V(0, 6, 4), + /* 0110 */ V(1, 6, 3), + /* 0111 */ V(1, 6, 3), + /* 1000 */ V(6, 1, 3), + /* 1001 */ V(6, 1, 3), + /* 1010 */ V(5, 1, 4), + /* 1011 */ V(3, 4, 4), + /* 1100 */ V(5, 0, 4), + /* 1101 */ PTR(102, 1), + /* 1110 */ V(2, 4, 4), + /* 1111 */ V(4, 2, 4), + + /* 0010 ... */ + /* 0000 */ V(1, 4, 4), /* 48 */ + /* 0001 */ V(4, 1, 4), + /* 0010 */ V(0, 4, 4), + /* 0011 */ V(4, 0, 4), + /* 0100 */ V(2, 3, 3), + /* 0101 */ V(2, 3, 3), + /* 0110 */ V(3, 2, 3), + /* 0111 */ V(3, 2, 3), + /* 1000 */ V(1, 3, 2), + /* 1001 */ V(1, 3, 2), + /* 1010 */ V(1, 3, 2), + /* 1011 */ V(1, 3, 2), + /* 1100 */ V(3, 1, 2), + /* 1101 */ V(3, 1, 2), + /* 1110 */ V(3, 1, 2), + /* 1111 */ V(3, 1, 2), + + /* 0011 ... */ + /* 000 */ V(0, 3, 3), /* 64 */ + /* 001 */ V(3, 0, 3), + /* 010 */ V(2, 2, 2), + /* 011 */ V(2, 2, 2), + /* 100 */ V(2, 1, 1), + /* 101 */ V(2, 1, 1), + /* 110 */ V(2, 1, 1), + /* 111 */ V(2, 1, 1), + + /* 0101 ... */ + /* 0 */ V(0, 2, 1), /* 72 */ + /* 1 */ V(2, 0, 1), + + /* 0000 0000 ... */ + /* 00 */ V(7, 7, 2), /* 74 */ + /* 01 */ V(6, 7, 2), + /* 10 */ V(7, 6, 2), + /* 11 */ V(7, 5, 2), + + /* 0000 0001 ... */ + /* 000 */ V(6, 6, 2), /* 78 */ + /* 001 */ V(6, 6, 2), + /* 010 */ V(4, 7, 2), + /* 011 */ V(4, 7, 2), + /* 100 */ V(7, 4, 2), + /* 101 */ V(7, 4, 2), + /* 110 */ V(5, 7, 3), + /* 111 */ V(5, 5, 3), + + /* 0000 0010 ... */ + /* 00 */ V(5, 6, 2), /* 86 */ + /* 01 */ V(6, 5, 2), + /* 10 */ V(3, 7, 1), + /* 11 */ V(3, 7, 1), + + /* 0000 0011 ... */ + /* 0 */ V(7, 3, 1), /* 90 */ + /* 1 */ V(4, 6, 1), + + /* 0000 0100 ... */ + /* 00 */ V(4, 5, 2), /* 92 */ + /* 01 */ V(5, 4, 2), + /* 10 */ V(3, 5, 2), + /* 11 */ V(5, 3, 2), + + /* 0000 0111 ... */ + /* 0 */ V(6, 4, 1), /* 96 */ + /* 1 */ V(0, 7, 1), + + /* 0000 1111 ... */ + /* 0 */ V(4, 4, 1), /* 98 */ + /* 1 */ V(2, 5, 1), + + /* 0001 0000 ... */ + /* 0 */ V(5, 2, 1), /* 100 */ + /* 1 */ V(0, 5, 1), + + /* 0001 1101 ... */ + /* 0 */ V(4, 3, 1), /* 102 */ + /* 1 */ V(3, 3, 1) +]; + +const hufftab12 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ PTR(64, 2), + /* 0100 */ PTR(68, 3), + /* 0101 */ PTR(76, 1), + /* 0110 */ V(1, 2, 4), + /* 0111 */ V(2, 1, 4), + /* 1000 */ PTR(78, 1), + /* 1001 */ V(0, 0, 4), + /* 1010 */ V(1, 1, 3), + /* 1011 */ V(1, 1, 3), + /* 1100 */ V(0, 1, 3), + /* 1101 */ V(0, 1, 3), + /* 1110 */ V(1, 0, 3), + /* 1111 */ V(1, 0, 3), + + /* 0000 ... */ + /* 0000 */ PTR(80, 2), /* 16 */ + /* 0001 */ PTR(84, 1), + /* 0010 */ PTR(86, 1), + /* 0011 */ PTR(88, 1), + /* 0100 */ V(5, 6, 4), + /* 0101 */ V(3, 7, 4), + /* 0110 */ PTR(90, 1), + /* 0111 */ V(2, 7, 4), + /* 1000 */ V(7, 2, 4), + /* 1001 */ V(4, 6, 4), + /* 1010 */ V(6, 4, 4), + /* 1011 */ V(1, 7, 4), + /* 1100 */ V(7, 1, 4), + /* 1101 */ PTR(92, 1), + /* 1110 */ V(3, 6, 4), + /* 1111 */ V(6, 3, 4), + + /* 0001 ... */ + /* 0000 */ V(4, 5, 4), /* 32 */ + /* 0001 */ V(5, 4, 4), + /* 0010 */ V(4, 4, 4), + /* 0011 */ PTR(94, 1), + /* 0100 */ V(2, 6, 3), + /* 0101 */ V(2, 6, 3), + /* 0110 */ V(6, 2, 3), + /* 0111 */ V(6, 2, 3), + /* 1000 */ V(6, 1, 3), + /* 1001 */ V(6, 1, 3), + /* 1010 */ V(1, 6, 4), + /* 1011 */ V(6, 0, 4), + /* 1100 */ V(3, 5, 4), + /* 1101 */ V(5, 3, 4), + /* 1110 */ V(2, 5, 4), + /* 1111 */ V(5, 2, 4), + + /* 0010 ... */ + /* 0000 */ V(1, 5, 3), /* 48 */ + /* 0001 */ V(1, 5, 3), + /* 0010 */ V(5, 1, 3), + /* 0011 */ V(5, 1, 3), + /* 0100 */ V(3, 4, 3), + /* 0101 */ V(3, 4, 3), + /* 0110 */ V(4, 3, 3), + /* 0111 */ V(4, 3, 3), + /* 1000 */ V(5, 0, 4), + /* 1001 */ V(0, 4, 4), + /* 1010 */ V(2, 4, 3), + /* 1011 */ V(2, 4, 3), + /* 1100 */ V(4, 2, 3), + /* 1101 */ V(4, 2, 3), + /* 1110 */ V(1, 4, 3), + /* 1111 */ V(1, 4, 3), + + /* 0011 ... */ + /* 00 */ V(3, 3, 2), /* 64 */ + /* 01 */ V(4, 1, 2), + /* 10 */ V(2, 3, 2), + /* 11 */ V(3, 2, 2), + + /* 0100 ... */ + /* 000 */ V(4, 0, 3), /* 68 */ + /* 001 */ V(0, 3, 3), + /* 010 */ V(3, 0, 2), + /* 011 */ V(3, 0, 2), + /* 100 */ V(1, 3, 1), + /* 101 */ V(1, 3, 1), + /* 110 */ V(1, 3, 1), + /* 111 */ V(1, 3, 1), + + /* 0101 ... */ + /* 0 */ V(3, 1, 1), /* 76 */ + /* 1 */ V(2, 2, 1), + + /* 1000 ... */ + /* 0 */ V(0, 2, 1), /* 78 */ + /* 1 */ V(2, 0, 1), + + /* 0000 0000 ... */ + /* 00 */ V(7, 7, 2), /* 80 */ + /* 01 */ V(6, 7, 2), + /* 10 */ V(7, 6, 1), + /* 11 */ V(7, 6, 1), + + /* 0000 0001 ... */ + /* 0 */ V(5, 7, 1), /* 84 */ + /* 1 */ V(7, 5, 1), + + /* 0000 0010 ... */ + /* 0 */ V(6, 6, 1), /* 86 */ + /* 1 */ V(4, 7, 1), + + /* 0000 0011 ... */ + /* 0 */ V(7, 4, 1), /* 88 */ + /* 1 */ V(6, 5, 1), + + /* 0000 0110 ... */ + /* 0 */ V(7, 3, 1), /* 90 */ + /* 1 */ V(5, 5, 1), + + /* 0000 1101 ... */ + /* 0 */ V(0, 7, 1), /* 92 */ + /* 1 */ V(7, 0, 1), + + /* 0001 0011 ... */ + /* 0 */ V(0, 6, 1), /* 94 */ + /* 1 */ V(0, 5, 1) +]; + +const hufftab13 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ PTR(64, 2), + /* 0100 */ V(1, 1, 4), + /* 0101 */ V(0, 1, 4), + /* 0110 */ V(1, 0, 3), + /* 0111 */ V(1, 0, 3), + /* 1000 */ V(0, 0, 1), + /* 1001 */ V(0, 0, 1), + /* 1010 */ V(0, 0, 1), + /* 1011 */ V(0, 0, 1), + /* 1100 */ V(0, 0, 1), + /* 1101 */ V(0, 0, 1), + /* 1110 */ V(0, 0, 1), + /* 1111 */ V(0, 0, 1), + + /* 0000 ... */ + /* 0000 */ PTR(68, 4), /* 16 */ + /* 0001 */ PTR(84, 4), + /* 0010 */ PTR(100, 4), + /* 0011 */ PTR(116, 4), + /* 0100 */ PTR(132, 4), + /* 0101 */ PTR(148, 4), + /* 0110 */ PTR(164, 3), + /* 0111 */ PTR(172, 3), + /* 1000 */ PTR(180, 3), + /* 1001 */ PTR(188, 3), + /* 1010 */ PTR(196, 3), + /* 1011 */ PTR(204, 3), + /* 1100 */ PTR(212, 1), + /* 1101 */ PTR(214, 2), + /* 1110 */ PTR(218, 3), + /* 1111 */ PTR(226, 1), + + /* 0001 ... */ + /* 0000 */ PTR(228, 2), /* 32 */ + /* 0001 */ PTR(232, 2), + /* 0010 */ PTR(236, 2), + /* 0011 */ PTR(240, 2), + /* 0100 */ V(8, 1, 4), + /* 0101 */ PTR(244, 1), + /* 0110 */ PTR(246, 1), + /* 0111 */ PTR(248, 1), + /* 1000 */ PTR(250, 2), + /* 1001 */ PTR(254, 1), + /* 1010 */ V(1, 5, 4), + /* 1011 */ V(5, 1, 4), + /* 1100 */ PTR(256, 1), + /* 1101 */ PTR(258, 1), + /* 1110 */ PTR(260, 1), + /* 1111 */ V(1, 4, 4), + + /* 0010 ... */ + /* 0000 */ V(4, 1, 3), /* 48 */ + /* 0001 */ V(4, 1, 3), + /* 0010 */ V(0, 4, 4), + /* 0011 */ V(4, 0, 4), + /* 0100 */ V(2, 3, 4), + /* 0101 */ V(3, 2, 4), + /* 0110 */ V(1, 3, 3), + /* 0111 */ V(1, 3, 3), + /* 1000 */ V(3, 1, 3), + /* 1001 */ V(3, 1, 3), + /* 1010 */ V(0, 3, 3), + /* 1011 */ V(0, 3, 3), + /* 1100 */ V(3, 0, 3), + /* 1101 */ V(3, 0, 3), + /* 1110 */ V(2, 2, 3), + /* 1111 */ V(2, 2, 3), + + /* 0011 ... */ + /* 00 */ V(1, 2, 2), /* 64 */ + /* 01 */ V(2, 1, 2), + /* 10 */ V(0, 2, 2), + /* 11 */ V(2, 0, 2), + + /* 0000 0000 ... */ + /* 0000 */ PTR(262, 4), /* 68 */ + /* 0001 */ PTR(278, 4), + /* 0010 */ PTR(294, 4), + /* 0011 */ PTR(310, 3), + /* 0100 */ PTR(318, 2), + /* 0101 */ PTR(322, 2), + /* 0110 */ PTR(326, 3), + /* 0111 */ PTR(334, 2), + /* 1000 */ PTR(338, 1), + /* 1001 */ PTR(340, 2), + /* 1010 */ PTR(344, 2), + /* 1011 */ PTR(348, 2), + /* 1100 */ PTR(352, 2), + /* 1101 */ PTR(356, 2), + /* 1110 */ V(1, 15, 4), + /* 1111 */ V(15, 1, 4), + + /* 0000 0001 ... */ + /* 0000 */ V(15, 0, 4), /* 84 */ + /* 0001 */ PTR(360, 1), + /* 0010 */ PTR(362, 1), + /* 0011 */ PTR(364, 1), + /* 0100 */ V(14, 2, 4), + /* 0101 */ PTR(366, 1), + /* 0110 */ V(1, 14, 4), + /* 0111 */ V(14, 1, 4), + /* 1000 */ PTR(368, 1), + /* 1001 */ PTR(370, 1), + /* 1010 */ PTR(372, 1), + /* 1011 */ PTR(374, 1), + /* 1100 */ PTR(376, 1), + /* 1101 */ PTR(378, 1), + /* 1110 */ V(12, 6, 4), + /* 1111 */ V(3, 13, 4), + + /* 0000 0010 ... */ + /* 0000 */ PTR(380, 1), /* 100 */ + /* 0001 */ V(2, 13, 4), + /* 0010 */ V(13, 2, 4), + /* 0011 */ V(1, 13, 4), + /* 0100 */ V(11, 7, 4), + /* 0101 */ PTR(382, 1), + /* 0110 */ PTR(384, 1), + /* 0111 */ V(12, 3, 4), + /* 1000 */ PTR(386, 1), + /* 1001 */ V(4, 11, 4), + /* 1010 */ V(13, 1, 3), + /* 1011 */ V(13, 1, 3), + /* 1100 */ V(0, 13, 4), + /* 1101 */ V(13, 0, 4), + /* 1110 */ V(8, 10, 4), + /* 1111 */ V(10, 8, 4), + + /* 0000 0011 ... */ + /* 0000 */ V(4, 12, 4), /* 116 */ + /* 0001 */ V(12, 4, 4), + /* 0010 */ V(6, 11, 4), + /* 0011 */ V(11, 6, 4), + /* 0100 */ V(3, 12, 3), + /* 0101 */ V(3, 12, 3), + /* 0110 */ V(2, 12, 3), + /* 0111 */ V(2, 12, 3), + /* 1000 */ V(12, 2, 3), + /* 1001 */ V(12, 2, 3), + /* 1010 */ V(5, 11, 3), + /* 1011 */ V(5, 11, 3), + /* 1100 */ V(11, 5, 4), + /* 1101 */ V(8, 9, 4), + /* 1110 */ V(1, 12, 3), + /* 1111 */ V(1, 12, 3), + + /* 0000 0100 ... */ + /* 0000 */ V(12, 1, 3), /* 132 */ + /* 0001 */ V(12, 1, 3), + /* 0010 */ V(9, 8, 4), + /* 0011 */ V(0, 12, 4), + /* 0100 */ V(12, 0, 3), + /* 0101 */ V(12, 0, 3), + /* 0110 */ V(11, 4, 4), + /* 0111 */ V(6, 10, 4), + /* 1000 */ V(10, 6, 4), + /* 1001 */ V(7, 9, 4), + /* 1010 */ V(3, 11, 3), + /* 1011 */ V(3, 11, 3), + /* 1100 */ V(11, 3, 3), + /* 1101 */ V(11, 3, 3), + /* 1110 */ V(8, 8, 4), + /* 1111 */ V(5, 10, 4), + + /* 0000 0101 ... */ + /* 0000 */ V(2, 11, 3), /* 148 */ + /* 0001 */ V(2, 11, 3), + /* 0010 */ V(10, 5, 4), + /* 0011 */ V(6, 9, 4), + /* 0100 */ V(10, 4, 3), + /* 0101 */ V(10, 4, 3), + /* 0110 */ V(7, 8, 4), + /* 0111 */ V(8, 7, 4), + /* 1000 */ V(9, 4, 3), + /* 1001 */ V(9, 4, 3), + /* 1010 */ V(7, 7, 4), + /* 1011 */ V(7, 6, 4), + /* 1100 */ V(11, 2, 2), + /* 1101 */ V(11, 2, 2), + /* 1110 */ V(11, 2, 2), + /* 1111 */ V(11, 2, 2), + + /* 0000 0110 ... */ + /* 000 */ V(1, 11, 2), /* 164 */ + /* 001 */ V(1, 11, 2), + /* 010 */ V(11, 1, 2), + /* 011 */ V(11, 1, 2), + /* 100 */ V(0, 11, 3), + /* 101 */ V(11, 0, 3), + /* 110 */ V(9, 6, 3), + /* 111 */ V(4, 10, 3), + + /* 0000 0111 ... */ + /* 000 */ V(3, 10, 3), /* 172 */ + /* 001 */ V(10, 3, 3), + /* 010 */ V(5, 9, 3), + /* 011 */ V(9, 5, 3), + /* 100 */ V(2, 10, 2), + /* 101 */ V(2, 10, 2), + /* 110 */ V(10, 2, 2), + /* 111 */ V(10, 2, 2), + + /* 0000 1000 ... */ + /* 000 */ V(1, 10, 2), /* 180 */ + /* 001 */ V(1, 10, 2), + /* 010 */ V(10, 1, 2), + /* 011 */ V(10, 1, 2), + /* 100 */ V(0, 10, 3), + /* 101 */ V(6, 8, 3), + /* 110 */ V(10, 0, 2), + /* 111 */ V(10, 0, 2), + + /* 0000 1001 ... */ + /* 000 */ V(8, 6, 3), /* 188 */ + /* 001 */ V(4, 9, 3), + /* 010 */ V(9, 3, 2), + /* 011 */ V(9, 3, 2), + /* 100 */ V(3, 9, 3), + /* 101 */ V(5, 8, 3), + /* 110 */ V(8, 5, 3), + /* 111 */ V(6, 7, 3), + + /* 0000 1010 ... */ + /* 000 */ V(2, 9, 2), /* 196 */ + /* 001 */ V(2, 9, 2), + /* 010 */ V(9, 2, 2), + /* 011 */ V(9, 2, 2), + /* 100 */ V(5, 7, 3), + /* 101 */ V(7, 5, 3), + /* 110 */ V(3, 8, 2), + /* 111 */ V(3, 8, 2), + + /* 0000 1011 ... */ + /* 000 */ V(8, 3, 2), /* 204 */ + /* 001 */ V(8, 3, 2), + /* 010 */ V(6, 6, 3), + /* 011 */ V(4, 7, 3), + /* 100 */ V(7, 4, 3), + /* 101 */ V(5, 6, 3), + /* 110 */ V(6, 5, 3), + /* 111 */ V(7, 3, 3), + + /* 0000 1100 ... */ + /* 0 */ V(1, 9, 1), /* 212 */ + /* 1 */ V(9, 1, 1), + + /* 0000 1101 ... */ + /* 00 */ V(0, 9, 2), /* 214 */ + /* 01 */ V(9, 0, 2), + /* 10 */ V(4, 8, 2), + /* 11 */ V(8, 4, 2), + + /* 0000 1110 ... */ + /* 000 */ V(7, 2, 2), /* 218 */ + /* 001 */ V(7, 2, 2), + /* 010 */ V(4, 6, 3), + /* 011 */ V(6, 4, 3), + /* 100 */ V(2, 8, 1), + /* 101 */ V(2, 8, 1), + /* 110 */ V(2, 8, 1), + /* 111 */ V(2, 8, 1), + + /* 0000 1111 ... */ + /* 0 */ V(8, 2, 1), /* 226 */ + /* 1 */ V(1, 8, 1), + + /* 0001 0000 ... */ + /* 00 */ V(3, 7, 2), /* 228 */ + /* 01 */ V(2, 7, 2), + /* 10 */ V(1, 7, 1), + /* 11 */ V(1, 7, 1), + + /* 0001 0001 ... */ + /* 00 */ V(7, 1, 1), /* 232 */ + /* 01 */ V(7, 1, 1), + /* 10 */ V(5, 5, 2), + /* 11 */ V(0, 7, 2), + + /* 0001 0010 ... */ + /* 00 */ V(7, 0, 2), /* 236 */ + /* 01 */ V(3, 6, 2), + /* 10 */ V(6, 3, 2), + /* 11 */ V(4, 5, 2), + + /* 0001 0011 ... */ + /* 00 */ V(5, 4, 2), /* 240 */ + /* 01 */ V(2, 6, 2), + /* 10 */ V(6, 2, 2), + /* 11 */ V(3, 5, 2), + + /* 0001 0101 ... */ + /* 0 */ V(0, 8, 1), /* 244 */ + /* 1 */ V(8, 0, 1), + + /* 0001 0110 ... */ + /* 0 */ V(1, 6, 1), /* 246 */ + /* 1 */ V(6, 1, 1), + + /* 0001 0111 ... */ + /* 0 */ V(0, 6, 1), /* 248 */ + /* 1 */ V(6, 0, 1), + + /* 0001 1000 ... */ + /* 00 */ V(5, 3, 2), /* 250 */ + /* 01 */ V(4, 4, 2), + /* 10 */ V(2, 5, 1), + /* 11 */ V(2, 5, 1), + + /* 0001 1001 ... */ + /* 0 */ V(5, 2, 1), /* 254 */ + /* 1 */ V(0, 5, 1), + + /* 0001 1100 ... */ + /* 0 */ V(3, 4, 1), /* 256 */ + /* 1 */ V(4, 3, 1), + + /* 0001 1101 ... */ + /* 0 */ V(5, 0, 1), /* 258 */ + /* 1 */ V(2, 4, 1), + + /* 0001 1110 ... */ + /* 0 */ V(4, 2, 1), /* 260 */ + /* 1 */ V(3, 3, 1), + + /* 0000 0000 0000 ... */ + /* 0000 */ PTR(388, 3), /* 262 */ + /* 0001 */ V(15, 15, 4), + /* 0010 */ V(14, 15, 4), + /* 0011 */ V(13, 15, 4), + /* 0100 */ V(14, 14, 4), + /* 0101 */ V(12, 15, 4), + /* 0110 */ V(13, 14, 4), + /* 0111 */ V(11, 15, 4), + /* 1000 */ V(15, 11, 4), + /* 1001 */ V(12, 14, 4), + /* 1010 */ V(13, 12, 4), + /* 1011 */ PTR(396, 1), + /* 1100 */ V(14, 12, 3), + /* 1101 */ V(14, 12, 3), + /* 1110 */ V(13, 13, 3), + /* 1111 */ V(13, 13, 3), + + /* 0000 0000 0001 ... */ + /* 0000 */ V(15, 10, 4), /* 278 */ + /* 0001 */ V(12, 13, 4), + /* 0010 */ V(11, 14, 3), + /* 0011 */ V(11, 14, 3), + /* 0100 */ V(14, 11, 3), + /* 0101 */ V(14, 11, 3), + /* 0110 */ V(9, 15, 3), + /* 0111 */ V(9, 15, 3), + /* 1000 */ V(15, 9, 3), + /* 1001 */ V(15, 9, 3), + /* 1010 */ V(14, 10, 3), + /* 1011 */ V(14, 10, 3), + /* 1100 */ V(11, 13, 3), + /* 1101 */ V(11, 13, 3), + /* 1110 */ V(13, 11, 3), + /* 1111 */ V(13, 11, 3), + + /* 0000 0000 0010 ... */ + /* 0000 */ V(8, 15, 3), /* 294 */ + /* 0001 */ V(8, 15, 3), + /* 0010 */ V(15, 8, 3), + /* 0011 */ V(15, 8, 3), + /* 0100 */ V(12, 12, 3), + /* 0101 */ V(12, 12, 3), + /* 0110 */ V(10, 14, 4), + /* 0111 */ V(9, 14, 4), + /* 1000 */ V(8, 14, 3), + /* 1001 */ V(8, 14, 3), + /* 1010 */ V(7, 15, 4), + /* 1011 */ V(7, 14, 4), + /* 1100 */ V(15, 7, 2), + /* 1101 */ V(15, 7, 2), + /* 1110 */ V(15, 7, 2), + /* 1111 */ V(15, 7, 2), + + /* 0000 0000 0011 ... */ + /* 000 */ V(13, 10, 2), /* 310 */ + /* 001 */ V(13, 10, 2), + /* 010 */ V(10, 13, 3), + /* 011 */ V(11, 12, 3), + /* 100 */ V(12, 11, 3), + /* 101 */ V(15, 6, 3), + /* 110 */ V(6, 15, 2), + /* 111 */ V(6, 15, 2), + + /* 0000 0000 0100 ... */ + /* 00 */ V(14, 8, 2), /* 318 */ + /* 01 */ V(5, 15, 2), + /* 10 */ V(9, 13, 2), + /* 11 */ V(13, 9, 2), + + /* 0000 0000 0101 ... */ + /* 00 */ V(15, 5, 2), /* 322 */ + /* 01 */ V(14, 7, 2), + /* 10 */ V(10, 12, 2), + /* 11 */ V(11, 11, 2), + + /* 0000 0000 0110 ... */ + /* 000 */ V(4, 15, 2), /* 326 */ + /* 001 */ V(4, 15, 2), + /* 010 */ V(15, 4, 2), + /* 011 */ V(15, 4, 2), + /* 100 */ V(12, 10, 3), + /* 101 */ V(14, 6, 3), + /* 110 */ V(15, 3, 2), + /* 111 */ V(15, 3, 2), + + /* 0000 0000 0111 ... */ + /* 00 */ V(3, 15, 1), /* 334 */ + /* 01 */ V(3, 15, 1), + /* 10 */ V(8, 13, 2), + /* 11 */ V(13, 8, 2), + + /* 0000 0000 1000 ... */ + /* 0 */ V(2, 15, 1), /* 338 */ + /* 1 */ V(15, 2, 1), + + /* 0000 0000 1001 ... */ + /* 00 */ V(6, 14, 2), /* 340 */ + /* 01 */ V(9, 12, 2), + /* 10 */ V(0, 15, 1), + /* 11 */ V(0, 15, 1), + + /* 0000 0000 1010 ... */ + /* 00 */ V(12, 9, 2), /* 344 */ + /* 01 */ V(5, 14, 2), + /* 10 */ V(10, 11, 1), + /* 11 */ V(10, 11, 1), + + /* 0000 0000 1011 ... */ + /* 00 */ V(7, 13, 2), /* 348 */ + /* 01 */ V(13, 7, 2), + /* 10 */ V(4, 14, 1), + /* 11 */ V(4, 14, 1), + + /* 0000 0000 1100 ... */ + /* 00 */ V(12, 8, 2), /* 352 */ + /* 01 */ V(13, 6, 2), + /* 10 */ V(3, 14, 1), + /* 11 */ V(3, 14, 1), + + /* 0000 0000 1101 ... */ + /* 00 */ V(11, 9, 1), /* 356 */ + /* 01 */ V(11, 9, 1), + /* 10 */ V(9, 11, 2), + /* 11 */ V(10, 10, 2), + + /* 0000 0001 0001 ... */ + /* 0 */ V(11, 10, 1), /* 360 */ + /* 1 */ V(14, 5, 1), + + /* 0000 0001 0010 ... */ + /* 0 */ V(14, 4, 1), /* 362 */ + /* 1 */ V(8, 12, 1), + + /* 0000 0001 0011 ... */ + /* 0 */ V(6, 13, 1), /* 364 */ + /* 1 */ V(14, 3, 1), + + /* 0000 0001 0101 ... */ + /* 0 */ V(2, 14, 1), /* 366 */ + /* 1 */ V(0, 14, 1), + + /* 0000 0001 1000 ... */ + /* 0 */ V(14, 0, 1), /* 368 */ + /* 1 */ V(5, 13, 1), + + /* 0000 0001 1001 ... */ + /* 0 */ V(13, 5, 1), /* 370 */ + /* 1 */ V(7, 12, 1), + + /* 0000 0001 1010 ... */ + /* 0 */ V(12, 7, 1), /* 372 */ + /* 1 */ V(4, 13, 1), + + /* 0000 0001 1011 ... */ + /* 0 */ V(8, 11, 1), /* 374 */ + /* 1 */ V(11, 8, 1), + + /* 0000 0001 1100 ... */ + /* 0 */ V(13, 4, 1), /* 376 */ + /* 1 */ V(9, 10, 1), + + /* 0000 0001 1101 ... */ + /* 0 */ V(10, 9, 1), /* 378 */ + /* 1 */ V(6, 12, 1), + + /* 0000 0010 0000 ... */ + /* 0 */ V(13, 3, 1), /* 380 */ + /* 1 */ V(7, 11, 1), + + /* 0000 0010 0101 ... */ + /* 0 */ V(5, 12, 1), /* 382 */ + /* 1 */ V(12, 5, 1), + + /* 0000 0010 0110 ... */ + /* 0 */ V(9, 9, 1), /* 384 */ + /* 1 */ V(7, 10, 1), + + /* 0000 0010 1000 ... */ + /* 0 */ V(10, 7, 1), /* 386 */ + /* 1 */ V(9, 7, 1), + + /* 0000 0000 0000 0000 ... */ + /* 000 */ V(15, 14, 3), /* 388 */ + /* 001 */ V(15, 12, 3), + /* 010 */ V(15, 13, 2), + /* 011 */ V(15, 13, 2), + /* 100 */ V(14, 13, 1), + /* 101 */ V(14, 13, 1), + /* 110 */ V(14, 13, 1), + /* 111 */ V(14, 13, 1), + + /* 0000 0000 0000 1011 ... */ + /* 0 */ V(10, 15, 1), /* 396 */ + /* 1 */ V(14, 9, 1) +]; + +const hufftab15 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ PTR(64, 4), + /* 0100 */ PTR(80, 4), + /* 0101 */ PTR(96, 3), + /* 0110 */ PTR(104, 3), + /* 0111 */ PTR(112, 2), + /* 1000 */ PTR(116, 1), + /* 1001 */ PTR(118, 1), + /* 1010 */ V(1, 1, 3), + /* 1011 */ V(1, 1, 3), + /* 1100 */ V(0, 1, 4), + /* 1101 */ V(1, 0, 4), + /* 1110 */ V(0, 0, 3), + /* 1111 */ V(0, 0, 3), + + /* 0000 ... */ + /* 0000 */ PTR(120, 4), /* 16 */ + /* 0001 */ PTR(136, 4), + /* 0010 */ PTR(152, 4), + /* 0011 */ PTR(168, 4), + /* 0100 */ PTR(184, 4), + /* 0101 */ PTR(200, 3), + /* 0110 */ PTR(208, 3), + /* 0111 */ PTR(216, 4), + /* 1000 */ PTR(232, 3), + /* 1001 */ PTR(240, 3), + /* 1010 */ PTR(248, 3), + /* 1011 */ PTR(256, 3), + /* 1100 */ PTR(264, 2), + /* 1101 */ PTR(268, 3), + /* 1110 */ PTR(276, 3), + /* 1111 */ PTR(284, 2), + + /* 0001 ... */ + /* 0000 */ PTR(288, 2), /* 32 */ + /* 0001 */ PTR(292, 2), + /* 0010 */ PTR(296, 2), + /* 0011 */ PTR(300, 2), + /* 0100 */ PTR(304, 2), + /* 0101 */ PTR(308, 2), + /* 0110 */ PTR(312, 2), + /* 0111 */ PTR(316, 2), + /* 1000 */ PTR(320, 1), + /* 1001 */ PTR(322, 1), + /* 1010 */ PTR(324, 1), + /* 1011 */ PTR(326, 2), + /* 1100 */ PTR(330, 1), + /* 1101 */ PTR(332, 1), + /* 1110 */ PTR(334, 2), + /* 1111 */ PTR(338, 1), + + /* 0010 ... */ + /* 0000 */ PTR(340, 1), /* 48 */ + /* 0001 */ PTR(342, 1), + /* 0010 */ V(9, 1, 4), + /* 0011 */ PTR(344, 1), + /* 0100 */ PTR(346, 1), + /* 0101 */ PTR(348, 1), + /* 0110 */ PTR(350, 1), + /* 0111 */ PTR(352, 1), + /* 1000 */ V(2, 8, 4), + /* 1001 */ V(8, 2, 4), + /* 1010 */ V(1, 8, 4), + /* 1011 */ V(8, 1, 4), + /* 1100 */ PTR(354, 1), + /* 1101 */ PTR(356, 1), + /* 1110 */ PTR(358, 1), + /* 1111 */ PTR(360, 1), + + /* 0011 ... */ + /* 0000 */ V(2, 7, 4), /* 64 */ + /* 0001 */ V(7, 2, 4), + /* 0010 */ V(6, 4, 4), + /* 0011 */ V(1, 7, 4), + /* 0100 */ V(5, 5, 4), + /* 0101 */ V(7, 1, 4), + /* 0110 */ PTR(362, 1), + /* 0111 */ V(3, 6, 4), + /* 1000 */ V(6, 3, 4), + /* 1001 */ V(4, 5, 4), + /* 1010 */ V(5, 4, 4), + /* 1011 */ V(2, 6, 4), + /* 1100 */ V(6, 2, 4), + /* 1101 */ V(1, 6, 4), + /* 1110 */ PTR(364, 1), + /* 1111 */ V(3, 5, 4), + + /* 0100 ... */ + /* 0000 */ V(6, 1, 3), /* 80 */ + /* 0001 */ V(6, 1, 3), + /* 0010 */ V(5, 3, 4), + /* 0011 */ V(4, 4, 4), + /* 0100 */ V(2, 5, 3), + /* 0101 */ V(2, 5, 3), + /* 0110 */ V(5, 2, 3), + /* 0111 */ V(5, 2, 3), + /* 1000 */ V(1, 5, 3), + /* 1001 */ V(1, 5, 3), + /* 1010 */ V(5, 1, 3), + /* 1011 */ V(5, 1, 3), + /* 1100 */ V(0, 5, 4), + /* 1101 */ V(5, 0, 4), + /* 1110 */ V(3, 4, 3), + /* 1111 */ V(3, 4, 3), + + /* 0101 ... */ + /* 000 */ V(4, 3, 3), /* 96 */ + /* 001 */ V(2, 4, 3), + /* 010 */ V(4, 2, 3), + /* 011 */ V(3, 3, 3), + /* 100 */ V(4, 1, 2), + /* 101 */ V(4, 1, 2), + /* 110 */ V(1, 4, 3), + /* 111 */ V(0, 4, 3), + + /* 0110 ... */ + /* 000 */ V(2, 3, 2), /* 104 */ + /* 001 */ V(2, 3, 2), + /* 010 */ V(3, 2, 2), + /* 011 */ V(3, 2, 2), + /* 100 */ V(4, 0, 3), + /* 101 */ V(0, 3, 3), + /* 110 */ V(1, 3, 2), + /* 111 */ V(1, 3, 2), + + /* 0111 ... */ + /* 00 */ V(3, 1, 2), /* 112 */ + /* 01 */ V(3, 0, 2), + /* 10 */ V(2, 2, 1), + /* 11 */ V(2, 2, 1), + + /* 1000 ... */ + /* 0 */ V(1, 2, 1), /* 116 */ + /* 1 */ V(2, 1, 1), + + /* 1001 ... */ + /* 0 */ V(0, 2, 1), /* 118 */ + /* 1 */ V(2, 0, 1), + + /* 0000 0000 ... */ + /* 0000 */ PTR(366, 1), /* 120 */ + /* 0001 */ PTR(368, 1), + /* 0010 */ V(14, 14, 4), + /* 0011 */ PTR(370, 1), + /* 0100 */ PTR(372, 1), + /* 0101 */ PTR(374, 1), + /* 0110 */ V(15, 11, 4), + /* 0111 */ PTR(376, 1), + /* 1000 */ V(13, 13, 4), + /* 1001 */ V(10, 15, 4), + /* 1010 */ V(15, 10, 4), + /* 1011 */ V(11, 14, 4), + /* 1100 */ V(14, 11, 4), + /* 1101 */ V(12, 13, 4), + /* 1110 */ V(13, 12, 4), + /* 1111 */ V(9, 15, 4), + + /* 0000 0001 ... */ + /* 0000 */ V(15, 9, 4), /* 136 */ + /* 0001 */ V(14, 10, 4), + /* 0010 */ V(11, 13, 4), + /* 0011 */ V(13, 11, 4), + /* 0100 */ V(8, 15, 4), + /* 0101 */ V(15, 8, 4), + /* 0110 */ V(12, 12, 4), + /* 0111 */ V(9, 14, 4), + /* 1000 */ V(14, 9, 4), + /* 1001 */ V(7, 15, 4), + /* 1010 */ V(15, 7, 4), + /* 1011 */ V(10, 13, 4), + /* 1100 */ V(13, 10, 4), + /* 1101 */ V(11, 12, 4), + /* 1110 */ V(6, 15, 4), + /* 1111 */ PTR(378, 1), + + /* 0000 0010 ... */ + /* 0000 */ V(12, 11, 3), /* 152 */ + /* 0001 */ V(12, 11, 3), + /* 0010 */ V(15, 6, 3), + /* 0011 */ V(15, 6, 3), + /* 0100 */ V(8, 14, 4), + /* 0101 */ V(14, 8, 4), + /* 0110 */ V(5, 15, 4), + /* 0111 */ V(9, 13, 4), + /* 1000 */ V(15, 5, 3), + /* 1001 */ V(15, 5, 3), + /* 1010 */ V(7, 14, 3), + /* 1011 */ V(7, 14, 3), + /* 1100 */ V(14, 7, 3), + /* 1101 */ V(14, 7, 3), + /* 1110 */ V(10, 12, 3), + /* 1111 */ V(10, 12, 3), + + /* 0000 0011 ... */ + /* 0000 */ V(12, 10, 3), /* 168 */ + /* 0001 */ V(12, 10, 3), + /* 0010 */ V(11, 11, 3), + /* 0011 */ V(11, 11, 3), + /* 0100 */ V(13, 9, 4), + /* 0101 */ V(8, 13, 4), + /* 0110 */ V(4, 15, 3), + /* 0111 */ V(4, 15, 3), + /* 1000 */ V(15, 4, 3), + /* 1001 */ V(15, 4, 3), + /* 1010 */ V(3, 15, 3), + /* 1011 */ V(3, 15, 3), + /* 1100 */ V(15, 3, 3), + /* 1101 */ V(15, 3, 3), + /* 1110 */ V(13, 8, 3), + /* 1111 */ V(13, 8, 3), + + /* 0000 0100 ... */ + /* 0000 */ V(14, 6, 3), /* 184 */ + /* 0001 */ V(14, 6, 3), + /* 0010 */ V(2, 15, 3), + /* 0011 */ V(2, 15, 3), + /* 0100 */ V(15, 2, 3), + /* 0101 */ V(15, 2, 3), + /* 0110 */ V(6, 14, 4), + /* 0111 */ V(15, 0, 4), + /* 1000 */ V(1, 15, 3), + /* 1001 */ V(1, 15, 3), + /* 1010 */ V(15, 1, 3), + /* 1011 */ V(15, 1, 3), + /* 1100 */ V(9, 12, 3), + /* 1101 */ V(9, 12, 3), + /* 1110 */ V(12, 9, 3), + /* 1111 */ V(12, 9, 3), + + /* 0000 0101 ... */ + /* 000 */ V(5, 14, 3), /* 200 */ + /* 001 */ V(10, 11, 3), + /* 010 */ V(11, 10, 3), + /* 011 */ V(14, 5, 3), + /* 100 */ V(7, 13, 3), + /* 101 */ V(13, 7, 3), + /* 110 */ V(4, 14, 3), + /* 111 */ V(14, 4, 3), + + /* 0000 0110 ... */ + /* 000 */ V(8, 12, 3), /* 208 */ + /* 001 */ V(12, 8, 3), + /* 010 */ V(3, 14, 3), + /* 011 */ V(6, 13, 3), + /* 100 */ V(13, 6, 3), + /* 101 */ V(14, 3, 3), + /* 110 */ V(9, 11, 3), + /* 111 */ V(11, 9, 3), + + /* 0000 0111 ... */ + /* 0000 */ V(2, 14, 3), /* 216 */ + /* 0001 */ V(2, 14, 3), + /* 0010 */ V(10, 10, 3), + /* 0011 */ V(10, 10, 3), + /* 0100 */ V(14, 2, 3), + /* 0101 */ V(14, 2, 3), + /* 0110 */ V(1, 14, 3), + /* 0111 */ V(1, 14, 3), + /* 1000 */ V(14, 1, 3), + /* 1001 */ V(14, 1, 3), + /* 1010 */ V(0, 14, 4), + /* 1011 */ V(14, 0, 4), + /* 1100 */ V(5, 13, 3), + /* 1101 */ V(5, 13, 3), + /* 1110 */ V(13, 5, 3), + /* 1111 */ V(13, 5, 3), + + /* 0000 1000 ... */ + /* 000 */ V(7, 12, 3), /* 232 */ + /* 001 */ V(12, 7, 3), + /* 010 */ V(4, 13, 3), + /* 011 */ V(8, 11, 3), + /* 100 */ V(13, 4, 2), + /* 101 */ V(13, 4, 2), + /* 110 */ V(11, 8, 3), + /* 111 */ V(9, 10, 3), + + /* 0000 1001 ... */ + /* 000 */ V(10, 9, 3), /* 240 */ + /* 001 */ V(6, 12, 3), + /* 010 */ V(12, 6, 3), + /* 011 */ V(3, 13, 3), + /* 100 */ V(13, 3, 2), + /* 101 */ V(13, 3, 2), + /* 110 */ V(13, 2, 2), + /* 111 */ V(13, 2, 2), + + /* 0000 1010 ... */ + /* 000 */ V(2, 13, 3), /* 248 */ + /* 001 */ V(0, 13, 3), + /* 010 */ V(1, 13, 2), + /* 011 */ V(1, 13, 2), + /* 100 */ V(7, 11, 2), + /* 101 */ V(7, 11, 2), + /* 110 */ V(11, 7, 2), + /* 111 */ V(11, 7, 2), + + /* 0000 1011 ... */ + /* 000 */ V(13, 1, 2), /* 256 */ + /* 001 */ V(13, 1, 2), + /* 010 */ V(5, 12, 3), + /* 011 */ V(13, 0, 3), + /* 100 */ V(12, 5, 2), + /* 101 */ V(12, 5, 2), + /* 110 */ V(8, 10, 2), + /* 111 */ V(8, 10, 2), + + /* 0000 1100 ... */ + /* 00 */ V(10, 8, 2), /* 264 */ + /* 01 */ V(4, 12, 2), + /* 10 */ V(12, 4, 2), + /* 11 */ V(6, 11, 2), + + /* 0000 1101 ... */ + /* 000 */ V(11, 6, 2), /* 268 */ + /* 001 */ V(11, 6, 2), + /* 010 */ V(9, 9, 3), + /* 011 */ V(0, 12, 3), + /* 100 */ V(3, 12, 2), + /* 101 */ V(3, 12, 2), + /* 110 */ V(12, 3, 2), + /* 111 */ V(12, 3, 2), + + /* 0000 1110 ... */ + /* 000 */ V(7, 10, 2), /* 276 */ + /* 001 */ V(7, 10, 2), + /* 010 */ V(10, 7, 2), + /* 011 */ V(10, 7, 2), + /* 100 */ V(10, 6, 2), + /* 101 */ V(10, 6, 2), + /* 110 */ V(12, 0, 3), + /* 111 */ V(0, 11, 3), + + /* 0000 1111 ... */ + /* 00 */ V(12, 2, 1), /* 284 */ + /* 01 */ V(12, 2, 1), + /* 10 */ V(2, 12, 2), + /* 11 */ V(5, 11, 2), + + /* 0001 0000 ... */ + /* 00 */ V(11, 5, 2), /* 288 */ + /* 01 */ V(1, 12, 2), + /* 10 */ V(8, 9, 2), + /* 11 */ V(9, 8, 2), + + /* 0001 0001 ... */ + /* 00 */ V(12, 1, 2), /* 292 */ + /* 01 */ V(4, 11, 2), + /* 10 */ V(11, 4, 2), + /* 11 */ V(6, 10, 2), + + /* 0001 0010 ... */ + /* 00 */ V(3, 11, 2), /* 296 */ + /* 01 */ V(7, 9, 2), + /* 10 */ V(11, 3, 1), + /* 11 */ V(11, 3, 1), + + /* 0001 0011 ... */ + /* 00 */ V(9, 7, 2), /* 300 */ + /* 01 */ V(8, 8, 2), + /* 10 */ V(2, 11, 2), + /* 11 */ V(5, 10, 2), + + /* 0001 0100 ... */ + /* 00 */ V(11, 2, 1), /* 304 */ + /* 01 */ V(11, 2, 1), + /* 10 */ V(10, 5, 2), + /* 11 */ V(1, 11, 2), + + /* 0001 0101 ... */ + /* 00 */ V(11, 1, 1), /* 308 */ + /* 01 */ V(11, 1, 1), + /* 10 */ V(11, 0, 2), + /* 11 */ V(6, 9, 2), + + /* 0001 0110 ... */ + /* 00 */ V(9, 6, 2), /* 312 */ + /* 01 */ V(4, 10, 2), + /* 10 */ V(10, 4, 2), + /* 11 */ V(7, 8, 2), + + /* 0001 0111 ... */ + /* 00 */ V(8, 7, 2), /* 316 */ + /* 01 */ V(3, 10, 2), + /* 10 */ V(10, 3, 1), + /* 11 */ V(10, 3, 1), + + /* 0001 1000 ... */ + /* 0 */ V(5, 9, 1), /* 320 */ + /* 1 */ V(9, 5, 1), + + /* 0001 1001 ... */ + /* 0 */ V(2, 10, 1), /* 322 */ + /* 1 */ V(10, 2, 1), + + /* 0001 1010 ... */ + /* 0 */ V(1, 10, 1), /* 324 */ + /* 1 */ V(10, 1, 1), + + /* 0001 1011 ... */ + /* 00 */ V(0, 10, 2), /* 326 */ + /* 01 */ V(10, 0, 2), + /* 10 */ V(6, 8, 1), + /* 11 */ V(6, 8, 1), + + /* 0001 1100 ... */ + /* 0 */ V(8, 6, 1), /* 330 */ + /* 1 */ V(4, 9, 1), + + /* 0001 1101 ... */ + /* 0 */ V(9, 4, 1), /* 332 */ + /* 1 */ V(3, 9, 1), + + /* 0001 1110 ... */ + /* 00 */ V(9, 3, 1), /* 334 */ + /* 01 */ V(9, 3, 1), + /* 10 */ V(7, 7, 2), + /* 11 */ V(0, 9, 2), + + /* 0001 1111 ... */ + /* 0 */ V(5, 8, 1), /* 338 */ + /* 1 */ V(8, 5, 1), + + /* 0010 0000 ... */ + /* 0 */ V(2, 9, 1), /* 340 */ + /* 1 */ V(6, 7, 1), + + /* 0010 0001 ... */ + /* 0 */ V(7, 6, 1), /* 342 */ + /* 1 */ V(9, 2, 1), + + /* 0010 0011 ... */ + /* 0 */ V(1, 9, 1), /* 344 */ + /* 1 */ V(9, 0, 1), + + /* 0010 0100 ... */ + /* 0 */ V(4, 8, 1), /* 346 */ + /* 1 */ V(8, 4, 1), + + /* 0010 0101 ... */ + /* 0 */ V(5, 7, 1), /* 348 */ + /* 1 */ V(7, 5, 1), + + /* 0010 0110 ... */ + /* 0 */ V(3, 8, 1), /* 350 */ + /* 1 */ V(8, 3, 1), + + /* 0010 0111 ... */ + /* 0 */ V(6, 6, 1), /* 352 */ + /* 1 */ V(4, 7, 1), + + /* 0010 1100 ... */ + /* 0 */ V(7, 4, 1), /* 354 */ + /* 1 */ V(0, 8, 1), + + /* 0010 1101 ... */ + /* 0 */ V(8, 0, 1), /* 356 */ + /* 1 */ V(5, 6, 1), + + /* 0010 1110 ... */ + /* 0 */ V(6, 5, 1), /* 358 */ + /* 1 */ V(3, 7, 1), + + /* 0010 1111 ... */ + /* 0 */ V(7, 3, 1), /* 360 */ + /* 1 */ V(4, 6, 1), + + /* 0011 0110 ... */ + /* 0 */ V(0, 7, 1), /* 362 */ + /* 1 */ V(7, 0, 1), + + /* 0011 1110 ... */ + /* 0 */ V(0, 6, 1), /* 364 */ + /* 1 */ V(6, 0, 1), + + /* 0000 0000 0000 ... */ + /* 0 */ V(15, 15, 1), /* 366 */ + /* 1 */ V(14, 15, 1), + + /* 0000 0000 0001 ... */ + /* 0 */ V(15, 14, 1), /* 368 */ + /* 1 */ V(13, 15, 1), + + /* 0000 0000 0011 ... */ + /* 0 */ V(15, 13, 1), /* 370 */ + /* 1 */ V(12, 15, 1), + + /* 0000 0000 0100 ... */ + /* 0 */ V(15, 12, 1), /* 372 */ + /* 1 */ V(13, 14, 1), + + /* 0000 0000 0101 ... */ + /* 0 */ V(14, 13, 1), /* 374 */ + /* 1 */ V(11, 15, 1), + + /* 0000 0000 0111 ... */ + /* 0 */ V(12, 14, 1), /* 376 */ + /* 1 */ V(14, 12, 1), + + /* 0000 0001 1111 ... */ + /* 0 */ V(10, 14, 1), /* 378 */ + /* 1 */ V(0, 15, 1) +]; + +const hufftab16 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ PTR(64, 2), + /* 0100 */ V(1, 1, 4), + /* 0101 */ V(0, 1, 4), + /* 0110 */ V(1, 0, 3), + /* 0111 */ V(1, 0, 3), + /* 1000 */ V(0, 0, 1), + /* 1001 */ V(0, 0, 1), + /* 1010 */ V(0, 0, 1), + /* 1011 */ V(0, 0, 1), + /* 1100 */ V(0, 0, 1), + /* 1101 */ V(0, 0, 1), + /* 1110 */ V(0, 0, 1), + /* 1111 */ V(0, 0, 1), + + /* 0000 ... */ + /* 0000 */ PTR(68, 3), /* 16 */ + /* 0001 */ PTR(76, 3), + /* 0010 */ PTR(84, 2), + /* 0011 */ V(15, 15, 4), + /* 0100 */ PTR(88, 2), + /* 0101 */ PTR(92, 1), + /* 0110 */ PTR(94, 4), + /* 0111 */ V(15, 2, 4), + /* 1000 */ PTR(110, 1), + /* 1001 */ V(1, 15, 4), + /* 1010 */ V(15, 1, 4), + /* 1011 */ PTR(112, 4), + /* 1100 */ PTR(128, 4), + /* 1101 */ PTR(144, 4), + /* 1110 */ PTR(160, 4), + /* 1111 */ PTR(176, 4), + + /* 0001 ... */ + /* 0000 */ PTR(192, 4), /* 32 */ + /* 0001 */ PTR(208, 3), + /* 0010 */ PTR(216, 3), + /* 0011 */ PTR(224, 3), + /* 0100 */ PTR(232, 3), + /* 0101 */ PTR(240, 3), + /* 0110 */ PTR(248, 3), + /* 0111 */ PTR(256, 3), + /* 1000 */ PTR(264, 2), + /* 1001 */ PTR(268, 2), + /* 1010 */ PTR(272, 1), + /* 1011 */ PTR(274, 2), + /* 1100 */ PTR(278, 2), + /* 1101 */ PTR(282, 1), + /* 1110 */ V(5, 1, 4), + /* 1111 */ PTR(284, 1), + + /* 0010 ... */ + /* 0000 */ PTR(286, 1), /* 48 */ + /* 0001 */ PTR(288, 1), + /* 0010 */ PTR(290, 1), + /* 0011 */ V(1, 4, 4), + /* 0100 */ V(4, 1, 4), + /* 0101 */ PTR(292, 1), + /* 0110 */ V(2, 3, 4), + /* 0111 */ V(3, 2, 4), + /* 1000 */ V(1, 3, 3), + /* 1001 */ V(1, 3, 3), + /* 1010 */ V(3, 1, 3), + /* 1011 */ V(3, 1, 3), + /* 1100 */ V(0, 3, 4), + /* 1101 */ V(3, 0, 4), + /* 1110 */ V(2, 2, 3), + /* 1111 */ V(2, 2, 3), + + /* 0011 ... */ + /* 00 */ V(1, 2, 2), /* 64 */ + /* 01 */ V(2, 1, 2), + /* 10 */ V(0, 2, 2), + /* 11 */ V(2, 0, 2), + + /* 0000 0000 ... */ + /* 000 */ V(14, 15, 3), /* 68 */ + /* 001 */ V(15, 14, 3), + /* 010 */ V(13, 15, 3), + /* 011 */ V(15, 13, 3), + /* 100 */ V(12, 15, 3), + /* 101 */ V(15, 12, 3), + /* 110 */ V(11, 15, 3), + /* 111 */ V(15, 11, 3), + + /* 0000 0001 ... */ + /* 000 */ V(10, 15, 2), /* 76 */ + /* 001 */ V(10, 15, 2), + /* 010 */ V(15, 10, 3), + /* 011 */ V(9, 15, 3), + /* 100 */ V(15, 9, 3), + /* 101 */ V(15, 8, 3), + /* 110 */ V(8, 15, 2), + /* 111 */ V(8, 15, 2), + + /* 0000 0010 ... */ + /* 00 */ V(7, 15, 2), /* 84 */ + /* 01 */ V(15, 7, 2), + /* 10 */ V(6, 15, 2), + /* 11 */ V(15, 6, 2), + + /* 0000 0100 ... */ + /* 00 */ V(5, 15, 2), /* 88 */ + /* 01 */ V(15, 5, 2), + /* 10 */ V(4, 15, 1), + /* 11 */ V(4, 15, 1), + + /* 0000 0101 ... */ + /* 0 */ V(15, 4, 1), /* 92 */ + /* 1 */ V(15, 3, 1), + + /* 0000 0110 ... */ + /* 0000 */ V(15, 0, 1), /* 94 */ + /* 0001 */ V(15, 0, 1), + /* 0010 */ V(15, 0, 1), + /* 0011 */ V(15, 0, 1), + /* 0100 */ V(15, 0, 1), + /* 0101 */ V(15, 0, 1), + /* 0110 */ V(15, 0, 1), + /* 0111 */ V(15, 0, 1), + /* 1000 */ V(3, 15, 2), + /* 1001 */ V(3, 15, 2), + /* 1010 */ V(3, 15, 2), + /* 1011 */ V(3, 15, 2), + /* 1100 */ PTR(294, 4), + /* 1101 */ PTR(310, 3), + /* 1110 */ PTR(318, 3), + /* 1111 */ PTR(326, 3), + + /* 0000 1000 ... */ + /* 0 */ V(2, 15, 1), /* 110 */ + /* 1 */ V(0, 15, 1), + + /* 0000 1011 ... */ + /* 0000 */ PTR(334, 2), /* 112 */ + /* 0001 */ PTR(338, 2), + /* 0010 */ PTR(342, 2), + /* 0011 */ PTR(346, 1), + /* 0100 */ PTR(348, 2), + /* 0101 */ PTR(352, 2), + /* 0110 */ PTR(356, 1), + /* 0111 */ PTR(358, 2), + /* 1000 */ PTR(362, 2), + /* 1001 */ PTR(366, 2), + /* 1010 */ PTR(370, 2), + /* 1011 */ V(14, 3, 4), + /* 1100 */ PTR(374, 1), + /* 1101 */ PTR(376, 1), + /* 1110 */ PTR(378, 1), + /* 1111 */ PTR(380, 1), + + /* 0000 1100 ... */ + /* 0000 */ PTR(382, 1), /* 128 */ + /* 0001 */ PTR(384, 1), + /* 0010 */ PTR(386, 1), + /* 0011 */ V(0, 13, 4), + /* 0100 */ PTR(388, 1), + /* 0101 */ PTR(390, 1), + /* 0110 */ PTR(392, 1), + /* 0111 */ V(3, 12, 4), + /* 1000 */ PTR(394, 1), + /* 1001 */ V(1, 12, 4), + /* 1010 */ V(12, 0, 4), + /* 1011 */ PTR(396, 1), + /* 1100 */ V(14, 2, 3), + /* 1101 */ V(14, 2, 3), + /* 1110 */ V(2, 14, 4), + /* 1111 */ V(1, 14, 4), + + /* 0000 1101 ... */ + /* 0000 */ V(13, 3, 4), /* 144 */ + /* 0001 */ V(2, 13, 4), + /* 0010 */ V(13, 2, 4), + /* 0011 */ V(13, 1, 4), + /* 0100 */ V(3, 11, 4), + /* 0101 */ PTR(398, 1), + /* 0110 */ V(1, 13, 3), + /* 0111 */ V(1, 13, 3), + /* 1000 */ V(12, 4, 4), + /* 1001 */ V(6, 11, 4), + /* 1010 */ V(12, 3, 4), + /* 1011 */ V(10, 7, 4), + /* 1100 */ V(2, 12, 3), + /* 1101 */ V(2, 12, 3), + /* 1110 */ V(12, 2, 4), + /* 1111 */ V(11, 5, 4), + + /* 0000 1110 ... */ + /* 0000 */ V(12, 1, 4), /* 160 */ + /* 0001 */ V(0, 12, 4), + /* 0010 */ V(4, 11, 4), + /* 0011 */ V(11, 4, 4), + /* 0100 */ V(6, 10, 4), + /* 0101 */ V(10, 6, 4), + /* 0110 */ V(11, 3, 3), + /* 0111 */ V(11, 3, 3), + /* 1000 */ V(5, 10, 4), + /* 1001 */ V(10, 5, 4), + /* 1010 */ V(2, 11, 3), + /* 1011 */ V(2, 11, 3), + /* 1100 */ V(11, 2, 3), + /* 1101 */ V(11, 2, 3), + /* 1110 */ V(1, 11, 3), + /* 1111 */ V(1, 11, 3), + + /* 0000 1111 ... */ + /* 0000 */ V(11, 1, 3), /* 176 */ + /* 0001 */ V(11, 1, 3), + /* 0010 */ V(0, 11, 4), + /* 0011 */ V(11, 0, 4), + /* 0100 */ V(6, 9, 4), + /* 0101 */ V(9, 6, 4), + /* 0110 */ V(4, 10, 4), + /* 0111 */ V(10, 4, 4), + /* 1000 */ V(7, 8, 4), + /* 1001 */ V(8, 7, 4), + /* 1010 */ V(10, 3, 3), + /* 1011 */ V(10, 3, 3), + /* 1100 */ V(3, 10, 4), + /* 1101 */ V(5, 9, 4), + /* 1110 */ V(2, 10, 3), + /* 1111 */ V(2, 10, 3), + + /* 0001 0000 ... */ + /* 0000 */ V(9, 5, 4), /* 192 */ + /* 0001 */ V(6, 8, 4), + /* 0010 */ V(10, 1, 3), + /* 0011 */ V(10, 1, 3), + /* 0100 */ V(8, 6, 4), + /* 0101 */ V(7, 7, 4), + /* 0110 */ V(9, 4, 3), + /* 0111 */ V(9, 4, 3), + /* 1000 */ V(4, 9, 4), + /* 1001 */ V(5, 7, 4), + /* 1010 */ V(6, 7, 3), + /* 1011 */ V(6, 7, 3), + /* 1100 */ V(10, 2, 2), + /* 1101 */ V(10, 2, 2), + /* 1110 */ V(10, 2, 2), + /* 1111 */ V(10, 2, 2), + + /* 0001 0001 ... */ + /* 000 */ V(1, 10, 2), /* 208 */ + /* 001 */ V(1, 10, 2), + /* 010 */ V(0, 10, 3), + /* 011 */ V(10, 0, 3), + /* 100 */ V(3, 9, 3), + /* 101 */ V(9, 3, 3), + /* 110 */ V(5, 8, 3), + /* 111 */ V(8, 5, 3), + + /* 0001 0010 ... */ + /* 000 */ V(2, 9, 2), /* 216 */ + /* 001 */ V(2, 9, 2), + /* 010 */ V(9, 2, 2), + /* 011 */ V(9, 2, 2), + /* 100 */ V(7, 6, 3), + /* 101 */ V(0, 9, 3), + /* 110 */ V(1, 9, 2), + /* 111 */ V(1, 9, 2), + + /* 0001 0011 ... */ + /* 000 */ V(9, 1, 2), /* 224 */ + /* 001 */ V(9, 1, 2), + /* 010 */ V(9, 0, 3), + /* 011 */ V(4, 8, 3), + /* 100 */ V(8, 4, 3), + /* 101 */ V(7, 5, 3), + /* 110 */ V(3, 8, 3), + /* 111 */ V(8, 3, 3), + + /* 0001 0100 ... */ + /* 000 */ V(6, 6, 3), /* 232 */ + /* 001 */ V(2, 8, 3), + /* 010 */ V(8, 2, 2), + /* 011 */ V(8, 2, 2), + /* 100 */ V(4, 7, 3), + /* 101 */ V(7, 4, 3), + /* 110 */ V(1, 8, 2), + /* 111 */ V(1, 8, 2), + + /* 0001 0101 ... */ + /* 000 */ V(8, 1, 2), /* 240 */ + /* 001 */ V(8, 1, 2), + /* 010 */ V(8, 0, 2), + /* 011 */ V(8, 0, 2), + /* 100 */ V(0, 8, 3), + /* 101 */ V(5, 6, 3), + /* 110 */ V(3, 7, 2), + /* 111 */ V(3, 7, 2), + + /* 0001 0110 ... */ + /* 000 */ V(7, 3, 2), /* 248 */ + /* 001 */ V(7, 3, 2), + /* 010 */ V(6, 5, 3), + /* 011 */ V(4, 6, 3), + /* 100 */ V(2, 7, 2), + /* 101 */ V(2, 7, 2), + /* 110 */ V(7, 2, 2), + /* 111 */ V(7, 2, 2), + + /* 0001 0111 ... */ + /* 000 */ V(6, 4, 3), /* 256 */ + /* 001 */ V(5, 5, 3), + /* 010 */ V(0, 7, 2), + /* 011 */ V(0, 7, 2), + /* 100 */ V(1, 7, 1), + /* 101 */ V(1, 7, 1), + /* 110 */ V(1, 7, 1), + /* 111 */ V(1, 7, 1), + + /* 0001 1000 ... */ + /* 00 */ V(7, 1, 1), /* 264 */ + /* 01 */ V(7, 1, 1), + /* 10 */ V(7, 0, 2), + /* 11 */ V(3, 6, 2), + + /* 0001 1001 ... */ + /* 00 */ V(6, 3, 2), /* 268 */ + /* 01 */ V(4, 5, 2), + /* 10 */ V(5, 4, 2), + /* 11 */ V(2, 6, 2), + + /* 0001 1010 ... */ + /* 0 */ V(6, 2, 1), /* 272 */ + /* 1 */ V(1, 6, 1), + + /* 0001 1011 ... */ + /* 00 */ V(6, 1, 1), /* 274 */ + /* 01 */ V(6, 1, 1), + /* 10 */ V(0, 6, 2), + /* 11 */ V(6, 0, 2), + + /* 0001 1100 ... */ + /* 00 */ V(5, 3, 1), /* 278 */ + /* 01 */ V(5, 3, 1), + /* 10 */ V(3, 5, 2), + /* 11 */ V(4, 4, 2), + + /* 0001 1101 ... */ + /* 0 */ V(2, 5, 1), /* 282 */ + /* 1 */ V(5, 2, 1), + + /* 0001 1111 ... */ + /* 0 */ V(1, 5, 1), /* 284 */ + /* 1 */ V(0, 5, 1), + + /* 0010 0000 ... */ + /* 0 */ V(3, 4, 1), /* 286 */ + /* 1 */ V(4, 3, 1), + + /* 0010 0001 ... */ + /* 0 */ V(5, 0, 1), /* 288 */ + /* 1 */ V(2, 4, 1), + + /* 0010 0010 ... */ + /* 0 */ V(4, 2, 1), /* 290 */ + /* 1 */ V(3, 3, 1), + + /* 0010 0101 ... */ + /* 0 */ V(0, 4, 1), /* 292 */ + /* 1 */ V(4, 0, 1), + + /* 0000 0110 1100 ... */ + /* 0000 */ V(12, 14, 4), /* 294 */ + /* 0001 */ PTR(400, 1), + /* 0010 */ V(13, 14, 3), + /* 0011 */ V(13, 14, 3), + /* 0100 */ V(14, 9, 3), + /* 0101 */ V(14, 9, 3), + /* 0110 */ V(14, 10, 4), + /* 0111 */ V(13, 9, 4), + /* 1000 */ V(14, 14, 2), + /* 1001 */ V(14, 14, 2), + /* 1010 */ V(14, 14, 2), + /* 1011 */ V(14, 14, 2), + /* 1100 */ V(14, 13, 3), + /* 1101 */ V(14, 13, 3), + /* 1110 */ V(14, 11, 3), + /* 1111 */ V(14, 11, 3), + + /* 0000 0110 1101 ... */ + /* 000 */ V(11, 14, 2), /* 310 */ + /* 001 */ V(11, 14, 2), + /* 010 */ V(12, 13, 2), + /* 011 */ V(12, 13, 2), + /* 100 */ V(13, 12, 3), + /* 101 */ V(13, 11, 3), + /* 110 */ V(10, 14, 2), + /* 111 */ V(10, 14, 2), + + /* 0000 0110 1110 ... */ + /* 000 */ V(12, 12, 2), /* 318 */ + /* 001 */ V(12, 12, 2), + /* 010 */ V(10, 13, 3), + /* 011 */ V(13, 10, 3), + /* 100 */ V(7, 14, 3), + /* 101 */ V(10, 12, 3), + /* 110 */ V(12, 10, 2), + /* 111 */ V(12, 10, 2), + + /* 0000 0110 1111 ... */ + /* 000 */ V(12, 9, 3), /* 326 */ + /* 001 */ V(7, 13, 3), + /* 010 */ V(5, 14, 2), + /* 011 */ V(5, 14, 2), + /* 100 */ V(11, 13, 1), + /* 101 */ V(11, 13, 1), + /* 110 */ V(11, 13, 1), + /* 111 */ V(11, 13, 1), + + /* 0000 1011 0000 ... */ + /* 00 */ V(9, 14, 1), /* 334 */ + /* 01 */ V(9, 14, 1), + /* 10 */ V(11, 12, 2), + /* 11 */ V(12, 11, 2), + + /* 0000 1011 0001 ... */ + /* 00 */ V(8, 14, 2), /* 338 */ + /* 01 */ V(14, 8, 2), + /* 10 */ V(9, 13, 2), + /* 11 */ V(14, 7, 2), + + /* 0000 1011 0010 ... */ + /* 00 */ V(11, 11, 2), /* 342 */ + /* 01 */ V(8, 13, 2), + /* 10 */ V(13, 8, 2), + /* 11 */ V(6, 14, 2), + + /* 0000 1011 0011 ... */ + /* 0 */ V(14, 6, 1), /* 346 */ + /* 1 */ V(9, 12, 1), + + /* 0000 1011 0100 ... */ + /* 00 */ V(10, 11, 2), /* 348 */ + /* 01 */ V(11, 10, 2), + /* 10 */ V(14, 5, 2), + /* 11 */ V(13, 7, 2), + + /* 0000 1011 0101 ... */ + /* 00 */ V(4, 14, 1), /* 352 */ + /* 01 */ V(4, 14, 1), + /* 10 */ V(14, 4, 2), + /* 11 */ V(8, 12, 2), + + /* 0000 1011 0110 ... */ + /* 0 */ V(12, 8, 1), /* 356 */ + /* 1 */ V(3, 14, 1), + + /* 0000 1011 0111 ... */ + /* 00 */ V(6, 13, 1), /* 358 */ + /* 01 */ V(6, 13, 1), + /* 10 */ V(13, 6, 2), + /* 11 */ V(9, 11, 2), + + /* 0000 1011 1000 ... */ + /* 00 */ V(11, 9, 2), /* 362 */ + /* 01 */ V(10, 10, 2), + /* 10 */ V(14, 1, 1), + /* 11 */ V(14, 1, 1), + + /* 0000 1011 1001 ... */ + /* 00 */ V(13, 4, 1), /* 366 */ + /* 01 */ V(13, 4, 1), + /* 10 */ V(11, 8, 2), + /* 11 */ V(10, 9, 2), + + /* 0000 1011 1010 ... */ + /* 00 */ V(7, 11, 1), /* 370 */ + /* 01 */ V(7, 11, 1), + /* 10 */ V(11, 7, 2), + /* 11 */ V(13, 0, 2), + + /* 0000 1011 1100 ... */ + /* 0 */ V(0, 14, 1), /* 374 */ + /* 1 */ V(14, 0, 1), + + /* 0000 1011 1101 ... */ + /* 0 */ V(5, 13, 1), /* 376 */ + /* 1 */ V(13, 5, 1), + + /* 0000 1011 1110 ... */ + /* 0 */ V(7, 12, 1), /* 378 */ + /* 1 */ V(12, 7, 1), + + /* 0000 1011 1111 ... */ + /* 0 */ V(4, 13, 1), /* 380 */ + /* 1 */ V(8, 11, 1), + + /* 0000 1100 0000 ... */ + /* 0 */ V(9, 10, 1), /* 382 */ + /* 1 */ V(6, 12, 1), + + /* 0000 1100 0001 ... */ + /* 0 */ V(12, 6, 1), /* 384 */ + /* 1 */ V(3, 13, 1), + + /* 0000 1100 0010 ... */ + /* 0 */ V(5, 12, 1), /* 386 */ + /* 1 */ V(12, 5, 1), + + /* 0000 1100 0100 ... */ + /* 0 */ V(8, 10, 1), /* 388 */ + /* 1 */ V(10, 8, 1), + + /* 0000 1100 0101 ... */ + /* 0 */ V(9, 9, 1), /* 390 */ + /* 1 */ V(4, 12, 1), + + /* 0000 1100 0110 ... */ + /* 0 */ V(11, 6, 1), /* 392 */ + /* 1 */ V(7, 10, 1), + + /* 0000 1100 1000 ... */ + /* 0 */ V(5, 11, 1), /* 394 */ + /* 1 */ V(8, 9, 1), + + /* 0000 1100 1011 ... */ + /* 0 */ V(9, 8, 1), /* 396 */ + /* 1 */ V(7, 9, 1), + + /* 0000 1101 0101 ... */ + /* 0 */ V(9, 7, 1), /* 398 */ + /* 1 */ V(8, 8, 1), + + /* 0000 0110 1100 0001 ... */ + /* 0 */ V(14, 12, 1), /* 400 */ + /* 1 */ V(13, 13, 1) +]; + +const hufftab24 = [ + /* 0000 */ PTR(16, 4), + /* 0001 */ PTR(32, 4), + /* 0010 */ PTR(48, 4), + /* 0011 */ V(15, 15, 4), + /* 0100 */ PTR(64, 4), + /* 0101 */ PTR(80, 4), + /* 0110 */ PTR(96, 4), + /* 0111 */ PTR(112, 4), + /* 1000 */ PTR(128, 4), + /* 1001 */ PTR(144, 4), + /* 1010 */ PTR(160, 3), + /* 1011 */ PTR(168, 2), + /* 1100 */ V(1, 1, 4), + /* 1101 */ V(0, 1, 4), + /* 1110 */ V(1, 0, 4), + /* 1111 */ V(0, 0, 4), + + /* 0000 ... */ + /* 0000 */ V(14, 15, 4), /* 16 */ + /* 0001 */ V(15, 14, 4), + /* 0010 */ V(13, 15, 4), + /* 0011 */ V(15, 13, 4), + /* 0100 */ V(12, 15, 4), + /* 0101 */ V(15, 12, 4), + /* 0110 */ V(11, 15, 4), + /* 0111 */ V(15, 11, 4), + /* 1000 */ V(15, 10, 3), + /* 1001 */ V(15, 10, 3), + /* 1010 */ V(10, 15, 4), + /* 1011 */ V(9, 15, 4), + /* 1100 */ V(15, 9, 3), + /* 1101 */ V(15, 9, 3), + /* 1110 */ V(15, 8, 3), + /* 1111 */ V(15, 8, 3), + + /* 0001 ... */ + /* 0000 */ V(8, 15, 4), /* 32 */ + /* 0001 */ V(7, 15, 4), + /* 0010 */ V(15, 7, 3), + /* 0011 */ V(15, 7, 3), + /* 0100 */ V(6, 15, 3), + /* 0101 */ V(6, 15, 3), + /* 0110 */ V(15, 6, 3), + /* 0111 */ V(15, 6, 3), + /* 1000 */ V(5, 15, 3), + /* 1001 */ V(5, 15, 3), + /* 1010 */ V(15, 5, 3), + /* 1011 */ V(15, 5, 3), + /* 1100 */ V(4, 15, 3), + /* 1101 */ V(4, 15, 3), + /* 1110 */ V(15, 4, 3), + /* 1111 */ V(15, 4, 3), + + /* 0010 ... */ + /* 0000 */ V(3, 15, 3), /* 48 */ + /* 0001 */ V(3, 15, 3), + /* 0010 */ V(15, 3, 3), + /* 0011 */ V(15, 3, 3), + /* 0100 */ V(2, 15, 3), + /* 0101 */ V(2, 15, 3), + /* 0110 */ V(15, 2, 3), + /* 0111 */ V(15, 2, 3), + /* 1000 */ V(15, 1, 3), + /* 1001 */ V(15, 1, 3), + /* 1010 */ V(1, 15, 4), + /* 1011 */ V(15, 0, 4), + /* 1100 */ PTR(172, 3), + /* 1101 */ PTR(180, 3), + /* 1110 */ PTR(188, 3), + /* 1111 */ PTR(196, 3), + + /* 0100 ... */ + /* 0000 */ PTR(204, 4), /* 64 */ + /* 0001 */ PTR(220, 3), + /* 0010 */ PTR(228, 3), + /* 0011 */ PTR(236, 3), + /* 0100 */ PTR(244, 2), + /* 0101 */ PTR(248, 2), + /* 0110 */ PTR(252, 2), + /* 0111 */ PTR(256, 2), + /* 1000 */ PTR(260, 2), + /* 1001 */ PTR(264, 2), + /* 1010 */ PTR(268, 2), + /* 1011 */ PTR(272, 2), + /* 1100 */ PTR(276, 2), + /* 1101 */ PTR(280, 3), + /* 1110 */ PTR(288, 2), + /* 1111 */ PTR(292, 2), + + /* 0101 ... */ + /* 0000 */ PTR(296, 2), /* 80 */ + /* 0001 */ PTR(300, 3), + /* 0010 */ PTR(308, 2), + /* 0011 */ PTR(312, 3), + /* 0100 */ PTR(320, 1), + /* 0101 */ PTR(322, 2), + /* 0110 */ PTR(326, 2), + /* 0111 */ PTR(330, 1), + /* 1000 */ PTR(332, 2), + /* 1001 */ PTR(336, 1), + /* 1010 */ PTR(338, 1), + /* 1011 */ PTR(340, 1), + /* 1100 */ PTR(342, 1), + /* 1101 */ PTR(344, 1), + /* 1110 */ PTR(346, 1), + /* 1111 */ PTR(348, 1), + + /* 0110 ... */ + /* 0000 */ PTR(350, 1), /* 96 */ + /* 0001 */ PTR(352, 1), + /* 0010 */ PTR(354, 1), + /* 0011 */ PTR(356, 1), + /* 0100 */ PTR(358, 1), + /* 0101 */ PTR(360, 1), + /* 0110 */ PTR(362, 1), + /* 0111 */ PTR(364, 1), + /* 1000 */ PTR(366, 1), + /* 1001 */ PTR(368, 1), + /* 1010 */ PTR(370, 2), + /* 1011 */ PTR(374, 1), + /* 1100 */ PTR(376, 2), + /* 1101 */ V(7, 3, 4), + /* 1110 */ PTR(380, 1), + /* 1111 */ V(7, 2, 4), + + /* 0111 ... */ + /* 0000 */ V(4, 6, 4), /* 112 */ + /* 0001 */ V(6, 4, 4), + /* 0010 */ V(5, 5, 4), + /* 0011 */ V(7, 1, 4), + /* 0100 */ V(3, 6, 4), + /* 0101 */ V(6, 3, 4), + /* 0110 */ V(4, 5, 4), + /* 0111 */ V(5, 4, 4), + /* 1000 */ V(2, 6, 4), + /* 1001 */ V(6, 2, 4), + /* 1010 */ V(1, 6, 4), + /* 1011 */ V(6, 1, 4), + /* 1100 */ PTR(382, 1), + /* 1101 */ V(3, 5, 4), + /* 1110 */ V(5, 3, 4), + /* 1111 */ V(4, 4, 4), + + /* 1000 ... */ + /* 0000 */ V(2, 5, 4), /* 128 */ + /* 0001 */ V(5, 2, 4), + /* 0010 */ V(1, 5, 4), + /* 0011 */ PTR(384, 1), + /* 0100 */ V(5, 1, 3), + /* 0101 */ V(5, 1, 3), + /* 0110 */ V(3, 4, 4), + /* 0111 */ V(4, 3, 4), + /* 1000 */ V(2, 4, 3), + /* 1001 */ V(2, 4, 3), + /* 1010 */ V(4, 2, 3), + /* 1011 */ V(4, 2, 3), + /* 1100 */ V(3, 3, 3), + /* 1101 */ V(3, 3, 3), + /* 1110 */ V(1, 4, 3), + /* 1111 */ V(1, 4, 3), + + /* 1001 ... */ + /* 0000 */ V(4, 1, 3), /* 144 */ + /* 0001 */ V(4, 1, 3), + /* 0010 */ V(0, 4, 4), + /* 0011 */ V(4, 0, 4), + /* 0100 */ V(2, 3, 3), + /* 0101 */ V(2, 3, 3), + /* 0110 */ V(3, 2, 3), + /* 0111 */ V(3, 2, 3), + /* 1000 */ V(1, 3, 2), + /* 1001 */ V(1, 3, 2), + /* 1010 */ V(1, 3, 2), + /* 1011 */ V(1, 3, 2), + /* 1100 */ V(3, 1, 2), + /* 1101 */ V(3, 1, 2), + /* 1110 */ V(3, 1, 2), + /* 1111 */ V(3, 1, 2), + + /* 1010 ... */ + /* 000 */ V(0, 3, 3), /* 160 */ + /* 001 */ V(3, 0, 3), + /* 010 */ V(2, 2, 2), + /* 011 */ V(2, 2, 2), + /* 100 */ V(1, 2, 1), + /* 101 */ V(1, 2, 1), + /* 110 */ V(1, 2, 1), + /* 111 */ V(1, 2, 1), + + /* 1011 ... */ + /* 00 */ V(2, 1, 1), /* 168 */ + /* 01 */ V(2, 1, 1), + /* 10 */ V(0, 2, 2), + /* 11 */ V(2, 0, 2), + + /* 0010 1100 ... */ + /* 000 */ V(0, 15, 1), /* 172 */ + /* 001 */ V(0, 15, 1), + /* 010 */ V(0, 15, 1), + /* 011 */ V(0, 15, 1), + /* 100 */ V(14, 14, 3), + /* 101 */ V(13, 14, 3), + /* 110 */ V(14, 13, 3), + /* 111 */ V(12, 14, 3), + + /* 0010 1101 ... */ + /* 000 */ V(14, 12, 3), /* 180 */ + /* 001 */ V(13, 13, 3), + /* 010 */ V(11, 14, 3), + /* 011 */ V(14, 11, 3), + /* 100 */ V(12, 13, 3), + /* 101 */ V(13, 12, 3), + /* 110 */ V(10, 14, 3), + /* 111 */ V(14, 10, 3), + + /* 0010 1110 ... */ + /* 000 */ V(11, 13, 3), /* 188 */ + /* 001 */ V(13, 11, 3), + /* 010 */ V(12, 12, 3), + /* 011 */ V(9, 14, 3), + /* 100 */ V(14, 9, 3), + /* 101 */ V(10, 13, 3), + /* 110 */ V(13, 10, 3), + /* 111 */ V(11, 12, 3), + + /* 0010 1111 ... */ + /* 000 */ V(12, 11, 3), /* 196 */ + /* 001 */ V(8, 14, 3), + /* 010 */ V(14, 8, 3), + /* 011 */ V(9, 13, 3), + /* 100 */ V(13, 9, 3), + /* 101 */ V(7, 14, 3), + /* 110 */ V(14, 7, 3), + /* 111 */ V(10, 12, 3), + + /* 0100 0000 ... */ + /* 0000 */ V(12, 10, 3), /* 204 */ + /* 0001 */ V(12, 10, 3), + /* 0010 */ V(11, 11, 3), + /* 0011 */ V(11, 11, 3), + /* 0100 */ V(8, 13, 3), + /* 0101 */ V(8, 13, 3), + /* 0110 */ V(13, 8, 3), + /* 0111 */ V(13, 8, 3), + /* 1000 */ V(0, 14, 4), + /* 1001 */ V(14, 0, 4), + /* 1010 */ V(0, 13, 3), + /* 1011 */ V(0, 13, 3), + /* 1100 */ V(14, 6, 2), + /* 1101 */ V(14, 6, 2), + /* 1110 */ V(14, 6, 2), + /* 1111 */ V(14, 6, 2), + + /* 0100 0001 ... */ + /* 000 */ V(6, 14, 3), /* 220 */ + /* 001 */ V(9, 12, 3), + /* 010 */ V(12, 9, 2), + /* 011 */ V(12, 9, 2), + /* 100 */ V(5, 14, 2), + /* 101 */ V(5, 14, 2), + /* 110 */ V(11, 10, 2), + /* 111 */ V(11, 10, 2), + + /* 0100 0010 ... */ + /* 000 */ V(14, 5, 2), /* 228 */ + /* 001 */ V(14, 5, 2), + /* 010 */ V(10, 11, 3), + /* 011 */ V(7, 13, 3), + /* 100 */ V(13, 7, 2), + /* 101 */ V(13, 7, 2), + /* 110 */ V(14, 4, 2), + /* 111 */ V(14, 4, 2), + + /* 0100 0011 ... */ + /* 000 */ V(8, 12, 2), /* 236 */ + /* 001 */ V(8, 12, 2), + /* 010 */ V(12, 8, 2), + /* 011 */ V(12, 8, 2), + /* 100 */ V(4, 14, 3), + /* 101 */ V(2, 14, 3), + /* 110 */ V(3, 14, 2), + /* 111 */ V(3, 14, 2), + + /* 0100 0100 ... */ + /* 00 */ V(6, 13, 2), /* 244 */ + /* 01 */ V(13, 6, 2), + /* 10 */ V(14, 3, 2), + /* 11 */ V(9, 11, 2), + + /* 0100 0101 ... */ + /* 00 */ V(11, 9, 2), /* 248 */ + /* 01 */ V(10, 10, 2), + /* 10 */ V(14, 2, 2), + /* 11 */ V(1, 14, 2), + + /* 0100 0110 ... */ + /* 00 */ V(14, 1, 2), /* 252 */ + /* 01 */ V(5, 13, 2), + /* 10 */ V(13, 5, 2), + /* 11 */ V(7, 12, 2), + + /* 0100 0111 ... */ + /* 00 */ V(12, 7, 2), /* 256 */ + /* 01 */ V(4, 13, 2), + /* 10 */ V(8, 11, 2), + /* 11 */ V(11, 8, 2), + + /* 0100 1000 ... */ + /* 00 */ V(13, 4, 2), /* 260 */ + /* 01 */ V(9, 10, 2), + /* 10 */ V(10, 9, 2), + /* 11 */ V(6, 12, 2), + + /* 0100 1001 ... */ + /* 00 */ V(12, 6, 2), /* 264 */ + /* 01 */ V(3, 13, 2), + /* 10 */ V(13, 3, 2), + /* 11 */ V(2, 13, 2), + + /* 0100 1010 ... */ + /* 00 */ V(13, 2, 2), /* 268 */ + /* 01 */ V(1, 13, 2), + /* 10 */ V(7, 11, 2), + /* 11 */ V(11, 7, 2), + + /* 0100 1011 ... */ + /* 00 */ V(13, 1, 2), /* 272 */ + /* 01 */ V(5, 12, 2), + /* 10 */ V(12, 5, 2), + /* 11 */ V(8, 10, 2), + + /* 0100 1100 ... */ + /* 00 */ V(10, 8, 2), /* 276 */ + /* 01 */ V(9, 9, 2), + /* 10 */ V(4, 12, 2), + /* 11 */ V(12, 4, 2), + + /* 0100 1101 ... */ + /* 000 */ V(6, 11, 2), /* 280 */ + /* 001 */ V(6, 11, 2), + /* 010 */ V(11, 6, 2), + /* 011 */ V(11, 6, 2), + /* 100 */ V(13, 0, 3), + /* 101 */ V(0, 12, 3), + /* 110 */ V(3, 12, 2), + /* 111 */ V(3, 12, 2), + + /* 0100 1110 ... */ + /* 00 */ V(12, 3, 2), /* 288 */ + /* 01 */ V(7, 10, 2), + /* 10 */ V(10, 7, 2), + /* 11 */ V(2, 12, 2), + + /* 0100 1111 ... */ + /* 00 */ V(12, 2, 2), /* 292 */ + /* 01 */ V(5, 11, 2), + /* 10 */ V(11, 5, 2), + /* 11 */ V(1, 12, 2), + + /* 0101 0000 ... */ + /* 00 */ V(8, 9, 2), /* 296 */ + /* 01 */ V(9, 8, 2), + /* 10 */ V(12, 1, 2), + /* 11 */ V(4, 11, 2), + + /* 0101 0001 ... */ + /* 000 */ V(12, 0, 3), /* 300 */ + /* 001 */ V(0, 11, 3), + /* 010 */ V(3, 11, 2), + /* 011 */ V(3, 11, 2), + /* 100 */ V(11, 0, 3), + /* 101 */ V(0, 10, 3), + /* 110 */ V(1, 10, 2), + /* 111 */ V(1, 10, 2), + + /* 0101 0010 ... */ + /* 00 */ V(11, 4, 1), /* 308 */ + /* 01 */ V(11, 4, 1), + /* 10 */ V(6, 10, 2), + /* 11 */ V(10, 6, 2), + + /* 0101 0011 ... */ + /* 000 */ V(7, 9, 2), /* 312 */ + /* 001 */ V(7, 9, 2), + /* 010 */ V(9, 7, 2), + /* 011 */ V(9, 7, 2), + /* 100 */ V(10, 0, 3), + /* 101 */ V(0, 9, 3), + /* 110 */ V(9, 0, 2), + /* 111 */ V(9, 0, 2), + + /* 0101 0100 ... */ + /* 0 */ V(11, 3, 1), /* 320 */ + /* 1 */ V(8, 8, 1), + + /* 0101 0101 ... */ + /* 00 */ V(2, 11, 2), /* 322 */ + /* 01 */ V(5, 10, 2), + /* 10 */ V(11, 2, 1), + /* 11 */ V(11, 2, 1), + + /* 0101 0110 ... */ + /* 00 */ V(10, 5, 2), /* 326 */ + /* 01 */ V(1, 11, 2), + /* 10 */ V(11, 1, 2), + /* 11 */ V(6, 9, 2), + + /* 0101 0111 ... */ + /* 0 */ V(9, 6, 1), /* 330 */ + /* 1 */ V(10, 4, 1), + + /* 0101 1000 ... */ + /* 00 */ V(4, 10, 2), /* 332 */ + /* 01 */ V(7, 8, 2), + /* 10 */ V(8, 7, 1), + /* 11 */ V(8, 7, 1), + + /* 0101 1001 ... */ + /* 0 */ V(3, 10, 1), /* 336 */ + /* 1 */ V(10, 3, 1), + + /* 0101 1010 ... */ + /* 0 */ V(5, 9, 1), /* 338 */ + /* 1 */ V(9, 5, 1), + + /* 0101 1011 ... */ + /* 0 */ V(2, 10, 1), /* 340 */ + /* 1 */ V(10, 2, 1), + + /* 0101 1100 ... */ + /* 0 */ V(10, 1, 1), /* 342 */ + /* 1 */ V(6, 8, 1), + + /* 0101 1101 ... */ + /* 0 */ V(8, 6, 1), /* 344 */ + /* 1 */ V(7, 7, 1), + + /* 0101 1110 ... */ + /* 0 */ V(4, 9, 1), /* 346 */ + /* 1 */ V(9, 4, 1), + + /* 0101 1111 ... */ + /* 0 */ V(3, 9, 1), /* 348 */ + /* 1 */ V(9, 3, 1), + + /* 0110 0000 ... */ + /* 0 */ V(5, 8, 1), /* 350 */ + /* 1 */ V(8, 5, 1), + + /* 0110 0001 ... */ + /* 0 */ V(2, 9, 1), /* 352 */ + /* 1 */ V(6, 7, 1), + + /* 0110 0010 ... */ + /* 0 */ V(7, 6, 1), /* 354 */ + /* 1 */ V(9, 2, 1), + + /* 0110 0011 ... */ + /* 0 */ V(1, 9, 1), /* 356 */ + /* 1 */ V(9, 1, 1), + + /* 0110 0100 ... */ + /* 0 */ V(4, 8, 1), /* 358 */ + /* 1 */ V(8, 4, 1), + + /* 0110 0101 ... */ + /* 0 */ V(5, 7, 1), /* 360 */ + /* 1 */ V(7, 5, 1), + + /* 0110 0110 ... */ + /* 0 */ V(3, 8, 1), /* 362 */ + /* 1 */ V(8, 3, 1), + + /* 0110 0111 ... */ + /* 0 */ V(6, 6, 1), /* 364 */ + /* 1 */ V(2, 8, 1), + + /* 0110 1000 ... */ + /* 0 */ V(8, 2, 1), /* 366 */ + /* 1 */ V(1, 8, 1), + + /* 0110 1001 ... */ + /* 0 */ V(4, 7, 1), /* 368 */ + /* 1 */ V(7, 4, 1), + + /* 0110 1010 ... */ + /* 00 */ V(8, 1, 1), /* 370 */ + /* 01 */ V(8, 1, 1), + /* 10 */ V(0, 8, 2), + /* 11 */ V(8, 0, 2), + + /* 0110 1011 ... */ + /* 0 */ V(5, 6, 1), /* 374 */ + /* 1 */ V(6, 5, 1), + + /* 0110 1100 ... */ + /* 00 */ V(1, 7, 1), /* 376 */ + /* 01 */ V(1, 7, 1), + /* 10 */ V(0, 7, 2), + /* 11 */ V(7, 0, 2), + + /* 0110 1110 ... */ + /* 0 */ V(3, 7, 1), /* 380 */ + /* 1 */ V(2, 7, 1), + + /* 0111 1100 ... */ + /* 0 */ V(0, 6, 1), /* 382 */ + /* 1 */ V(6, 0, 1), + + /* 1000 0011 ... */ + /* 0 */ V(0, 5, 1), /* 384 */ + /* 1 */ V(5, 0, 1) +]; + +/* hufftable constructor */ +function MP3Hufftable(table, linbits, startbits) { + this.table = table; + this.linbits = linbits; + this.startbits = startbits; +}; + +/* external tables */ +exports.huff_quad_table = [ hufftabA, hufftabB ]; +exports.huff_pair_table = [ + /* 0 */ new MP3Hufftable(hufftab0, 0, 0), + /* 1 */ new MP3Hufftable(hufftab1, 0, 3), + /* 2 */ new MP3Hufftable(hufftab2, 0, 3), + /* 3 */ new MP3Hufftable(hufftab3, 0, 3), + /* 4 */ null, //new MP3Hufftable(0 /* not used */), + /* 5 */ new MP3Hufftable(hufftab5, 0, 3), + /* 6 */ new MP3Hufftable(hufftab6, 0, 4), + /* 7 */ new MP3Hufftable(hufftab7, 0, 4), + /* 8 */ new MP3Hufftable(hufftab8, 0, 4), + /* 9 */ new MP3Hufftable(hufftab9, 0, 4), + /* 10 */ new MP3Hufftable(hufftab10, 0, 4), + /* 11 */ new MP3Hufftable(hufftab11, 0, 4), + /* 12 */ new MP3Hufftable(hufftab12, 0, 4), + /* 13 */ new MP3Hufftable(hufftab13, 0, 4), + /* 14 */ null, //new MP3Hufftable(0 /* not used */), + /* 15 */ new MP3Hufftable(hufftab15, 0, 4), + /* 16 */ new MP3Hufftable(hufftab16, 1, 4), + /* 17 */ new MP3Hufftable(hufftab16, 2, 4), + /* 18 */ new MP3Hufftable(hufftab16, 3, 4), + /* 19 */ new MP3Hufftable(hufftab16, 4, 4), + /* 20 */ new MP3Hufftable(hufftab16, 6, 4), + /* 21 */ new MP3Hufftable(hufftab16, 8, 4), + /* 22 */ new MP3Hufftable(hufftab16, 10, 4), + /* 23 */ new MP3Hufftable(hufftab16, 13, 4), + /* 24 */ new MP3Hufftable(hufftab24, 4, 4), + /* 25 */ new MP3Hufftable(hufftab24, 5, 4), + /* 26 */ new MP3Hufftable(hufftab24, 6, 4), + /* 27 */ new MP3Hufftable(hufftab24, 7, 4), + /* 28 */ new MP3Hufftable(hufftab24, 8, 4), + /* 29 */ new MP3Hufftable(hufftab24, 9, 4), + /* 30 */ new MP3Hufftable(hufftab24, 11, 4), + /* 31 */ new MP3Hufftable(hufftab24, 13, 4) +]; + +},{}],7:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); + +const ENCODINGS = ['latin1', 'utf16-bom', 'utf16-be', 'utf8']; + +var ID3Stream = AV.Base.extend({ + constructor: function(header, stream) { + this.header = header; + this.stream = stream; + this.offset = 0; + }, + + read: function() { + if (!this.data) { + this.data = {}; + + // read all frames + var frame; + while (frame = this.readFrame()) { + // if we already have an instance of this key, add it to an array + if (frame.key in this.data) { + if (!Array.isArray(this.data[frame.key])) + this.data[frame.key] = [this.data[frame.key]]; + + this.data[frame.key].push(frame.value); + } else { + this.data[frame.key] = frame.value; + } + } + } + + return this.data; + }, + + readFrame: function() { + if (this.offset >= this.header.length) + return null; + + // get the header + var header = this.readHeader(); + var decoder = header.identifier; + + if (header.identifier.charCodeAt(0) === 0) { + this.offset += this.header.length + 1; + return null; + } + + // map common frame names to a single type + if (!this.frameTypes[decoder]) { + for (var key in this.map) { + if (this.map[key].indexOf(decoder) !== -1) { + decoder = key; + break; + } + } + } + + if (this.frameTypes[decoder]) { + // decode the frame + var frame = this.decodeFrame(header, this.frameTypes[decoder]), + keys = Object.keys(frame); + + // if it only returned one key, use that as the value + if (keys.length === 1) + frame = frame[keys[0]]; + + var result = { + value: frame + }; + + } else { + // No frame type found, treat it as binary + var result = { + value: this.stream.readBuffer(Math.min(header.length, this.header.length - this.offset)) + }; + } + + result.key = this.names[header.identifier] ? this.names[header.identifier] : header.identifier; + + // special sauce for cover art, which should just be a buffer + if (result.key === 'coverArt') + result.value = result.value.data; + + this.offset += 10 + header.length; + return result; + }, + + decodeFrame: function(header, fields) { + var stream = this.stream, + start = stream.offset; + + var encoding = 0, ret = {}; + var len = Object.keys(fields).length, i = 0; + + for (var key in fields) { + var type = fields[key]; + var rest = header.length - (stream.offset - start); + i++; + + // check for special field names + switch (key) { + case 'encoding': + encoding = stream.readUInt8(); + continue; + + case 'language': + ret.language = stream.readString(3); + continue; + } + + // check types + switch (type) { + case 'latin1': + ret[key] = stream.readString(i === len ? rest : null, 'latin1'); + break; + + case 'string': + ret[key] = stream.readString(i === len ? rest : null, ENCODINGS[encoding]); + break; + + case 'binary': + ret[key] = stream.readBuffer(rest) + break; + + case 'int16': + ret[key] = stream.readInt16(); + break; + + case 'int8': + ret[key] = stream.readInt8(); + break; + + case 'int24': + ret[key] = stream.readInt24(); + break; + + case 'int32': + ret[key] = stream.readInt32(); + break; + + case 'int32+': + ret[key] = stream.readInt32(); + if (rest > 4) + throw new Error('Seriously dude? Stop playing this song and get a life!'); + + break; + + case 'date': + var val = stream.readString(8); + ret[key] = new Date(val.slice(0, 4), val.slice(4, 6) - 1, val.slice(6, 8)); + break; + + case 'frame_id': + ret[key] = stream.readString(4); + break; + + default: + throw new Error('Unknown key type ' + type); + } + } + + // Just in case something went wrong... + var rest = header.length - (stream.offset - start); + if (rest > 0) + stream.advance(rest); + + return ret; + } +}); + +// ID3 v2.3 and v2.4 support +exports.ID3v23Stream = ID3Stream.extend({ + readHeader: function() { + var identifier = this.stream.readString(4); + var length = 0; + + if (this.header.major === 4) { + for (var i = 0; i < 4; i++) + length = (length << 7) + (this.stream.readUInt8() & 0x7f); + } else { + length = this.stream.readUInt32(); + } + + return { + identifier: identifier, + length: length, + flags: this.stream.readUInt16() + }; + }, + + map: { + text: [ + // Identification Frames + 'TIT1', 'TIT2', 'TIT3', 'TALB', 'TOAL', 'TRCK', 'TPOS', 'TSST', 'TSRC', + + // Involved Persons Frames + 'TPE1', 'TPE2', 'TPE3', 'TPE4', 'TOPE', 'TEXT', 'TOLY', 'TCOM', 'TMCL', 'TIPL', 'TENC', + + // Derived and Subjective Properties Frames + 'TBPM', 'TLEN', 'TKEY', 'TLAN', 'TCON', 'TFLT', 'TMED', 'TMOO', + + // Rights and Licence Frames + 'TCOP', 'TPRO', 'TPUB', 'TOWN', 'TRSN', 'TRSO', + + // Other Text Frames + 'TOFN', 'TDLY', 'TDEN', 'TDOR', 'TDRC', 'TDRL', 'TDTG', 'TSSE', 'TSOA', 'TSOP', 'TSOT', + + // Deprecated Text Frames + 'TDAT', 'TIME', 'TORY', 'TRDA', 'TSIZ', 'TYER', + + // Non-standard iTunes Frames + 'TCMP', 'TSO2', 'TSOC' + ], + + url: [ + 'WCOM', 'WCOP', 'WOAF', 'WOAR', 'WOAS', 'WORS', 'WPAY', 'WPUB' + ] + }, + + frameTypes: { + text: { + encoding: 1, + value: 'string' + }, + + url: { + value: 'latin1' + }, + + TXXX: { + encoding: 1, + description: 'string', + value: 'string' + }, + + WXXX: { + encoding: 1, + description: 'string', + value: 'latin1', + }, + + USLT: { + encoding: 1, + language: 1, + description: 'string', + value: 'string' + }, + + COMM: { + encoding: 1, + language: 1, + description: 'string', + value: 'string' + }, + + APIC: { + encoding: 1, + mime: 'latin1', + type: 'int8', + description: 'string', + data: 'binary' + }, + + UFID: { + owner: 'latin1', + identifier: 'binary' + }, + + MCDI: { + value: 'binary' + }, + + PRIV: { + owner: 'latin1', + value: 'binary' + }, + + GEOB: { + encoding: 1, + mime: 'latin1', + filename: 'string', + description: 'string', + data: 'binary' + }, + + PCNT: { + value: 'int32+' + }, + + POPM: { + email: 'latin1', + rating: 'int8', + counter: 'int32+' + }, + + AENC: { + owner: 'latin1', + previewStart: 'int16', + previewLength: 'int16', + encryptionInfo: 'binary' + }, + + ETCO: { + format: 'int8', + data: 'binary' // TODO + }, + + MLLT: { + framesBetweenReference: 'int16', + bytesBetweenReference: 'int24', + millisecondsBetweenReference: 'int24', + bitsForBytesDeviation: 'int8', + bitsForMillisecondsDev: 'int8', + data: 'binary' // TODO + }, + + SYTC: { + format: 'int8', + tempoData: 'binary' // TODO + }, + + SYLT: { + encoding: 1, + language: 1, + format: 'int8', + contentType: 'int8', + description: 'string', + data: 'binary' // TODO + }, + + RVA2: { + identification: 'latin1', + data: 'binary' // TODO + }, + + EQU2: { + interpolationMethod: 'int8', + identification: 'latin1', + data: 'binary' // TODO + }, + + RVRB: { + left: 'int16', + right: 'int16', + bouncesLeft: 'int8', + bouncesRight: 'int8', + feedbackLL: 'int8', + feedbackLR: 'int8', + feedbackRR: 'int8', + feedbackRL: 'int8', + premixLR: 'int8', + premixRL: 'int8' + }, + + RBUF: { + size: 'int24', + flag: 'int8', + offset: 'int32' + }, + + LINK: { + identifier: 'frame_id', + url: 'latin1', + data: 'binary' // TODO stringlist? + }, + + POSS: { + format: 'int8', + position: 'binary' // TODO + }, + + USER: { + encoding: 1, + language: 1, + value: 'string' + }, + + OWNE: { + encoding: 1, + price: 'latin1', + purchaseDate: 'date', + seller: 'string' + }, + + COMR: { + encoding: 1, + price: 'latin1', + validUntil: 'date', + contactURL: 'latin1', + receivedAs: 'int8', + seller: 'string', + description: 'string', + logoMime: 'latin1', + logo: 'binary' + }, + + ENCR: { + owner: 'latin1', + methodSymbol: 'int8', + data: 'binary' + }, + + GRID: { + owner: 'latin1', + groupSymbol: 'int8', + data: 'binary' + }, + + SIGN: { + groupSymbol: 'int8', + signature: 'binary' + }, + + SEEK: { + value: 'int32' + }, + + ASPI: { + dataStart: 'int32', + dataLength: 'int32', + numPoints: 'int16', + bitsPerPoint: 'int8', + data: 'binary' // TODO + }, + + // Deprecated ID3 v2.3 frames + IPLS: { + encoding: 1, + value: 'string' // list? + }, + + RVAD: { + adjustment: 'int8', + bits: 'int8', + data: 'binary' // TODO + }, + + EQUA: { + adjustmentBits: 'int8', + data: 'binary' // TODO + } + }, + + names: { + // Identification Frames + 'TIT1': 'grouping', + 'TIT2': 'title', + 'TIT3': 'subtitle', + 'TALB': 'album', + 'TOAL': 'originalAlbumTitle', + 'TRCK': 'trackNumber', + 'TPOS': 'diskNumber', + 'TSST': 'setSubtitle', + 'TSRC': 'ISRC', + + // Involved Persons Frames + 'TPE1': 'artist', + 'TPE2': 'albumArtist', + 'TPE3': 'conductor', + 'TPE4': 'modifiedBy', + 'TOPE': 'originalArtist', + 'TEXT': 'lyricist', + 'TOLY': 'originalLyricist', + 'TCOM': 'composer', + 'TMCL': 'musicianCreditsList', + 'TIPL': 'involvedPeopleList', + 'TENC': 'encodedBy', + + // Derived and Subjective Properties Frames + 'TBPM': 'tempo', + 'TLEN': 'length', + 'TKEY': 'initialKey', + 'TLAN': 'language', + 'TCON': 'genre', + 'TFLT': 'fileType', + 'TMED': 'mediaType', + 'TMOO': 'mood', + + // Rights and Licence Frames + 'TCOP': 'copyright', + 'TPRO': 'producedNotice', + 'TPUB': 'publisher', + 'TOWN': 'fileOwner', + 'TRSN': 'internetRadioStationName', + 'TRSO': 'internetRadioStationOwner', + + // Other Text Frames + 'TOFN': 'originalFilename', + 'TDLY': 'playlistDelay', + 'TDEN': 'encodingTime', + 'TDOR': 'originalReleaseTime', + 'TDRC': 'recordingTime', + 'TDRL': 'releaseTime', + 'TDTG': 'taggingTime', + 'TSSE': 'encodedWith', + 'TSOA': 'albumSortOrder', + 'TSOP': 'performerSortOrder', + 'TSOT': 'titleSortOrder', + + // User defined text information + 'TXXX': 'userText', + + // Unsynchronised lyrics/text transcription + 'USLT': 'lyrics', + + // Attached Picture Frame + 'APIC': 'coverArt', + + // Unique Identifier Frame + 'UFID': 'uniqueIdentifier', + + // Music CD Identifier Frame + 'MCDI': 'CDIdentifier', + + // Comment Frame + 'COMM': 'comments', + + // URL link frames + 'WCOM': 'commercialInformation', + 'WCOP': 'copyrightInformation', + 'WOAF': 'officialAudioFileWebpage', + 'WOAR': 'officialArtistWebpage', + 'WOAS': 'officialAudioSourceWebpage', + 'WORS': 'officialInternetRadioStationHomepage', + 'WPAY': 'payment', + 'WPUB': 'officialPublisherWebpage', + + // User Defined URL Link Frame + 'WXXX': 'url', + + 'PRIV': 'private', + 'GEOB': 'generalEncapsulatedObject', + 'PCNT': 'playCount', + 'POPM': 'rating', + 'AENC': 'audioEncryption', + 'ETCO': 'eventTimingCodes', + 'MLLT': 'MPEGLocationLookupTable', + 'SYTC': 'synchronisedTempoCodes', + 'SYLT': 'synchronisedLyrics', + 'RVA2': 'volumeAdjustment', + 'EQU2': 'equalization', + 'RVRB': 'reverb', + 'RBUF': 'recommendedBufferSize', + 'LINK': 'link', + 'POSS': 'positionSynchronisation', + 'USER': 'termsOfUse', + 'OWNE': 'ownership', + 'COMR': 'commercial', + 'ENCR': 'encryption', + 'GRID': 'groupIdentifier', + 'SIGN': 'signature', + 'SEEK': 'seek', + 'ASPI': 'audioSeekPointIndex', + + // Deprecated ID3 v2.3 frames + 'TDAT': 'date', + 'TIME': 'time', + 'TORY': 'originalReleaseYear', + 'TRDA': 'recordingDates', + 'TSIZ': 'size', + 'TYER': 'year', + 'IPLS': 'involvedPeopleList', + 'RVAD': 'volumeAdjustment', + 'EQUA': 'equalization', + + // Non-standard iTunes frames + 'TCMP': 'compilation', + 'TSO2': 'albumArtistSortOrder', + 'TSOC': 'composerSortOrder' + } +}); + +// ID3 v2.2 support +exports.ID3v22Stream = exports.ID3v23Stream.extend({ + readHeader: function() { + var id = this.stream.readString(3); + + if (this.frameReplacements[id] && !this.frameTypes[id]) + this.frameTypes[id] = this.frameReplacements[id]; + + return { + identifier: this.replacements[id] || id, + length: this.stream.readUInt24() + }; + }, + + // map 3 char ID3 v2.2 names to 4 char ID3 v2.3/4 names + replacements: { + 'UFI': 'UFID', + 'TT1': 'TIT1', + 'TT2': 'TIT2', + 'TT3': 'TIT3', + 'TP1': 'TPE1', + 'TP2': 'TPE2', + 'TP3': 'TPE3', + 'TP4': 'TPE4', + 'TCM': 'TCOM', + 'TXT': 'TEXT', + 'TLA': 'TLAN', + 'TCO': 'TCON', + 'TAL': 'TALB', + 'TPA': 'TPOS', + 'TRK': 'TRCK', + 'TRC': 'TSRC', + 'TYE': 'TYER', + 'TDA': 'TDAT', + 'TIM': 'TIME', + 'TRD': 'TRDA', + 'TMT': 'TMED', + 'TFT': 'TFLT', + 'TBP': 'TBPM', + 'TCR': 'TCOP', + 'TPB': 'TPUB', + 'TEN': 'TENC', + 'TSS': 'TSSE', + 'TOF': 'TOFN', + 'TLE': 'TLEN', + 'TSI': 'TSIZ', + 'TDY': 'TDLY', + 'TKE': 'TKEY', + 'TOT': 'TOAL', + 'TOA': 'TOPE', + 'TOL': 'TOLY', + 'TOR': 'TORY', + 'TXX': 'TXXX', + + 'WAF': 'WOAF', + 'WAR': 'WOAR', + 'WAS': 'WOAS', + 'WCM': 'WCOM', + 'WCP': 'WCOP', + 'WPB': 'WPUB', + 'WXX': 'WXXX', + + 'IPL': 'IPLS', + 'MCI': 'MCDI', + 'ETC': 'ETCO', + 'MLL': 'MLLT', + 'STC': 'SYTC', + 'ULT': 'USLT', + 'SLT': 'SYLT', + 'COM': 'COMM', + 'RVA': 'RVAD', + 'EQU': 'EQUA', + 'REV': 'RVRB', + + 'GEO': 'GEOB', + 'CNT': 'PCNT', + 'POP': 'POPM', + 'BUF': 'RBUF', + 'CRA': 'AENC', + 'LNK': 'LINK', + + // iTunes stuff + 'TST': 'TSOT', + 'TSP': 'TSOP', + 'TSA': 'TSOA', + 'TCP': 'TCMP', + 'TS2': 'TSO2', + 'TSC': 'TSOC' + }, + + // replacements for ID3 v2.3/4 frames + frameReplacements: { + PIC: { + encoding: 1, + format: 'int24', + type: 'int8', + description: 'string', + data: 'binary' + }, + + CRM: { + owner: 'latin1', + description: 'latin1', + data: 'binary' + } + } +}); +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],8:[function(require,module,exports){ +function IMDCT() { + this.tmp_imdct36 = new Float64Array(18); + this.tmp_dctIV = new Float64Array(18); + this.tmp_sdctII = new Float64Array(9); +} + +// perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm +IMDCT.prototype.imdct36 = function(x, y) { + var tmp = this.tmp_imdct36; + + /* DCT-IV */ + this.dctIV(x, tmp); + + // convert 18-point DCT-IV to 36-point IMDCT + for (var i = 0; i < 9; ++i) { + y[i] = tmp[9 + i]; + } + for (var i = 9; i < 27; ++i) { + y[i] = -tmp[36 - (9 + i) - 1]; + } + for (var i = 27; i < 36; ++i) { + y[i] = -tmp[i - 27]; + } +}; + +var dctIV_scale = []; +for(i = 0; i < 18; i++) { + dctIV_scale[i] = 2 * Math.cos(Math.PI * (2 * i + 1) / (4 * 18)); +} + +IMDCT.prototype.dctIV = function(y, X) { + var tmp = this.tmp_dctIV; + + // scaling + for (var i = 0; i < 18; ++i) { + tmp[i] = y[i] * dctIV_scale[i]; + } + + // SDCT-II + this.sdctII(tmp, X); + + // scale reduction and output accumulation + X[0] /= 2; + for (var i = 1; i < 18; ++i) { + X[i] = X[i] / 2 - X[i - 1]; + } +}; + +var sdctII_scale = []; +for (var i = 0; i < 9; ++i) { + sdctII_scale[i] = 2 * Math.cos(Math.PI * (2 * i + 1) / (2 * 18)); +} + +IMDCT.prototype.sdctII = function(x, X) { + // divide the 18-point SDCT-II into two 9-point SDCT-IIs + var tmp = this.tmp_sdctII; + + // even input butterfly + for (var i = 0; i < 9; ++i) { + tmp[i] = x[i] + x[18 - i - 1]; + } + + fastsdct(tmp, X, 0); + + // odd input butterfly and scaling + for (var i = 0; i < 9; ++i) { + tmp[i] = (x[i] - x[18 - i - 1]) * sdctII_scale[i]; + } + + fastsdct(tmp, X, 1); + + // output accumulation + for (var i = 3; i < 18; i += 2) { + X[i] -= X[i - 2]; + } +}; + +var c0 = 2 * Math.cos( 1 * Math.PI / 18); +var c1 = 2 * Math.cos( 3 * Math.PI / 18); +var c2 = 2 * Math.cos( 4 * Math.PI / 18); +var c3 = 2 * Math.cos( 5 * Math.PI / 18); +var c4 = 2 * Math.cos( 7 * Math.PI / 18); +var c5 = 2 * Math.cos( 8 * Math.PI / 18); +var c6 = 2 * Math.cos(16 * Math.PI / 18); + +function fastsdct(x, y, offset) { + var a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12; + var a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25; + var m0, m1, m2, m3, m4, m5, m6, m7; + + a0 = x[3] + x[5]; + a1 = x[3] - x[5]; + a2 = x[6] + x[2]; + a3 = x[6] - x[2]; + a4 = x[1] + x[7]; + a5 = x[1] - x[7]; + a6 = x[8] + x[0]; + a7 = x[8] - x[0]; + + a8 = a0 + a2; + a9 = a0 - a2; + a10 = a0 - a6; + a11 = a2 - a6; + a12 = a8 + a6; + a13 = a1 - a3; + a14 = a13 + a7; + a15 = a3 + a7; + a16 = a1 - a7; + a17 = a1 + a3; + + m0 = a17 * -c3; + m1 = a16 * -c0; + m2 = a15 * -c4; + m3 = a14 * -c1; + m4 = a5 * -c1; + m5 = a11 * -c6; + m6 = a10 * -c5; + m7 = a9 * -c2; + + a18 = x[4] + a4; + a19 = 2 * x[4] - a4; + a20 = a19 + m5; + a21 = a19 - m5; + a22 = a19 + m6; + a23 = m4 + m2; + a24 = m4 - m2; + a25 = m4 + m1; + + // output to every other slot for convenience + y[offset + 0] = a18 + a12; + y[offset + 2] = m0 - a25; + y[offset + 4] = m7 - a20; + y[offset + 6] = m3; + y[offset + 8] = a21 - m6; + y[offset + 10] = a24 - m1; + y[offset + 12] = a12 - 2 * a18; + y[offset + 14] = a23 + m0; + y[offset + 16] = a22 + m7; +} + +IMDCT.S = [ + /* 0 */ [ 0.608761429, + -0.923879533, + -0.130526192, + 0.991444861, + -0.382683432, + -0.793353340 ], + + /* 6 */ [ -0.793353340, + 0.382683432, + 0.991444861, + 0.130526192, + -0.923879533, + -0.608761429 ], + + /* 1 */ [ 0.382683432, + -0.923879533, + 0.923879533, + -0.382683432, + -0.382683432, + 0.923879533 ], + + /* 7 */ [ -0.923879533, + -0.382683432, + 0.382683432, + 0.923879533, + 0.923879533, + 0.382683432 ], + + /* 2 */ [ 0.130526192, + -0.382683432, + 0.608761429, + -0.793353340, + 0.923879533, + -0.991444861 ], + + /* 8 */ [ -0.991444861, + -0.923879533, + -0.793353340, + -0.608761429, + -0.382683432, + -0.130526192 ] +]; + +module.exports = IMDCT; + +},{}],9:[function(require,module,exports){ +var tables = require('./tables'); +var MP3FrameHeader = require('./header'); +var MP3Frame = require('./frame'); +var utils = require('./utils'); + +function Layer1() { + this.allocation = utils.makeArray([2, 32], Uint8Array); + this.scalefactor = utils.makeArray([2, 32], Uint8Array); +} + +MP3Frame.layers[1] = Layer1; + +// linear scaling table +const LINEAR_TABLE = new Float32Array([ + 1.33333333333333, 1.14285714285714, 1.06666666666667, + 1.03225806451613, 1.01587301587302, 1.00787401574803, + 1.00392156862745, 1.00195694716243, 1.00097751710655, + 1.00048851978505, 1.00024420024420, 1.00012208521548, + 1.00006103888177, 1.00003051850948 +]); + +Layer1.prototype.decode = function(stream, frame) { + var header = frame.header; + var nch = header.nchannels(); + + var bound = 32; + if (header.mode === MP3FrameHeader.MODE.JOINT_STEREO) { + header.flags |= MP3FrameHeader.FLAGS.I_STEREO; + bound = 4 + header.mode_extension * 4; + } + + if (header.flags & MP3FrameHeader.FLAGS.PROTECTION) { + // TODO: crc check + } + + // decode bit allocations + var allocation = this.allocation; + for (var sb = 0; sb < bound; sb++) { + for (var ch = 0; ch < nch; ch++) { + var nb = stream.read(4); + if (nb === 15) + throw new Error("forbidden bit allocation value"); + + allocation[ch][sb] = nb ? nb + 1 : 0; + } + } + + for (var sb = bound; sb < 32; sb++) { + var nb = stream.read(4); + if (nb === 15) + throw new Error("forbidden bit allocation value"); + + allocation[0][sb] = + allocation[1][sb] = nb ? nb + 1 : 0; + } + + // decode scalefactors + var scalefactor = this.scalefactor; + for (var sb = 0; sb < 32; sb++) { + for (var ch = 0; ch < nch; ch++) { + if (allocation[ch][sb]) { + scalefactor[ch][sb] = stream.read(6); + + /* + * Scalefactor index 63 does not appear in Table B.1 of + * ISO/IEC 11172-3. Nonetheless, other implementations accept it, + * so we do as well + */ + } + } + } + + // decode samples + for (var s = 0; s < 12; s++) { + for (var sb = 0; sb < bound; sb++) { + for (var ch = 0; ch < nch; ch++) { + var nb = allocation[ch][sb]; + frame.sbsample[ch][s][sb] = nb ? this.sample(stream, nb) * tables.SF_TABLE[scalefactor[ch][sb]] : 0; + } + } + + for (var sb = bound; sb < 32; sb++) { + var nb = allocation[0][sb]; + if (nb) { + var sample = this.sample(stream, nb); + + for (var ch = 0; ch < nch; ch++) { + frame.sbsample[ch][s][sb] = sample * tables.SF_TABLE[scalefactor[ch][sb]]; + } + } else { + for (var ch = 0; ch < nch; ch++) { + frame.sbsample[ch][s][sb] = 0; + } + } + } + } +}; + +Layer1.prototype.sample = function(stream, nb) { + var sample = stream.read(nb); + + // invert most significant bit, and form a 2's complement sample + sample ^= 1 << (nb - 1); + sample |= -(sample & (1 << (nb - 1))); + sample /= (1 << (nb - 1)); + + // requantize the sample + // s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) + sample += 1 >> (nb - 1); + return sample * LINEAR_TABLE[nb - 2]; +}; + +module.exports = Layer1; + +},{"./frame":4,"./header":5,"./tables":14,"./utils":15}],10:[function(require,module,exports){ +var tables = require('./tables'); +var MP3FrameHeader = require('./header'); +var MP3Frame = require('./frame'); +var utils = require('./utils'); + +function Layer2() { + this.samples = new Float64Array(3); + this.allocation = utils.makeArray([2, 32], Uint8Array); + this.scfsi = utils.makeArray([2, 32], Uint8Array); + this.scalefactor = utils.makeArray([2, 32, 3], Uint8Array); +} + +MP3Frame.layers[2] = Layer2; + +// possible quantization per subband table +const SBQUANT = [ + // ISO/IEC 11172-3 Table B.2a + { sblimit: 27, offsets: + [ 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 ] }, + + // ISO/IEC 11172-3 Table B.2b + { sblimit: 30, offsets: + [ 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0 ] }, + + // ISO/IEC 11172-3 Table B.2c + { sblimit: 8, offsets: + [ 5, 5, 2, 2, 2, 2, 2, 2 ] }, + + // ISO/IEC 11172-3 Table B.2d + { sblimit: 12, offsets: + [ 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] }, + + // ISO/IEC 13818-3 Table B.1 + { sblimit: 30, offsets: + [ 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] } +]; + +// bit allocation table +const BITALLOC = [ + { nbal: 2, offset: 0 }, // 0 + { nbal: 2, offset: 3 }, // 1 + { nbal: 3, offset: 3 }, // 2 + { nbal: 3, offset: 1 }, // 3 + { nbal: 4, offset: 2 }, // 4 + { nbal: 4, offset: 3 }, // 5 + { nbal: 4, offset: 4 }, // 6 + { nbal: 4, offset: 5 } // 7 +]; + +// offsets into quantization class table +const OFFSETS = [ + [ 0, 1, 16 ], // 0 + [ 0, 1, 2, 3, 4, 5, 16 ], // 1 + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ], // 2 + [ 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ], // 3 + [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 ], // 4 + [ 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] // 5 +]; + + + +/* + * These are the Layer II classes of quantization. + * The table is derived from Table B.4 of ISO/IEC 11172-3. + */ +const QC_TABLE = [ + { nlevels: 3, group: 2, bits: 5, C: 1.33333333333, D: 0.50000000000 }, + { nlevels: 5, group: 3, bits: 7, C: 1.60000000000, D: 0.50000000000 }, + { nlevels: 7, group: 0, bits: 3, C: 1.14285714286, D: 0.25000000000 }, + { nlevels: 9, group: 4, bits: 10, C: 1.77777777777, D: 0.50000000000 }, + { nlevels: 15, group: 0, bits: 4, C: 1.06666666666, D: 0.12500000000 }, + { nlevels: 31, group: 0, bits: 5, C: 1.03225806452, D: 0.06250000000 }, + { nlevels: 63, group: 0, bits: 6, C: 1.01587301587, D: 0.03125000000 }, + { nlevels: 127, group: 0, bits: 7, C: 1.00787401575, D: 0.01562500000 }, + { nlevels: 255, group: 0, bits: 8, C: 1.00392156863, D: 0.00781250000 }, + { nlevels: 511, group: 0, bits: 9, C: 1.00195694716, D: 0.00390625000 }, + { nlevels: 1023, group: 0, bits: 10, C: 1.00097751711, D: 0.00195312500 }, + { nlevels: 2047, group: 0, bits: 11, C: 1.00048851979, D: 0.00097656250 }, + { nlevels: 4095, group: 0, bits: 12, C: 1.00024420024, D: 0.00048828125 }, + { nlevels: 8191, group: 0, bits: 13, C: 1.00012208522, D: 0.00024414063 }, + { nlevels: 16383, group: 0, bits: 14, C: 1.00006103888, D: 0.00012207031 }, + { nlevels: 32767, group: 0, bits: 15, C: 1.00003051851, D: 0.00006103516 }, + { nlevels: 65535, group: 0, bits: 16, C: 1.00001525902, D: 0.00003051758 } +]; + +Layer2.prototype.decode = function(stream, frame) { + var header = frame.header; + var nch = header.nchannels(); + var index; + + if (header.flags & MP3FrameHeader.FLAGS.LSF_EXT) { + index = 4; + } else if (header.flags & MP3FrameHeader.FLAGS.FREEFORMAT) { + index = header.samplerate === 48000 ? 0 : 1; + } else { + var bitrate_per_channel = header.bitrate; + + if (nch === 2) { + bitrate_per_channel /= 2; + + /* + * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and + * 80 kbps bitrates in Layer II, but some encoders ignore this + * restriction, so we ignore it as well. + */ + } else { + /* + * ISO/IEC 11172-3 does not allow single channel mode for 224, 256, + * 320, or 384 kbps bitrates in Layer II. + */ + if (bitrate_per_channel > 192000) + throw new Error('bad bitrate/mode combination'); + } + + if (bitrate_per_channel <= 48000) + index = header.samplerate === 32000 ? 3 : 2; + else if (bitrate_per_channel <= 80000) + index = 0; + else + index = header.samplerate === 48000 ? 0 : 1; + } + + var sblimit = SBQUANT[index].sblimit; + var offsets = SBQUANT[index].offsets; + + var bound = 32; + if (header.mode === MP3FrameHeader.MODE.JOINT_STEREO) { + header.flags |= MP3FrameHeader.FLAGS.I_STEREO; + bound = 4 + header.mode_extension * 4; + } + + if (bound > sblimit) + bound = sblimit; + + // decode bit allocations + var allocation = this.allocation; + for (var sb = 0; sb < bound; sb++) { + var nbal = BITALLOC[offsets[sb]].nbal; + + for (var ch = 0; ch < nch; ch++) + allocation[ch][sb] = stream.read(nbal); + } + + for (var sb = bound; sb < sblimit; sb++) { + var nbal = BITALLOC[offsets[sb]].nbal; + + allocation[0][sb] = + allocation[1][sb] = stream.read(nbal); + } + + // decode scalefactor selection info + var scfsi = this.scfsi; + for (var sb = 0; sb < sblimit; sb++) { + for (var ch = 0; ch < nch; ch++) { + if (allocation[ch][sb]) + scfsi[ch][sb] = stream.read(2); + } + } + + if (header.flags & MP3FrameHeader.FLAGS.PROTECTION) { + // TODO: crc check + } + + // decode scalefactors + var scalefactor = this.scalefactor; + for (var sb = 0; sb < sblimit; sb++) { + for (var ch = 0; ch < nch; ch++) { + if (allocation[ch][sb]) { + scalefactor[ch][sb][0] = stream.read(6); + + switch (scfsi[ch][sb]) { + case 2: + scalefactor[ch][sb][2] = + scalefactor[ch][sb][1] = scalefactor[ch][sb][0]; + break; + + case 0: + scalefactor[ch][sb][1] = stream.read(6); + // fall through + + case 1: + case 3: + scalefactor[ch][sb][2] = stream.read(6); + } + + if (scfsi[ch][sb] & 1) + scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1]; + + /* + * Scalefactor index 63 does not appear in Table B.1 of + * ISO/IEC 11172-3. Nonetheless, other implementations accept it, + * so we do as well. + */ + } + } + } + + // decode samples + for (var gr = 0; gr < 12; gr++) { + // normal + for (var sb = 0; sb < bound; sb++) { + for (var ch = 0; ch < nch; ch++) { + if (index = allocation[ch][sb]) { + index = OFFSETS[BITALLOC[offsets[sb]].offset][index - 1]; + this.decodeSamples(stream, QC_TABLE[index]); + + var scale = tables.SF_TABLE[scalefactor[ch][sb][gr >> 2]]; + for (var s = 0; s < 3; s++) { + frame.sbsample[ch][3 * gr + s][sb] = this.samples[s] * scale; + } + } else { + for (var s = 0; s < 3; s++) { + frame.sbsample[ch][3 * gr + s][sb] = 0; + } + } + } + } + + // joint stereo + for (var sb = bound; sb < sblimit; sb++) { + if (index = allocation[0][sb]) { + index = OFFSETS[BITALLOC[offsets[sb]].offset][index - 1]; + this.decodeSamples(stream, QC_TABLE[index]); + + for (var ch = 0; ch < nch; ch++) { + var scale = tables.SF_TABLE[scalefactor[ch][sb][gr >> 2]]; + for (var s = 0; s < 3; s++) { + frame.sbsample[ch][3 * gr + s][sb] = this.samples[s] * scale; + } + } + } else { + for (var ch = 0; ch < nch; ch++) { + for (var s = 0; s < 3; s++) { + frame.sbsample[ch][3 * gr + s][sb] = 0; + } + } + } + } + + // the rest + for (var ch = 0; ch < nch; ch++) { + for (var s = 0; s < 3; s++) { + for (var sb = sblimit; sb < 32; sb++) { + frame.sbsample[ch][3 * gr + s][sb] = 0; + } + } + } + } +}; + +Layer2.prototype.decodeSamples = function(stream, quantclass) { + var sample = this.samples; + var nb = quantclass.group; + + if (nb) { + // degrouping + var c = stream.read(quantclass.bits); + var nlevels = quantclass.nlevels; + + for (var s = 0; s < 3; s++) { + sample[s] = c % nlevels; + c = c / nlevels | 0; + } + } else { + nb = quantclass.bits; + for (var s = 0; s < 3; s++) { + sample[s] = stream.read(nb); + } + } + + for (var s = 0; s < 3; s++) { + // invert most significant bit, and form a 2's complement sample + var requantized = sample[s] ^ (1 << (nb - 1)); + requantized |= -(requantized & (1 << (nb - 1))); + requantized /= (1 << (nb - 1)); + + // requantize the sample + sample[s] = (requantized + quantclass.D) * quantclass.C; + } +}; + +module.exports = Layer2; + +},{"./frame":4,"./header":5,"./tables":14,"./utils":15}],11:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); +var tables = require('./tables'); +var MP3FrameHeader = require('./header'); +var MP3Frame = require('./frame'); +var huffman = require('./huffman'); +var IMDCT = require('./imdct'); +var utils = require('./utils'); + +function MP3SideInfo() { + this.main_data_begin = null; + this.private_bits = null; + this.gr = [new MP3Granule(), new MP3Granule()]; + this.scfsi = new Uint8Array(2); +} + +function MP3Granule() { + this.ch = [new MP3Channel(), new MP3Channel()]; +} + +function MP3Channel() { + // from side info + this.part2_3_length = null; + this.big_values = null; + this.global_gain = null; + this.scalefac_compress = null; + + this.flags = null; + this.block_type = null; + this.table_select = new Uint8Array(3); + this.subblock_gain = new Uint8Array(3); + this.region0_count = null; + this.region1_count = null; + + // from main_data + this.scalefac = new Uint8Array(39); +} + +function Layer3() { + this.imdct = new IMDCT(); + this.si = new MP3SideInfo(); + + // preallocate reusable typed arrays for performance + this.xr = [new Float64Array(576), new Float64Array(576)]; + this._exponents = new Int32Array(39); + this.reqcache = new Float64Array(16); + this.modes = new Int16Array(39); + this.output = new Float64Array(36); + + this.tmp = utils.makeArray([32, 3, 6]); + this.tmp2 = new Float64Array(32 * 3 * 6); +} + +MP3Frame.layers[3] = Layer3; + +Layer3.prototype.decode = function(stream, frame) { + var header = frame.header; + var next_md_begin = 0; + var md_len = 0; + + var nch = header.nchannels(); + var si_len = (header.flags & MP3FrameHeader.FLAGS.LSF_EXT) ? (nch === 1 ? 9 : 17) : (nch === 1 ? 17 : 32); + + // check frame sanity + if (stream.next_frame - stream.nextByte() < si_len) { + stream.md_len = 0; + throw new Error('Bad frame length'); + } + + // check CRC word + if (header.flags & MP3FrameHeader.FLAGS.PROTECTION) { + // TODO: crc check + } + + // decode frame side information + var sideInfo = this.sideInfo(stream, nch, header.flags & MP3FrameHeader.FLAGS.LSF_EXT); + var si = sideInfo.si; + var data_bitlen = sideInfo.data_bitlen; + var priv_bitlen = sideInfo.priv_bitlen; + + header.flags |= priv_bitlen; + header.private_bits |= si.private_bits; + + // find main_data of next frame + var peek = stream.copy(); + peek.seek(stream.next_frame * 8); + + var nextHeader = peek.read(16); + if ((nextHeader & 0xffe6) === 0xffe2) { // syncword | layer + if ((nextHeader & 1) === 0) // protection bit + peek.advance(16); // crc check + + peek.advance(16); // skip the rest of the header + next_md_begin = peek.read((nextHeader & 8) ? 9 : 8); + } + + // find main_data of this frame + var frame_space = stream.next_frame - stream.nextByte(); + + if (next_md_begin > si.main_data_begin + frame_space) + next_md_begin = 0; + + var md_len = si.main_data_begin + frame_space - next_md_begin; + var frame_used = 0; + var ptr; + + if (si.main_data_begin === 0) { + ptr = stream.stream; + stream.md_len = 0; + frame_used = md_len; + } else { + if (si.main_data_begin > stream.md_len) { + throw new Error('bad main_data_begin pointer'); + } else { + var old_md_len = stream.md_len; + + if (md_len > si.main_data_begin) { + if (stream.md_len + md_len - si.main_data_begin > MP3FrameHeader.BUFFER_MDLEN) { + throw new Error("Assertion failed: (stream.md_len + md_len - si.main_data_begin <= MAD_MP3FrameHeader.BUFFER_MDLEN)"); + } + + frame_used = md_len - si.main_data_begin; + this.memcpy(stream.main_data, stream.md_len, stream.stream.stream, stream.nextByte(), frame_used); + stream.md_len += frame_used; + } + + ptr = new AV.Bitstream(AV.Stream.fromBuffer(new AV.Buffer(stream.main_data))); + ptr.advance((old_md_len - si.main_data_begin) * 8); + } + } + + var frame_free = frame_space - frame_used; + + // decode main_data + this.decodeMainData(ptr, frame, si, nch); + + // preload main_data buffer with up to 511 bytes for next frame(s) + if (frame_free >= next_md_begin) { + this.memcpy(stream.main_data, 0, stream.stream.stream, stream.next_frame - next_md_begin, next_md_begin); + stream.md_len = next_md_begin; + } else { + if (md_len < si.main_data_begin) { + var extra = si.main_data_begin - md_len; + if (extra + frame_free > next_md_begin) + extra = next_md_begin - frame_free; + + if (extra < stream.md_len) { + this.memcpy(stream.main_data, 0, stream.main_data, stream.md_len - extra, extra); + stream.md_len = extra; + } + } else { + stream.md_len = 0; + } + + this.memcpy(stream.main_data, stream.md_len, stream.stream.stream, stream.next_frame - frame_free, frame_free); + stream.md_len += frame_free; + } +}; + +Layer3.prototype.memcpy = function(dst, dstOffset, pSrc, srcOffset, length) { + var subarr; + if (pSrc.subarray) + subarr = pSrc.subarray(srcOffset, srcOffset + length); + else + subarr = pSrc.peekBuffer(srcOffset - pSrc.offset, length).data; + + // oh my, memcpy actually exists in JavaScript? + dst.set(subarr, dstOffset); + return dst; +}; + +Layer3.prototype.sideInfo = function(stream, nch, lsf) { + var si = this.si; + var data_bitlen = 0; + var priv_bitlen = lsf ? ((nch === 1) ? 1 : 2) : ((nch === 1) ? 5 : 3); + + si.main_data_begin = stream.read(lsf ? 8 : 9); + si.private_bits = stream.read(priv_bitlen); + + var ngr = 1; + if (!lsf) { + ngr = 2; + for (var ch = 0; ch < nch; ++ch) + si.scfsi[ch] = stream.read(4); + } + + for (var gr = 0; gr < ngr; gr++) { + var granule = si.gr[gr]; + + for (var ch = 0; ch < nch; ch++) { + var channel = granule.ch[ch]; + + channel.part2_3_length = stream.read(12); + channel.big_values = stream.read(9); + channel.global_gain = stream.read(8); + channel.scalefac_compress = stream.read(lsf ? 9 : 4); + + data_bitlen += channel.part2_3_length; + + if (channel.big_values > 288) + throw new Error('bad big_values count'); + + channel.flags = 0; + + // window_switching_flag + if (stream.read(1)) { + channel.block_type = stream.read(2); + + if (channel.block_type === 0) + throw new Error('reserved block_type'); + + if (!lsf && channel.block_type === 2 && si.scfsi[ch]) + throw new Error('bad scalefactor selection info'); + + channel.region0_count = 7; + channel.region1_count = 36; + + if (stream.read(1)) + channel.flags |= tables.MIXED_BLOCK_FLAG; + else if (channel.block_type === 2) + channel.region0_count = 8; + + for (var i = 0; i < 2; i++) + channel.table_select[i] = stream.read(5); + + for (var i = 0; i < 3; i++) + channel.subblock_gain[i] = stream.read(3); + } else { + channel.block_type = 0; + + for (var i = 0; i < 3; i++) + channel.table_select[i] = stream.read(5); + + channel.region0_count = stream.read(4); + channel.region1_count = stream.read(3); + } + + // [preflag,] scalefac_scale, count1table_select + channel.flags |= stream.read(lsf ? 2 : 3); + } + } + + return { + si: si, + data_bitlen: data_bitlen, + priv_bitlen: priv_bitlen + }; +}; + +Layer3.prototype.decodeMainData = function(stream, frame, si, nch) { + var header = frame.header; + var sfreq = header.samplerate; + + if (header.flags & MP3FrameHeader.FLAGS.MPEG_2_5_EXT) + sfreq *= 2; + + // 48000 => 0, 44100 => 1, 32000 => 2, + // 24000 => 3, 22050 => 4, 16000 => 5 + var sfreqi = ((sfreq >> 7) & 0x000f) + ((sfreq >> 15) & 0x0001) - 8; + + if (header.flags & MP3FrameHeader.FLAGS.MPEG_2_5_EXT) + sfreqi += 3; + + // scalefactors, Huffman decoding, requantization + var ngr = (header.flags & MP3FrameHeader.FLAGS.LSF_EXT) ? 1 : 2; + var xr = this.xr; + + for (var gr = 0; gr < ngr; ++gr) { + var granule = si.gr[gr]; + var sfbwidth = []; + var l = 0; + + for (var ch = 0; ch < nch; ++ch) { + var channel = granule.ch[ch]; + var part2_length; + + sfbwidth[ch] = tables.SFBWIDTH_TABLE[sfreqi].l; + if (channel.block_type === 2) { + sfbwidth[ch] = (channel.flags & tables.MIXED_BLOCK_FLAG) ? tables.SFBWIDTH_TABLE[sfreqi].m : tables.SFBWIDTH_TABLE[sfreqi].s; + } + + if (header.flags & MP3FrameHeader.FLAGS.LSF_EXT) { + part2_length = this.scalefactors_lsf(stream, channel, ch === 0 ? 0 : si.gr[1].ch[1], header.mode_extension); + } else { + part2_length = this.scalefactors(stream, channel, si.gr[0].ch[ch], gr === 0 ? 0 : si.scfsi[ch]); + } + + this.huffmanDecode(stream, xr[ch], channel, sfbwidth[ch], part2_length); + } + + // joint stereo processing + if (header.mode === MP3FrameHeader.MODE.JOINT_STEREO && header.mode_extension !== 0) + this.stereo(xr, si.gr, gr, header, sfbwidth[0]); + + // reordering, alias reduction, IMDCT, overlap-add, frequency inversion + for (var ch = 0; ch < nch; ch++) { + var channel = granule.ch[ch]; + var sample = frame.sbsample[ch].slice(18 * gr); + + var sb, l = 0, i, sblimit; + var output = this.output; + + if (channel.block_type === 2) { + this.reorder(xr[ch], channel, sfbwidth[ch]); + + /* + * According to ISO/IEC 11172-3, "Alias reduction is not applied for + * granules with block_type === 2 (short block)." However, other + * sources suggest alias reduction should indeed be performed on the + * lower two subbands of mixed blocks. Most other implementations do + * this, so by default we will too. + */ + if (channel.flags & tables.MIXED_BLOCK_FLAG) + this.aliasreduce(xr[ch], 36); + } else { + this.aliasreduce(xr[ch], 576); + } + + // subbands 0-1 + if (channel.block_type !== 2 || (channel.flags & tables.MIXED_BLOCK_FLAG)) { + var block_type = channel.block_type; + if (channel.flags & tables.MIXED_BLOCK_FLAG) + block_type = 0; + + // long blocks + for (var sb = 0; sb < 2; ++sb, l += 18) { + this.imdct_l(xr[ch].subarray(l, l + 18), output, block_type); + this.overlap(output, frame.overlap[ch][sb], sample, sb); + } + } else { + // short blocks + for (var sb = 0; sb < 2; ++sb, l += 18) { + this.imdct_s(xr[ch].subarray(l, l + 18), output); + this.overlap(output, frame.overlap[ch][sb], sample, sb); + } + } + + this.freqinver(sample, 1); + + // (nonzero) subbands 2-31 + var i = 576; + while (i > 36 && xr[ch][i - 1] === 0) { + --i; + } + + sblimit = 32 - (((576 - i) / 18) << 0); + + if (channel.block_type !== 2) { + // long blocks + for (var sb = 2; sb < sblimit; ++sb, l += 18) { + this.imdct_l(xr[ch].subarray(l, l + 18), output, channel.block_type); + this.overlap(output, frame.overlap[ch][sb], sample, sb); + + if (sb & 1) + this.freqinver(sample, sb); + } + } else { + // short blocks + for (var sb = 2; sb < sblimit; ++sb, l += 18) { + this.imdct_s(xr[ch].subarray(l, l + 18), output); + this.overlap(output, frame.overlap[ch][sb], sample, sb); + + if (sb & 1) + this.freqinver(sample, sb); + } + } + + // remaining (zero) subbands + for (var sb = sblimit; sb < 32; ++sb) { + this.overlap_z(frame.overlap[ch][sb], sample, sb); + + if (sb & 1) + this.freqinver(sample, sb); + } + } + } +}; + +Layer3.prototype.scalefactors = function(stream, channel, gr0ch, scfsi) { + var start = stream.offset(); + var slen1 = tables.SFLEN_TABLE[channel.scalefac_compress].slen1; + var slen2 = tables.SFLEN_TABLE[channel.scalefac_compress].slen2; + var sfbi; + + if (channel.block_type === 2) { + sfbi = 0; + + var nsfb = (channel.flags & tables.MIXED_BLOCK_FLAG) ? 8 + 3 * 3 : 6 * 3; + while (nsfb--) + channel.scalefac[sfbi++] = stream.read(slen1); + + nsfb = 6 * 3; + while (nsfb--) + channel.scalefac[sfbi++] = stream.read(slen2); + + nsfb = 1 * 3; + while (nsfb--) + channel.scalefac[sfbi++] = 0; + } else { + if (scfsi & 0x8) { + for (var sfbi = 0; sfbi < 6; ++sfbi) + channel.scalefac[sfbi] = gr0ch.scalefac[sfbi]; + } else { + for (var sfbi = 0; sfbi < 6; ++sfbi) + channel.scalefac[sfbi] = stream.read(slen1); + } + + if (scfsi & 0x4) { + for (var sfbi = 6; sfbi < 11; ++sfbi) + channel.scalefac[sfbi] = gr0ch.scalefac[sfbi]; + } else { + for (var sfbi = 6; sfbi < 11; ++sfbi) + channel.scalefac[sfbi] = stream.read(slen1); + } + + if (scfsi & 0x2) { + for (var sfbi = 11; sfbi < 16; ++sfbi) + channel.scalefac[sfbi] = gr0ch.scalefac[sfbi]; + } else { + for (var sfbi = 11; sfbi < 16; ++sfbi) + channel.scalefac[sfbi] = stream.read(slen2); + } + + if (scfsi & 0x1) { + for (var sfbi = 16; sfbi < 21; ++sfbi) + channel.scalefac[sfbi] = gr0ch.scalefac[sfbi]; + } else { + for (var sfbi = 16; sfbi < 21; ++sfbi) + channel.scalefac[sfbi] = stream.read(slen2); + } + + channel.scalefac[21] = 0; + } + + return stream.offset() - start; +}; + +Layer3.prototype.scalefactors_lsf = function(stream, channel, gr1ch, mode_extension) { + var start = stream.offset(); + var scalefac_compress = channel.scalefac_compress; + var index = channel.block_type === 2 ? (channel.flags & tables.MIXED_BLOCK_FLAG ? 2 : 1) : 0; + var slen = new Int32Array(4); + var nsfb; + + if (!((mode_extension & tables.I_STEREO) && gr1ch)) { + if (scalefac_compress < 400) { + slen[0] = (scalefac_compress >>> 4) / 5; + slen[1] = (scalefac_compress >>> 4) % 5; + slen[2] = (scalefac_compress % 16) >>> 2; + slen[3] = scalefac_compress % 4; + + nsfb = tables.NSFB_TABLE[0][index]; + } else if (scalefac_compress < 500) { + scalefac_compress -= 400; + + slen[0] = (scalefac_compress >>> 2) / 5; + slen[1] = (scalefac_compress >>> 2) % 5; + slen[2] = scalefac_compress % 4; + slen[3] = 0; + + nsfb = tables.NSFB_TABLE[1][index]; + } else { + scalefac_compress -= 500; + + slen[0] = scalefac_compress / 3; + slen[1] = scalefac_compress % 3; + slen[2] = 0; + slen[3] = 0; + + channel.flags |= tables.PREFLAG; + nsfb = tables.NSFB_TABLE[2][index]; + } + + var n = 0; + for (var part = 0; part < 4; part++) { + for (var i = 0; i < nsfb[part]; i++) { + channel.scalefac[n++] = stream.read(slen[part]); + } + } + + while (n < 39) { + channel.scalefac[n++] = 0; + } + } else { // (mode_extension & tables.I_STEREO) && gr1ch (i.e. ch == 1) + scalefac_compress >>>= 1; + + if (scalefac_compress < 180) { + slen[0] = scalefac_compress / 36; + slen[1] = (scalefac_compress % 36) / 6; + slen[2] = (scalefac_compress % 36) % 6; + slen[3] = 0; + + nsfb = tables.NSFB_TABLE[3][index]; + } else if (scalefac_compress < 244) { + scalefac_compress -= 180; + + slen[0] = (scalefac_compress % 64) >>> 4; + slen[1] = (scalefac_compress % 16) >>> 2; + slen[2] = scalefac_compress % 4; + slen[3] = 0; + + nsfb = tables.NSFB_TABLE[4][index]; + } else { + scalefac_compress -= 244; + + slen[0] = scalefac_compress / 3; + slen[1] = scalefac_compress % 3; + slen[2] = 0; + slen[3] = 0; + + nsfb = tables.NSFB_TABLE[5][index]; + } + + var n = 0; + for (var part = 0; part < 4; ++part) { + var max = (1 << slen[part]) - 1; + for (var i = 0; i < nsfb[part]; ++i) { + var is_pos = stream.read(slen[part]); + + channel.scalefac[n] = is_pos; + gr1ch.scalefac[n++] = is_pos === max ? 1 : 0; + } + } + + while (n < 39) { + channel.scalefac[n] = 0; + gr1ch.scalefac[n++] = 0; // apparently not illegal + } + } + + return stream.offset() - start; +}; + +Layer3.prototype.huffmanDecode = function(stream, xr, channel, sfbwidth, part2_length) { + var exponents = this._exponents; + var sfbwidthptr = 0; + + var bits_left = channel.part2_3_length - part2_length; + if (bits_left < 0) + throw new Error('bad audio data length'); + + this.exponents(channel, sfbwidth, exponents); + + var peek = stream.copy(); + stream.advance(bits_left); + + /* align bit reads to byte boundaries */ + var cachesz = 8 - peek.bitPosition; + cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7; + + var bitcache = peek.read(cachesz); + bits_left -= cachesz; + + var xrptr = 0; + + // big_values + var region = 0; + var reqcache = this.reqcache; + + var sfbound = xrptr + sfbwidth[sfbwidthptr++]; + var rcount = channel.region0_count + 1; + + var entry = huffman.huff_pair_table[channel.table_select[region]]; + var table = entry.table; + var linbits = entry.linbits; + var startbits = entry.startbits; + + if (typeof table === 'undefined') + throw new Error('bad Huffman table select'); + + var expptr = 0; + var exp = exponents[expptr++]; + var reqhits = 0; + var big_values = channel.big_values; + + while (big_values-- && cachesz + bits_left > 0) { + if (xrptr === sfbound) { + sfbound += sfbwidth[sfbwidthptr++]; + + // change table if region boundary + if (--rcount === 0) { + if (region === 0) + rcount = channel.region1_count + 1; + else + rcount = 0; // all remaining + + entry = huffman.huff_pair_table[channel.table_select[++region]]; + table = entry.table; + linbits = entry.linbits; + startbits = entry.startbits; + + if (typeof table === 'undefined') + throw new Error('bad Huffman table select'); + } + + if (exp !== exponents[expptr]) { + exp = exponents[expptr]; + reqhits = 0; + } + + ++expptr; + } + + if (cachesz < 21) { + var bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7; + bitcache = (bitcache << bits) | peek.read(bits); + cachesz += bits; + bits_left -= bits; + } + + var clumpsz = startbits; + var pair = table[ (((bitcache) >> ((cachesz) - (clumpsz))) & ((1 << (clumpsz)) - 1))]; + + while (!pair.final) { + cachesz -= clumpsz; + clumpsz = pair.ptr.bits; + pair = table[pair.ptr.offset + (((bitcache) >> ((cachesz) - (clumpsz))) & ((1 << (clumpsz)) - 1))]; + } + + cachesz -= pair.value.hlen; + + if (linbits) { + var value = pair.value.x; + var x_final = false; + + switch (value) { + case 0: + xr[xrptr] = 0; + break; + + case 15: + if (cachesz < linbits + 2) { + bitcache = (bitcache << 16) | peek.read(16); + cachesz += 16; + bits_left -= 16; + } + + value += (((bitcache) >> ((cachesz) - (linbits))) & ((1 << (linbits)) - 1)); + cachesz -= linbits; + + requantized = this.requantize(value, exp); + x_final = true; // simulating goto, yay + break; + + default: + if (reqhits & (1 << value)) { + requantized = reqcache[value]; + } else { + reqhits |= (1 << value); + requantized = reqcache[value] = this.requantize(value, exp); + } + + x_final = true; + } + + if(x_final) { + xr[xrptr] = ((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized; + } + + value = pair.value.y; + var y_final = false; + + switch (value) { + case 0: + xr[xrptr + 1] = 0; + break; + + case 15: + if (cachesz < linbits + 1) { + bitcache = (bitcache << 16) | peek.read(16); + cachesz += 16; + bits_left -= 16; + } + + value += (((bitcache) >> ((cachesz) - (linbits))) & ((1 << (linbits)) - 1)); + cachesz -= linbits; + + requantized = this.requantize(value, exp); + y_final = true; + break; // simulating goto, yayzor + + default: + if (reqhits & (1 << value)) { + requantized = reqcache[value]; + } else { + reqhits |= (1 << value); + reqcache[value] = this.requantize(value, exp); + requantized = reqcache[value]; + } + + y_final = true; + } + + if(y_final) { + xr[xrptr + 1] = ((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized; + } + + } else { + var value = pair.value.x; + + if (value === 0) { + xr[xrptr] = 0; + } else { + if (reqhits & (1 << value)) + requantized = reqcache[value]; + else { + reqhits |= (1 << value); + requantized = reqcache[value] = this.requantize(value, exp); + } + + xr[xrptr] = ((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized; + } + + value = pair.value.y; + + if (value === 0) { + xr[xrptr + 1] = 0; + } else { + if (reqhits & (1 << value)) + requantized = reqcache[value]; + else { + reqhits |= (1 << value); + requantized = reqcache[value] = this.requantize(value, exp); + } + + xr[xrptr + 1] = ((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized; + } + } + + xrptr += 2; + } + + if (cachesz + bits_left < 0) + throw new Error('Huffman data overrun'); + + // count1 + var table = huffman.huff_quad_table[channel.flags & tables.COUNT1TABLE_SELECT]; + var requantized = this.requantize(1, exp); + + while (cachesz + bits_left > 0 && xrptr <= 572) { + if (cachesz < 10) { + bitcache = (bitcache << 16) | peek.read(16); + cachesz += 16; + bits_left -= 16; + } + + var quad = table[(((bitcache) >> ((cachesz) - (4))) & ((1 << (4)) - 1))]; + + // quad tables guaranteed to have at most one extra lookup + if (!quad.final) { + cachesz -= 4; + quad = table[quad.ptr.offset + (((bitcache) >> ((cachesz) - (quad.ptr.bits))) & ((1 << (quad.ptr.bits)) - 1))]; + } + + cachesz -= quad.value.hlen; + + if (xrptr === sfbound) { + sfbound += sfbwidth[sfbwidthptr++]; + + if (exp !== exponents[expptr]) { + exp = exponents[expptr]; + requantized = this.requantize(1, exp); + } + + ++expptr; + } + + // v (0..1) + xr[xrptr] = quad.value.v ? (((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized) : 0; + + // w (0..1) + xr[xrptr + 1] = quad.value.w ? (((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized) : 0; + + xrptr += 2; + if (xrptr === sfbound) { + sfbound += sfbwidth[sfbwidthptr++]; + + if (exp !== exponents[expptr]) { + exp = exponents[expptr]; + requantized = this.requantize(1, exp); + } + + ++expptr; + } + + // x (0..1) + xr[xrptr] = quad.value.x ? (((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized) : 0; + + // y (0..1) + xr[xrptr + 1] = quad.value.y ? (((bitcache) & (1 << ((cachesz--) - 1))) ? -requantized : requantized) : 0; + + xrptr += 2; + + if (cachesz + bits_left < 0) { + // technically the bitstream is misformatted, but apparently + // some encoders are just a bit sloppy with stuffing bits + xrptr -= 4; + } + } + + if (-bits_left > MP3FrameHeader.BUFFER_GUARD * 8) { + throw new Error("assertion failed: (-bits_left <= MP3FrameHeader.BUFFER_GUARD * CHAR_BIT)"); + } + + // rzero + while (xrptr < 576) { + xr[xrptr] = 0; + xr[xrptr + 1] = 0; + xrptr += 2; + } +}; + +Layer3.prototype.requantize = function(value, exp) { + // usual (x >> 0) tricks to make sure frac and exp stay integers + var frac = (exp % 4) >> 0; // assumes sign(frac) === sign(exp) + exp = (exp / 4) >> 0; + + var requantized = Math.pow(value, 4.0 / 3.0); + requantized *= Math.pow(2.0, (exp / 4.0)); + + if (frac) { + requantized *= Math.pow(2.0, (frac / 4.0)); + } + + if (exp < 0) { + requantized /= Math.pow(2.0, -exp * (3.0 / 4.0)); + } + + return requantized; +}; + +Layer3.prototype.exponents = function(channel, sfbwidth, exponents) { + var gain = channel.global_gain - 210; + var scalefac_multiplier = (channel.flags & tables.SCALEFAC_SCALE) ? 2 : 1; + + if (channel.block_type === 2) { + var sfbi = 0, l = 0; + + if (channel.flags & tables.MIXED_BLOCK_FLAG) { + var premask = (channel.flags & tables.PREFLAG) ? ~0 : 0; + + // long block subbands 0-1 + while (l < 36) { + exponents[sfbi] = gain - ((channel.scalefac[sfbi] + (tables.PRETAB[sfbi] & premask)) << scalefac_multiplier); + l += sfbwidth[sfbi++]; + } + } + + // this is probably wrong for 8000 Hz short/mixed blocks + var gain0 = gain - 8 * channel.subblock_gain[0]; + var gain1 = gain - 8 * channel.subblock_gain[1]; + var gain2 = gain - 8 * channel.subblock_gain[2]; + + while (l < 576) { + exponents[sfbi + 0] = gain0 - (channel.scalefac[sfbi + 0] << scalefac_multiplier); + exponents[sfbi + 1] = gain1 - (channel.scalefac[sfbi + 1] << scalefac_multiplier); + exponents[sfbi + 2] = gain2 - (channel.scalefac[sfbi + 2] << scalefac_multiplier); + + l += 3 * sfbwidth[sfbi]; + sfbi += 3; + } + } else { + if (channel.flags & tables.PREFLAG) { + for (var sfbi = 0; sfbi < 22; sfbi++) { + exponents[sfbi] = gain - ((channel.scalefac[sfbi] + tables.PRETAB[sfbi]) << scalefac_multiplier); + } + } else { + for (var sfbi = 0; sfbi < 22; sfbi++) { + exponents[sfbi] = gain - (channel.scalefac[sfbi] << scalefac_multiplier); + } + } + } +}; + +Layer3.prototype.stereo = function(xr, granules, gr, header, sfbwidth) { + var granule = granules[gr]; + var modes = this.modes; + var sfbi, l, n, i; + + if (granule.ch[0].block_type !== granule.ch[1].block_type || (granule.ch[0].flags & tables.MIXED_BLOCK_FLAG) !== (granule.ch[1].flags & tables.MIXED_BLOCK_FLAG)) + throw new Error('incompatible stereo block_type'); + + for (var i = 0; i < 39; i++) + modes[i] = header.mode_extension; + + // intensity stereo + if (header.mode_extension & tables.I_STEREO) { + var right_ch = granule.ch[1]; + var right_xr = xr[1]; + + header.flags |= MP3FrameHeader.FLAGS.I_STEREO; + + // first determine which scalefactor bands are to be processed + if (right_ch.block_type === 2) { + var lower, start, max, bound = new Uint32Array(3), w; + + lower = start = max = bound[0] = bound[1] = bound[2] = 0; + sfbi = l = 0; + + if (right_ch.flags & tables.MIXED_BLOCK_FLAG) { + while (l < 36) { + n = sfbwidth[sfbi++]; + + for (var i = 0; i < n; ++i) { + if (right_xr[i]) { + lower = sfbi; + break; + } + } + + right_xr += n; + l += n; + } + + start = sfbi; + } + + var w = 0; + while (l < 576) { + n = sfbwidth[sfbi++]; + + for (i = 0; i < n; ++i) { + if (right_xr[i]) { + max = bound[w] = sfbi; + break; + } + } + + right_xr += n; + l += n; + w = (w + 1) % 3; + } + + if (max) + lower = start; + + // long blocks + for (i = 0; i < lower; ++i) + modes[i] = header.mode_extension & ~tables.I_STEREO; + + // short blocks + w = 0; + for (i = start; i < max; ++i) { + if (i < bound[w]) + modes[i] = header.mode_extension & ~tables.I_STEREO; + + w = (w + 1) % 3; + } + } else { + var bound = 0; + for (sfbi = l = 0; l < 576; l += n) { + n = sfbwidth[sfbi++]; + + for (i = 0; i < n; ++i) { + if (right_xr[i]) { + bound = sfbi; + break; + } + } + + right_xr += n; + } + + for (i = 0; i < bound; ++i) + modes[i] = header.mode_extension & ~tables.I_STEREO; + } + + // now do the actual processing + if (header.flags & MP3FrameHeader.FLAGS.LSF_EXT) { + var illegal_pos = granules[gr + 1].ch[1].scalefac; + + // intensity_scale + var lsf_scale = IS_Ltables.SF_TABLE[right_ch.scalefac_compress & 0x1]; + + for (sfbi = l = 0; l < 576; ++sfbi, l += n) { + n = sfbwidth[sfbi]; + + if (!(modes[sfbi] & tables.I_STEREO)) + continue; + + if (illegal_pos[sfbi]) { + modes[sfbi] &= ~tables.I_STEREO; + continue; + } + + is_pos = right_ch.scalefac[sfbi]; + + for (i = 0; i < n; ++i) { + var left = xr[0][l + i]; + + if (is_pos === 0) { + xr[1][l + i] = left; + } else { + var opposite = left * lsf_scale[(is_pos - 1) / 2]; + + if (is_pos & 1) { + xr[0][l + i] = opposite; + xr[1][l + i] = left; + } + else { + xr[1][l + i] = opposite; + } + } + } + } + } else { + for (sfbi = l = 0; l < 576; ++sfbi, l += n) { + n = sfbwidth[sfbi]; + + if (!(modes[sfbi] & tables.I_STEREO)) + continue; + + is_pos = right_ch.scalefac[sfbi]; + + if (is_pos >= 7) { // illegal intensity position + modes[sfbi] &= ~tables.I_STEREO; + continue; + } + + for (i = 0; i < n; ++i) { + var left = xr[0][l + i]; + xr[0][l + i] = left * tables.IS_TABLE[is_pos]; + xr[1][l + i] = left * tables.IS_TABLE[6 - is_pos]; + } + } + } + } + + // middle/side stereo + if (header.mode_extension & tables.MS_STEREO) { + header.flags |= tables.MS_STEREO; + + var invsqrt2 = tables.ROOT_TABLE[3 + -2]; + + for (sfbi = l = 0; l < 576; ++sfbi, l += n) { + n = sfbwidth[sfbi]; + + if (modes[sfbi] !== tables.MS_STEREO) + continue; + + for (i = 0; i < n; ++i) { + var m = xr[0][l + i]; + var s = xr[1][l + i]; + + xr[0][l + i] = (m + s) * invsqrt2; // l = (m + s) / sqrt(2) + xr[1][l + i] = (m - s) * invsqrt2; // r = (m - s) / sqrt(2) + } + } + } +}; + +Layer3.prototype.aliasreduce = function(xr, lines) { + for (var xrPointer = 18; xrPointer < lines; xrPointer += 18) { + for (var i = 0; i < 8; ++i) { + var a = xr[xrPointer - i - 1]; + var b = xr[xrPointer + i]; + + xr[xrPointer - i - 1] = a * tables.CS[i] - b * tables.CA[i]; + xr[xrPointer + i] = b * tables.CS[i] + a * tables.CA[i]; + } + } +}; + +// perform IMDCT and windowing for long blocks +Layer3.prototype.imdct_l = function (X, z, block_type) { + // IMDCT + this.imdct.imdct36(X, z); + + // windowing + switch (block_type) { + case 0: // normal window + for (var i = 0; i < 36; ++i) z[i] = z[i] * tables.WINDOW_L[i]; + break; + + case 1: // start block + for (var i = 0; i < 18; ++i) z[i] = z[i] * tables.WINDOW_L[i]; + for (var i = 24; i < 30; ++i) z[i] = z[i] * tables.WINDOW_S[i - 18]; + for (var i = 30; i < 36; ++i) z[i] = 0; + break; + + case 3: // stop block + for (var i = 0; i < 6; ++i) z[i] = 0; + for (var i = 6; i < 12; ++i) z[i] = z[i] * tables.WINDOW_S[i - 6]; + for (var i = 18; i < 36; ++i) z[i] = z[i] * tables.WINDOW_L[i]; + break; + } +}; + +/* + * perform IMDCT and windowing for short blocks + */ +Layer3.prototype.imdct_s = function (X, z) { + var yptr = 0; + var wptr; + var Xptr = 0; + + var y = new Float64Array(36); + var hi, lo; + + // IMDCT + for (var w = 0; w < 3; ++w) { + var sptr = 0; + + for (var i = 0; i < 3; ++i) { + lo = X[Xptr + 0] * IMDCT.S[sptr][0] + + X[Xptr + 1] * IMDCT.S[sptr][1] + + X[Xptr + 2] * IMDCT.S[sptr][2] + + X[Xptr + 3] * IMDCT.S[sptr][3] + + X[Xptr + 4] * IMDCT.S[sptr][4] + + X[Xptr + 5] * IMDCT.S[sptr][5]; + + + y[yptr + i + 0] = lo; + y[yptr + 5 - i] = -y[yptr + i + 0]; + + ++sptr; + + lo = X[Xptr + 0] * IMDCT.S[sptr][0] + + X[Xptr + 1] * IMDCT.S[sptr][1] + + X[Xptr + 2] * IMDCT.S[sptr][2] + + X[Xptr + 3] * IMDCT.S[sptr][3] + + X[Xptr + 4] * IMDCT.S[sptr][4] + + X[Xptr + 5] * IMDCT.S[sptr][5]; + + y[yptr + i + 6] = lo; + y[yptr + 11 - i] = y[yptr + i + 6]; + + ++sptr; + } + + yptr += 12; + Xptr += 6; + } + + // windowing, overlapping and concatenation + yptr = 0; + var wptr = 0; + + for (var i = 0; i < 6; ++i) { + z[i + 0] = 0; + z[i + 6] = y[yptr + 0 + 0] * tables.WINDOW_S[wptr + 0]; + + lo = y[yptr + 0 + 6] * tables.WINDOW_S[wptr + 6] + + y[yptr + 12 + 0] * tables.WINDOW_S[wptr + 0]; + + z[i + 12] = lo; + + lo = y[yptr + 12 + 6] * tables.WINDOW_S[wptr + 6] + + y[yptr + 24 + 0] * tables.WINDOW_S[wptr + 0]; + + z[i + 18] = lo; + z[i + 24] = y[yptr + 24 + 6] * tables.WINDOW_S[wptr + 6]; + z[i + 30] = 0; + + ++yptr; + ++wptr; + } +}; + +Layer3.prototype.overlap = function (output, overlap, sample, sb) { + for (var i = 0; i < 18; ++i) { + sample[i][sb] = output[i] + overlap[i]; + overlap[i] = output[i + 18]; + } +}; + +Layer3.prototype.freqinver = function (sample, sb) { + for (var i = 1; i < 18; i += 2) + sample[i][sb] = -sample[i][sb]; +}; + +Layer3.prototype.overlap_z = function (overlap, sample, sb) { + for (var i = 0; i < 18; ++i) { + sample[i][sb] = overlap[i]; + overlap[i] = 0; + } +}; + +Layer3.prototype.reorder = function (xr, channel, sfbwidth) { + var sfbwidthPointer = 0; + var tmp = this.tmp; + var sbw = new Uint32Array(3); + var sw = new Uint32Array(3); + + // this is probably wrong for 8000 Hz mixed blocks + + var sb = 0; + if (channel.flags & tables.MIXED_BLOCK_FLAG) { + var sb = 2; + + var l = 0; + while (l < 36) + l += sfbwidth[sfbwidthPointer++]; + } + + for (var w = 0; w < 3; ++w) { + sbw[w] = sb; + sw[w] = 0; + } + + f = sfbwidth[sfbwidthPointer++]; + w = 0; + + for (var l = 18 * sb; l < 576; ++l) { + if (f-- === 0) { + f = sfbwidth[sfbwidthPointer++] - 1; + w = (w + 1) % 3; + } + + tmp[sbw[w]][w][sw[w]++] = xr[l]; + + if (sw[w] === 6) { + sw[w] = 0; + ++sbw[w]; + } + } + + var tmp2 = this.tmp2; + var ptr = 0; + + for (var i = 0; i < 32; i++) { + for (var j = 0; j < 3; j++) { + for (var k = 0; k < 6; k++) { + tmp2[ptr++] = tmp[i][j][k]; + } + } + } + + var len = (576 - 18 * sb); + for (var i = 0; i < len; i++) { + xr[18 * sb + i] = tmp2[sb + i]; + } +}; + +module.exports = Layer3; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./frame":4,"./header":5,"./huffman":6,"./imdct":8,"./tables":14,"./utils":15}],12:[function(require,module,exports){ +(function (global){ +var AV = (typeof window !== "undefined" ? window['AV'] : typeof global !== "undefined" ? global['AV'] : null); +var MP3FrameHeader = require('./header'); + +function MP3Stream(stream) { + this.stream = stream; // actual bitstream + this.sync = false; // stream sync found + this.freerate = 0; // free bitrate (fixed) + this.this_frame = stream.stream.offset; // start of current frame + this.next_frame = stream.stream.offset; // start of next frame + + this.main_data = new Uint8Array(MP3FrameHeader.BUFFER_MDLEN); // actual audio data + this.md_len = 0; // length of main data + + // copy methods from actual stream + for (var key in stream) { + if (typeof stream[key] === 'function') + this[key] = stream[key].bind(stream); + } +} + +MP3Stream.prototype.getU8 = function(offset) { + var stream = this.stream.stream; + return stream.peekUInt8(offset - stream.offset); +}; + +MP3Stream.prototype.nextByte = function() { + var stream = this.stream; + return stream.bitPosition === 0 ? stream.stream.offset : stream.stream.offset + 1; +}; + +MP3Stream.prototype.doSync = function() { + var stream = this.stream.stream; + this.align(); + + while (this.available(16) && !(stream.peekUInt8(0) === 0xff && (stream.peekUInt8(1) & 0xe0) === 0xe0)) { + this.advance(8); + } + + if (!this.available(MP3FrameHeader.BUFFER_GUARD)) + return false; + + return true; +}; + +MP3Stream.prototype.reset = function(byteOffset) { + this.seek(byteOffset * 8); + this.next_frame = byteOffset; + this.sync = true; +}; + +module.exports = MP3Stream; + +}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./header":5}],13:[function(require,module,exports){ +var utils = require('./utils'); + +function MP3Synth() { + this.filter = utils.makeArray([2, 2, 2, 16, 8]); // polyphase filterbank outputs + this.phase = 0; + + this.pcm = { + samplerate: 0, + channels: 0, + length: 0, + samples: [new Float64Array(1152), new Float64Array(1152)] + }; +} + +/* costab[i] = cos(PI / (2 * 32) * i) */ +const costab1 = 0.998795456; +const costab2 = 0.995184727; +const costab3 = 0.989176510; +const costab4 = 0.980785280; +const costab5 = 0.970031253; +const costab6 = 0.956940336; +const costab7 = 0.941544065; +const costab8 = 0.923879533; +const costab9 = 0.903989293; +const costab10 = 0.881921264; +const costab11 = 0.857728610; +const costab12 = 0.831469612; +const costab13 = 0.803207531; +const costab14 = 0.773010453; +const costab15 = 0.740951125; +const costab16 = 0.707106781; +const costab17 = 0.671558955; +const costab18 = 0.634393284; +const costab19 = 0.595699304; +const costab20 = 0.555570233; +const costab21 = 0.514102744; +const costab22 = 0.471396737; +const costab23 = 0.427555093; +const costab24 = 0.382683432; +const costab25 = 0.336889853; +const costab26 = 0.290284677; +const costab27 = 0.242980180; +const costab28 = 0.195090322; +const costab29 = 0.146730474; +const costab30 = 0.098017140; +const costab31 = 0.049067674; + +/* + * NAME: dct32() + * DESCRIPTION: perform fast in[32].out[32] DCT + */ +MP3Synth.dct32 = function (_in, slot, lo, hi) { + var t0, t1, t2, t3, t4, t5, t6, t7; + var t8, t9, t10, t11, t12, t13, t14, t15; + var t16, t17, t18, t19, t20, t21, t22, t23; + var t24, t25, t26, t27, t28, t29, t30, t31; + var t32, t33, t34, t35, t36, t37, t38, t39; + var t40, t41, t42, t43, t44, t45, t46, t47; + var t48, t49, t50, t51, t52, t53, t54, t55; + var t56, t57, t58, t59, t60, t61, t62, t63; + var t64, t65, t66, t67, t68, t69, t70, t71; + var t72, t73, t74, t75, t76, t77, t78, t79; + var t80, t81, t82, t83, t84, t85, t86, t87; + var t88, t89, t90, t91, t92, t93, t94, t95; + var t96, t97, t98, t99, t100, t101, t102, t103; + var t104, t105, t106, t107, t108, t109, t110, t111; + var t112, t113, t114, t115, t116, t117, t118, t119; + var t120, t121, t122, t123, t124, t125, t126, t127; + var t128, t129, t130, t131, t132, t133, t134, t135; + var t136, t137, t138, t139, t140, t141, t142, t143; + var t144, t145, t146, t147, t148, t149, t150, t151; + var t152, t153, t154, t155, t156, t157, t158, t159; + var t160, t161, t162, t163, t164, t165, t166, t167; + var t168, t169, t170, t171, t172, t173, t174, t175; + var t176; + + t0 = _in[0] + _in[31]; t16 = ((_in[0] - _in[31]) * (costab1)); + t1 = _in[15] + _in[16]; t17 = ((_in[15] - _in[16]) * (costab31)); + + t41 = t16 + t17; + t59 = ((t16 - t17) * (costab2)); + t33 = t0 + t1; + t50 = ((t0 - t1) * ( costab2)); + + t2 = _in[7] + _in[24]; t18 = ((_in[7] - _in[24]) * (costab15)); + t3 = _in[8] + _in[23]; t19 = ((_in[8] - _in[23]) * (costab17)); + + t42 = t18 + t19; + t60 = ((t18 - t19) * (costab30)); + t34 = t2 + t3; + t51 = ((t2 - t3) * ( costab30)); + + t4 = _in[3] + _in[28]; t20 = ((_in[3] - _in[28]) * (costab7)); + t5 = _in[12] + _in[19]; t21 = ((_in[12] - _in[19]) * (costab25)); + + t43 = t20 + t21; + t61 = ((t20 - t21) * (costab14)); + t35 = t4 + t5; + t52 = ((t4 - t5) * ( costab14)); + + t6 = _in[4] + _in[27]; t22 = ((_in[4] - _in[27]) * (costab9)); + t7 = _in[11] + _in[20]; t23 = ((_in[11] - _in[20]) * (costab23)); + + t44 = t22 + t23; + t62 = ((t22 - t23) * (costab18)); + t36 = t6 + t7; + t53 = ((t6 - t7) * ( costab18)); + + t8 = _in[1] + _in[30]; t24 = ((_in[1] - _in[30]) * (costab3)); + t9 = _in[14] + _in[17]; t25 = ((_in[14] - _in[17]) * (costab29)); + + t45 = t24 + t25; + t63 = ((t24 - t25) * (costab6)); + t37 = t8 + t9; + t54 = ((t8 - t9) * ( costab6)); + + t10 = _in[6] + _in[25]; t26 = ((_in[6] - _in[25]) * (costab13)); + t11 = _in[9] + _in[22]; t27 = ((_in[9] - _in[22]) * (costab19)); + + t46 = t26 + t27; + t64 = ((t26 - t27) * (costab26)); + t38 = t10 + t11; + t55 = ((t10 - t11) * (costab26)); + + t12 = _in[2] + _in[29]; t28 = ((_in[2] - _in[29]) * (costab5)); + t13 = _in[13] + _in[18]; t29 = ((_in[13] - _in[18]) * (costab27)); + + t47 = t28 + t29; + t65 = ((t28 - t29) * (costab10)); + t39 = t12 + t13; + t56 = ((t12 - t13) * (costab10)); + + t14 = _in[5] + _in[26]; t30 = ((_in[5] - _in[26]) * (costab11)); + t15 = _in[10] + _in[21]; t31 = ((_in[10] - _in[21]) * (costab21)); + + t48 = t30 + t31; + t66 = ((t30 - t31) * (costab22)); + t40 = t14 + t15; + t57 = ((t14 - t15) * (costab22)); + + t69 = t33 + t34; t89 = ((t33 - t34) * (costab4)); + t70 = t35 + t36; t90 = ((t35 - t36) * (costab28)); + t71 = t37 + t38; t91 = ((t37 - t38) * (costab12)); + t72 = t39 + t40; t92 = ((t39 - t40) * (costab20)); + t73 = t41 + t42; t94 = ((t41 - t42) * (costab4)); + t74 = t43 + t44; t95 = ((t43 - t44) * (costab28)); + t75 = t45 + t46; t96 = ((t45 - t46) * (costab12)); + t76 = t47 + t48; t97 = ((t47 - t48) * (costab20)); + + t78 = t50 + t51; t100 = ((t50 - t51) * (costab4)); + t79 = t52 + t53; t101 = ((t52 - t53) * (costab28)); + t80 = t54 + t55; t102 = ((t54 - t55) * (costab12)); + t81 = t56 + t57; t103 = ((t56 - t57) * (costab20)); + + t83 = t59 + t60; t106 = ((t59 - t60) * (costab4)); + t84 = t61 + t62; t107 = ((t61 - t62) * (costab28)); + t85 = t63 + t64; t108 = ((t63 - t64) * (costab12)); + t86 = t65 + t66; t109 = ((t65 - t66) * (costab20)); + + t113 = t69 + t70; + t114 = t71 + t72; + + /* 0 */ hi[15][slot] = t113 + t114; + /* 16 */ lo[ 0][slot] = ((t113 - t114) * (costab16)); + + t115 = t73 + t74; + t116 = t75 + t76; + + t32 = t115 + t116; + + /* 1 */ hi[14][slot] = t32; + + t118 = t78 + t79; + t119 = t80 + t81; + + t58 = t118 + t119; + + /* 2 */ hi[13][slot] = t58; + + t121 = t83 + t84; + t122 = t85 + t86; + + t67 = t121 + t122; + + t49 = (t67 * 2) - t32; + + /* 3 */ hi[12][slot] = t49; + + t125 = t89 + t90; + t126 = t91 + t92; + + t93 = t125 + t126; + + /* 4 */ hi[11][slot] = t93; + + t128 = t94 + t95; + t129 = t96 + t97; + + t98 = t128 + t129; + + t68 = (t98 * 2) - t49; + + /* 5 */ hi[10][slot] = t68; + + t132 = t100 + t101; + t133 = t102 + t103; + + t104 = t132 + t133; + + t82 = (t104 * 2) - t58; + + /* 6 */ hi[ 9][slot] = t82; + + t136 = t106 + t107; + t137 = t108 + t109; + + t110 = t136 + t137; + + t87 = (t110 * 2) - t67; + + t77 = (t87 * 2) - t68; + + /* 7 */ hi[ 8][slot] = t77; + + t141 = ((t69 - t70) * (costab8)); + t142 = ((t71 - t72) * (costab24)); + t143 = t141 + t142; + + /* 8 */ hi[ 7][slot] = t143; + /* 24 */ lo[ 8][slot] = + (((t141 - t142) * (costab16) * 2)) - t143; + + t144 = ((t73 - t74) * (costab8)); + t145 = ((t75 - t76) * (costab24)); + t146 = t144 + t145; + + t88 = (t146 * 2) - t77; + + /* 9 */ hi[ 6][slot] = t88; + + t148 = ((t78 - t79) * (costab8)); + t149 = ((t80 - t81) * (costab24)); + t150 = t148 + t149; + + t105 = (t150 * 2) - t82; + + /* 10 */ hi[ 5][slot] = t105; + + t152 = ((t83 - t84) * (costab8)); + t153 = ((t85 - t86) * (costab24)); + t154 = t152 + t153; + + t111 = (t154 * 2) - t87; + + t99 = (t111 * 2) - t88; + + /* 11 */ hi[ 4][slot] = t99; + + t157 = ((t89 - t90) * (costab8)); + t158 = ((t91 - t92) * (costab24)); + t159 = t157 + t158; + + t127 = (t159 * 2) - t93; + + /* 12 */ hi[ 3][slot] = t127; + + t160 = (((t125 - t126) * (costab16) * 2)) - t127; + + /* 20 */ lo[ 4][slot] = t160; + /* 28 */ lo[12][slot] = + (((((t157 - t158) * (costab16) * 2) - t159) * 2)) - t160; + + t161 = ((t94 - t95) * (costab8)); + t162 = ((t96 - t97) * (costab24)); + t163 = t161 + t162; + + t130 = (t163 * 2) - t98; + + t112 = (t130 * 2) - t99; + + /* 13 */ hi[ 2][slot] = t112; + + t164 = (((t128 - t129) * (costab16) * 2)) - t130; + + t166 = ((t100 - t101) * (costab8)); + t167 = ((t102 - t103) * (costab24)); + t168 = t166 + t167; + + t134 = (t168 * 2) - t104; + + t120 = (t134 * 2) - t105; + + /* 14 */ hi[ 1][slot] = t120; + + t135 = (((t118 - t119) * (costab16) * 2)) - t120; + + /* 18 */ lo[ 2][slot] = t135; + + t169 = (((t132 - t133) * (costab16) * 2)) - t134; + + t151 = (t169 * 2) - t135; + + /* 22 */ lo[ 6][slot] = t151; + + t170 = (((((t148 - t149) * (costab16) * 2) - t150) * 2)) - t151; + + /* 26 */ lo[10][slot] = t170; + /* 30 */ lo[14][slot] = + (((((((t166 - t167) * (costab16)) * 2 - + t168) * 2) - t169) * 2) - t170); + + t171 = ((t106 - t107) * (costab8)); + t172 = ((t108 - t109) * (costab24)); + t173 = t171 + t172; + + t138 = (t173 * 2) - t110; + t123 = (t138 * 2) - t111; + t139 = (((t121 - t122) * (costab16) * 2)) - t123; + t117 = (t123 * 2) - t112; + + /* 15 */ hi[ 0][slot] = t117; + + t124 = (((t115 - t116) * (costab16) * 2)) - t117; + + /* 17 */ lo[ 1][slot] = t124; + + t131 = (t139 * 2) - t124; + + /* 19 */ lo[ 3][slot] = t131; + + t140 = (t164 * 2) - t131; + + /* 21 */ lo[ 5][slot] = t140; + + t174 = (((t136 - t137) * (costab16) * 2)) - t138; + t155 = (t174 * 2) - t139; + t147 = (t155 * 2) - t140; + + /* 23 */ lo[ 7][slot] = t147; + + t156 = (((((t144 - t145) * (costab16) * 2) - t146) * 2)) - t147; + + /* 25 */ lo[ 9][slot] = t156; + + t175 = (((((t152 - t153) * (costab16) * 2) - t154) * 2)) - t155; + t165 = (t175 * 2) - t156; + + /* 27 */ lo[11][slot] = t165; + + t176 = (((((((t161 - t162) * (costab16) * 2)) - + t163) * 2) - t164) * 2) - t165; + + /* 29 */ lo[13][slot] = t176; + /* 31 */ lo[15][slot] = + (((((((((t171 - t172) * (costab16)) * 2 - + t173) * 2) - t174) * 2) - t175) * 2) - t176); + + /* + * Totals: + * 80 multiplies + * 80 additions + * 119 subtractions + * 49 shifts (not counting SSO) + */ +}; + +/* + * These are the coefficients for the subband synthesis window. This is a + * reordered version of Table B.3 from ISO/IEC 11172-3. + */ +const D = [ + [ 0.000000000, /* 0 */ + -0.000442505, + 0.003250122, + -0.007003784, + 0.031082153, + -0.078628540, + 0.100311279, + -0.572036743, + 1.144989014, + 0.572036743, + 0.100311279, + 0.078628540, + 0.031082153, + 0.007003784, + 0.003250122, + 0.000442505, + + 0.000000000, + -0.000442505, + 0.003250122, + -0.007003784, + 0.031082153, + -0.078628540, + 0.100311279, + -0.572036743, + 1.144989014, + 0.572036743, + 0.100311279, + 0.078628540, + 0.031082153, + 0.007003784, + 0.003250122, + 0.000442505 ], + + [ -0.000015259, /* 1 */ + -0.000473022, + 0.003326416, + -0.007919312, + 0.030517578, + -0.084182739, + 0.090927124, + -0.600219727, + 1.144287109, + 0.543823242, + 0.108856201, + 0.073059082, + 0.031478882, + 0.006118774, + 0.003173828, + 0.000396729, + + -0.000015259, + -0.000473022, + 0.003326416, + -0.007919312, + 0.030517578, + -0.084182739, + 0.090927124, + -0.600219727, + 1.144287109, + 0.543823242, + 0.108856201, + 0.073059082, + 0.031478882, + 0.006118774, + 0.003173828, + 0.000396729 ], + + [ -0.000015259, /* 2 */ + -0.000534058, + 0.003387451, + -0.008865356, + 0.029785156, + -0.089706421, + 0.080688477, + -0.628295898, + 1.142211914, + 0.515609741, + 0.116577148, + 0.067520142, + 0.031738281, + 0.005294800, + 0.003082275, + 0.000366211, + + -0.000015259, + -0.000534058, + 0.003387451, + -0.008865356, + 0.029785156, + -0.089706421, + 0.080688477, + -0.628295898, + 1.142211914, + 0.515609741, + 0.116577148, + 0.067520142, + 0.031738281, + 0.005294800, + 0.003082275, + 0.000366211 ], + + [ -0.000015259, /* 3 */ + -0.000579834, + 0.003433228, + -0.009841919, + 0.028884888, + -0.095169067, + 0.069595337, + -0.656219482, + 1.138763428, + 0.487472534, + 0.123474121, + 0.061996460, + 0.031845093, + 0.004486084, + 0.002990723, + 0.000320435, + + -0.000015259, + -0.000579834, + 0.003433228, + -0.009841919, + 0.028884888, + -0.095169067, + 0.069595337, + -0.656219482, + 1.138763428, + 0.487472534, + 0.123474121, + 0.061996460, + 0.031845093, + 0.004486084, + 0.002990723, + 0.000320435 ], + + [ -0.000015259, /* 4 */ + -0.000625610, + 0.003463745, + -0.010848999, + 0.027801514, + -0.100540161, + 0.057617187, + -0.683914185, + 1.133926392, + 0.459472656, + 0.129577637, + 0.056533813, + 0.031814575, + 0.003723145, + 0.002899170, + 0.000289917, + + -0.000015259, + -0.000625610, + 0.003463745, + -0.010848999, + 0.027801514, + -0.100540161, + 0.057617187, + -0.683914185, + 1.133926392, + 0.459472656, + 0.129577637, + 0.056533813, + 0.031814575, + 0.003723145, + 0.002899170, + 0.000289917 ], + + [ -0.000015259, /* 5 */ + -0.000686646, + 0.003479004, + -0.011886597, + 0.026535034, + -0.105819702, + 0.044784546, + -0.711318970, + 1.127746582, + 0.431655884, + 0.134887695, + 0.051132202, + 0.031661987, + 0.003005981, + 0.002792358, + 0.000259399, + + -0.000015259, + -0.000686646, + 0.003479004, + -0.011886597, + 0.026535034, + -0.105819702, + 0.044784546, + -0.711318970, + 1.127746582, + 0.431655884, + 0.134887695, + 0.051132202, + 0.031661987, + 0.003005981, + 0.002792358, + 0.000259399 ], + + [ -0.000015259, /* 6 */ + -0.000747681, + 0.003479004, + -0.012939453, + 0.025085449, + -0.110946655, + 0.031082153, + -0.738372803, + 1.120223999, + 0.404083252, + 0.139450073, + 0.045837402, + 0.031387329, + 0.002334595, + 0.002685547, + 0.000244141, + + -0.000015259, + -0.000747681, + 0.003479004, + -0.012939453, + 0.025085449, + -0.110946655, + 0.031082153, + -0.738372803, + 1.120223999, + 0.404083252, + 0.139450073, + 0.045837402, + 0.031387329, + 0.002334595, + 0.002685547, + 0.000244141 ], + + [ -0.000030518, /* 7 */ + -0.000808716, + 0.003463745, + -0.014022827, + 0.023422241, + -0.115921021, + 0.016510010, + -0.765029907, + 1.111373901, + 0.376800537, + 0.143264771, + 0.040634155, + 0.031005859, + 0.001693726, + 0.002578735, + 0.000213623, + + -0.000030518, + -0.000808716, + 0.003463745, + -0.014022827, + 0.023422241, + -0.115921021, + 0.016510010, + -0.765029907, + 1.111373901, + 0.376800537, + 0.143264771, + 0.040634155, + 0.031005859, + 0.001693726, + 0.002578735, + 0.000213623 ], + + [ -0.000030518, /* 8 */ + -0.000885010, + 0.003417969, + -0.015121460, + 0.021575928, + -0.120697021, + 0.001068115, + -0.791213989, + 1.101211548, + 0.349868774, + 0.146362305, + 0.035552979, + 0.030532837, + 0.001098633, + 0.002456665, + 0.000198364, + + -0.000030518, + -0.000885010, + 0.003417969, + -0.015121460, + 0.021575928, + -0.120697021, + 0.001068115, + -0.791213989, + 1.101211548, + 0.349868774, + 0.146362305, + 0.035552979, + 0.030532837, + 0.001098633, + 0.002456665, + 0.000198364 ], + + [ -0.000030518, /* 9 */ + -0.000961304, + 0.003372192, + -0.016235352, + 0.019531250, + -0.125259399, + -0.015228271, + -0.816864014, + 1.089782715, + 0.323318481, + 0.148773193, + 0.030609131, + 0.029937744, + 0.000549316, + 0.002349854, + 0.000167847, + + -0.000030518, + -0.000961304, + 0.003372192, + -0.016235352, + 0.019531250, + -0.125259399, + -0.015228271, + -0.816864014, + 1.089782715, + 0.323318481, + 0.148773193, + 0.030609131, + 0.029937744, + 0.000549316, + 0.002349854, + 0.000167847 ], + + [ -0.000030518, /* 10 */ + -0.001037598, + 0.003280640, + -0.017349243, + 0.017257690, + -0.129562378, + -0.032379150, + -0.841949463, + 1.077117920, + 0.297210693, + 0.150497437, + 0.025817871, + 0.029281616, + 0.000030518, + 0.002243042, + 0.000152588, + + -0.000030518, + -0.001037598, + 0.003280640, + -0.017349243, + 0.017257690, + -0.129562378, + -0.032379150, + -0.841949463, + 1.077117920, + 0.297210693, + 0.150497437, + 0.025817871, + 0.029281616, + 0.000030518, + 0.002243042, + 0.000152588 ], + + [ -0.000045776, /* 11 */ + -0.001113892, + 0.003173828, + -0.018463135, + 0.014801025, + -0.133590698, + -0.050354004, + -0.866363525, + 1.063217163, + 0.271591187, + 0.151596069, + 0.021179199, + 0.028533936, + -0.000442505, + 0.002120972, + 0.000137329, + + -0.000045776, + -0.001113892, + 0.003173828, + -0.018463135, + 0.014801025, + -0.133590698, + -0.050354004, + -0.866363525, + 1.063217163, + 0.271591187, + 0.151596069, + 0.021179199, + 0.028533936, + -0.000442505, + 0.002120972, + 0.000137329 ], + + [ -0.000045776, /* 12 */ + -0.001205444, + 0.003051758, + -0.019577026, + 0.012115479, + -0.137298584, + -0.069168091, + -0.890090942, + 1.048156738, + 0.246505737, + 0.152069092, + 0.016708374, + 0.027725220, + -0.000869751, + 0.002014160, + 0.000122070, + + -0.000045776, + -0.001205444, + 0.003051758, + -0.019577026, + 0.012115479, + -0.137298584, + -0.069168091, + -0.890090942, + 1.048156738, + 0.246505737, + 0.152069092, + 0.016708374, + 0.027725220, + -0.000869751, + 0.002014160, + 0.000122070 ], + + [ -0.000061035, /* 13 */ + -0.001296997, + 0.002883911, + -0.020690918, + 0.009231567, + -0.140670776, + -0.088775635, + -0.913055420, + 1.031936646, + 0.221984863, + 0.151962280, + 0.012420654, + 0.026840210, + -0.001266479, + 0.001907349, + 0.000106812, + + -0.000061035, + -0.001296997, + 0.002883911, + -0.020690918, + 0.009231567, + -0.140670776, + -0.088775635, + -0.913055420, + 1.031936646, + 0.221984863, + 0.151962280, + 0.012420654, + 0.026840210, + -0.001266479, + 0.001907349, + 0.000106812 ], + + [ -0.000061035, /* 14 */ + -0.001388550, + 0.002700806, + -0.021789551, + 0.006134033, + -0.143676758, + -0.109161377, + -0.935195923, + 1.014617920, + 0.198059082, + 0.151306152, + 0.008316040, + 0.025909424, + -0.001617432, + 0.001785278, + 0.000106812, + + -0.000061035, + -0.001388550, + 0.002700806, + -0.021789551, + 0.006134033, + -0.143676758, + -0.109161377, + -0.935195923, + 1.014617920, + 0.198059082, + 0.151306152, + 0.008316040, + 0.025909424, + -0.001617432, + 0.001785278, + 0.000106812 ], + + [ -0.000076294, /* 15 */ + -0.001480103, + 0.002487183, + -0.022857666, + 0.002822876, + -0.146255493, + -0.130310059, + -0.956481934, + 0.996246338, + 0.174789429, + 0.150115967, + 0.004394531, + 0.024932861, + -0.001937866, + 0.001693726, + 0.000091553, + + -0.000076294, + -0.001480103, + 0.002487183, + -0.022857666, + 0.002822876, + -0.146255493, + -0.130310059, + -0.956481934, + 0.996246338, + 0.174789429, + 0.150115967, + 0.004394531, + 0.024932861, + -0.001937866, + 0.001693726, + 0.000091553 ], + + [ -0.000076294, /* 16 */ + -0.001586914, + 0.002227783, + -0.023910522, + -0.000686646, + -0.148422241, + -0.152206421, + -0.976852417, + 0.976852417, + 0.152206421, + 0.148422241, + 0.000686646, + 0.023910522, + -0.002227783, + 0.001586914, + 0.000076294, + + -0.000076294, + -0.001586914, + 0.002227783, + -0.023910522, + -0.000686646, + -0.148422241, + -0.152206421, + -0.976852417, + 0.976852417, + 0.152206421, + 0.148422241, + 0.000686646, + 0.023910522, + -0.002227783, + 0.001586914, + 0.000076294 ] +]; + +/* + * perform full frequency PCM synthesis + */ +MP3Synth.prototype.full = function(frame, nch, ns) { + var Dptr, hi, lo, ptr; + + for (var ch = 0; ch < nch; ++ch) { + var sbsample = frame.sbsample[ch]; + var filter = this.filter[ch]; + var phase = this.phase; + var pcm = this.pcm.samples[ch]; + var pcm1Ptr = 0; + var pcm2Ptr = 0; + + for (var s = 0; s < ns; ++s) { + MP3Synth.dct32(sbsample[s], phase >> 1, filter[0][phase & 1], filter[1][phase & 1]); + + var pe = phase & ~1; + var po = ((phase - 1) & 0xf) | 1; + + /* calculate 32 samples */ + var fe = filter[0][ phase & 1]; + var fx = filter[0][~phase & 1]; + var fo = filter[1][~phase & 1]; + + var fePtr = 0; + var fxPtr = 0; + var foPtr = 0; + + Dptr = 0; + + ptr = D[Dptr]; + _fx = fx[fxPtr]; + _fe = fe[fePtr]; + + lo = _fx[0] * ptr[po + 0]; + lo += _fx[1] * ptr[po + 14]; + lo += _fx[2] * ptr[po + 12]; + lo += _fx[3] * ptr[po + 10]; + lo += _fx[4] * ptr[po + 8]; + lo += _fx[5] * ptr[po + 6]; + lo += _fx[6] * ptr[po + 4]; + lo += _fx[7] * ptr[po + 2]; + lo = -lo; + + lo += _fe[0] * ptr[pe + 0]; + lo += _fe[1] * ptr[pe + 14]; + lo += _fe[2] * ptr[pe + 12]; + lo += _fe[3] * ptr[pe + 10]; + lo += _fe[4] * ptr[pe + 8]; + lo += _fe[5] * ptr[pe + 6]; + lo += _fe[6] * ptr[pe + 4]; + lo += _fe[7] * ptr[pe + 2]; + + pcm[pcm1Ptr++] = lo; + pcm2Ptr = pcm1Ptr + 30; + + for (var sb = 1; sb < 16; ++sb) { + ++fePtr; + ++Dptr; + + /* D[32 - sb][i] === -D[sb][31 - i] */ + + ptr = D[Dptr]; + _fo = fo[foPtr]; + _fe = fe[fePtr]; + + lo = _fo[0] * ptr[po + 0]; + lo += _fo[1] * ptr[po + 14]; + lo += _fo[2] * ptr[po + 12]; + lo += _fo[3] * ptr[po + 10]; + lo += _fo[4] * ptr[po + 8]; + lo += _fo[5] * ptr[po + 6]; + lo += _fo[6] * ptr[po + 4]; + lo += _fo[7] * ptr[po + 2]; + lo = -lo; + + lo += _fe[7] * ptr[pe + 2]; + lo += _fe[6] * ptr[pe + 4]; + lo += _fe[5] * ptr[pe + 6]; + lo += _fe[4] * ptr[pe + 8]; + lo += _fe[3] * ptr[pe + 10]; + lo += _fe[2] * ptr[pe + 12]; + lo += _fe[1] * ptr[pe + 14]; + lo += _fe[0] * ptr[pe + 0]; + + pcm[pcm1Ptr++] = lo; + + lo = _fe[0] * ptr[-pe + 31 - 16]; + lo += _fe[1] * ptr[-pe + 31 - 14]; + lo += _fe[2] * ptr[-pe + 31 - 12]; + lo += _fe[3] * ptr[-pe + 31 - 10]; + lo += _fe[4] * ptr[-pe + 31 - 8]; + lo += _fe[5] * ptr[-pe + 31 - 6]; + lo += _fe[6] * ptr[-pe + 31 - 4]; + lo += _fe[7] * ptr[-pe + 31 - 2]; + + lo += _fo[7] * ptr[-po + 31 - 2]; + lo += _fo[6] * ptr[-po + 31 - 4]; + lo += _fo[5] * ptr[-po + 31 - 6]; + lo += _fo[4] * ptr[-po + 31 - 8]; + lo += _fo[3] * ptr[-po + 31 - 10]; + lo += _fo[2] * ptr[-po + 31 - 12]; + lo += _fo[1] * ptr[-po + 31 - 14]; + lo += _fo[0] * ptr[-po + 31 - 16]; + + pcm[pcm2Ptr--] = lo; + ++foPtr; + } + + ++Dptr; + + ptr = D[Dptr]; + _fo = fo[foPtr]; + + lo = _fo[0] * ptr[po + 0]; + lo += _fo[1] * ptr[po + 14]; + lo += _fo[2] * ptr[po + 12]; + lo += _fo[3] * ptr[po + 10]; + lo += _fo[4] * ptr[po + 8]; + lo += _fo[5] * ptr[po + 6]; + lo += _fo[6] * ptr[po + 4]; + lo += _fo[7] * ptr[po + 2]; + + pcm[pcm1Ptr] = -lo; + pcm1Ptr += 16; + phase = (phase + 1) % 16; + } + } +}; + +// TODO: synth.half() + +/* + * NAME: synth.frame() + * DESCRIPTION: perform PCM synthesis of frame subband samples + */ +MP3Synth.prototype.frame = function (frame) { + var nch = frame.header.nchannels(); + var ns = frame.header.nbsamples(); + + this.pcm.samplerate = frame.header.samplerate; + this.pcm.channels = nch; + this.pcm.length = 32 * ns; + + /* + if (frame.options & Mad.Option.HALFSAMPLERATE) { + this.pcm.samplerate /= 2; + this.pcm.length /= 2; + + throw new Error("HALFSAMPLERATE is not supported. What do you think? As if I have the time for this"); + } + */ + + this.full(frame, nch, ns); + this.phase = (this.phase + ns) % 16; +}; + +module.exports = MP3Synth; + +},{"./utils":15}],14:[function(require,module,exports){ +/* + * These are the scalefactor values for Layer I and Layer II. + * The values are from Table B.1 of ISO/IEC 11172-3. + * + * Strictly speaking, Table B.1 has only 63 entries (0-62), thus a strict + * interpretation of ISO/IEC 11172-3 would suggest that a scalefactor index of + * 63 is invalid. However, for better compatibility with current practices, we + * add a 64th entry. + */ +exports.SF_TABLE = new Float32Array([ + 2.000000000000, 1.587401051968, 1.259921049895, 1.000000000000, + 0.793700525984, 0.629960524947, 0.500000000000, 0.396850262992, + 0.314980262474, 0.250000000000, 0.198425131496, 0.157490131237, + 0.125000000000, 0.099212565748, 0.078745065618, 0.062500000000, + 0.049606282874, 0.039372532809, 0.031250000000, 0.024803141437, + 0.019686266405, 0.015625000000, 0.012401570719, 0.009843133202, + 0.007812500000, 0.006200785359, 0.004921566601, 0.003906250000, + 0.003100392680, 0.002460783301, 0.001953125000, 0.001550196340, + 0.001230391650, 0.000976562500, 0.000775098170, 0.000615195825, + 0.000488281250, 0.000387549085, 0.000307597913, 0.000244140625, + 0.000193774542, 0.000153798956, 0.000122070313, 0.000096887271, + 0.000076899478, 0.000061035156, 0.000048443636, 0.000038449739, + 0.000030517578, 0.000024221818, 0.000019224870, 0.000015258789, + 0.000012110909, 0.000009612435, 0.000007629395, 0.000006055454, + 0.000004806217, 0.000003814697, 0.000003027727, 0.000002403109, + 0.000001907349, 0.000001513864, 0.000001201554, 0.000000000000 +]); + +/* + * MPEG-1 scalefactor band widths + * derived from Table B.8 of ISO/IEC 11172-3 + */ +const SFB_48000_LONG = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10, + 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192 +]); + +const SFB_44100_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 +]); + +const SFB_32000_LONG = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12, + 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26 +]); + +const SFB_48000_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, + 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14, + 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 +]); + +const SFB_44100_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, + 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, + 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 +]); + +const SFB_32000_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, + 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20, + 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 +]); + +const SFB_48000_MIXED = new Uint8Array([ + /* long */ 4, 4, 4, 4, 4, 4, 6, 6, + /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10, + 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, + 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 +]); + +const SFB_44100_MIXED = new Uint8Array([ + /* long */ 4, 4, 4, 4, 4, 4, 6, 6, + /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, + 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, + 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 +]); + +const SFB_32000_MIXED = new Uint8Array([ + /* long */ 4, 4, 4, 4, 4, 4, 6, 6, + /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12, + 12, 12, 16, 16, 16, 20, 20, 20, 26, 26, + 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 +]); + +/* + * MPEG-2 scalefactor band widths + * derived from Table B.2 of ISO/IEC 13818-3 + */ +const SFB_24000_LONG = new Uint8Array([ + 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, + 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36 +]); + +const SFB_22050_LONG = new Uint8Array([ + 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, + 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54 +]); + +const SFB_16000_LONG = SFB_22050_LONG; + +const SFB_24000_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, + 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, + 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12 +]); + +const SFB_22050_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, + 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18, + 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18 +]); + +const SFB_16000_SHORT = new Uint8Array([ + 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, + 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, + 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18 +]); + +const SFB_24000_MIXED = new Uint8Array([ + /* long */ 6, 6, 6, 6, 6, 6, + /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, + 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, + 24, 32, 32, 32, 44, 44, 44, 12, 12, 12 +]); + +const SFB_22050_MIXED = new Uint8Array([ + /* long */ 6, 6, 6, 6, 6, 6, + /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, + 10, 10, 14, 14, 14, 18, 18, 18, 26, 26, + 26, 32, 32, 32, 42, 42, 42, 18, 18, 18 +]); + +const SFB_16000_MIXED = new Uint8Array([ + /* long */ 6, 6, 6, 6, 6, 6, + /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, + 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, + 24, 30, 30, 30, 40, 40, 40, 18, 18, 18 +]); + +/* + * MPEG 2.5 scalefactor band widths + * derived from public sources + */ +const SFB_12000_LONG = SFB_16000_LONG; +const SFB_11025_LONG = SFB_12000_LONG; + +const SFB_8000_LONG = new Uint8Array([ + 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32, + 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2 +]); + +const SFB_12000_SHORT = SFB_16000_SHORT; +const SFB_11025_SHORT = SFB_12000_SHORT; + +const SFB_8000_SHORT = new Uint8Array([ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16, + 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, + 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 +]); + +const SFB_12000_MIXED = SFB_16000_MIXED; +const SFB_11025_MIXED = SFB_12000_MIXED; + +/* the 8000 Hz short block scalefactor bands do not break after + the first 36 frequency lines, so this is probably wrong */ +const SFB_8000_MIXED = new Uint8Array([ + /* long */ 12, 12, 12, + /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16, + 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 +]); + +exports.SFBWIDTH_TABLE = [ + { l: SFB_48000_LONG, s: SFB_48000_SHORT, m: SFB_48000_MIXED }, + { l: SFB_44100_LONG, s: SFB_44100_SHORT, m: SFB_44100_MIXED }, + { l: SFB_32000_LONG, s: SFB_32000_SHORT, m: SFB_32000_MIXED }, + { l: SFB_24000_LONG, s: SFB_24000_SHORT, m: SFB_24000_MIXED }, + { l: SFB_22050_LONG, s: SFB_22050_SHORT, m: SFB_22050_MIXED }, + { l: SFB_16000_LONG, s: SFB_16000_SHORT, m: SFB_16000_MIXED }, + { l: SFB_12000_LONG, s: SFB_12000_SHORT, m: SFB_12000_MIXED }, + { l: SFB_11025_LONG, s: SFB_11025_SHORT, m: SFB_11025_MIXED }, + { l: SFB_8000_LONG, s: SFB_8000_SHORT, m: SFB_8000_MIXED } +]; + +exports.PRETAB = new Uint8Array([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 +]); + +/* + * fractional powers of two + * used for requantization and joint stereo decoding + * + * ROOT_TABLE[3 + x] = 2^(x/4) + */ +exports.ROOT_TABLE = new Float32Array([ + /* 2^(-3/4) */ 0.59460355750136, + /* 2^(-2/4) */ 0.70710678118655, + /* 2^(-1/4) */ 0.84089641525371, + /* 2^( 0/4) */ 1.00000000000000, + /* 2^(+1/4) */ 1.18920711500272, + /* 2^(+2/4) */ 1.41421356237310, + /* 2^(+3/4) */ 1.68179283050743 +]); + +exports.CS = new Float32Array([ + +0.857492926 , +0.881741997, + +0.949628649 , +0.983314592, + +0.995517816 , +0.999160558, + +0.999899195 , +0.999993155 +]); + +exports.CA = new Float32Array([ + -0.514495755, -0.471731969, + -0.313377454, -0.181913200, + -0.094574193, -0.040965583, + -0.014198569, -0.003699975 +]); + +exports.COUNT1TABLE_SELECT = 0x01; +exports.SCALEFAC_SCALE = 0x02; +exports.PREFLAG = 0x04; +exports.MIXED_BLOCK_FLAG = 0x08; + +exports.I_STEREO = 0x1; +exports.MS_STEREO = 0x2; + +/* + * windowing coefficients for long blocks + * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3 + * + * WINDOW_L[i] = sin((PI / 36) * (i + 1/2)) + */ +exports.WINDOW_L = new Float32Array([ + 0.043619387, 0.130526192, + 0.216439614, 0.300705800, + 0.382683432, 0.461748613, + 0.537299608, 0.608761429, + 0.675590208, 0.737277337, + 0.793353340, 0.843391446, + + 0.887010833, 0.923879533, + 0.953716951, 0.976296007, + 0.991444861, 0.999048222, + 0.999048222, 0.991444861, + 0.976296007, 0.953716951, + 0.923879533, 0.887010833, + + 0.843391446, 0.793353340, + 0.737277337, 0.675590208, + 0.608761429, 0.537299608, + 0.461748613, 0.382683432, + 0.300705800, 0.216439614, + 0.130526192, 0.043619387 +]); + +/* + * windowing coefficients for short blocks + * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3 + * + * WINDOW_S[i] = sin((PI / 12) * (i + 1/2)) + */ +exports.WINDOW_S = new Float32Array([ + 0.130526192, 0.382683432, + 0.608761429, 0.793353340, + 0.923879533, 0.991444861, + 0.991444861, 0.923879533, + 0.793353340, 0.608761429, + 0.382683432, 0.130526192 +]); + +/* + * coefficients for intensity stereo processing + * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3 + * + * is_ratio[i] = tan(i * (PI / 12)) + * IS_TABLE[i] = is_ratio[i] / (1 + is_ratio[i]) + */ +exports.IS_TABLE = new Float32Array([ + 0.000000000, + 0.211324865, + 0.366025404, + 0.500000000, + 0.633974596, + 0.788675135, + 1.000000000 +]); + +/* + * coefficients for LSF intensity stereo processing + * derived from section 2.4.3.2 of ISO/IEC 13818-3 + * + * IS_LSF_TABLE[0][i] = (1 / sqrt(sqrt(2)))^(i + 1) + * IS_LSF_TABLE[1][i] = (1 / sqrt(2)) ^(i + 1) + */ +exports.IS_LSF_TABLE = [ + new Float32Array([ + 0.840896415, + 0.707106781, + 0.594603558, + 0.500000000, + 0.420448208, + 0.353553391, + 0.297301779, + 0.250000000, + 0.210224104, + 0.176776695, + 0.148650889, + 0.125000000, + 0.105112052, + 0.088388348, + 0.074325445 + ]), + new Float32Array([ + 0.707106781, + 0.500000000, + 0.353553391, + 0.250000000, + 0.176776695, + 0.125000000, + 0.088388348, + 0.062500000, + 0.044194174, + 0.031250000, + 0.022097087, + 0.015625000, + 0.011048543, + 0.007812500, + 0.005524272 + ]) +]; + +/* + * scalefactor bit lengths + * derived from section 2.4.2.7 of ISO/IEC 11172-3 + */ +exports.SFLEN_TABLE = [ + { slen1: 0, slen2: 0 }, { slen1: 0, slen2: 1 }, { slen1: 0, slen2: 2 }, { slen1: 0, slen2: 3 }, + { slen1: 3, slen2: 0 }, { slen1: 1, slen2: 1 }, { slen1: 1, slen2: 2 }, { slen1: 1, slen2: 3 }, + { slen1: 2, slen2: 1 }, { slen1: 2, slen2: 2 }, { slen1: 2, slen2: 3 }, { slen1: 3, slen2: 1 }, + { slen1: 3, slen2: 2 }, { slen1: 3, slen2: 3 }, { slen1: 4, slen2: 2 }, { slen1: 4, slen2: 3 } +]; + +/* + * number of LSF scalefactor band values + * derived from section 2.4.3.2 of ISO/IEC 13818-3 + */ +exports.NSFB_TABLE = [ + [ [ 6, 5, 5, 5 ], + [ 9, 9, 9, 9 ], + [ 6, 9, 9, 9 ] ], + + [ [ 6, 5, 7, 3 ], + [ 9, 9, 12, 6 ], + [ 6, 9, 12, 6 ] ], + + [ [ 11, 10, 0, 0 ], + [ 18, 18, 0, 0 ], + [ 15, 18, 0, 0 ] ], + + [ [ 7, 7, 7, 0 ], + [ 12, 12, 12, 0 ], + [ 6, 15, 12, 0 ] ], + + [ [ 6, 6, 6, 3 ], + [ 12, 9, 9, 6 ], + [ 6, 12, 9, 6 ] ], + + [ [ 8, 8, 5, 0 ], + [ 15, 12, 9, 0 ], + [ 6, 18, 9, 0 ] ] +]; + +},{}],15:[function(require,module,exports){ +/** + * Makes a multidimensional array + */ +exports.makeArray = function(lengths, Type) { + if (!Type) Type = Float64Array; + + if (lengths.length === 1) { + return new Type(lengths[0]); + } + + var ret = [], + len = lengths[0]; + + for (var j = 0; j < len; j++) { + ret[j] = exports.makeArray(lengths.slice(1), Type); + } + + return ret; +}; + +},{}]},{},[1]) + + +//# sourceMappingURL=mp3.js.map \ No newline at end of file diff --git a/gns3server/static/web-ui/assets/xpra-html5/js/lib/brotli_decode.js b/gns3server/static/web-ui/assets/xpra-html5/js/lib/brotli_decode.js new file mode 100644 index 000000000..019e9a37b --- /dev/null +++ b/gns3server/static/web-ui/assets/xpra-html5/js/lib/brotli_decode.js @@ -0,0 +1,1711 @@ +/* Copyright 2017 Google Inc. All Rights Reserved. + + Distributed under MIT license. + See file LICENSE for detail or copy at https://opensource.org/licenses/MIT +*/ + +/** @export */ +var BrotliDecode = (function() { + "use strict"; + + /** @type {!Int8Array} */ + var DICTIONARY_DATA = new Int8Array(0); + + /** + * @constructor + * @param {!Int8Array} bytes + * @struct + */ + function InputStream(bytes) { + /** @type {!Int8Array} */ + this.data = bytes; + /** @type {!number} */ + this.offset = 0; + } + var CODE_LENGTH_CODE_ORDER = Int32Array.from([1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15]); + var DISTANCE_SHORT_CODE_INDEX_OFFSET = Int32Array.from([3, 2, 1, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2]); + var DISTANCE_SHORT_CODE_VALUE_OFFSET = Int32Array.from([0, 0, 0, 0, -1, 1, -2, 2, -3, 3, -1, 1, -2, 2, -3, 3]); + var FIXED_TABLE = Int32Array.from([0x020000, 0x020004, 0x020003, 0x030002, 0x020000, 0x020004, 0x020003, 0x040001, 0x020000, 0x020004, 0x020003, 0x030002, 0x020000, 0x020004, 0x020003, 0x040005]); + var DICTIONARY_OFFSETS_BY_LENGTH = Int32Array.from([0, 0, 0, 0, 0, 4096, 9216, 21504, 35840, 44032, 53248, 63488, 74752, 87040, 93696, 100864, 104704, 106752, 108928, 113536, 115968, 118528, 119872, 121280, 122016]); + var DICTIONARY_SIZE_BITS_BY_LENGTH = Int32Array.from([0, 0, 0, 0, 10, 10, 11, 11, 10, 10, 10, 10, 10, 9, 9, 8, 7, 7, 8, 7, 7, 6, 6, 5, 5]); + var BLOCK_LENGTH_OFFSET = Int32Array.from([1, 5, 9, 13, 17, 25, 33, 41, 49, 65, 81, 97, 113, 145, 177, 209, 241, 305, 369, 497, 753, 1265, 2289, 4337, 8433, 16625]); + var BLOCK_LENGTH_N_BITS = Int32Array.from([2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 24]); + var INSERT_LENGTH_OFFSET = Int32Array.from([0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594]); + var INSERT_LENGTH_N_BITS = Int32Array.from([0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 12, 14, 24]); + var COPY_LENGTH_OFFSET = Int32Array.from([2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30, 38, 54, 70, 102, 134, 198, 326, 582, 1094, 2118]); + var COPY_LENGTH_N_BITS = Int32Array.from([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 24]); + var INSERT_RANGE_LUT = Int32Array.from([0, 0, 8, 8, 0, 16, 8, 16, 16]); + var COPY_RANGE_LUT = Int32Array.from([0, 8, 0, 8, 16, 0, 16, 8, 16]); + /** + * @param {!State} s + * @return {!number} + */ + function decodeWindowBits(s) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + if (readFewBits(s, 1) == 0) { + return 16; + } + var /** !number */ n = readFewBits(s, 3); + if (n != 0) { + return 17 + n; + } + n = readFewBits(s, 3); + if (n != 0) { + return 8 + n; + } + return 17; + } + /** + * @param {!State} s + * @param {!InputStream} input + * @return {!void} + */ + function initState(s, input) { + if (s.runningState != 0) { + throw "State MUST be uninitialized"; + } + s.blockTrees = new Int32Array(6480); + s.input = input; + initBitReader(s); + var /** !number */ windowBits = decodeWindowBits(s); + if (windowBits == 9) { + throw "Invalid 'windowBits' code"; + } + s.maxRingBufferSize = 1 << windowBits; + s.maxBackwardDistance = s.maxRingBufferSize - 16; + s.runningState = 1; + } + /** + * @param {!State} s + * @return {!void} + */ + function close(s) { + if (s.runningState == 0) { + throw "State MUST be initialized"; + } + if (s.runningState == 11) { + return; + } + s.runningState = 11; + if (s.input != null) { + closeInput(s.input); + s.input = null; + } + } + /** + * @param {!State} s + * @return {!number} + */ + function decodeVarLenUnsignedByte(s) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + if (readFewBits(s, 1) != 0) { + var /** !number */ n = readFewBits(s, 3); + if (n == 0) { + return 1; + } else { + return readFewBits(s, n) + (1 << n); + } + } + return 0; + } + /** + * @param {!State} s + * @return {!void} + */ + function decodeMetaBlockLength(s) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + s.inputEnd = readFewBits(s, 1); + s.metaBlockLength = 0; + s.isUncompressed = 0; + s.isMetadata = 0; + if ((s.inputEnd != 0) && readFewBits(s, 1) != 0) { + return; + } + var /** !number */ sizeNibbles = readFewBits(s, 2) + 4; + if (sizeNibbles == 7) { + s.isMetadata = 1; + if (readFewBits(s, 1) != 0) { + throw "Corrupted reserved bit"; + } + var /** !number */ sizeBytes = readFewBits(s, 2); + if (sizeBytes == 0) { + return; + } + for (var /** !number */ i = 0; i < sizeBytes; i++) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ bits = readFewBits(s, 8); + if (bits == 0 && i + 1 == sizeBytes && sizeBytes > 1) { + throw "Exuberant nibble"; + } + s.metaBlockLength |= bits << (i * 8); + } + } else { + for (var /** !number */ i = 0; i < sizeNibbles; i++) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ bits = readFewBits(s, 4); + if (bits == 0 && i + 1 == sizeNibbles && sizeNibbles > 4) { + throw "Exuberant nibble"; + } + s.metaBlockLength |= bits << (i * 4); + } + } + s.metaBlockLength++; + if (s.inputEnd == 0) { + s.isUncompressed = readFewBits(s, 1); + } + } + /** + * @param {!Int32Array} table + * @param {!number} offset + * @param {!State} s + * @return {!number} + */ + function readSymbol(table, offset, s) { + var /** !number */ val = (s.accumulator32 >>> s.bitOffset); + offset += val & 0xFF; + var /** !number */ bits = table[offset] >> 16; + var /** !number */ sym = table[offset] & 0xFFFF; + if (bits <= 8) { + s.bitOffset += bits; + return sym; + } + offset += sym; + var /** !number */ mask = (1 << bits) - 1; + offset += (val & mask) >>> 8; + s.bitOffset += ((table[offset] >> 16) + 8); + return table[offset] & 0xFFFF; + } + /** + * @param {!Int32Array} table + * @param {!number} offset + * @param {!State} s + * @return {!number} + */ + function readBlockLength(table, offset, s) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ code = readSymbol(table, offset, s); + var /** !number */ n = BLOCK_LENGTH_N_BITS[code]; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + return BLOCK_LENGTH_OFFSET[code] + ((n <= 16) ? readFewBits(s, n) : readManyBits(s, n)); + } + /** + * @param {!number} code + * @param {!Int32Array} ringBuffer + * @param {!number} index + * @return {!number} + */ + function translateShortCodes(code, ringBuffer, index) { + if (code < 16) { + index += DISTANCE_SHORT_CODE_INDEX_OFFSET[code]; + index &= 3; + return ringBuffer[index] + DISTANCE_SHORT_CODE_VALUE_OFFSET[code]; + } + return code - 16 + 1; + } + /** + * @param {!Int32Array} v + * @param {!number} index + * @return {!void} + */ + function moveToFront(v, index) { + var /** !number */ value = v[index]; + for (; index > 0; index--) { + v[index] = v[index - 1]; + } + v[0] = value; + } + /** + * @param {!Int8Array} v + * @param {!number} vLen + * @return {!void} + */ + function inverseMoveToFrontTransform(v, vLen) { + var /** !Int32Array */ mtf = new Int32Array(256); + for (var /** !number */ i = 0; i < 256; i++) { + mtf[i] = i; + } + for (var /** !number */ i = 0; i < vLen; i++) { + var /** !number */ index = v[i] & 0xFF; + v[i] = mtf[index]; + if (index != 0) { + moveToFront(mtf, index); + } + } + } + /** + * @param {!Int32Array} codeLengthCodeLengths + * @param {!number} numSymbols + * @param {!Int32Array} codeLengths + * @param {!State} s + * @return {!void} + */ + function readHuffmanCodeLengths(codeLengthCodeLengths, numSymbols, codeLengths, s) { + var /** !number */ symbol = 0; + var /** !number */ prevCodeLen = 8; + var /** !number */ repeat = 0; + var /** !number */ repeatCodeLen = 0; + var /** !number */ space = 32768; + var /** !Int32Array */ table = new Int32Array(32); + buildHuffmanTable(table, 0, 5, codeLengthCodeLengths, 18); + while (symbol < numSymbols && space > 0) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ p = (s.accumulator32 >>> s.bitOffset) & 31; + s.bitOffset += table[p] >> 16; + var /** !number */ codeLen = table[p] & 0xFFFF; + if (codeLen < 16) { + repeat = 0; + codeLengths[symbol++] = codeLen; + if (codeLen != 0) { + prevCodeLen = codeLen; + space -= 32768 >> codeLen; + } + } else { + var /** !number */ extraBits = codeLen - 14; + var /** !number */ newLen = 0; + if (codeLen == 16) { + newLen = prevCodeLen; + } + if (repeatCodeLen != newLen) { + repeat = 0; + repeatCodeLen = newLen; + } + var /** !number */ oldRepeat = repeat; + if (repeat > 0) { + repeat -= 2; + repeat <<= extraBits; + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + repeat += readFewBits(s, extraBits) + 3; + var /** !number */ repeatDelta = repeat - oldRepeat; + if (symbol + repeatDelta > numSymbols) { + throw "symbol + repeatDelta > numSymbols"; + } + for (var /** !number */ i = 0; i < repeatDelta; i++) { + codeLengths[symbol++] = repeatCodeLen; + } + if (repeatCodeLen != 0) { + space -= repeatDelta << (15 - repeatCodeLen); + } + } + } + if (space != 0) { + throw "Unused space"; + } + codeLengths.fill(0, symbol, numSymbols); + } + /** + * @param {!Int32Array} symbols + * @param {!number} length + * @return {!number} + */ + function checkDupes(symbols, length) { + for (var /** !number */ i = 0; i < length - 1; ++i) { + for (var /** !number */ j = i + 1; j < length; ++j) { + if (symbols[i] == symbols[j]) { + return 0; + } + } + } + return 1; + } + /** + * @param {!number} alphabetSize + * @param {!Int32Array} table + * @param {!number} offset + * @param {!State} s + * @return {!void} + */ + function readHuffmanCode(alphabetSize, table, offset, s) { + var /** !number */ ok = 1; + var /** !number */ simpleCodeOrSkip; + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + var /** !Int32Array */ codeLengths = new Int32Array(alphabetSize); + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + simpleCodeOrSkip = readFewBits(s, 2); + if (simpleCodeOrSkip == 1) { + var /** !number */ maxBitsCounter = alphabetSize - 1; + var /** !number */ maxBits = 0; + var /** !Int32Array */ symbols = new Int32Array(4); + var /** !number */ numSymbols = readFewBits(s, 2) + 1; + while (maxBitsCounter != 0) { + maxBitsCounter >>= 1; + maxBits++; + } + for (var /** !number */ i = 0; i < numSymbols; i++) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + symbols[i] = readFewBits(s, maxBits) % alphabetSize; + codeLengths[symbols[i]] = 2; + } + codeLengths[symbols[0]] = 1; + switch(numSymbols) { + case 2: + codeLengths[symbols[1]] = 1; + break; + case 4: + if (readFewBits(s, 1) == 1) { + codeLengths[symbols[2]] = 3; + codeLengths[symbols[3]] = 3; + } else { + codeLengths[symbols[0]] = 2; + } + break; + default: + break; + } + ok = checkDupes(symbols, numSymbols); + } else { + var /** !Int32Array */ codeLengthCodeLengths = new Int32Array(18); + var /** !number */ space = 32; + var /** !number */ numCodes = 0; + for (var /** !number */ i = simpleCodeOrSkip; i < 18 && space > 0; i++) { + var /** !number */ codeLenIdx = CODE_LENGTH_CODE_ORDER[i]; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ p = (s.accumulator32 >>> s.bitOffset) & 15; + s.bitOffset += FIXED_TABLE[p] >> 16; + var /** !number */ v = FIXED_TABLE[p] & 0xFFFF; + codeLengthCodeLengths[codeLenIdx] = v; + if (v != 0) { + space -= (32 >> v); + numCodes++; + } + } + if (space != 0 && numCodes != 1) { + ok = 0; + } + readHuffmanCodeLengths(codeLengthCodeLengths, alphabetSize, codeLengths, s); + } + if (ok == 0) { + throw "Can't readHuffmanCode"; + } + buildHuffmanTable(table, offset, 8, codeLengths, alphabetSize); + } + /** + * @param {!number} contextMapSize + * @param {!Int8Array} contextMap + * @param {!State} s + * @return {!number} + */ + function decodeContextMap(contextMapSize, contextMap, s) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + var /** !number */ numTrees = decodeVarLenUnsignedByte(s) + 1; + if (numTrees == 1) { + contextMap.fill(0, 0, contextMapSize); + return numTrees; + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ useRleForZeros = readFewBits(s, 1); + var /** !number */ maxRunLengthPrefix = 0; + if (useRleForZeros != 0) { + maxRunLengthPrefix = readFewBits(s, 4) + 1; + } + var /** !Int32Array */ table = new Int32Array(1080); + readHuffmanCode(numTrees + maxRunLengthPrefix, table, 0, s); + for (var /** !number */ i = 0; i < contextMapSize; ) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ code = readSymbol(table, 0, s); + if (code == 0) { + contextMap[i] = 0; + i++; + } else if (code <= maxRunLengthPrefix) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ reps = (1 << code) + readFewBits(s, code); + while (reps != 0) { + if (i >= contextMapSize) { + throw "Corrupted context map"; + } + contextMap[i] = 0; + i++; + reps--; + } + } else { + contextMap[i] = (code - maxRunLengthPrefix); + i++; + } + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + if (readFewBits(s, 1) == 1) { + inverseMoveToFrontTransform(contextMap, contextMapSize); + } + return numTrees; + } + /** + * @param {!State} s + * @param {!number} treeType + * @param {!number} numBlockTypes + * @return {!number} + */ + function decodeBlockTypeAndLength(s, treeType, numBlockTypes) { + var /** !Int32Array */ ringBuffers = s.rings; + var /** !number */ offset = 4 + treeType * 2; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ blockType = readSymbol(s.blockTrees, treeType * 1080, s); + var /** !number */ result = readBlockLength(s.blockTrees, (treeType + 3) * 1080, s); + if (blockType == 1) { + blockType = ringBuffers[offset + 1] + 1; + } else if (blockType == 0) { + blockType = ringBuffers[offset]; + } else { + blockType -= 2; + } + if (blockType >= numBlockTypes) { + blockType -= numBlockTypes; + } + ringBuffers[offset] = ringBuffers[offset + 1]; + ringBuffers[offset + 1] = blockType; + return result; + } + /** + * @param {!State} s + * @return {!void} + */ + function decodeLiteralBlockSwitch(s) { + s.literalBlockLength = decodeBlockTypeAndLength(s, 0, s.numLiteralBlockTypes); + var /** !number */ literalBlockType = s.rings[5]; + s.contextMapSlice = literalBlockType << 6; + s.literalTreeIndex = s.contextMap[s.contextMapSlice] & 0xFF; + s.literalTree = s.hGroup0[s.literalTreeIndex]; + var /** !number */ contextMode = s.contextModes[literalBlockType]; + s.contextLookupOffset1 = contextMode << 9; + s.contextLookupOffset2 = s.contextLookupOffset1 + 256; + } + /** + * @param {!State} s + * @return {!void} + */ + function decodeCommandBlockSwitch(s) { + s.commandBlockLength = decodeBlockTypeAndLength(s, 1, s.numCommandBlockTypes); + s.treeCommandOffset = s.hGroup1[s.rings[7]]; + } + /** + * @param {!State} s + * @return {!void} + */ + function decodeDistanceBlockSwitch(s) { + s.distanceBlockLength = decodeBlockTypeAndLength(s, 2, s.numDistanceBlockTypes); + s.distContextMapSlice = s.rings[9] << 2; + } + /** + * @param {!State} s + * @return {!void} + */ + function maybeReallocateRingBuffer(s) { + var /** !number */ newSize = s.maxRingBufferSize; + if (newSize > s.expectedTotalSize) { + var /** !number */ minimalNewSize = s.expectedTotalSize; + while ((newSize >> 1) > minimalNewSize) { + newSize >>= 1; + } + if ((s.inputEnd == 0) && newSize < 16384 && s.maxRingBufferSize >= 16384) { + newSize = 16384; + } + } + if (newSize <= s.ringBufferSize) { + return; + } + var /** !number */ ringBufferSizeWithSlack = newSize + 37; + var /** !Int8Array */ newBuffer = new Int8Array(ringBufferSizeWithSlack); + if (s.ringBuffer.length != 0) { + newBuffer.set(s.ringBuffer.subarray(0, 0 + s.ringBufferSize), 0); + } + s.ringBuffer = newBuffer; + s.ringBufferSize = newSize; + } + /** + * @param {!State} s + * @return {!void} + */ + function readNextMetablockHeader(s) { + if (s.inputEnd != 0) { + s.nextRunningState = 10; + s.bytesToWrite = s.pos; + s.bytesWritten = 0; + s.runningState = 12; + return; + } + s.hGroup0 = new Int32Array(0); + s.hGroup1 = new Int32Array(0); + s.hGroup2 = new Int32Array(0); + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + decodeMetaBlockLength(s); + if ((s.metaBlockLength == 0) && (s.isMetadata == 0)) { + return; + } + if ((s.isUncompressed != 0) || (s.isMetadata != 0)) { + jumpToByteBoundary(s); + s.runningState = (s.isMetadata != 0) ? 4 : 5; + } else { + s.runningState = 2; + } + if (s.isMetadata != 0) { + return; + } + s.expectedTotalSize += s.metaBlockLength; + if (s.expectedTotalSize > 1 << 30) { + s.expectedTotalSize = 1 << 30; + } + if (s.ringBufferSize < s.maxRingBufferSize) { + maybeReallocateRingBuffer(s); + } + } + /** + * @param {!State} s + * @param {!number} treeType + * @param {!number} numBlockTypes + * @return {!number} + */ + function readMetablockPartition(s, treeType, numBlockTypes) { + if (numBlockTypes <= 1) { + return 1 << 28; + } + readHuffmanCode(numBlockTypes + 2, s.blockTrees, treeType * 1080, s); + readHuffmanCode(26, s.blockTrees, (treeType + 3) * 1080, s); + return readBlockLength(s.blockTrees, (treeType + 3) * 1080, s); + } + /** + * @param {!State} s + * @return {!void} + */ + function readMetablockHuffmanCodesAndContextMaps(s) { + s.numLiteralBlockTypes = decodeVarLenUnsignedByte(s) + 1; + s.literalBlockLength = readMetablockPartition(s, 0, s.numLiteralBlockTypes); + s.numCommandBlockTypes = decodeVarLenUnsignedByte(s) + 1; + s.commandBlockLength = readMetablockPartition(s, 1, s.numCommandBlockTypes); + s.numDistanceBlockTypes = decodeVarLenUnsignedByte(s) + 1; + s.distanceBlockLength = readMetablockPartition(s, 2, s.numDistanceBlockTypes); + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + s.distancePostfixBits = readFewBits(s, 2); + s.numDirectDistanceCodes = 16 + (readFewBits(s, 4) << s.distancePostfixBits); + s.distancePostfixMask = (1 << s.distancePostfixBits) - 1; + var /** !number */ numDistanceCodes = s.numDirectDistanceCodes + (48 << s.distancePostfixBits); + s.contextModes = new Int8Array(s.numLiteralBlockTypes); + for (var /** !number */ i = 0; i < s.numLiteralBlockTypes; ) { + var /** !number */ limit = min(i + 96, s.numLiteralBlockTypes); + for (; i < limit; ++i) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + s.contextModes[i] = (readFewBits(s, 2)); + } + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + } + s.contextMap = new Int8Array(s.numLiteralBlockTypes << 6); + var /** !number */ numLiteralTrees = decodeContextMap(s.numLiteralBlockTypes << 6, s.contextMap, s); + s.trivialLiteralContext = 1; + for (var /** !number */ j = 0; j < s.numLiteralBlockTypes << 6; j++) { + if (s.contextMap[j] != j >> 6) { + s.trivialLiteralContext = 0; + break; + } + } + s.distContextMap = new Int8Array(s.numDistanceBlockTypes << 2); + var /** !number */ numDistTrees = decodeContextMap(s.numDistanceBlockTypes << 2, s.distContextMap, s); + s.hGroup0 = decodeHuffmanTreeGroup(256, numLiteralTrees, s); + s.hGroup1 = decodeHuffmanTreeGroup(704, s.numCommandBlockTypes, s); + s.hGroup2 = decodeHuffmanTreeGroup(numDistanceCodes, numDistTrees, s); + s.contextMapSlice = 0; + s.distContextMapSlice = 0; + s.contextLookupOffset1 = (s.contextModes[0]) << 9; + s.contextLookupOffset2 = s.contextLookupOffset1 + 256; + s.literalTreeIndex = 0; + s.literalTree = s.hGroup0[0]; + s.treeCommandOffset = s.hGroup1[0]; + s.rings[4] = 1; + s.rings[5] = 0; + s.rings[6] = 1; + s.rings[7] = 0; + s.rings[8] = 1; + s.rings[9] = 0; + } + /** + * @param {!State} s + * @return {!void} + */ + function copyUncompressedData(s) { + var /** !Int8Array */ ringBuffer = s.ringBuffer; + if (s.metaBlockLength <= 0) { + reload(s); + s.runningState = 1; + return; + } + var /** !number */ chunkLength = min(s.ringBufferSize - s.pos, s.metaBlockLength); + copyBytes(s, ringBuffer, s.pos, chunkLength); + s.metaBlockLength -= chunkLength; + s.pos += chunkLength; + if (s.pos == s.ringBufferSize) { + s.nextRunningState = 5; + s.bytesToWrite = s.ringBufferSize; + s.bytesWritten = 0; + s.runningState = 12; + return; + } + reload(s); + s.runningState = 1; + } + /** + * @param {!State} s + * @return {!number} + */ + function writeRingBuffer(s) { + var /** !number */ toWrite = min(s.outputLength - s.outputUsed, s.bytesToWrite - s.bytesWritten); + if (toWrite != 0) { + s.output.set(s.ringBuffer.subarray(s.bytesWritten, s.bytesWritten + toWrite), s.outputOffset + s.outputUsed); + s.outputUsed += toWrite; + s.bytesWritten += toWrite; + } + if (s.outputUsed < s.outputLength) { + return 1; + } else { + return 0; + } + } + /** + * @param {!number} alphabetSize + * @param {!number} n + * @param {!State} s + * @return {!Int32Array} + */ + function decodeHuffmanTreeGroup(alphabetSize, n, s) { + var /** !Int32Array */ group = new Int32Array(n + (n * 1080)); + var /** !number */ next = n; + for (var /** !number */ i = 0; i < n; i++) { + group[i] = next; + readHuffmanCode(alphabetSize, group, next, s); + next += 1080; + } + return group; + } + /** + * @param {!State} s + * @return {!void} + */ + function decompress(s) { + if (s.runningState == 0) { + throw "Can't decompress until initialized"; + } + if (s.runningState == 11) { + throw "Can't decompress after close"; + } + var /** !number */ ringBufferMask = s.ringBufferSize - 1; + var /** !Int8Array */ ringBuffer = s.ringBuffer; + while (s.runningState != 10) { + switch(s.runningState) { + case 1: + if (s.metaBlockLength < 0) { + throw "Invalid metablock length"; + } + readNextMetablockHeader(s); + ringBufferMask = s.ringBufferSize - 1; + ringBuffer = s.ringBuffer; + continue; + case 2: + readMetablockHuffmanCodesAndContextMaps(s); + s.runningState = 3; + case 3: + if (s.metaBlockLength <= 0) { + s.runningState = 1; + continue; + } + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.commandBlockLength == 0) { + decodeCommandBlockSwitch(s); + } + s.commandBlockLength--; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ cmdCode = readSymbol(s.hGroup1, s.treeCommandOffset, s); + var /** !number */ rangeIdx = cmdCode >>> 6; + s.distanceCode = 0; + if (rangeIdx >= 2) { + rangeIdx -= 2; + s.distanceCode = -1; + } + var /** !number */ insertCode = INSERT_RANGE_LUT[rangeIdx] + ((cmdCode >>> 3) & 7); + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ insertBits = INSERT_LENGTH_N_BITS[insertCode]; + var /** !number */ insertExtra = ((insertBits <= 16) ? readFewBits(s, insertBits) : readManyBits(s, insertBits)); + s.insertLength = INSERT_LENGTH_OFFSET[insertCode] + insertExtra; + var /** !number */ copyCode = COPY_RANGE_LUT[rangeIdx] + (cmdCode & 7); + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ copyBits = COPY_LENGTH_N_BITS[copyCode]; + var /** !number */ copyExtra = ((copyBits <= 16) ? readFewBits(s, copyBits) : readManyBits(s, copyBits)); + s.copyLength = COPY_LENGTH_OFFSET[copyCode] + copyExtra; + s.j = 0; + s.runningState = 6; + case 6: + if (s.trivialLiteralContext != 0) { + while (s.j < s.insertLength) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.literalBlockLength == 0) { + decodeLiteralBlockSwitch(s); + } + s.literalBlockLength--; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + ringBuffer[s.pos] = readSymbol(s.hGroup0, s.literalTree, s); + s.j++; + if (s.pos++ == ringBufferMask) { + s.nextRunningState = 6; + s.bytesToWrite = s.ringBufferSize; + s.bytesWritten = 0; + s.runningState = 12; + break; + } + } + } else { + var /** !number */ prevByte1 = ringBuffer[(s.pos - 1) & ringBufferMask] & 0xFF; + var /** !number */ prevByte2 = ringBuffer[(s.pos - 2) & ringBufferMask] & 0xFF; + while (s.j < s.insertLength) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.literalBlockLength == 0) { + decodeLiteralBlockSwitch(s); + } + var /** !number */ literalTreeIndex = s.contextMap[s.contextMapSlice + (LOOKUP[s.contextLookupOffset1 + prevByte1] | LOOKUP[s.contextLookupOffset2 + prevByte2])] & 0xFF; + s.literalBlockLength--; + prevByte2 = prevByte1; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + prevByte1 = readSymbol(s.hGroup0, s.hGroup0[literalTreeIndex], s); + ringBuffer[s.pos] = prevByte1; + s.j++; + if (s.pos++ == ringBufferMask) { + s.nextRunningState = 6; + s.bytesToWrite = s.ringBufferSize; + s.bytesWritten = 0; + s.runningState = 12; + break; + } + } + } + if (s.runningState != 6) { + continue; + } + s.metaBlockLength -= s.insertLength; + if (s.metaBlockLength <= 0) { + s.runningState = 3; + continue; + } + if (s.distanceCode < 0) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.distanceBlockLength == 0) { + decodeDistanceBlockSwitch(s); + } + s.distanceBlockLength--; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + s.distanceCode = readSymbol(s.hGroup2, s.hGroup2[s.distContextMap[s.distContextMapSlice + (s.copyLength > 4 ? 3 : s.copyLength - 2)] & 0xFF], s); + if (s.distanceCode >= s.numDirectDistanceCodes) { + s.distanceCode -= s.numDirectDistanceCodes; + var /** !number */ postfix = s.distanceCode & s.distancePostfixMask; + s.distanceCode >>>= s.distancePostfixBits; + var /** !number */ n = (s.distanceCode >>> 1) + 1; + var /** !number */ offset = ((2 + (s.distanceCode & 1)) << n) - 4; + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + var /** !number */ distanceExtra = ((n <= 16) ? readFewBits(s, n) : readManyBits(s, n)); + s.distanceCode = s.numDirectDistanceCodes + postfix + ((offset + distanceExtra) << s.distancePostfixBits); + } + } + s.distance = translateShortCodes(s.distanceCode, s.rings, s.distRbIdx); + if (s.distance < 0) { + throw "Negative distance"; + } + if (s.maxDistance != s.maxBackwardDistance && s.pos < s.maxBackwardDistance) { + s.maxDistance = s.pos; + } else { + s.maxDistance = s.maxBackwardDistance; + } + s.copyDst = s.pos; + if (s.distance > s.maxDistance) { + s.runningState = 9; + continue; + } + if (s.distanceCode > 0) { + s.rings[s.distRbIdx & 3] = s.distance; + s.distRbIdx++; + } + if (s.copyLength > s.metaBlockLength) { + throw "Invalid backward reference"; + } + s.j = 0; + s.runningState = 7; + case 7: + var /** !number */ src = (s.pos - s.distance) & ringBufferMask; + var /** !number */ dst = s.pos; + var /** !number */ copyLength = s.copyLength - s.j; + var /** !number */ srcEnd = src + copyLength; + var /** !number */ dstEnd = dst + copyLength; + if ((srcEnd < ringBufferMask) && (dstEnd < ringBufferMask)) { + if (copyLength < 12 || (srcEnd > dst && dstEnd > src)) { + for (var /** !number */ k = 0; k < copyLength; k += 4) { + ringBuffer[dst++] = ringBuffer[src++]; + ringBuffer[dst++] = ringBuffer[src++]; + ringBuffer[dst++] = ringBuffer[src++]; + ringBuffer[dst++] = ringBuffer[src++]; + } + } else { + ringBuffer.copyWithin(dst, src, srcEnd); + } + s.j += copyLength; + s.metaBlockLength -= copyLength; + s.pos += copyLength; + } else { + for (; s.j < s.copyLength; ) { + ringBuffer[s.pos] = ringBuffer[(s.pos - s.distance) & ringBufferMask]; + s.metaBlockLength--; + s.j++; + if (s.pos++ == ringBufferMask) { + s.nextRunningState = 7; + s.bytesToWrite = s.ringBufferSize; + s.bytesWritten = 0; + s.runningState = 12; + break; + } + } + } + if (s.runningState == 7) { + s.runningState = 3; + } + continue; + case 9: + if (s.copyLength >= 4 && s.copyLength <= 24) { + var /** !number */ offset = DICTIONARY_OFFSETS_BY_LENGTH[s.copyLength]; + var /** !number */ wordId = s.distance - s.maxDistance - 1; + var /** !number */ shift = DICTIONARY_SIZE_BITS_BY_LENGTH[s.copyLength]; + var /** !number */ mask = (1 << shift) - 1; + var /** !number */ wordIdx = wordId & mask; + var /** !number */ transformIdx = wordId >>> shift; + offset += wordIdx * s.copyLength; + if (transformIdx < 121) { + var /** !number */ len = transformDictionaryWord(ringBuffer, s.copyDst, DICTIONARY_DATA, offset, s.copyLength, transformIdx); + s.copyDst += len; + s.pos += len; + s.metaBlockLength -= len; + if (s.copyDst >= s.ringBufferSize) { + s.nextRunningState = 8; + s.bytesToWrite = s.ringBufferSize; + s.bytesWritten = 0; + s.runningState = 12; + continue; + } + } else { + throw "Invalid backward reference"; + } + } else { + throw "Invalid backward reference"; + } + s.runningState = 3; + continue; + case 8: + ringBuffer.copyWithin(0, s.ringBufferSize, s.copyDst); + s.runningState = 3; + continue; + case 4: + while (s.metaBlockLength > 0) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + readFewBits(s, 8); + s.metaBlockLength--; + } + s.runningState = 1; + continue; + case 5: + copyUncompressedData(s); + continue; + case 12: + if (writeRingBuffer(s) == 0) { + return; + } + if (s.pos >= s.maxBackwardDistance) { + s.maxDistance = s.maxBackwardDistance; + } + s.pos &= ringBufferMask; + s.runningState = s.nextRunningState; + continue; + default: + throw "Unexpected state " + s.runningState; + } + } + if (s.runningState == 10) { + if (s.metaBlockLength < 0) { + throw "Invalid metablock length"; + } + jumpToByteBoundary(s); + checkHealth(s, 1); + } + } + + var TRANSFORMS = new Int32Array(363); + var PREFIX_SUFFIX = new Int8Array(217); + var PREFIX_SUFFIX_HEADS = new Int32Array(51); + /** + * @param {!Int8Array} prefixSuffix + * @param {!Int32Array} prefixSuffixHeads + * @param {!Int32Array} transforms + * @param {!string} prefixSuffixSrc + * @param {!string} transformsSrc + * @return {!void} + */ + function unpackTransforms(prefixSuffix, prefixSuffixHeads, transforms, prefixSuffixSrc, transformsSrc) { + var /** !number */ n = prefixSuffixSrc.length; + var /** !number */ index = 1; + for (var /** !number */ i = 0; i < n; ++i) { + var /** !number */ c = prefixSuffixSrc.charCodeAt(i); + prefixSuffix[i] = c; + if (c == 35) { + prefixSuffixHeads[index++] = i + 1; + prefixSuffix[i] = 0; + } + } + for (var /** !number */ i = 0; i < 363; ++i) { + transforms[i] = transformsSrc.charCodeAt(i) - 32; + } + } + { + unpackTransforms(PREFIX_SUFFIX, PREFIX_SUFFIX_HEADS, TRANSFORMS, "# #s #, #e #.# the #.com/#\u00C2\u00A0# of # and # in # to #\"#\">#\n#]# for # a # that #. # with #'# from # by #. The # on # as # is #ing #\n\t#:#ed #(# at #ly #=\"# of the #. This #,# not #er #al #='#ful #ive #less #est #ize #ous #", " !! ! , *! &! \" ! ) * * - ! # ! #!*! + ,$ ! - % . / # 0 1 . \" 2 3!* 4% ! # / 5 6 7 8 0 1 & $ 9 + : ; < ' != > ?! 4 @ 4 2 & A *# ( B C& ) % ) !*# *-% A +! *. D! %' & E *6 F G% ! *A *% H! D I!+! J!+ K +- *4! A L!*4 M N +6 O!*% +.! K *G P +%( ! G *D +D Q +# *K!*G!+D!+# +G +A +4!+% +K!+4!*D!+K!*K"); + } + /** + * @param {!Int8Array} dst + * @param {!number} dstOffset + * @param {!Int8Array} data + * @param {!number} wordOffset + * @param {!number} len + * @param {!number} transformIndex + * @return {!number} + */ + function transformDictionaryWord(dst, dstOffset, data, wordOffset, len, transformIndex) { + var /** !number */ offset = dstOffset; + var /** !number */ transformOffset = 3 * transformIndex; + var /** !number */ transformPrefix = PREFIX_SUFFIX_HEADS[TRANSFORMS[transformOffset]]; + var /** !number */ transformType = TRANSFORMS[transformOffset + 1]; + var /** !number */ transformSuffix = PREFIX_SUFFIX_HEADS[TRANSFORMS[transformOffset + 2]]; + while (PREFIX_SUFFIX[transformPrefix] != 0) { + dst[offset++] = PREFIX_SUFFIX[transformPrefix++]; + } + var /** !number */ omitFirst = transformType >= 12 ? (transformType - 11) : 0; + if (omitFirst > len) { + omitFirst = len; + } + wordOffset += omitFirst; + len -= omitFirst; + len -= transformType <= 9 ? transformType : 0; + var /** !number */ i = len; + while (i > 0) { + dst[offset++] = data[wordOffset++]; + i--; + } + if (transformType == 11 || transformType == 10) { + var /** !number */ uppercaseOffset = offset - len; + if (transformType == 10) { + len = 1; + } + while (len > 0) { + var /** !number */ tmp = dst[uppercaseOffset] & 0xFF; + if (tmp < 0xc0) { + if (tmp >= 97 && tmp <= 122) { + dst[uppercaseOffset] ^= 32; + } + uppercaseOffset += 1; + len -= 1; + } else if (tmp < 0xe0) { + dst[uppercaseOffset + 1] ^= 32; + uppercaseOffset += 2; + len -= 2; + } else { + dst[uppercaseOffset + 2] ^= 5; + uppercaseOffset += 3; + len -= 3; + } + } + } + while (PREFIX_SUFFIX[transformSuffix] != 0) { + dst[offset++] = PREFIX_SUFFIX[transformSuffix++]; + } + return offset - dstOffset; + } + + /** + * @param {!number} key + * @param {!number} len + * @return {!number} + */ + function getNextKey(key, len) { + var /** !number */ step = 1 << (len - 1); + while ((key & step) != 0) { + step >>= 1; + } + return (key & (step - 1)) + step; + } + /** + * @param {!Int32Array} table + * @param {!number} offset + * @param {!number} step + * @param {!number} end + * @param {!number} item + * @return {!void} + */ + function replicateValue(table, offset, step, end, item) { + do { + end -= step; + table[offset + end] = item; + } while (end > 0); + } + /** + * @param {!Int32Array} count + * @param {!number} len + * @param {!number} rootBits + * @return {!number} + */ + function nextTableBitSize(count, len, rootBits) { + var /** !number */ left = 1 << (len - rootBits); + while (len < 15) { + left -= count[len]; + if (left <= 0) { + break; + } + len++; + left <<= 1; + } + return len - rootBits; + } + /** + * @param {!Int32Array} rootTable + * @param {!number} tableOffset + * @param {!number} rootBits + * @param {!Int32Array} codeLengths + * @param {!number} codeLengthsSize + * @return {!void} + */ + function buildHuffmanTable(rootTable, tableOffset, rootBits, codeLengths, codeLengthsSize) { + var /** !number */ key; + var /** !Int32Array */ sorted = new Int32Array(codeLengthsSize); + var /** !Int32Array */ count = new Int32Array(16); + var /** !Int32Array */ offset = new Int32Array(16); + var /** !number */ symbol; + for (symbol = 0; symbol < codeLengthsSize; symbol++) { + count[codeLengths[symbol]]++; + } + offset[1] = 0; + for (var /** !number */ len = 1; len < 15; len++) { + offset[len + 1] = offset[len] + count[len]; + } + for (symbol = 0; symbol < codeLengthsSize; symbol++) { + if (codeLengths[symbol] != 0) { + sorted[offset[codeLengths[symbol]]++] = symbol; + } + } + var /** !number */ tableBits = rootBits; + var /** !number */ tableSize = 1 << tableBits; + var /** !number */ totalSize = tableSize; + if (offset[15] == 1) { + for (key = 0; key < totalSize; key++) { + rootTable[tableOffset + key] = sorted[0]; + } + return; + } + key = 0; + symbol = 0; + for (var /** !number */ len = 1, step = 2; len <= rootBits; len++, step <<= 1) { + for (; count[len] > 0; count[len]--) { + replicateValue(rootTable, tableOffset + key, step, tableSize, len << 16 | sorted[symbol++]); + key = getNextKey(key, len); + } + } + var /** !number */ mask = totalSize - 1; + var /** !number */ low = -1; + var /** !number */ currentOffset = tableOffset; + for (var /** !number */ len = rootBits + 1, step = 2; len <= 15; len++, step <<= 1) { + for (; count[len] > 0; count[len]--) { + if ((key & mask) != low) { + currentOffset += tableSize; + tableBits = nextTableBitSize(count, len, rootBits); + tableSize = 1 << tableBits; + totalSize += tableSize; + low = key & mask; + rootTable[tableOffset + low] = (tableBits + rootBits) << 16 | (currentOffset - tableOffset - low); + } + replicateValue(rootTable, currentOffset + (key >> rootBits), step, tableSize, (len - rootBits) << 16 | sorted[symbol++]); + key = getNextKey(key, len); + } + } + } + + /** + * @param {!State} s + * @return {!void} + */ + function doReadMoreInput(s) { + if (s.endOfStreamReached != 0) { + if (halfAvailable(s) >= -2) { + return; + } + throw "No more input"; + } + var /** !number */ readOffset = s.halfOffset << 1; + var /** !number */ bytesInBuffer = 4096 - readOffset; + s.byteBuffer.copyWithin(0, readOffset, 4096); + s.halfOffset = 0; + while (bytesInBuffer < 4096) { + var /** !number */ spaceLeft = 4096 - bytesInBuffer; + var /** !number */ len = readInput(s.input, s.byteBuffer, bytesInBuffer, spaceLeft); + if (len <= 0) { + s.endOfStreamReached = 1; + s.tailBytes = bytesInBuffer; + bytesInBuffer += 1; + break; + } + bytesInBuffer += len; + } + bytesToNibbles(s, bytesInBuffer); + } + /** + * @param {!State} s + * @param {!number} endOfStream + * @return {!void} + */ + function checkHealth(s, endOfStream) { + if (s.endOfStreamReached == 0) { + return; + } + var /** !number */ byteOffset = (s.halfOffset << 1) + ((s.bitOffset + 7) >> 3) - 4; + if (byteOffset > s.tailBytes) { + throw "Read after end"; + } + if ((endOfStream != 0) && (byteOffset != s.tailBytes)) { + throw "Unused bytes after end"; + } + } + /** + * @param {!State} s + * @param {!number} n + * @return {!number} + */ + function readFewBits(s, n) { + var /** !number */ val = (s.accumulator32 >>> s.bitOffset) & ((1 << n) - 1); + s.bitOffset += n; + return val; + } + /** + * @param {!State} s + * @param {!number} n + * @return {!number} + */ + function readManyBits(s, n) { + var /** !number */ low = readFewBits(s, 16); + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + return low | (readFewBits(s, n - 16) << 16); + } + /** + * @param {!State} s + * @return {!void} + */ + function initBitReader(s) { + s.byteBuffer = new Int8Array(4160); + s.accumulator32 = 0; + s.shortBuffer = new Int16Array(2080); + s.bitOffset = 32; + s.halfOffset = 2048; + s.endOfStreamReached = 0; + prepare(s); + } + /** + * @param {!State} s + * @return {!void} + */ + function prepare(s) { + if (s.halfOffset > 2030) { + doReadMoreInput(s); + } + checkHealth(s, 0); + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + /** + * @param {!State} s + * @return {!void} + */ + function reload(s) { + if (s.bitOffset == 32) { + prepare(s); + } + } + /** + * @param {!State} s + * @return {!void} + */ + function jumpToByteBoundary(s) { + var /** !number */ padding = (32 - s.bitOffset) & 7; + if (padding != 0) { + var /** !number */ paddingBits = readFewBits(s, padding); + if (paddingBits != 0) { + throw "Corrupted padding bits"; + } + } + } + /** + * @param {!State} s + * @return {!number} + */ + function halfAvailable(s) { + var /** !number */ limit = 2048; + if (s.endOfStreamReached != 0) { + limit = (s.tailBytes + 1) >> 1; + } + return limit - s.halfOffset; + } + /** + * @param {!State} s + * @param {!Int8Array} data + * @param {!number} offset + * @param {!number} length + * @return {!void} + */ + function copyBytes(s, data, offset, length) { + if ((s.bitOffset & 7) != 0) { + throw "Unaligned copyBytes"; + } + while ((s.bitOffset != 32) && (length != 0)) { + data[offset++] = (s.accumulator32 >>> s.bitOffset); + s.bitOffset += 8; + length--; + } + if (length == 0) { + return; + } + var /** !number */ copyNibbles = min(halfAvailable(s), length >> 1); + if (copyNibbles > 0) { + var /** !number */ readOffset = s.halfOffset << 1; + var /** !number */ delta = copyNibbles << 1; + data.set(s.byteBuffer.subarray(readOffset, readOffset + delta), offset); + offset += delta; + length -= delta; + s.halfOffset += copyNibbles; + } + if (length == 0) { + return; + } + if (halfAvailable(s) > 0) { + if (s.bitOffset >= 16) { + s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16); + s.bitOffset -= 16; + } + while (length != 0) { + data[offset++] = (s.accumulator32 >>> s.bitOffset); + s.bitOffset += 8; + length--; + } + checkHealth(s, 0); + return; + } + while (length > 0) { + var /** !number */ len = readInput(s.input, data, offset, length); + if (len == -1) { + throw "Unexpected end of input"; + } + offset += len; + length -= len; + } + } + /** + * @param {!State} s + * @param {!number} byteLen + * @return {!void} + */ + function bytesToNibbles(s, byteLen) { + var /** !Int8Array */ byteBuffer = s.byteBuffer; + var /** !number */ halfLen = byteLen >> 1; + var /** !Int16Array */ shortBuffer = s.shortBuffer; + for (var /** !number */ i = 0; i < halfLen; ++i) { + shortBuffer[i] = ((byteBuffer[i * 2] & 0xFF) | ((byteBuffer[(i * 2) + 1] & 0xFF) << 8)); + } + } + + var LOOKUP = new Int32Array(2048); + /** + * @param {!Int32Array} lookup + * @param {!string} map + * @param {!string} rle + * @return {!void} + */ + function unpackLookupTable(lookup, map, rle) { + for (var /** !number */ i = 0; i < 256; ++i) { + lookup[i] = i & 0x3F; + lookup[512 + i] = i >> 2; + lookup[1792 + i] = 2 + (i >> 6); + } + for (var /** !number */ i = 0; i < 128; ++i) { + lookup[1024 + i] = 4 * (map.charCodeAt(i) - 32); + } + for (var /** !number */ i = 0; i < 64; ++i) { + lookup[1152 + i] = i & 1; + lookup[1216 + i] = 2 + (i & 1); + } + var /** !number */ offset = 1280; + for (var /** !number */ k = 0; k < 19; ++k) { + var /** !number */ value = k & 3; + var /** !number */ rep = rle.charCodeAt(k) - 32; + for (var /** !number */ i = 0; i < rep; ++i) { + lookup[offset++] = value; + } + } + for (var /** !number */ i = 0; i < 16; ++i) { + lookup[1792 + i] = 1; + lookup[2032 + i] = 6; + } + lookup[1792] = 0; + lookup[2047] = 7; + for (var /** !number */ i = 0; i < 256; ++i) { + lookup[1536 + i] = lookup[1792 + i] << 3; + } + } + { + unpackLookupTable(LOOKUP, " !! ! \"#$##%#$&'##(#)#++++++++++((&*'##,---,---,-----,-----,-----&#'###.///.///./////./////./////&#'# ", "A/* ': & : $ \u0081 @"); + } + + /** + * @constructor + * @struct + */ + function State() { + /** @type {!Int8Array} */ + this.ringBuffer = new Int8Array(0); + /** @type {!Int8Array} */ + this.contextModes = new Int8Array(0); + /** @type {!Int8Array} */ + this.contextMap = new Int8Array(0); + /** @type {!Int8Array} */ + this.distContextMap = new Int8Array(0); + /** @type {!Int8Array} */ + this.output = new Int8Array(0); + /** @type {!Int8Array} */ + this.byteBuffer = new Int8Array(0); + /** @type {!Int16Array} */ + this.shortBuffer = new Int16Array(0); + /** @type {!Int32Array} */ + this.intBuffer = new Int32Array(0); + /** @type {!Int32Array} */ + this.rings = new Int32Array(0); + /** @type {!Int32Array} */ + this.blockTrees = new Int32Array(0); + /** @type {!Int32Array} */ + this.hGroup0 = new Int32Array(0); + /** @type {!Int32Array} */ + this.hGroup1 = new Int32Array(0); + /** @type {!Int32Array} */ + this.hGroup2 = new Int32Array(0); + /** @type {!number} */ + this.runningState = 0; + /** @type {!number} */ + this.nextRunningState = 0; + /** @type {!number} */ + this.accumulator32 = 0; + /** @type {!number} */ + this.bitOffset = 0; + /** @type {!number} */ + this.halfOffset = 0; + /** @type {!number} */ + this.tailBytes = 0; + /** @type {!number} */ + this.endOfStreamReached = 0; + /** @type {!number} */ + this.metaBlockLength = 0; + /** @type {!number} */ + this.inputEnd = 0; + /** @type {!number} */ + this.isUncompressed = 0; + /** @type {!number} */ + this.isMetadata = 0; + /** @type {!number} */ + this.literalBlockLength = 0; + /** @type {!number} */ + this.numLiteralBlockTypes = 0; + /** @type {!number} */ + this.commandBlockLength = 0; + /** @type {!number} */ + this.numCommandBlockTypes = 0; + /** @type {!number} */ + this.distanceBlockLength = 0; + /** @type {!number} */ + this.numDistanceBlockTypes = 0; + /** @type {!number} */ + this.pos = 0; + /** @type {!number} */ + this.maxDistance = 0; + /** @type {!number} */ + this.distRbIdx = 0; + /** @type {!number} */ + this.trivialLiteralContext = 0; + /** @type {!number} */ + this.literalTreeIndex = 0; + /** @type {!number} */ + this.literalTree = 0; + /** @type {!number} */ + this.j = 0; + /** @type {!number} */ + this.insertLength = 0; + /** @type {!number} */ + this.contextMapSlice = 0; + /** @type {!number} */ + this.distContextMapSlice = 0; + /** @type {!number} */ + this.contextLookupOffset1 = 0; + /** @type {!number} */ + this.contextLookupOffset2 = 0; + /** @type {!number} */ + this.treeCommandOffset = 0; + /** @type {!number} */ + this.distanceCode = 0; + /** @type {!number} */ + this.numDirectDistanceCodes = 0; + /** @type {!number} */ + this.distancePostfixMask = 0; + /** @type {!number} */ + this.distancePostfixBits = 0; + /** @type {!number} */ + this.distance = 0; + /** @type {!number} */ + this.copyLength = 0; + /** @type {!number} */ + this.copyDst = 0; + /** @type {!number} */ + this.maxBackwardDistance = 0; + /** @type {!number} */ + this.maxRingBufferSize = 0; + /** @type {!number} */ + this.ringBufferSize = 0; + /** @type {!number} */ + this.expectedTotalSize = 0; + /** @type {!number} */ + this.outputOffset = 0; + /** @type {!number} */ + this.outputLength = 0; + /** @type {!number} */ + this.outputUsed = 0; + /** @type {!number} */ + this.bytesWritten = 0; + /** @type {!number} */ + this.bytesToWrite = 0; + /** @type {!InputStream|null} */ + this.input = null; + this.ringBuffer = new Int8Array(0); + this.rings = new Int32Array(10); + this.rings[0] = 16; + this.rings[1] = 15; + this.rings[2] = 11; + this.rings[3] = 4; + } + + /** + * @param {!Int8Array} dictionary + * @param {!string} data0 + * @param {!string} data1 + * @param {!string} skipFlip + * @return {!void} + */ + function unpackDictionaryData(dictionary, data0, data1, skipFlip) { + var /** !number */ n0 = data0.length; + var /** !number */ n1 = data1.length; + if (n0 + n1 != dictionary.length) { + throw "Corrupted brotli dictionary"; + } + var /** !number */ offset = 0; + for (var /** !number */ i = 0; i < n0; ++i) { + dictionary[offset] = data0.charCodeAt(i); + offset++; + } + for (var /** !number */ i = 0; i < n1; ++i) { + dictionary[offset] = data1.charCodeAt(i); + offset++; + } + offset = 0; + var /** !number */ n = skipFlip.length; + for (var /** !number */ i = 0; i < n; i += 2) { + var /** !number */ skip = skipFlip.charCodeAt(i) - 36; + var /** !number */ flip = skipFlip.charCodeAt(i + 1) - 36; + offset += skip; + for (var /** !number */ j = 0; j < flip; ++j) { + dictionary[offset] = (dictionary[offset] | 0x80); + offset++; + } + } + } + { + var /** !Int8Array */ dictionary = new Int8Array(122784); + unpackDictionaryData(dictionary, "timedownlifeleftbackcodedatashowonlysitecityopenjustlikefreeworktextyearoverbodyloveformbookplaylivelinehelphomesidemorewordlongthemviewfindpagedaysfullheadtermeachareafromtruemarkableuponhighdatelandnewsevennextcasebothpostusedmadehandherewhatnameLinkblogsizebaseheldmakemainuser') +holdendswithNewsreadweresigntakehavegameseencallpathwellplusmenufilmpartjointhislistgoodneedwayswestjobsmindalsologorichuseslastteamarmyfoodkingwilleastwardbestfirePageknowaway.pngmovethanloadgiveselfnotemuchfeedmanyrockicononcelookhidediedHomerulehostajaxinfoclublawslesshalfsomesuchzone100%onescareTimeracebluefourweekfacehopegavehardlostwhenparkkeptpassshiproomHTMLplanTypedonesavekeepflaglinksoldfivetookratetownjumpthusdarkcardfilefearstaykillthatfallautoever.comtalkshopvotedeepmoderestturnbornbandfellroseurl(skinrolecomeactsagesmeetgold.jpgitemvaryfeltthensenddropViewcopy1.0\"stopelseliestourpack.gifpastcss?graymean>rideshotlatesaidroadvar feeljohnrickportfast'UA-deadpoorbilltypeU.S.woodmust2px;Inforankwidewantwalllead[0];paulwavesure$('#waitmassarmsgoesgainlangpaid!-- lockunitrootwalkfirmwifexml\"songtest20pxkindrowstoolfontmailsafestarmapscorerainflowbabyspansays4px;6px;artsfootrealwikiheatsteptriporg/lakeweaktoldFormcastfansbankveryrunsjulytask1px;goalgrewslowedgeid=\"sets5px;.js?40pxif (soonseatnonetubezerosentreedfactintogiftharm18pxcamehillboldzoomvoideasyringfillpeakinitcost3px;jacktagsbitsrolleditknewnearironfreddiskwentsoilputs/js/holyT22:ISBNT20:adamsees

json', 'contT21: RSSloopasiamoon

soulLINEfortcartT14:

80px!--<9px;T04:mike:46ZniceinchYorkricezh:d'));puremageparatonebond:37Z_of_']);000,zh:gtankyardbowlbush:56ZJava30px\n|}\n%C3%:34ZjeffEXPIcashvisagolfsnowzh:iquer.csssickmeatmin.binddellhirepicsrent:36ZHTTP-201fotowolfEND xbox:54ZBODYdick;\n}\nexit:35Zvarsbeat'});diet999;anne}}sonyguysfuckpipe|-\n!002)ndow[1];[];\nLog salt\r\n\t\tbangtrimbath){\r\n00px\n});ko:lfeesad>\rs:// [];tollplug(){\n{\r\n .js'200pdualboat.JPG);\n}quot);\n\n');\n\r\n}\r201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037201320122011201020092008200720062005200420032002200120001999199819971996199519941993199219911990198919881987198619851984198319821981198019791978197719761975197419731972197119701969196819671966196519641963196219611960195919581957195619551954195319521951195010001024139400009999comomC!sesteestaperotodohacecadaaC1obiendC-aasC-vidacasootroforosolootracualdijosidograntipotemadebealgoquC)estonadatrespococasabajotodasinoaguapuesunosantediceluisellamayozonaamorpisoobraclicellodioshoracasiP7P0P=P0P>PP>Q\u0002P8P7P=P>P4P>Q\u0002P>P6P5P>P=P8Q\u0005P\u001DP0P5P5P1Q\u000BPP2Q\u000BP2P>P\u001DP>P>P1P\u001FP>P;P8P=P8P P$P\u001DP5P\u001CQ\u000BQ\u0002Q\u000BP\u001EP=P8Pthing.org/multiheardPowerstandtokensolid(thisbringshipsstafftriedcallsfullyfactsagentThis //-->adminegyptEvent15px;Emailtrue\"crossspentblogsbox\">notedleavechinasizesguest

robotheavytrue,sevengrandcrimesignsawaredancephase>\n\n\r\nname=diegopage swiss-->\n\n#fff;\">Log.com\"treatsheet) && 14px;sleepntentfiledja:c\u0003id=\"cName\"worseshots-box-delta\n<bears:48Z spendbakershops= \"\";php\">ction13px;brianhellosize=o=%2F joinmaybe, fjsimg\" \")[0]MTopBType\"newlyDanskczechtrailknowsfaq\">zh-cn10);\n-1\");type=bluestrulydavis.js';>\r\n\r\nform jesus100% menu.\r\n\t\r\nwalesrisksumentddingb-likteachgif\" vegasdanskeestishqipsuomisobredesdeentretodospuedeaC1osestC!tienehastaotrospartedondenuevohacerformamismomejormundoaquC-dC-assC3loayudafechatodastantomenosdatosotrassitiomuchoahoralugarmayorestoshorastenerantesfotosestaspaC-snuevasaludforosmedioquienmesespoderchileserC!vecesdecirjosC)estarventagrupohechoellostengoamigocosasnivelgentemismaairesjuliotemashaciafavorjuniolibrepuntobuenoautorabrilbuenatextomarzosaberlistaluegocC3moenerojuegoperC:haberestoynuncamujervalorfueralibrogustaigualvotoscasosguC-apuedosomosavisousteddebennochebuscafaltaeurosseriedichocursoclavecasasleC3nplazolargoobrasvistaapoyojuntotratavistocrearcampohemoscincocargopisosordenhacenC!readiscopedrocercapuedapapelmenorC:tilclarojorgecalleponertardenadiemarcasigueellassiglocochemotosmadreclaserestoniC1oquedapasarbancohijosviajepabloC)stevienereinodejarfondocanalnorteletracausatomarmanoslunesautosvillavendopesartipostengamarcollevapadreunidovamoszonasambosbandamariaabusomuchasubirriojavivirgradochicaallC-jovendichaestantalessalirsuelopesosfinesllamabuscoC)stalleganegroplazahumorpagarjuntadobleislasbolsabaC1ohablaluchaC\u0001readicenjugarnotasvalleallC!cargadolorabajoestC)gustomentemariofirmacostofichaplatahogarartesleyesaquelmuseobasespocosmitadcielochicomiedoganarsantoetapadebesplayaredessietecortecoreadudasdeseoviejodeseaaguas"domaincommonstatuseventsmastersystemactionbannerremovescrollupdateglobalmediumfilternumberchangeresultpublicscreenchoosenormaltravelissuessourcetargetspringmodulemobileswitchphotosborderregionitselfsocialactivecolumnrecordfollowtitle>eitherlengthfamilyfriendlayoutauthorcreatereviewsummerserverplayedplayerexpandpolicyformatdoublepointsseriespersonlivingdesignmonthsforcesuniqueweightpeopleenergynaturesearchfigurehavingcustomoffsetletterwindowsubmitrendergroupsuploadhealthmethodvideosschoolfutureshadowdebatevaluesObjectothersrightsleaguechromesimplenoticesharedendingseasonreportonlinesquarebuttonimagesenablemovinglatestwinterFranceperiodstrongrepeatLondondetailformeddemandsecurepassedtoggleplacesdevicestaticcitiesstreamyellowattackstreetflighthiddeninfo\">openedusefulvalleycausesleadersecretseconddamagesportsexceptratingsignedthingseffectfieldsstatesofficevisualeditorvolumeReportmuseummoviesparentaccessmostlymother\" id=\"marketgroundchancesurveybeforesymbolmomentspeechmotioninsidematterCenterobjectexistsmiddleEuropegrowthlegacymannerenoughcareeransweroriginportalclientselectrandomclosedtopicscomingfatheroptionsimplyraisedescapechosenchurchdefinereasoncorneroutputmemoryiframepolicemodelsNumberduringoffersstyleskilledlistedcalledsilvermargindeletebetterbrowselimitsGlobalsinglewidgetcenterbudgetnowrapcreditclaimsenginesafetychoicespirit-stylespreadmakingneededrussiapleaseextentScriptbrokenallowschargedividefactormember-basedtheoryconfigaroundworkedhelpedChurchimpactshouldalwayslogo\" bottomlist\">){var prefixorangeHeader.push(couplegardenbridgelaunchReviewtakingvisionlittledatingButtonbeautythemesforgotSearchanchoralmostloadedChangereturnstringreloadMobileincomesupplySourceordersviewed courseAbout island: The dialoghousesBEGIN MexicostartscentreheightaddingIslandassetsEmpireSchooleffortdirectnearlymanualSelect.\n\nOnejoinedmenu\">PhilipawardshandleimportOfficeregardskillsnationSportsdegreeweekly (e.g.behinddoctorloggedunitedbeyond-scaleacceptservedmarineFootercamera\n_form\"leavesstress\" />\r\n.gif\" onloadloaderOxfordsistersurvivlistenfemaleDesignsize=\"appealtext\">levelsthankshigherforcedanimalanyoneAfricaagreedrecentPeople
wonderpricesturned|| {};main\">inlinesundaywrap\">failedcensusminutebeaconquotes150px|estateremoteemail\"linkedright;signalformal1.htmlsignupprincefloat:.png\" forum.AccesspaperssoundsextendHeightsliderUTF-8\"& Before. WithstudioownersmanageprofitjQueryannualparamsboughtfamousgooglelongeri++) {israelsayingdecidehome\">headerensurebranchpiecesblock;statedtop\">boston.test(avatartested_countforumsschemaindex,filledsharesreaderalert(appearSubmitline\">body\">\n* TheThoughseeingjerseyNews\nSystem DavidcancertablesprovedApril reallydriveritem\">more\">boardscolorscampusfirst || [];media.guitarfinishwidth:showedOther .php\" assumelayerswilsonstoresreliefswedenCustomeasily your String\n\nWhiltaylorclear:resortfrenchthough\") + \"buyingbrandsMembername\">oppingsector5px;\">vspacepostermajor coffeemartinmaturehappenkansaslink\">Images=falsewhile hspace0& \n\nIn powerPolski-colorjordanBottomStart -count2.htmlnews\">01.jpgOnline-rightmillerseniorISBN 00,000 guidesvalue)ectionrepair.xml\" rights.html-blockregExp:hoverwithinvirginphones\rusing \n\tvar >');\n\t\n\nbahasabrasilgalegomagyarpolskisrpskiX1X/Y\u0008d8-f\u0016\u0007g.\u0000d=\u0013g9\u0001i+\u0014d?!f\u0001/d8-e\u001B=f\u0008\u0011d;,d8\u0000d8*e\u0005,e\u000F8g.!g\u0010\u0006h.:e\u001D\u001Be\u000F/d;%f\u001C\re\n!f\u00176i\u00174d8*d::d:'e\u0013\u0001h\u0007*e71d<\u0001d8\u001Af\u001F%g\u001C\u000Be7%d=\u001Ch\u0001\u0014g3;f2!f\u001C\tg=\u0011g+\u0019f\t\u0000f\u001C\th/\u0004h.:d8-e?\u0003f\u0016\u0007g+ g\u0014(f\u00087i&\u0016i!5d=\u001Ch\u0000\u0005f\n\u0000f\u001C/i\u0017.i\"\u0018g\u001B8e\u00053d8\u000Bh==f\u0010\u001Cg4\"d=?g\u0014(h=/d;6e\u001C(g:?d8;i\"\u0018h5\u0004f\u0016\u0019h'\u0006i\"\u0011e\u001B\u001Ee$\rf3(e\u0006\u000Cg=\u0011g;\u001Cf\u00146h\u0017\u000Fe\u0006\u0005e.9f\u000E(h\r\u0010e8\u0002e\u001C:f6\u0008f\u0001/g):i\u00174e\u000F\u0011e8\u0003d;\u0000d9\u0008e%=e\u000F\u000Bg\u0014\u001Ff4;e\u001B>g\t\u0007e\u000F\u0011e1\u0015e&\u0002f\u001E\u001Cf\t\u000Bf\u001C:f\u00160i\u0017;f\u001C\u0000f\u00160f\u00169e<\u000Fe\u000C\u0017d:,f\u000F\u0010d>\u001Be\u00053d:\u000Ef\u001B4e$\u001Ah?\u0019d8*g3;g;\u001Fg\u001F%i\u0001\u0013f88f\u0008\u000Fe9?e\u0011\ne\u00056d;\u0016e\u000F\u0011h!(e.\te\u0005(g,,d8\u0000d<\u001Ae\u0011\u0018h?\u001Bh!\u000Cg\u00029e\u0007;g\t\u0008f\u001D\u0003g\u00145e-\u0010d8\u0016g\u0015\u000Ch.>h.!e\u0005\rh49f\u0015\u0019h\u00022e\n e\u0005%f4;e\n(d;\u0016d;,e\u0015\u0006e\u0013\u0001e\r\u001Ae.\"g\u000E0e\u001C(d8\nf57e&\u0002d=\u0015e72g;\u000Fg\u0015\u0019h(\u0000h/&g;\u0006g$>e\u000C:g\u0019;e=\u0015f\u001C,g+\u0019i\u001C\u0000h&\u0001d;7f f\u000E%e\u001B=e.6e;:h.>f\u001C\u000Be\u000F\u000Bi\u0018\u0005h/;f3\u0015e>\u000Bd=\rg=.g;\u000Ff5\u000Ei\u0000\tf\u000B)h?\u0019f 7e=\u0013e\t\re\u0008\u0006g1;f\u000E\u0012h!\u000Ce\u001B d8:d:$f\u0018\u0013f\u001C\u0000e\u0010\u000Ei\u001F3d9\u0010d8\rh\u0003=i\u0000\u001Ah?\u0007h!\u000Cd8\u001Ag'\u0011f\n\u0000e\u000F/h\u0003=h.>e$\u0007e\u0010\u0008d=\u001Ce$'e.6g$>d<\u001Ag \u0014g)6d8\u0013d8\u001Ae\u0005(i\u0003(i!9g\u001B.h?\u0019i\u0007\u000Ch?\u0018f\u0018/e<\u0000e'\u000Bf\u0003\u0005e\u00065g\u00145h\u0004\u0011f\u0016\u0007d;6e\u0013\u0001g\t\u000Ce8.e\n)f\u0016\u0007e\u000C\u0016h5\u0004f:\u0010e$'e-&e-&d9 e\u001C0e\u001D\u0000f5\u000Fh'\u0008f\n\u0015h5\u0004e7%g(\u000Bh&\u0001f1\u0002f\u0000\u000Ed9\u0008f\u00176e\u0000\u0019e\n\u001Fh\u0003=d8;h&\u0001g\u001B.e\t\rh5\u0004h./e\u001F\u000Ee8\u0002f\u00169f3\u0015g\u00145e=1f\u000B\u001Bh\u0001\u0018e#0f\u0018\u000Ed;;d=\u0015e\u0001%e:7f\u00150f\r.g>\u000Ee\u001B=f1=h=&d;\u000Bg;\rd=\u0006f\u0018/d:$f5\u0001g\u0014\u001Fd:'f\t\u0000d;%g\u00145h/\u001Df\u0018>g$:d8\u0000d:\u001Be\r\u0015d=\rd::e\u0011\u0018e\u0008\u0006f\u001E\u0010e\u001C0e\u001B>f\u0017\u0005f88e7%e\u00057e-&g\u0014\u001Fg3;e\u0008\u0017g=\u0011e\u000F\u000Be8\u0016e-\u0010e/\u0006g \u0001i\"\u0011i\u0001\u0013f\u000E'e\u00086e\u001C0e\u000C:e\u001F:f\u001C,e\u0005(e\u001B=g=\u0011d8\ni\u0007\rh&\u0001g,,d:\u000Ce\u0016\u001Cf,\"h?\u001Be\u0005%e\u000F\u000Bf\u0003\u0005h?\u0019d:\u001Bh\u0000\u0003h/\u0015e\u000F\u0011g\u000E0e\u001F9h.-d;%d8\nf\u0014?e:\u001Cf\u0008\u0010d8:g\u000E/e\"\u0003i&\u0019f8/e\u0010\u000Cf\u00176e(1d9\u0010e\u000F\u0011i\u0000\u0001d8\u0000e.\u001Ae<\u0000e\u000F\u0011d=\u001Ce\u0013\u0001f \u0007e\u0007\u0006f,\"h?\u000Eh'#e\u00063e\u001C0f\u00169d8\u0000d8\u000Bd;%e\u000F\nh4#d;;f\u0008\u0016h\u0000\u0005e.\"f\u00087d;#h!(g'/e\u0008\u0006e%3d::f\u00150g \u0001i\u0014\u0000e\u0014.e\u0007:g\u000E0g&;g:?e:\u0014g\u0014(e\u0008\u0017h!(d8\re\u0010\u000Cg<\u0016h>\u0011g;\u001Fh.!f\u001F%h/\"d8\rh&\u0001f\u001C\te\u00053f\u001C:f\u001E\u0004e>\u0008e$\u001Af\u0012-f\u0014>g;\u0004g;\u0007f\u0014?g-\u0016g\u001B4f\u000E%h\u0003=e\n\u001Bf\u001D%f:\u0010f\u0019\u0002i\u0016\u0013g\u001C\u000Be\u00080g\u0003-i\u0017(e\u00053i\u0014.d8\u0013e\u000C:i\u001D\u001Ee88h\u000B1h/-g\u0019>e:&e8\u000Cf\u001C\u001Bg>\u000Ee%3f/\u0014h>\u0003g\u001F%h/\u0006h'\u0004e.\u001Ae;:h..i\u0003(i\u0017(f\u0004\u000Fh'\u0001g2>e=)f\u0017%f\u001C,f\u000F\u0010i+\u0018e\u000F\u0011h(\u0000f\u00169i\u001D\"e\u001F:i\u0007\u0011e$\u0004g\u0010\u0006f\u001D\u0003i\u0019\u0010e=1g\t\u0007i\u00136h!\u000Ch?\u0018f\u001C\te\u0008\u0006d:+g\t)e\u0013\u0001g;\u000Fh\u0010%f7;e\n d8\u0013e.6h?\u0019g'\rh/\u001Di\"\u0018h57f\u001D%d8\u001Ae\n!e\u0005,e\u0011\nh.0e=\u0015g.\u0000d;\u000Bh4(i\u0007\u000Fg\u00147d::e=1e\u0013\re<\u0015g\u0014(f\n%e\u0011\ni\u0003(e\u0008\u0006e?+i\u0000\u001Fe\u0012(h/\"f\u00176e0\u001Af3(f\u0004\u000Fg\u00143h/7e-&f !e:\u0014h/%e\u000E\u0006e\u000F2e\u000F*f\u0018/h?\u0014e\u001B\u001Eh4-d90e\u0010\rg'0d8:d:\u0006f\u0008\u0010e\n\u001Fh/4f\u0018\u000Ed>\u001Be:\u0014e-)e-\u0010d8\u0013i\"\u0018g(\u000Be:\u000Fd8\u0000h\u0008,f\u001C\u0003e\u0013!e\u000F*f\u001C\te\u00056e.\u0003d?\u001Df\n$h\u0000\u000Cd8\u0014d;\ne$)g*\u0017e\u000F#e\n(f\u0000\u0001g\n6f\u0000\u0001g\t9e\u0008+h.$d8:e?\u0005i!;f\u001B4f\u00160e0\u000Fh/4f\u0008\u0011e\u0000\u0011d=\u001Cd8:e*\u0012d=\u0013e\u000C\u0005f\u000B,i\u0002#d9\u0008d8\u0000f 7e\u001B=e\u0006\u0005f\u0018/e\u0010&f 9f\r.g\u00145h'\u0006e-&i\u0019\"e\u00057f\u001C\th?\u0007g(\u000Bg\u00141d:\u000Ed::f\t\re\u0007:f\u001D%d8\rh?\u0007f-#e\u001C(f\u0018\u000Ef\u0018\u001Ff\u0015\u0005d:\u000Be\u00053g3;f \u0007i\"\u0018e\u0015\u0006e\n!h>\u0013e\u0005%d8\u0000g\u001B4e\u001F:g!\u0000f\u0015\u0019e-&d:\u0006h'#e;:g-\u0011g;\u0013f\u001E\u001Ce\u0005(g\u0010\u0003i\u0000\u001Ag\u001F%h.!e\u0008\u0012e/9d:\u000Eh\t:f\u001C/g\u001B8e\u0006\u000Ce\u000F\u0011g\u0014\u001Fg\u001C\u001Fg\u001A\u0004e;:g+\u000Bg-\tg:'g1;e\u001E\u000Bg;\u000Fi*\u000Ce.\u001Eg\u000E0e\u00086d=\u001Cf\u001D%h\u0007*f \u0007g->d;%d8\u000Be\u000E\u001Fe\u0008\u001Bf\u0017 f3\u0015e\u00056d8-e\u0000\u000Bd::d8\u0000e\u0008\u0007f\u000C\u0007e\r\u0017e\u00053i\u0017-i\u001B\u0006e\u001B\"g,,d8\te\u00053f3(e\u001B f-$g\u0005'g\t\u0007f71e\u001C3e\u0015\u0006d8\u001Ae9?e7\u001Ef\u0017%f\u001C\u001Fi+\u0018g:'f\u001C\u0000h?\u0011g;\u0011h!\u000Cd8:d:$i\u0000\u001Ah/\u0004d;7h'\te>\u0017g2>e\r\u000Ee.6e:-e.\u000Cf\u0008\u0010f\u0004\u001Fh'\te.\th#\u0005e>\u0017e\u00080i\u0002.d;6e\u00086e:&i#\u001Fe\u0013\u0001h\u0019=g\u00046h=,h==f\n%d;7h.0h\u0000\u0005f\u00169f!\u0008h!\u000Cf\u0014?d::f0\u0011g\u0014(e\u0013\u0001d8\u001Ch%?f\u000F\u0010e\u0007:i\u0005\u0012e:\u0017g\u00046e\u0010\u000Ed;\u0018f,>g\u0003-g\u00029d;%e\t\re.\u000Ce\u0005(e\u000F\u0011e8\u0016h.>g=.i\"\u0006e/g%\u001Eh\u000E7e>\u0017e\u0008)g\u0014(g;'g;-d= d;,h?\u0019d9\u0008f(!e<\u000Fh/-h(\u0000h\u0003=e$\u001Fi\u001B\u0005h\u0019\u000Ef\u0013\rd=\u001Ci#\u000Ef d9&f\u001C\tf\u0015\u0008f5\u000Bh/\u0015g';e\n(f\t\rh\u0003=e\u00063e.\u001Ah\u0002!g%(d8\rf\u0016-i\u001C\u0000f1\u0002d8\re>\u0017e\n\u001Ef3\u0015d9\u000Bi\u00174i\u0007\u0007g\u0014(h\u0010%i\u0014\u0000f\n\u0015h/\tg\u001B.f \u0007g\u00081f\u0003\u0005f\u0011\u0004e=1f\u001C\td:\u001Bh$\u0007h#=f\u0016\u0007e-&f\u001C:d<\u001Af\u00150e-\u0017h#\u0005d?.h4-g\t)e\u0006\u001Cf\u001D\u0011e\u0005(i\u001D\"g2>e\u0013\u0001e\u00056e.\u001Ed:\u000Bf\u0003\u0005f04e93f\u000F\u0010g$:d8\ne8\u0002h0\"h0\"f\u0019.i\u0000\u001Af\u0015\u0019e8\u0008d8\nd< g1;e\u0008+f-\u000Cf\u001B2f\u000B%f\u001C\te\u0008\u001Bf\u00160i\u0005\rd;6e\u000F*h&\u0001f\u00176d;#h3\u0007h(\nh>>e\u00080d::g\u0014\u001Fh.\"i\u0018\u0005h\u0000\u0001e8\u0008e1\u0015g$:e?\u0003g\u0010\u0006h44e-\u0010g62g+\u0019d8;i!\u000Ch\u0007*g\u00046g:'e\u0008+g.\u0000e\r\u0015f\u00149i\u001D)i\u0002#d:\u001Bf\u001D%h/4f\t\u0013e<\u0000d;#g \u0001e\u0008 i\u0019$h/\u0001e\u00088h\n\u0002g\u001B.i\u0007\rg\u00029f,!f\u00158e$\u001Ae0\u0011h'\u0004e\u0008\u0012h5\u0004i\u0007\u0011f\t>e\u00080d;%e\u0010\u000Ee$'e\u0005(d8;i!5f\u001C\u0000d=3e\u001B\u001Eg-\u0014e$)d8\u000Bd?\u001Di\u001A\u001Cg\u000E0d;#f#\u0000f\u001F%f\n\u0015g%(e0\u000Ff\u00176f2\u0012f\u001C\tf-#e88g\u0014\u001Ah\u00073d;#g\u0010\u0006g\u001B.e=\u0015e\u0005,e<\u0000e$\re\u00086i\u0007\u0011h\u001E\re98g&\u000Fg\t\u0008f\u001C,e=\"f\u0008\u0010e\u0007\u0006e$\u0007h!\u000Cf\u0003\u0005e\u001B\u001Ee\u00080f\u0000\u001Df\u00033f\u0000\u000Ef 7e\r\u000Fh..h.$h/\u0001f\u001C\u0000e%=d:'g\u0014\u001Ff\u000C\tg\u0005'f\u001C\rh#\u0005e9?d8\u001Ce\n(f<+i\u0007\u0007h4-f\u00160f\t\u000Bg;\u0004e\u001B>i\u001D\"f\u001D?e\u000F\u0002h\u0000\u0003f\u0014?f2;e.9f\u0018\u0013e$)e\u001C0e\n*e\n\u001Bd::d;,e\r\u0007g:'i\u0000\u001Fe:&d::g\t)h0\u0003f\u00154f5\u0001h!\u000Ci\u0000 f\u0008\u0010f\u0016\u0007e-\u0017i\u001F)e\u001B=h48f\u0018\u0013e<\u0000e1\u0015g\u001B8i\u0017\u001Ch!(g\u000E0e=1h'\u0006e&\u0002f-$g>\u000Ee.9e$'e0\u000Ff\n%i\u0001\u0013f\u001D!f,>e?\u0003f\u0003\u0005h.8e$\u001Af3\u0015h'\u0004e.6e1\u0005d9&e:\u0017h?\u001Ef\u000E%g+\u000Be\r3d8>f\n%f\n\u0000e7'e%%h?\u0010g\u0019;e\u0005%d;%f\u001D%g\u0010\u0006h.:d:\u000Bd;6h\u0007*g\u00141d8-e\r\u000Ee\n\u001Ee\u0005,e&\u0008e&\u0008g\u001C\u001Ff-#d8\ri\u0014\u0019e\u0005(f\u0016\u0007e\u0010\u0008e\u0010\u000Cd;7e\u0000e7&e\u000F3h\u0002!d;=g-\u0014f!\u0008e.\u001Ei\u0019\u0005g\u00145d?!g;\u000Fg\u0010\u0006g\u0014\u001Fe\u0011=e.#d< d;;e\n!f-#e<\u000Fg\t9h\t2d8\u000Bf\u001D%e\r\u000Fd<\u001Ae\u000F*h\u0003=e=\u0013g\u00046i\u0007\rf\u00160e\u0005'e.9f\u000C\u0007e/g(\u000Be\u000C;g\u0016\u0017g;\u000Fh?\u0007h?\u0007e\u000E;d9\u000Be\t\rf\u00146e\u0005%e94e:&f\u001D\u0002e?\u0017g>\u000Ed8=f\u001C\u0000i+\u0018g\u0019;i\u0019\u0006f\u001C*f\u001D%e\n e7%e\u0005\rh4#f\u0015\u0019g(\u000Bg\t\u0008e\u001D\u0017h:+d=\u0013i\u0007\re:\u0006e\u0007:e\u0014.f\u0008\u0010f\u001C,e=\"e<\u000Fe\u001C\u001Fh1\u0006e\u0007:e\u00039d8\u001Cf\u00169i\u0002.g.1e\r\u0017d:,f1\u0002h\u0001\u000Ce\u000F\u0016e>\u0017h\u0001\u000Cd=\rg\u001B8d?!i!5i\u001D\"e\u0008\u0006i\u0012\u001Fg=\u0011i!5g!.e.\u001Ae\u001B>d>\u000Bg=\u0011e\u001D\u0000g'/f\u001E\u0001i\u0014\u0019h//g\u001B.g\u001A\u0004e.\u001Dh4\u001Df\u001C:e\u00053i#\u000Ei\u0019)f\u000E\u0008f\u001D\u0003g\u0017\u0005f/\u0012e. g\t)i\u0019$d:\u0006h)\u0015h+\u0016g\u0016>g\u0017\u0005e\u000F\nf\u00176f1\u0002h4-g+\u0019g\u00029e\u0004?g+%f/\u000Fe$)d8-e$.h.$h/\u0006f/\u000Fd8*e$)f4%e-\u0017d=\u0013e\u000F0g\u0001#g;4f\n$f\u001C,i!5d8*f\u0000'e.\u0018f\u00169e88h'\u0001g\u001B8f\u001C:f\u0008\u0018g\u0015%e:\u0014e=\u0013e>\u000Be8\u0008f\u00169d>?f !e\u001B-h\u0002!e8\u0002f\u0008?e1\u000Bf \u000Fg\u001B.e\u0011\u0018e7%e/\u000Ee\u0005\u0003e<\u0015h57f\u00149e\u000F\u0018g,,e\u001B\u001Bd<\u001Ah.!h**f\u0018\u000Ei\u001A\u0010g'\u0001e.\u001De.\u001Dh'\u0004h\u000C\u0003f6\u0008h49e\u00051e\u0010\u000Ce?\u0018h.0d=\u0013g3;e8&f\u001D%e\u0010\re-\u0017g\u0019e\n g\u001B\u001Fe\u000F\u0017e\u00080d:\u000Cf\t\u000Be$'i\u0007\u000Ff\u0008\u0010d::f\u00150i\u0007\u000Fe\u00051d:+e\u000C:e\u001F\u001Fe%3e-)e\u000E\u001Fe\u0008\u0019f\t\u0000e\u001C(g;\u0013f\u001D\u001Fi\u0000\u001Ad?!h6\u0005g:'i\u0005\rg=.e=\u0013f\u00176d<\u0018g'\u0000f\u0000'f\u0004\u001Ff\u0008?d:'i\u0001\nf\u00082e\u0007:e\u000F#f\u000F\u0010d:$e01d8\u001Ad?\u001De\u0001%g(\u000Be:&e\u000F\u0002f\u00150d:\u000Bd8\u001Af\u00154d8*e11d8\u001Cf\u0003\u0005f\u0004\u001Fg\t9f.\ne\u0008\u0006i!\u001Ef\u0010\u001Ce0\u000Be1\u001Ed:\u000Ei\u0017(f\u00087h4\"e\n!e#0i\u001F3e\u000F\ne\u00056h4\"g;\u000Fe\u001D\u001Af\u000C\u0001e92i\u0003(f\u0008\u0010g+\u000Be\u0008)g\u001B\nh\u0000\u0003h\u0019\u0011f\u0008\u0010i\u0003=e\u000C\u0005h#\u0005g\u0014(f\u00086f/\u0014h5\u001Bf\u0016\u0007f\u0018\u000Ef\u000B\u001Be\u0015\u0006e.\u000Cf\u00154g\u001C\u001Ff\u0018/g\u001Ce/\u0006g\"\u000Ei#\u001Fg;?h\t2g(3e.\u001Ag;\u0008d:\u000Eg\u0014\u001Fg\t)d>\u001Bf1\u0002f\u0010\u001Cg\u000B\u0010e\n\u001Bi\u0007\u000Fd8%i\u0007\rf08h?\u001Ce\u0006\u0019g\u001C\u001Ff\u001C\ti\u0019\u0010g+\u001Ed:\te/9h1!h49g\u0014(d8\re%=g;\u001De/9e\r\u0001e\u0008\u0006d?\u0003h?\u001Bg\u00029h/\u0004e=1i\u001F3d<\u0018e\n?d8\re0\u0011f,#h5\u000Fe96d8\u0014f\u001C\tg\u00029f\u00169e\u0010\u0011e\u0005(f\u00160d?!g\u0014(h.>f\u0016=e=\"h1!h5\u0004f \u000Ee\u0015\u0006e\u001F\u000Eg;\u001Fd8\u0000e\u0007:g\t\u0008f\t\u0013i\u0000 g\u0014\"e\u0013\u0001f&\u0002e\u00065g\u0014(d:\u000Ed?\u001Dg\u0015\u0019e\u001B g4 d8-e\u001C\u000Be-\u0018e\u0002(h44e\u001B>f\u001C\u0000f\u0004\u001Bi\u0015?f\u001C\u001Fe\u000F#d;7g\u0010\u0006h4\"e\u001F:e\u001C0e.\tf\u000E\u0012f-&f1\ti\u0007\u000Ci\u001D\"e\u0008\u001Be;:e$)g):i&\u0016e\u0005\u0008e.\u000Ce\u0016\u0004i)1e\n(d8\u000Bi\u001D\"d8\re\u0006\rh/\u001Ad?!f\u0004\u000Fd9\ti\u00183e\u0005\th\u000B1e\u001B=f<\u0002d:.e\u0006\u001Bd:\u000Bg\u000E)e.6g>$d<\u0017e\u0006\u001Cf0\u0011e\r3e\u000F/e\u0010\rg(1e.6e\u00057e\n(g\u0014;f\u00033e\u00080f3(f\u0018\u000Ee0\u000Fe-&f\u0000'h\u0003=h\u0000\u0003g \u0014g!,d;6h'\u0002g\u001C\u000Bf8\u0005f%\u001Af\u0010\u001Eg,\u0011i&\u0016i \u0001i;\u0004i\u0007\u0011i\u0000\u0002g\u0014(f1\u001Fh\u000B\u000Fg\u001C\u001Fe.\u001Ed8;g.!i\u00186f.5h(;e\u0006\ng?;h/\u0011f\u001D\u0003e\u0008)e\u0001\u001Ae%=d<P:P0P:P8P;P8Q\rQ\u0002P>P2Q\u0001P5P5P3P>P?Q\u0000P8Q\u0002P0P:P5Q\tP5Q\u0003P6P5P\u001AP0P:P1P5P7P1Q\u000BP;P>P=P8P\u0012Q\u0001P5P?P>P4P-Q\u0002P>Q\u0002P>PP=P0P3P4P5PP3P>P4P2P>Q\u0002Q\u0002P0PP2P0Q\u0001P2P0PQ\u0002Q\u0003Q\u0002P=P0P4P4P=Q\u000FP\u0012P>Q\u0002Q\u0002Q\u0000P8P=P5P9P\u0012P0Q\u0001P=P8PQ\u0002Q\u0000Q\u0003P1P\u001EP=P8PPP9P4P2P5P>P=P>Q\u0001Q\u0003P4`$\u0015`%\u0007`$9`%\u0008`$\u0015`%\u0000`$8`%\u0007`$\u0015`$>`$\u0015`%\u000B`$\u0014`$0`$*`$0`$(`%\u0007`$\u000F`$\u0015`$\u0015`$?`$-`%\u0000`$\u0007`$8`$\u0015`$0`$$`%\u000B`$9`%\u000B`$\u0006`$*`$9`%\u0000`$/`$9`$/`$>`$$`$\u0015`$%`$>jagran`$\u0006`$\u001C`$\u001C`%\u000B`$\u0005`$,`$&`%\u000B`$\u0017`$\u0008`$\u001C`$>`$\u0017`$\u000F`$9`$.`$\u0007`$(`$5`$9`$/`%\u0007`$%`%\u0007`$%`%\u0000`$\u0018`$0`$\u001C`$,`$&`%\u0000`$\u0015`$\u0008`$\u001C`%\u0000`$5`%\u0007`$(`$\u0008`$(`$\u000F`$9`$0`$\t`$8`$.`%\u0007`$\u0015`$.`$5`%\u000B`$2`%\u0007`$8`$,`$.`$\u0008`$&`%\u0007`$\u0013`$0`$\u0006`$.`$,`$8`$-`$0`$,`$(`$\u001A`$2`$.`$(`$\u0006`$\u0017`$8`%\u0000`$2`%\u0000X9Y\u0004Y\tX%Y\u0004Y\tY\u0007X0X'X\"X.X1X9X/X/X'Y\u0004Y\tY\u0007X0Y\u0007X5Y\u0008X1X:Y\nX1Y\u0003X'Y\u0006Y\u0008Y\u0004X'X(Y\nY\u0006X9X1X6X0Y\u0004Y\u0003Y\u0007Y\u0006X'Y\nY\u0008Y\u0005Y\u0002X'Y\u0004X9Y\u0004Y\nX'Y\u0006X'Y\u0004Y\u0003Y\u0006X-X*Y\tY\u0002X(Y\u0004Y\u0008X-X)X'X.X1Y\u0001Y\u0002X7X9X(X/X1Y\u0003Y\u0006X%X0X'Y\u0003Y\u0005X'X'X-X/X%Y\u0004X'Y\u0001Y\nY\u0007X(X9X6Y\u0003Y\nY\u0001X(X-X+Y\u0008Y\u0005Y\u0006Y\u0008Y\u0007Y\u0008X#Y\u0006X'X,X/X'Y\u0004Y\u0007X'X3Y\u0004Y\u0005X9Y\u0006X/Y\u0004Y\nX3X9X(X1X5Y\u0004Y\tY\u0005Y\u0006X0X(Y\u0007X'X#Y\u0006Y\u0007Y\u0005X+Y\u0004Y\u0003Y\u0006X*X'Y\u0004X'X-Y\nX+Y\u0005X5X1X4X1X-X-Y\u0008Y\u0004Y\u0008Y\u0001Y\nX'X0X'Y\u0004Y\u0003Y\u0004Y\u0005X1X)X'Y\u0006X*X'Y\u0004Y\u0001X#X(Y\u0008X.X'X5X#Y\u0006X*X'Y\u0006Y\u0007X'Y\u0004Y\nX9X6Y\u0008Y\u0008Y\u0002X/X'X(Y\u0006X.Y\nX1X(Y\u0006X*Y\u0004Y\u0003Y\u0005X4X'X!Y\u0008Y\u0007Y\nX'X(Y\u0008Y\u0002X5X5Y\u0008Y\u0005X'X1Y\u0002Y\u0005X#X-X/Y\u0006X-Y\u0006X9X/Y\u0005X1X#Y\nX'X-X)Y\u0003X*X(X/Y\u0008Y\u0006Y\nX,X(Y\u0005Y\u0006Y\u0007X*X-X*X,Y\u0007X)X3Y\u0006X)Y\nX*Y\u0005Y\u0003X1X)X:X2X)Y\u0006Y\u0001X3X(Y\nX*Y\u0004Y\u0004Y\u0007Y\u0004Y\u0006X'X*Y\u0004Y\u0003Y\u0002Y\u0004X(Y\u0004Y\u0005X'X9Y\u0006Y\u0007X#Y\u0008Y\u0004X4Y\nX!Y\u0006Y\u0008X1X#Y\u0005X'Y\u0001Y\nY\u0003X(Y\u0003Y\u0004X0X'X*X1X*X(X(X#Y\u0006Y\u0007Y\u0005X3X'Y\u0006Y\u0003X(Y\nX9Y\u0001Y\u0002X/X-X3Y\u0006Y\u0004Y\u0007Y\u0005X4X9X1X#Y\u0007Y\u0004X4Y\u0007X1Y\u0002X7X1X7Y\u0004X(profileservicedefaulthimselfdetailscontentsupportstartedmessagesuccessfashioncountryaccountcreatedstoriesresultsrunningprocesswritingobjectsvisiblewelcomearticleunknownnetworkcompanydynamicbrowserprivacyproblemServicerespectdisplayrequestreservewebsitehistoryfriendsoptionsworkingversionmillionchannelwindow.addressvisitedweathercorrectproductedirectforwardyou canremovedsubjectcontrolarchivecurrentreadinglibrarylimitedmanagerfurthersummarymachineminutesprivatecontextprogramsocietynumberswrittenenabledtriggersourcesloadingelementpartnerfinallyperfectmeaningsystemskeepingculture",journalprojectsurfaces"expiresreviewsbalanceEnglishContentthroughPlease opinioncontactaverageprimaryvillageSpanishgallerydeclinemeetingmissionpopularqualitymeasuregeneralspeciessessionsectionwriterscounterinitialreportsfiguresmembersholdingdisputeearlierexpressdigitalpictureAnothermarriedtrafficleadingchangedcentralvictoryimages/reasonsstudiesfeaturelistingmust beschoolsVersionusuallyepisodeplayinggrowingobviousoverlaypresentactions</ul>\r\nwrapperalreadycertainrealitystorageanotherdesktopofferedpatternunusualDigitalcapitalWebsitefailureconnectreducedAndroiddecadesregular & animalsreleaseAutomatgettingmethodsnothingPopularcaptionletterscapturesciencelicensechangesEngland=1&History = new CentralupdatedSpecialNetworkrequirecommentwarningCollegetoolbarremainsbecauseelectedDeutschfinanceworkersquicklybetweenexactlysettingdiseaseSocietyweaponsexhibit<!--Controlclassescoveredoutlineattacksdevices(windowpurposetitle=\"Mobile killingshowingItaliandroppedheavilyeffects-1']);\nconfirmCurrentadvancesharingopeningdrawingbillionorderedGermanyrelated</form>includewhetherdefinedSciencecatalogArticlebuttonslargestuniformjourneysidebarChicagoholidayGeneralpassage,"animatefeelingarrivedpassingnaturalroughly.\n\nThe but notdensityBritainChineselack oftributeIreland\" data-factorsreceivethat isLibraryhusbandin factaffairsCharlesradicalbroughtfindinglanding:lang=\"return leadersplannedpremiumpackageAmericaEdition]"Messageneed tovalue=\"complexlookingstationbelievesmaller-mobilerecordswant tokind ofFirefoxyou aresimilarstudiedmaximumheadingrapidlyclimatekingdomemergedamountsfoundedpioneerformuladynastyhow to SupportrevenueeconomyResultsbrothersoldierlargelycalling."AccountEdward segmentRobert effortsPacificlearnedup withheight:we haveAngelesnations_searchappliedacquiremassivegranted: falsetreatedbiggestbenefitdrivingStudiesminimumperhapsmorningsellingis usedreversevariant role=\"missingachievepromotestudentsomeoneextremerestorebottom:evolvedall thesitemapenglishway to AugustsymbolsCompanymattersmusicalagainstserving})();\r\npaymenttroubleconceptcompareparentsplayersregionsmonitor ''The winningexploreadaptedGalleryproduceabilityenhancecareers). The collectSearch ancientexistedfooter handlerprintedconsoleEasternexportswindowsChannelillegalneutralsuggest_headersigning.html\">settledwesterncausing-webkitclaimedJusticechaptervictimsThomas mozillapromisepartieseditionoutside:false,hundredOlympic_buttonauthorsreachedchronicdemandssecondsprotectadoptedprepareneithergreatlygreateroverallimprovecommandspecialsearch.worshipfundingthoughthighestinsteadutilityquarterCulturetestingclearlyexposedBrowserliberal} catchProjectexamplehide();FloridaanswersallowedEmperordefenseseriousfreedomSeveral-buttonFurtherout of != nulltrainedDenmarkvoid(0)/all.jspreventRequestStephen\n\nWhen observe</h2>\r\nModern provide\" alt=\"borders.\n\nFor \n\nMany artistspoweredperformfictiontype ofmedicalticketsopposedCouncilwitnessjusticeGeorge Belgium...</a>twitternotablywaitingwarfare Other rankingphrasesmentionsurvivescholar</p>\r\n Countryignoredloss ofjust asGeorgiastrange<head><stopped1']);\r\nislandsnotableborder:list ofcarried100,000</h3>\n severalbecomesselect wedding00.htmlmonarchoff theteacherhighly biologylife ofor evenrise of»plusonehunting(thoughDouglasjoiningcirclesFor theAncientVietnamvehiclesuch ascrystalvalue =Windowsenjoyeda smallassumed<a id=\"foreign All rihow theDisplayretiredhoweverhidden;battlesseekingcabinetwas notlook atconductget theJanuaryhappensturninga:hoverOnline French lackingtypicalextractenemieseven ifgeneratdecidedare not/searchbeliefs-image:locatedstatic.login\">convertviolententeredfirst\">circuitFinlandchemistshe was10px;\">as suchdivided</span>will beline ofa greatmystery/index.fallingdue to railwaycollegemonsterdescentit withnuclearJewish protestBritishflowerspredictreformsbutton who waslectureinstantsuicidegenericperiodsmarketsSocial fishingcombinegraphicwinners<br /><by the NaturalPrivacycookiesoutcomeresolveSwedishbrieflyPersianso muchCenturydepictscolumnshousingscriptsnext tobearingmappingrevisedjQuery(-width:title\">tooltipSectiondesignsTurkishyounger.match(})();\n\nburningoperatedegreessource=Richardcloselyplasticentries</tr>\r\ncolor:#ul id=\"possessrollingphysicsfailingexecutecontestlink toDefault<br />\n: true,chartertourismclassicproceedexplain</h1>\r\nonline.?xml vehelpingdiamonduse theairlineend -->).attr(readershosting#ffffffrealizeVincentsignals src=\"/ProductdespitediversetellingPublic held inJoseph theatreaffects<style>a largedoesn'tlater, ElementfaviconcreatorHungaryAirportsee theso thatMichaelSystemsPrograms, and width=e"tradingleft\">\npersonsGolden Affairsgrammarformingdestroyidea ofcase ofoldest this is.src = cartoonregistrCommonsMuslimsWhat isin manymarkingrevealsIndeed,equally/show_aoutdoorescape(Austriageneticsystem,In the sittingHe alsoIslandsAcademy\n\t\t<!--Daniel bindingblock\">imposedutilizeAbraham(except{width:putting).html(|| [];\nDATA[ *kitchenmountedactual dialectmainly _blank'installexpertsif(typeIt also© \">Termsborn inOptionseasterntalkingconcerngained ongoingjustifycriticsfactoryits ownassaultinvitedlastinghis ownhref=\"/\" rel=\"developconcertdiagramdollarsclusterphp?id=alcohol);})();using a><span>vesselsrevivalAddressamateurandroidallegedillnesswalkingcentersqualifymatchesunifiedextinctDefensedied in\n\t<!-- customslinkingLittle Book ofeveningmin.js?are thekontakttoday's.html\" target=wearingAll Rig;\n})();raising Also, crucialabout\">declare-->\n<scfirefoxas muchappliesindex, s, but type = \n\r\n<!--towardsRecordsPrivateForeignPremierchoicesVirtualreturnsCommentPoweredinline;povertychamberLiving volumesAnthonylogin\" RelatedEconomyreachescuttinggravitylife inChapter-shadowNotable</td>\r\n returnstadiumwidgetsvaryingtravelsheld bywho arework infacultyangularwho hadairporttown of\n\nSome 'click'chargeskeywordit willcity of(this);Andrew unique checkedor more300px; return;rsion=\"pluginswithin herselfStationFederalventurepublishsent totensionactresscome tofingersDuke ofpeople,exploitwhat isharmonya major\":\"httpin his menu\">\nmonthlyofficercouncilgainingeven inSummarydate ofloyaltyfitnessand wasemperorsupremeSecond hearingRussianlongestAlbertalateralset of small\">.appenddo withfederalbank ofbeneathDespiteCapitalgrounds), and percentit fromclosingcontainInsteadfifteenas well.yahoo.respondfighterobscurereflectorganic= Math.editingonline paddinga wholeonerroryear ofend of barrierwhen itheader home ofresumedrenamedstrong>heatingretainscloudfrway of March 1knowingin partBetweenlessonsclosestvirtuallinks\">crossedEND -->famous awardedLicenseHealth fairly wealthyminimalAfricancompetelabel\">singingfarmersBrasil)discussreplaceGregoryfont copursuedappearsmake uproundedboth ofblockedsaw theofficescoloursif(docuwhen heenforcepush(fuAugust UTF-8\">Fantasyin mostinjuredUsuallyfarmingclosureobject defenceuse of Medical<body>\nevidentbe usedkeyCodesixteenIslamic#000000entire widely active (typeofone cancolor =speakerextendsPhysicsterrain<tbody>funeralviewingmiddle cricketprophetshifteddoctorsRussell targetcompactalgebrasocial-bulk ofman and</td>\n he left).val()false);logicalbankinghome tonaming Arizonacredits);\n});\nfounderin turnCollinsbefore But thechargedTitle\">CaptainspelledgoddessTag -->Adding:but wasRecent patientback in=false&Lincolnwe knowCounterJudaismscript altered']);\n has theunclearEvent',both innot all\n\n<!-- placinghard to centersort ofclientsstreetsBernardassertstend tofantasydown inharbourFreedomjewelry/about..searchlegendsis mademodern only ononly toimage\" linear painterand notrarely acronymdelivershorter00&as manywidth=\"/* <![Ctitle =of the lowest picked escapeduses ofpeoples PublicMatthewtacticsdamagedway forlaws ofeasy to windowstrong simple}catch(seventhinfoboxwent topaintedcitizenI don'tretreat. Some ww.\");\nbombingmailto:made in. Many carries||{};wiwork ofsynonymdefeatsfavoredopticalpageTraunless sendingleft\"><comScorAll thejQuery.touristClassicfalse\" Wilhelmsuburbsgenuinebishops.split(global followsbody ofnominalContactsecularleft tochiefly-hidden-banner</li>\n\n. When in bothdismissExplorealways via thespaC1olwelfareruling arrangecaptainhis sonrule ofhe tookitself,=0&(calledsamplesto makecom/pagMartin Kennedyacceptsfull ofhandledBesides//--></able totargetsessencehim to its by common.mineralto takeways tos.org/ladvisedpenaltysimple:if theyLettersa shortHerbertstrikes groups.lengthflightsoverlapslowly lesser social </p>\n\t\tit intoranked rate oful>\r\n attemptpair ofmake itKontaktAntoniohaving ratings activestreamstrapped\").css(hostilelead tolittle groups,Picture-->\r\n\r\n rows=\" objectinverse<footerCustomV><\\/scrsolvingChamberslaverywoundedwhereas!= 'undfor allpartly -right:Arabianbacked centuryunit ofmobile-Europe,is homerisk ofdesiredClintoncost ofage of become none ofp"Middle ead')[0Criticsstudios>©group\">assemblmaking pressedwidget.ps:\" ? rebuiltby someFormer editorsdelayedCanonichad thepushingclass=\"but arepartialBabylonbottom carrierCommandits useAs withcoursesa thirddenotesalso inHouston20px;\">accuseddouble goal ofFamous ).bind(priests Onlinein Julyst + \"gconsultdecimalhelpfulrevivedis veryr'+'iptlosing femalesis alsostringsdays ofarrivalfuture <objectforcingString(\" />\n\t\there isencoded. The balloondone by/commonbgcolorlaw of Indianaavoidedbut the2px 3pxjquery.after apolicy.men andfooter-= true;for usescreen.Indian image =family,http://  driverseternalsame asnoticedviewers})();\n is moreseasonsformer the newis justconsent Searchwas thewhy theshippedbr><br>width: height=made ofcuisineis thata very Admiral fixed;normal MissionPress, ontariocharsettry to invaded=\"true\"spacingis mosta more totallyfall of});\r\n immensetime inset outsatisfyto finddown tolot of Playersin Junequantumnot thetime todistantFinnishsrc = (single help ofGerman law andlabeledforestscookingspace\">header-well asStanleybridges/globalCroatia About [0];\n it, andgroupedbeing a){throwhe madelighterethicalFFFFFF\"bottom\"like a employslive inas seenprintermost ofub-linkrejectsand useimage\">succeedfeedingNuclearinformato helpWomen'sNeitherMexicanprotein<table by manyhealthylawsuitdevised.push({sellerssimply Through.cookie Image(older\">us.js\"> Since universlarger open to!-- endlies in']);\r\n marketwho is (\"DOMComanagedone fortypeof Kingdomprofitsproposeto showcenter;made itdressedwere inmixtureprecisearisingsrc = 'make a securedBaptistvoting \n\t\tvar March 2grew upClimate.removeskilledway the</head>face ofacting right\">to workreduceshas haderectedshow();action=book ofan area== \"htt<header\n<html>conformfacing cookie.rely onhosted .customhe wentbut forspread Family a meansout theforums.footage\">MobilClements\" id=\"as highintense--><!--female is seenimpliedset thea stateand hisfastestbesidesbutton_bounded\"><img Infoboxevents,a youngand areNative cheaperTimeoutand hasengineswon the(mostlyright: find a -bottomPrince area ofmore ofsearch_nature,legallyperiod,land ofor withinducedprovingmissilelocallyAgainstthe wayk"px;\">\r\npushed abandonnumeralCertainIn thismore inor somename isand, incrownedISBN 0-createsOctobermay notcenter late inDefenceenactedwish tobroadlycoolingonload=it. TherecoverMembersheight assumes<html>\npeople.in one =windowfooter_a good reklamaothers,to this_cookiepanel\">London,definescrushedbaptismcoastalstatus title\" move tolost inbetter impliesrivalryservers SystemPerhapses and contendflowinglasted rise inGenesisview ofrising seem tobut in backinghe willgiven agiving cities.flow of Later all butHighwayonly bysign ofhe doesdiffersbattery&lasinglesthreatsintegertake onrefusedcalled =US&See thenativesby thissystem.head of:hover,lesbiansurnameand allcommon/header__paramsHarvard/pixel.removalso longrole ofjointlyskyscraUnicodebr />\r\nAtlantanucleusCounty,purely count\">easily build aonclicka givenpointerh"events else {\nditionsnow the, with man whoorg/Webone andcavalryHe diedseattle00,000 {windowhave toif(windand itssolely m"renewedDetroitamongsteither them inSenatorUs</a><King ofFrancis-produche usedart andhim andused byscoringat hometo haverelatesibilityfactionBuffalolink\"><what hefree toCity ofcome insectorscountedone daynervoussquare };if(goin whatimg\" alis onlysearch/tuesdaylooselySolomonsexual - <a hrmedium\"DO NOT France,with a war andsecond take a >\r\n\r\n\r\nmarket.highwaydone inctivity\"last\">obligedrise to\"undefimade to Early praisedin its for hisathleteJupiterYahoo! termed so manyreally s. The a woman?value=direct right\" bicycleacing=\"day andstatingRather,higher Office are nowtimes, when a pay foron this-link\">;borderaround annual the Newput the.com\" takin toa brief(in thegroups.; widthenzymessimple in late{returntherapya pointbanninginks\">\n();\" rea place\\u003Caabout atr>\r\n\t\tccount gives a<SCRIPTRailwaythemes/toolboxById(\"xhumans,watchesin some if (wicoming formats Under but hashanded made bythan infear ofdenoted/iframeleft involtagein eacha"base ofIn manyundergoregimesaction </p>\r\n<ustomVa;></importsor thatmostly &re size=\"</a></ha classpassiveHost = WhetherfertileVarious=[];(fucameras/></td>acts asIn some>\r\n\r\n<!organis <br />BeijingcatalC deutscheuropeueuskaragaeilgesvenskaespaC1amensajeusuariotrabajomC)xicopC!ginasiempresistemaoctubreduranteaC1adirempresamomentonuestroprimeratravC)sgraciasnuestraprocesoestadoscalidadpersonanC:meroacuerdomC:sicamiembroofertasalgunospaC-sesejemploderechoademC!sprivadoagregarenlacesposiblehotelessevillaprimeroC:ltimoeventosarchivoculturamujeresentradaanuncioembargomercadograndesestudiomejoresfebrerodiseC1oturismocC3digoportadaespaciofamiliaantoniopermiteguardaralgunaspreciosalguiensentidovisitastC-tuloconocersegundoconsejofranciaminutossegundatenemosefectosmC!lagasesiC3nrevistagranadacompraringresogarcC-aacciC3necuadorquienesinclusodeberC!materiahombresmuestrapodrC-amaC1anaC:ltimaestamosoficialtambienningC:nsaludospodemosmejorarpositionbusinesshomepagesecuritylanguagestandardcampaignfeaturescategoryexternalchildrenreservedresearchexchangefavoritetemplatemilitaryindustryservicesmaterialproductsz-index:commentssoftwarecompletecalendarplatformarticlesrequiredmovementquestionbuildingpoliticspossiblereligionphysicalfeedbackregisterpicturesdisabledprotocolaudiencesettingsactivityelementslearninganythingabstractprogressoverviewmagazineeconomictrainingpressurevarious <strong>propertyshoppingtogetheradvancedbehaviordownloadfeaturedfootballselectedLanguagedistanceremembertrackingpasswordmodifiedstudentsdirectlyfightingnortherndatabasefestivalbreakinglocationinternetdropdownpracticeevidencefunctionmarriageresponseproblemsnegativeprogramsanalysisreleasedbanner\">purchasepoliciesregionalcreativeargumentbookmarkreferrerchemicaldivisioncallbackseparateprojectsconflicthardwareinterestdeliverymountainobtained= false;for(var acceptedcapacitycomputeridentityaircraftemployedproposeddomesticincludesprovidedhospitalverticalcollapseapproachpartnerslogo\"><adaughterauthor\" culturalfamilies/images/assemblypowerfulteachingfinisheddistrictcriticalcgi-bin/purposesrequireselectionbecomingprovidesacademicexerciseactuallymedicineconstantaccidentMagazinedocumentstartingbottom\">observed: "extendedpreviousSoftwarecustomerdecisionstrengthdetailedslightlyplanningtextareacurrencyeveryonestraighttransferpositiveproducedheritageshippingabsolutereceivedrelevantbutton\" violenceanywherebenefitslaunchedrecentlyalliancefollowedmultiplebulletinincludedoccurredinternal$(this).republic><tr><tdcongressrecordedultimatesolution<ul id=\"discoverHome</a>websitesnetworksalthoughentirelymemorialmessagescontinueactive\">somewhatvictoriaWestern title=\"LocationcontractvisitorsDownloadwithout right\">\nmeasureswidth = variableinvolvedvirginianormallyhappenedaccountsstandingnationalRegisterpreparedcontrolsaccuratebirthdaystrategyofficialgraphicscriminalpossiblyconsumerPersonalspeakingvalidateachieved.jpg\" />machines</h2>\n keywordsfriendlybrotherscombinedoriginalcomposedexpectedadequatepakistanfollow\" valuable</label>relativebringingincreasegovernorplugins/List of Header\">\" name=\" ("graduate</head>\ncommercemalaysiadirectormaintain;height:schedulechangingback to catholicpatternscolor: #greatestsuppliesreliable</ul>\n\t\t<select citizensclothingwatching<li id=\"specificcarryingsentence<center>contrastthinkingcatch(e)southernMichael merchantcarouselpadding:interior.split(\"lizationOctober ){returnimproved-->\n\ncoveragechairman.png\" />subjectsRichard whateverprobablyrecoverybaseballjudgmentconnect..css\" /> websitereporteddefault\"/></a>\r\nelectricscotlandcreationquantity. ISBN 0did not instance-search-\" lang=\"speakersComputercontainsarchivesministerreactiondiscountItalianocriteriastrongly: 'http:'script'coveringofferingappearedBritish identifyFacebooknumerousvehiclesconcernsAmericanhandlingdiv id=\"William provider_contentaccuracysection andersonflexibleCategorylawrence<script>layout=\"approved maximumheader\"></table>Serviceshamiltoncurrent canadianchannels/themes//articleoptionalportugalvalue=\"\"intervalwirelessentitledagenciesSearch\" measuredthousandspending…new Date\" size=\"pageNamemiddle\" \" /></a>hidden\">sequencepersonaloverflowopinionsillinoislinks\">\n\t<title>versionssaturdayterminalitempropengineersectionsdesignerproposal=\"false\"EspaC1olreleasessubmit\" er"additionsymptomsorientedresourceright\"><pleasurestationshistory.leaving border=contentscenter\">.\n\nSome directedsuitablebulgaria.show();designedGeneral conceptsExampleswilliamsOriginal\"><span>search\">operatorrequestsa "allowingDocumentrevision. \n\nThe yourselfContact michiganEnglish columbiapriorityprintingdrinkingfacilityreturnedContent officersRussian generate-8859-1\"indicatefamiliar qualitymargin:0 contentviewportcontacts-title\">portable.length eligibleinvolvesatlanticonload=\"default.suppliedpaymentsglossary\n\nAfter guidance</td><tdencodingmiddle\">came to displaysscottishjonathanmajoritywidgets.clinicalthailandteachers<head>\n\taffectedsupportspointer;toString</small>oklahomawill be investor0\" alt=\"holidaysResourcelicensed (which . After considervisitingexplorerprimary search\" android\"quickly meetingsestimate;return ;color:# height=approval, " checked.min.js\"magnetic></a></hforecast. While thursdaydvertiseéhasClassevaluateorderingexistingpatients Online coloradoOptions\"campbell<!-- end</span><<br />\r\n_popups|sciences," quality Windows assignedheight: <b classle" value=\" Companyexamples<iframe believespresentsmarshallpart of properly).\n\nThe taxonomymuch of </span>\n\" data-srtuguC*sscrollTo project<head>\r\nattorneyemphasissponsorsfancyboxworld's wildlifechecked=sessionsprogrammpx;font- Projectjournalsbelievedvacationthompsonlightingand the special border=0checking</tbody><button Completeclearfix\n<head>\narticle <sectionfindingsrole in popular Octoberwebsite exposureused to changesoperatedclickingenteringcommandsinformed numbers </div>creatingonSubmitmarylandcollegesanalyticlistingscontact.loggedInadvisorysiblingscontent\"s")s. This packagescheckboxsuggestspregnanttomorrowspacing=icon.pngjapanesecodebasebutton\">gamblingsuch as , while </span> missourisportingtop:1px .</span>tensionswidth=\"2lazyloadnovemberused in height=\"cript\">\n </<tr><td height:2/productcountry include footer\" <!-- title\"></jquery.</form>\n(g.\u0000d=\u0013)(g9\u0001i+\u0014)hrvatskiitalianoromC\"nD\u0003tC<rkC'eX'X1X/Y\u0008tambiC)nnoticiasmensajespersonasderechosnacionalserviciocontactousuariosprogramagobiernoempresasanunciosvalenciacolombiadespuC)sdeportesproyectoproductopC:bliconosotroshistoriapresentemillonesmediantepreguntaanteriorrecursosproblemasantiagonuestrosopiniC3nimprimirmientrasamC)ricavendedorsociedadrespectorealizarregistropalabrasinterC)sentoncesespecialmiembrosrealidadcC3rdobazaragozapC!ginassocialesbloqueargestiC3nalquilersistemascienciascompletoversiC3ncompletaestudiospC:blicaobjetivoalicantebuscadorcantidadentradasaccionesarchivossuperiormayorC-aalemaniafunciC3nC:ltimoshaciendoaquellosediciC3nfernandoambientefacebooknuestrasclientesprocesosbastantepresentareportarcongresopublicarcomerciocontratojC3venesdistritotC)cnicaconjuntoenergC-atrabajarasturiasrecienteutilizarboletC-nsalvadorcorrectatrabajosprimerosnegocioslibertaddetallespantallaprC3ximoalmerC-aanimalesquiC)nescorazC3nsecciC3nbuscandoopcionesexteriorconceptotodavC-agalerC-aescribirmedicinalicenciaconsultaaspectoscrC-ticadC3laresjusticiadeberC!nperC-odonecesitamantenerpequeC1orecibidatribunaltenerifecanciC3ncanariasdescargadiversosmallorcarequieretC)cnicodeberC-aviviendafinanzasadelantefuncionaconsejosdifC-cilciudadesantiguasavanzadatC)rminounidadessC!nchezcampaC1asoftonicrevistascontienesectoresmomentosfacultadcrC)ditodiversassupuestofactoressegundospequeC1aP3P>P4P0P5Q\u0001P;P8P5Q\u0001Q\u0002Q\u000CP1Q\u000BP;P>P1Q\u000BQ\u0002Q\u000CQ\rQ\u0002P>P<P\u0015Q\u0001P;P8Q\u0002P>P3P>P<P5P=Q\u000FP2Q\u0001P5Q\u0005Q\rQ\u0002P>P9P4P0P6P5P1Q\u000BP;P8P3P>P4Q\u0003P4P5P=Q\u000CQ\rQ\u0002P>Q\u0002P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0006X4X(Y\u0003X)Y\u0001Y\nY\u0007X'X(Y\u0006X'X*X-Y\u0008X'X!X#Y\u0003X+X1X.Y\u0004X'Y\u0004X'Y\u0004X-X(X/Y\u0004Y\nY\u0004X/X1Y\u0008X3X'X6X:X7X*Y\u0003Y\u0008Y\u0006Y\u0007Y\u0006X'Y\u0003X3X'X-X)Y\u0006X'X/Y\nX'Y\u0004X7X(X9Y\u0004Y\nY\u0003X4Y\u0003X1X'Y\nY\u0005Y\u0003Y\u0006Y\u0005Y\u0006Y\u0007X'X4X1Y\u0003X)X1X&Y\nX3Y\u0006X4Y\nX7Y\u0005X'X0X'X'Y\u0004Y\u0001Y\u0006X4X(X'X(X*X9X(X1X1X-Y\u0005X)Y\u0003X'Y\u0001X)Y\nY\u0002Y\u0008Y\u0004Y\u0005X1Y\u0003X2Y\u0003Y\u0004Y\u0005X)X#X-Y\u0005X/Y\u0002Y\u0004X(Y\nY\nX9Y\u0006Y\nX5Y\u0008X1X)X7X1Y\nY\u0002X4X'X1Y\u0003X,Y\u0008X'Y\u0004X#X.X1Y\tY\u0005X9Y\u0006X'X'X(X-X+X9X1Y\u0008X6X(X4Y\u0003Y\u0004Y\u0005X3X,Y\u0004X(Y\u0006X'Y\u0006X.X'Y\u0004X/Y\u0003X*X'X(Y\u0003Y\u0004Y\nX)X(X/Y\u0008Y\u0006X#Y\nX6X'Y\nY\u0008X,X/Y\u0001X1Y\nY\u0002Y\u0003X*X(X*X#Y\u0001X6Y\u0004Y\u0005X7X(X.X'Y\u0003X+X1X(X'X1Y\u0003X'Y\u0001X6Y\u0004X'X-Y\u0004Y\tY\u0006Y\u0001X3Y\u0007X#Y\nX'Y\u0005X1X/Y\u0008X/X#Y\u0006Y\u0007X'X/Y\nY\u0006X'X'Y\u0004X'Y\u0006Y\u0005X9X1X6X*X9Y\u0004Y\u0005X/X'X.Y\u0004Y\u0005Y\u0005Y\u0003Y\u0006\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0002\u0000\u0002\u0000\u0002\u0000\u0002\u0000\u0004\u0000\u0004\u0000\u0004\u0000\u0004\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0007\u0006\u0005\u0004\u0003\u0002\u0001\u0000\u0008\t\n\u000B\u000C\r\u000E\u000F\u000F\u000E\r\u000C\u000B\n\t\u0008\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0017\u0016\u0015\u0014\u0013\u0012\u0011\u0010\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F\u001F\u001E\u001D\u001C\u001B\u001A\u0019\u0018\u007F\u007F\u007F\u007F\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u007F\u007F\u007F\u007F\u0001\u0000\u0000\u0000\u0002\u0000\u0000\u0000\u0002\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0003\u0000\u0000\u0000\u007F\u007F\u0000\u0001\u0000\u0000\u0000\u0001\u0000\u0000\u007F\u007F\u0000\u0001\u0000\u0000\u0000\u0008\u0000\u0008\u0000\u0008\u0000\u0008\u0000\u0000\u0000\u0001\u0000\u0002\u0000\u0003\u0000\u0004\u0000\u0005\u0000\u0006\u0000\u0007resourcescountriesquestionsequipmentcommunityavailablehighlightDTD/xhtmlmarketingknowledgesomethingcontainerdirectionsubscribeadvertisecharacter\" value=\"</select>Australia\" class=\"situationauthorityfollowingprimarilyoperationchallengedevelopedanonymousfunction functionscompaniesstructureagreement\" title=\"potentialeducationargumentssecondarycopyrightlanguagesexclusivecondition</form>\r\nstatementattentionBiography} else {\nsolutionswhen the Analyticstemplatesdangeroussatellitedocumentspublisherimportantprototypeinfluence»</effectivegenerallytransformbeautifultransportorganizedpublishedprominentuntil thethumbnailNational .focus();over the migrationannouncedfooter\">\nexceptionless thanexpensiveformationframeworkterritoryndicationcurrentlyclassNamecriticismtraditionelsewhereAlexanderappointedmaterialsbroadcastmentionedaffiliate</option>treatmentdifferent/default.Presidentonclick=\"biographyotherwisepermanentFranC'aisHollywoodexpansionstandards</style>\nreductionDecember preferredCambridgeopponentsBusiness confusion>\n<title>presentedexplaineddoes not worldwideinterfacepositionsnewspaper</table>\nmountainslike the essentialfinancialselectionaction=\"/abandonedEducationparseInt(stabilityunable to\nrelationsNote thatefficientperformedtwo yearsSince thethereforewrapper\">alternateincreasedBattle ofperceivedtrying tonecessaryportrayedelectionsElizabethdiscoveryinsurances.length;legendaryGeographycandidatecorporatesometimesservices.inheritedCommunityreligiouslocationsCommitteebuildingsthe worldno longerbeginningreferencecannot befrequencytypicallyinto the relative;recordingpresidentinitiallytechniquethe otherit can beexistenceunderlinethis timetelephoneitemscopepracticesadvantage);return For otherprovidingdemocracyboth the extensivesufferingsupportedcomputers functionpracticalsaid thatit may beEnglish\nsuspectedmargin: 0spiritual\n\nmicrosoftgraduallydiscussedhe becameexecutivejquery.jshouseholdconfirmedpurchasedliterallydestroyedup to thevariationremainingit is notcenturiesJapanese among thecompletedalgorithminterestsrebellionundefinedencourageresizableinvolvingsensitiveuniversalprovision(althoughfeaturingconducted), which continued-header\">February numerous overflow:componentfragmentsexcellentcolspan=\"technicalnear the Advanced source ofexpressedHong Kong Facebookmultiple mechanismelevationoffensive\n\tsponsoreddocument.or "there arethose whomovementsprocessesdifficultsubmittedrecommendconvincedpromoting\" width=\".replace(classicalcoalitionhis firstdecisionsassistantindicatedevolution-wrapper\"enough toalong thedelivered-->\r\n\n\r\n
Archbishop class=\"nobeing usedapproachesprivilegesnoscript>\nresults inmay be theEaster eggmechanismsreasonablePopulationCollectionselected\">noscript>\r/index.phparrival of-jssdk'));managed toincompletecasualtiescompletionChristiansSeptember arithmeticproceduresmight haveProductionit appearsPhilosophyfriendshipleading togiving thetoward theguaranteeddocumentedcolor:#000video gamecommissionreflectingchange theassociatedsans-serifonkeypress; padding:He was theunderlyingtypically , and the srcElementsuccessivesince the should be networkingaccountinguse of thelower thanshows that\n\t\tcomplaintscontinuousquantitiesastronomerhe did notdue to itsapplied toan averageefforts tothe futureattempt toTherefore,capabilityRepublicanwas formedElectronickilometerschallengespublishingthe formerindigenousdirectionssubsidiaryconspiracydetails ofand in theaffordablesubstancesreason forconventionitemtype=\"absolutelysupposedlyremained aattractivetravellingseparatelyfocuses onelementaryapplicablefound thatstylesheetmanuscriptstands for no-repeat(sometimesCommercialin Americaundertakenquarter ofan examplepersonallyindex.php?\npercentagebest-knowncreating a\" dir=\"ltrLieutenant\n
is said tostructuralreferendummost oftena separate->\n
soundtracksearchFormtend to beinput id=\"opening ofrestrictedadopted byaddressingtheologianmethods ofvariant ofChristian very largeautomotiveby far therange frompursuit offollow thebrought toin Englandagree thataccused ofcomes frompreventingdiv style=his or hertremendousfreedom ofconcerning0 1em 1em;Basketball/style.cssan earliereven after/\" title=\".com/indextaking thepittsburghcontent\">\rimplementedcan be seenthere was ademonstratecontainer\">connectionsthe Britishwas written!important;px; margin-followed byability to complicatedduring the immigrationalso called

\n

acquisitioncalled the persecutiondesignation{font-size:appeared ininvestigateexperiencedmost likelywidely useddiscussionspresence of (document.extensivelyIt has beenit does notcontrary toinhabitantsimprovementscholarshipconsumptioninstructionfor exampleone or morepx; paddingthe currenta series ofare usuallyrole in thepreviously derivativesevidence ofexperiencescolorschemestated thatcertificate
\n selected=\"high schoolresponse tocomfortableadoption ofthree yearsthe countryin Februaryso that thepeople who provided by\nhaving been\r\n\r\n< "The compilationhe had beenproduced byphilosopherconstructedintended toamong othercompared toto say thatEngineeringa differentreferred todifferencesbelief thatphotographsidentifyingHistory of Republic ofnecessarilyprobabilitytechnicallyleaving thespectacularfraction ofelectricityhead of therestaurantspartnershipemphasis onmost recentshare with saying thatfilled withdesigned toit is often\">as follows:merged withthrough thecommercial pointed outopportunityview of therequirementdivision ofprogramminghe receivedsetInterval\">maintainingChristopherMuch of thewritings of\" height=\"2size of theversion of mixture of between theExamples ofeducationalcompetitive onsubmit=\"director ofdistinctive/DTD XHTML relating totendency toprovince ofwhich woulddespite thescientific legislature.innerHTML allegationsAgriculturewas used inapproach tointelligentyears later,sans-serifdeterminingPerformanceappearances, which is foundationsabbreviatedhigher thans from the individual composed ofsupposed toclaims thatattributionfont-size:1elements ofHistorical his brotherat the timeanniversarygoverned byrelated to ultimately innovationsit is stillcan only bedefinitionstoGMTStringA number ofimg class=\"Eventually,was changedoccurred inneighboringdistinguishwhen he wasintroducingterrestrialMany of theargues thatan Americanconquest ofwidespread were killedscreen and In order toexpected todescendantsare locatedlegislativegenerations backgroundmost peopleyears afterthere is nothe highestfrequently they do notargued thatshowed thatpredominanttheologicalby the timeconsideringshort-livedcan be usedvery littleone of the had alreadyinterpretedcommunicatefeatures ofgovernment,entered the\" height=\"3Independentpopulationslarge-scale. Although used in thedestructionpossibilitystarting intwo or moreexpressionssubordinatelarger thanhistory and\r\nContinentaleliminatingwill not bepractice ofin front ofsite of theensure thatto create amississippipotentiallyoutstandingbetter thanwhat is nowsituated inmeta name=\"TraditionalsuggestionsTranslationthe form ofatmosphericideologicalenterprisescalculatingeast of theremnants ofpluginspage/index.php?remained intransformedHe was alsowas alreadystatisticalin favor ofMinistry ofmovement offormulationis required\nquestion ofwas electedto become abecause of some peopleinspired bysuccessful a time whenmore commonamongst thean officialwidth:100%;technology,was adoptedto keep thesettlementslive birthsindex.html\"Connecticutassigned to&times;account foralign=rightthe companyalways beenreturned toinvolvementBecause thethis period\" name=\"q\" confined toa result ofvalue=\"\" />is actuallyEnvironment\r\n\r\nConversely,>\n
this is notthe presentif they areand finallya matter of\r\n\t
\r\n\r\nfaster thanmajority ofafter whichcomparativeto maintainimprove theawarded theer\" class=\"frameborderrestorationin the sameanalysis oftheir firstDuring the continentalsequence offunction(){font-size: work on the\nadopted theproperty ofdirected byeffectivelywas broughtchildren ofProgramminglonger thanmanuscriptswar againstby means ofand most ofsimilar to proprietaryoriginatingprestigiousgrammaticalexperience.to make theIt was alsois found incompetitorsin the U.S.replace thebrought thecalculationfall of thethe generalpracticallyin honor ofreleased inresidentialand some ofking of thereaction to1st Earl ofculture andprincipally\n they can beback to thesome of hisexposure toare similarform of theaddFavoritecitizenshippart in thepeople within practiceto continue&minus;approved by the first allowed theand for thefunctioningplaying thesolution toheight=\"0\" in his bookmore than afollows thecreated thepresence in nationalistthe idea ofa characterwere forced class=\"btndays of thefeatured inshowing theinterest inin place ofturn of thethe head ofLord of thepoliticallyhas its ownEducationalapproval ofsome of theeach other,behavior ofand becauseand anotherappeared onrecorded inblack"may includethe world'scan lead torefers to aborder=\"0\" government winning theresulted in while the Washington,the subjectcity in the>\r\n\t\treflect theto completebecame moreradioactiverejected bywithout anyhis father,which couldcopy of theto indicatea politicalaccounts ofconstitutesworked wither
of his lifeaccompaniedclientWidthprevent theLegislativedifferentlytogether inhas severalfor anothertext of thefounded thee with the is used forchanged theusually theplace wherewhereas the> \nHowever thelead to the\tThe currentthe site ofsubstantialexperience,in the Westthey shouldslovenD\rinacomentariosuniversidadcondicionesactividadesexperienciatecnologC-aproducciC3npuntuaciC3naplicaciC3ncontraseC1acategorC-asregistrarseprofesionaltratamientoregC-stratesecretarC-aprincipalesprotecciC3nimportantesimportanciaposibilidadinteresantecrecimientonecesidadessuscribirseasociaciC3ndisponiblesevaluaciC3nestudiantesresponsableresoluciC3nguadalajararegistradosoportunidadcomercialesfotografC-aautoridadesingenierC-atelevisiC3ncompetenciaoperacionesestablecidosimplementeactualmentenavegaciC3nconformidadline-height:font-family:\" : \"http://applicationslink\" href=\"specifically//\n/index.html\"window.open( !important;application/independence//www.googleorganizationautocompleterequirementsconservative
most notably/>notification'undefined')Furthermore,believe thatinnerHTML = prior to thedramaticallyreferring tonegotiationsheadquartersSouth AfricaunsuccessfulPennsylvaniaAs a result,\npadding-top:experimentalgetAttributeinstructionstechnologiespart of the =function(){subscriptionl.dtd\">\r\nEnglish (US)appendChild(transmissions. However, intelligence\" tabindex=\"float:right;Commonwealthranging fromin which theat least onereproductionencyclopedia;font-size:1jurisdictionat that time\">compensationchampionshipmedia=\"all\" violation ofreference toreturn true;Strict//EN\" transactionsinterventionverificationInformation difficultiesChampionshipcapabilities}\n\nChristianityfor example,Professionalrestrictionssuggest thatwas released(such as theremoveClass(unemploymentthe Americanstructure of/index.html published inspan class=\"\">\n\nf (document.border: 1px {font-size:1treatment of0\" height=\"1modificationIndependencedivided intogreater thanachievementsestablishingJavaScript\" neverthelesssignificanceBroadcasting> container\">\nsuch as the influence ofa particularsrc='http://navigation\" half of the substantial  advantage ofdiscovery offundamental metropolitanthe opposite\" xml:lang=\"deliberatelyalign=centerevolution ofpreservationimprovementsbeginning inJesus ChristPublicationsdisagreementtext-align:r, function()similaritiesbody>is currentlyalphabeticalis sometimestype=\"image/many of the flow:hidden;available indescribe theexistence ofall over thethe Internet\t