├── LICENSE ├── README.md ├── ayumi.js ├── index.html ├── nq_taimat.fym └── pako_inflate.min.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) Peter Sovietov, http://sovietov.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ayumi.js 2 | ======== 3 | 4 | Highly precise emulation of AY-3-8910 and YM2149 sound chips. 5 | 6 | Ported to JavaScript from [original Ayumi C code by Peter Sovietov](https://github.com/true-grue/ayumi). 7 | 8 | [Listen to it in action](http://pure-garden-1548.herokuapp.com/) 9 | -------------------------------------------------------------------------------- /ayumi.js: -------------------------------------------------------------------------------- 1 | /* Author: Peter Sovietov */ 2 | /* Javascript version: Alexander Kovalenko */ 3 | 4 | const DECIMATE_FACTOR = 8; 5 | const FIR_SIZE = 192; 6 | const DC_FILTER_SIZE = 1024; 7 | 8 | const AY_DAC_TABLE = [ 9 | 0.0, 0.0, 10 | 0.00999465934234, 0.00999465934234, 11 | 0.0144502937362, 0.0144502937362, 12 | 0.0210574502174, 0.0210574502174, 13 | 0.0307011520562, 0.0307011520562, 14 | 0.0455481803616, 0.0455481803616, 15 | 0.0644998855573, 0.0644998855573, 16 | 0.107362478065, 0.107362478065, 17 | 0.126588845655, 0.126588845655, 18 | 0.20498970016, 0.20498970016, 19 | 0.292210269322, 0.292210269322, 20 | 0.372838941024, 0.372838941024, 21 | 0.492530708782, 0.492530708782, 22 | 0.635324635691, 0.635324635691, 23 | 0.805584802014, 0.805584802014, 24 | 1.0, 1.0 25 | ] 26 | 27 | const YM_DAC_TABLE = [ 28 | 0.0, 0.0, 29 | 0.00465400167849, 0.00772106507973, 30 | 0.0109559777218, 0.0139620050355, 31 | 0.0169985503929, 0.0200198367285, 32 | 0.024368657969, 0.029694056611, 33 | 0.0350652323186, 0.0403906309606, 34 | 0.0485389486534, 0.0583352407111, 35 | 0.0680552376593, 0.0777752346075, 36 | 0.0925154497597, 0.111085679408, 37 | 0.129747463188, 0.148485542077, 38 | 0.17666895552, 0.211551079576, 39 | 0.246387426566, 0.281101701381, 40 | 0.333730067903, 0.400427252613, 41 | 0.467383840696, 0.53443198291, 42 | 0.635172045472, 0.75800717174, 43 | 0.879926756695, 1.0 44 | ] 45 | 46 | Ayumi = function() { 47 | this.channels = this.getChannels(); 48 | 49 | this.noisePeriod = 0; 50 | this.noiseCounter = 0; 51 | this.noise = 0; 52 | 53 | this.envelopes = this.getEnvelopeShapes(); 54 | this.envelopeCounter = 0; 55 | this.envelopePeriod = 0; 56 | this.envelopeShape = 0; 57 | this.envelopeSegment = 0; 58 | this.envelope = 0; 59 | 60 | this.dacTable = YM_DAC_TABLE; 61 | 62 | this.step = 0.0; 63 | this.x = 0.0; 64 | 65 | this.left = 0.0; 66 | this.right = 0.0; 67 | 68 | this.interpolatorLeft = { 69 | c: new Float64Array(4), 70 | y: new Float64Array(4) 71 | } 72 | this.interpolatorRight = { 73 | c: new Float64Array(4), 74 | y: new Float64Array(4) 75 | } 76 | 77 | this.dcFilterLeft = { 78 | sum: 0.0, 79 | delay: new Float64Array(DC_FILTER_SIZE) 80 | } 81 | this.dcFilterRight = { 82 | sum: 0.0, 83 | delay: new Float64Array(DC_FILTER_SIZE) 84 | } 85 | this.dcIndex = 0; 86 | 87 | this.firLeft = new Float64Array(FIR_SIZE * 2); 88 | this.firRight = new Float64Array(FIR_SIZE * 2); 89 | this.firIndex = 0; 90 | } 91 | 92 | Ayumi.prototype.Channel = function() { 93 | return { 94 | toneCounter: 0, tonePeriod: 0, tone: 0, 95 | tOff: 0, nOff: 0, eOn: 0, 96 | volume: 0, 97 | panLeft: 1.0, panRight: 1.0 98 | }; 99 | } 100 | 101 | Ayumi.prototype.getChannels = function() { 102 | return [ 103 | new this.Channel, 104 | new this.Channel, 105 | new this.Channel 106 | ]; 107 | } 108 | 109 | Ayumi.prototype.getEnvelopeShapes = function() { 110 | return [ 111 | [ this.slideDown, this.holdBottom ], 112 | [ this.slideDown, this.holdBottom ], 113 | [ this.slideDown, this.holdBottom ], 114 | [ this.slideDown, this.holdBottom ], 115 | 116 | [ this.slideUp, this.holdBottom ], 117 | [ this.slideUp, this.holdBottom ], 118 | [ this.slideUp, this.holdBottom ], 119 | [ this.slideUp, this.holdBottom ], 120 | 121 | [ this.slideDown, this.slideDown ], 122 | [ this.slideDown, this.holdBottom ], 123 | [ this.slideDown, this.slideUp ], 124 | [ this.slideDown, this.holdTop ], 125 | 126 | [ this.slideUp, this.slideUp ], 127 | [ this.slideUp, this.holdTop ], 128 | [ this.slideUp, this.slideDown ], 129 | [ this.slideUp, this.holdBottom ] 130 | ] 131 | }; 132 | 133 | Ayumi.prototype.updateTone = function(index) { 134 | var ch = this.channels[index]; 135 | if(++ch.toneCounter >= ch.tonePeriod) { 136 | ch.toneCounter = 0; 137 | ch.tone ^= 1; 138 | } 139 | return ch.tone; 140 | } 141 | 142 | Ayumi.prototype.updateNoise = function() { 143 | if(++this.noiseCounter >= (this.noisePeriod << 1)) { 144 | this.noiseCounter = 0; 145 | var bit0x3 = (this.noise ^ (this.noise >> 3)) & 1; 146 | this.noise = (this.noise >> 1) | (bit0x3 << 16); 147 | } 148 | return this.noise & 1; 149 | } 150 | 151 | Ayumi.prototype.slideUp = function(e) { 152 | if(++e.envelope > 31) { 153 | e.envelopeSegment ^= 1; 154 | e.resetSegment(); 155 | } 156 | } 157 | 158 | Ayumi.prototype.slideDown = function(e) { 159 | if(--e.envelope < 0) { 160 | e.envelopeSegment ^= 1; 161 | e.resetSegment(); 162 | } 163 | } 164 | 165 | Ayumi.prototype.holdTop = function(e) {}; 166 | 167 | Ayumi.prototype.holdBottom = function(e) {}; 168 | 169 | Ayumi.prototype.resetSegment = function() { 170 | var env = this.envelopes[this.envelopeShape][this.envelopeSegment]; 171 | this.envelope = (env == this.slideDown || env == this.holdTop) ? 31 : 0; 172 | } 173 | 174 | Ayumi.prototype.updateEnvelope = function() { 175 | if(++this.envelopeCounter >= this.envelopePeriod) { 176 | this.envelopeCounter = 0; 177 | this.envelopes[this.envelopeShape][this.envelopeSegment](this); 178 | } 179 | return this.envelope; 180 | } 181 | 182 | Ayumi.prototype.updateMixer = function() { 183 | var out; 184 | var noise = this.updateNoise(); 185 | var envelope = this.updateEnvelope(); 186 | this.left = 0; 187 | this.right = 0; 188 | for(var i = 0; i < this.channels.length; i++) { 189 | out = (this.updateTone(i) | this.channels[i].tOff) & 190 | (noise | this.channels[i].nOff); 191 | out *= this.channels[i].eOn ? envelope : this.channels[i].volume * 2 + 1; 192 | this.left += this.dacTable[out] * this.channels[i].panLeft; 193 | this.right += this.dacTable[out] * this.channels[i].panRight; 194 | } 195 | } 196 | 197 | Ayumi.prototype.configure = function(isYM, clockRate, sr) { 198 | this.step = clockRate / (sr * 8 * DECIMATE_FACTOR); 199 | this.dacTable = isYM ? YM_DAC_TABLE : AY_DAC_TABLE; 200 | this.noise = 1; 201 | this.setEnvelope(1); 202 | for(var i = 0; i < this.channels.length; i++) { 203 | this.setTone(i, 1); 204 | } 205 | } 206 | 207 | Ayumi.prototype.setPan = function(index, pan, isEqp) { 208 | if(isEqp) { 209 | this.channels[index].panLeft = Math.sqrt(1 - pan); 210 | this.channels[index].panRight = Math.sqrt(pan); 211 | } else { 212 | this.channels[index].panLeft = 1 - pan; 213 | this.channels[index].panRight = pan; 214 | } 215 | } 216 | 217 | Ayumi.prototype.setTone = function(index, period) { 218 | period &= 0xfff; 219 | this.channels[index].tonePeriod = (period == 0) | period; 220 | } 221 | 222 | Ayumi.prototype.setNoise = function(period) { 223 | this.noisePeriod = period & 0x1f; 224 | } 225 | 226 | Ayumi.prototype.setMixer = function(index, tOff, nOff, eOn) { 227 | this.channels[index].tOff = tOff & 1; 228 | this.channels[index].nOff = nOff & 1; 229 | this.channels[index].eOn = eOn & 1; 230 | } 231 | 232 | Ayumi.prototype.setVolume = function(index, volume) { 233 | this.channels[index].volume = volume & 0x0f; 234 | } 235 | 236 | Ayumi.prototype.setEnvelope = function(period) { 237 | period &= 0xffff; 238 | this.envelopePeriod = (period == 0) | period; 239 | } 240 | 241 | Ayumi.prototype.setEnvelopeShape = function(shape) { 242 | this.envelopeShape = shape & 0x0f; 243 | this.envelopeCounter = 0; 244 | this.envelopeSegment = 0; 245 | this.resetSegment(); 246 | } 247 | 248 | Ayumi.prototype.decimate = function(x) { 249 | var y = -0.0000046183113992051936 * (x[1] + x[191]) + 250 | -0.00001117761640887225 * (x[2] + x[190]) + 251 | -0.000018610264502005432 * (x[3] + x[189]) + 252 | -0.000025134586135631012 * (x[4] + x[188]) + 253 | -0.000028494281690666197 * (x[5] + x[187]) + 254 | -0.000026396828793275159 * (x[6] + x[186]) + 255 | -0.000017094212558802156 * (x[7] + x[185]) + 256 | 0.000023798193576966866 * (x[9] + x[183]) + 257 | 0.000051281160242202183 * (x[10] + x[182]) + 258 | 0.00007762197826243427 * (x[11] + x[181]) + 259 | 0.000096759426664120416 * (x[12] + x[180]) + 260 | 0.00010240229300393402 * (x[13] + x[179]) + 261 | 0.000089344614218077106 * (x[14] + x[178]) + 262 | 0.000054875700118949183 * (x[15] + x[177]) + 263 | -0.000069839082210680165 * (x[17] + x[175]) + 264 | -0.0001447966132360757 * (x[18] + x[174]) + 265 | -0.00021158452917708308 * (x[19] + x[173]) + 266 | -0.00025535069106550544 * (x[20] + x[172]) + 267 | -0.00026228714374322104 * (x[21] + x[171]) + 268 | -0.00022258805927027799 * (x[22] + x[170]) + 269 | -0.00013323230495695704 * (x[23] + x[169]) + 270 | 0.00016182578767055206 * (x[25] + x[167]) + 271 | 0.00032846175385096581 * (x[26] + x[166]) + 272 | 0.00047045611576184863 * (x[27] + x[165]) + 273 | 0.00055713851457530944 * (x[28] + x[164]) + 274 | 0.00056212565121518726 * (x[29] + x[163]) + 275 | 0.00046901918553962478 * (x[30] + x[162]) + 276 | 0.00027624866838952986 * (x[31] + x[161]) + 277 | -0.00032564179486838622 * (x[33] + x[159]) + 278 | -0.00065182310286710388 * (x[34] + x[158]) + 279 | -0.00092127787309319298 * (x[35] + x[157]) + 280 | -0.0010772534348943575 * (x[36] + x[156]) + 281 | -0.0010737727700273478 * (x[37] + x[155]) + 282 | -0.00088556645390392634 * (x[38] + x[154]) + 283 | -0.00051581896090765534 * (x[39] + x[153]) + 284 | 0.00059548767193795277 * (x[41] + x[151]) + 285 | 0.0011803558710661009 * (x[42] + x[150]) + 286 | 0.0016527320270369871 * (x[43] + x[149]) + 287 | 0.0019152679330965555 * (x[44] + x[148]) + 288 | 0.0018927324805381538 * (x[45] + x[147]) + 289 | 0.0015481870327877937 * (x[46] + x[146]) + 290 | 0.00089470695834941306 * (x[47] + x[145]) + 291 | -0.0010178225878206125 * (x[49] + x[143]) + 292 | -0.0020037400552054292 * (x[50] + x[142]) + 293 | -0.0027874356824117317 * (x[51] + x[141]) + 294 | -0.003210329988021943 * (x[52] + x[140]) + 295 | -0.0031540624117984395 * (x[53] + x[139]) + 296 | -0.0025657163651900345 * (x[54] + x[138]) + 297 | -0.0014750752642111449 * (x[55] + x[137]) + 298 | 0.0016624165446378462 * (x[57] + x[135]) + 299 | 0.0032591192839069179 * (x[58] + x[134]) + 300 | 0.0045165685815867747 * (x[59] + x[133]) + 301 | 0.0051838984346123896 * (x[60] + x[132]) + 302 | 0.0050774264697459933 * (x[61] + x[131]) + 303 | 0.0041192521414141585 * (x[62] + x[130]) + 304 | 0.0023628575417966491 * (x[63] + x[129]) + 305 | -0.0026543507866759182 * (x[65] + x[127]) + 306 | -0.0051990251084333425 * (x[66] + x[126]) + 307 | -0.0072020238234656924 * (x[67] + x[125]) + 308 | -0.0082672928192007358 * (x[68] + x[124]) + 309 | -0.0081033739572956287 * (x[69] + x[123]) + 310 | -0.006583111539570221 * (x[70] + x[122]) + 311 | -0.0037839040415292386 * (x[71] + x[121]) + 312 | 0.0042781252851152507 * (x[73] + x[119]) + 313 | 0.0084176358598320178 * (x[74] + x[118]) + 314 | 0.01172566057463055 * (x[75] + x[117]) + 315 | 0.013550476647788672 * (x[76] + x[116]) + 316 | 0.013388189369997496 * (x[77] + x[115]) + 317 | 0.010979501242341259 * (x[78] + x[114]) + 318 | 0.006381274941685413 * (x[79] + x[113]) + 319 | -0.007421229604153888 * (x[81] + x[111]) + 320 | -0.01486456304340213 * (x[82] + x[110]) + 321 | -0.021143584622178104 * (x[83] + x[109]) + 322 | -0.02504275058758609 * (x[84] + x[108]) + 323 | -0.025473530942547201 * (x[85] + x[107]) + 324 | -0.021627310017882196 * (x[86] + x[106]) + 325 | -0.013104323383225543 * (x[87] + x[105]) + 326 | 0.017065133989980476 * (x[89] + x[103]) + 327 | 0.036978919264451952 * (x[90] + x[102]) + 328 | 0.05823318062093958 * (x[91] + x[101]) + 329 | 0.079072012081405949 * (x[92] + x[100]) + 330 | 0.097675998716952317 * (x[93] + x[99]) + 331 | 0.11236045936950932 * (x[94] + x[98]) + 332 | 0.12176343577287731 * (x[95] + x[97]) + 333 | 0.125 * x[96]; 334 | for(var i = 0; i < DECIMATE_FACTOR; i++) { 335 | x[FIR_SIZE - DECIMATE_FACTOR + i] = x[i]; 336 | } 337 | return y; 338 | } 339 | 340 | Ayumi.prototype.process = function() { 341 | var y1; 342 | 343 | var cLeft = this.interpolatorLeft.c; 344 | var yLeft = this.interpolatorLeft.y; 345 | 346 | var cRight = this.interpolatorRight.c; 347 | var yRight = this.interpolatorRight.y; 348 | 349 | var firOffset = FIR_SIZE - this.firIndex * DECIMATE_FACTOR; 350 | var firLeft = this.firLeft.subarray(firOffset); 351 | var firRight = this.firRight.subarray(firOffset); 352 | 353 | this.firIndex = (this.firIndex + 1) % (FIR_SIZE / DECIMATE_FACTOR - 1); 354 | 355 | for(var i = DECIMATE_FACTOR - 1; i >= 0; i--) { 356 | this.x += this.step; 357 | if(this.x >= 1) { 358 | this.x--; 359 | yLeft[0] = yLeft[1]; 360 | yLeft[1] = yLeft[2]; 361 | yLeft[2] = yLeft[3]; 362 | 363 | yRight[0] = yRight[1]; 364 | yRight[1] = yRight[2]; 365 | yRight[2] = yRight[3]; 366 | 367 | this.updateMixer(); 368 | 369 | yLeft[3] = this.left; 370 | yRight[3] = this.right; 371 | 372 | y1 = yLeft[2] - yLeft[0]; 373 | cLeft[0] = 0.5 * yLeft[1] + 0.25 * (yLeft[0] + yLeft[2]); 374 | cLeft[1] = 0.5 * y1; 375 | cLeft[2] = 0.25 * (yLeft[3] - yLeft[1] - y1); 376 | 377 | y1 = yRight[2] - yRight[0]; 378 | cRight[0] = 0.5 * yRight[1] + 0.25 * (yRight[0] + yRight[2]); 379 | cRight[1] = 0.5 * y1; 380 | cRight[2] = 0.25 * (yRight[3] - yRight[1] - y1); 381 | } 382 | firLeft[i] = (cLeft[2] * this.x + cLeft[1]) * this.x + cLeft[0]; 383 | firRight[i] = (cRight[2] * this.x + cRight[1]) * this.x + cRight[0]; 384 | } 385 | 386 | this.left = this.decimate(firLeft); 387 | this.right = this.decimate(firRight); 388 | } 389 | 390 | Ayumi.prototype.dcFilter = function(dc, index, x) { 391 | dc.sum += -dc.delay[index] + x; 392 | dc.delay[index] = x; 393 | return x - dc.sum / DC_FILTER_SIZE; 394 | } 395 | 396 | Ayumi.prototype.removeDC = function() { 397 | this.left = this.dcFilter(this.dcFilterLeft, this.dcIndex, this.left); 398 | this.right = this.dcFilter(this.dcFilterRight, this.dcIndex, this.right); 399 | this.dcIndex = (this.dcIndex + 1) & (DC_FILTER_SIZE - 1); 400 | } 401 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | ayumi.js 4 | 5 | 6 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /nq_taimat.fym: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexanderk23/ayumi-js/3a1fb9120cc2c5ef8f538af59b46701e4c2305bb/nq_taimat.fym -------------------------------------------------------------------------------- /pako_inflate.min.js: -------------------------------------------------------------------------------- 1 | /* pako 0.2.8 nodeca/pako */ 2 | !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.pako=e()}}(function(){return function e(t,i,n){function a(o,s){if(!i[o]){if(!t[o]){var f="function"==typeof require&&require;if(!s&&f)return f(o,!0);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var d=i[o]={exports:{}};t[o][0].call(d.exports,function(e){var i=t[o][1][e];return a(i?i:e)},d,d.exports,e,t,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;or;r++)e[a+r]=t[i+r]},flattenChunks:function(e){var t,i,n,a,r,o;for(n=0,t=0,i=e.length;i>t;t++)n+=e[t].length;for(o=new Uint8Array(n),a=0,t=0,i=e.length;i>t;t++)r=e[t],o.set(r,a),a+=r.length;return o}},r={arraySet:function(e,t,i,n,a){for(var r=0;n>r;r++)e[a+r]=t[i+r]},flattenChunks:function(e){return[].concat.apply([],e)}};i.setTyped=function(e){e?(i.Buf8=Uint8Array,i.Buf16=Uint16Array,i.Buf32=Int32Array,i.assign(i,a)):(i.Buf8=Array,i.Buf16=Array,i.Buf32=Array,i.assign(i,r))},i.setTyped(n)},{}],2:[function(e,t,i){"use strict";function n(e,t){if(65537>t&&(e.subarray&&o||!e.subarray&&r))return String.fromCharCode.apply(null,a.shrinkBuf(e,t));for(var i="",n=0;t>n;n++)i+=String.fromCharCode(e[n]);return i}var a=e("./common"),r=!0,o=!0;try{String.fromCharCode.apply(null,[0])}catch(s){r=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(s){o=!1}for(var f=new a.Buf8(256),l=0;256>l;l++)f[l]=l>=252?6:l>=248?5:l>=240?4:l>=224?3:l>=192?2:1;f[254]=f[254]=1,i.string2buf=function(e){var t,i,n,r,o,s=e.length,f=0;for(r=0;s>r;r++)i=e.charCodeAt(r),55296===(64512&i)&&s>r+1&&(n=e.charCodeAt(r+1),56320===(64512&n)&&(i=65536+(i-55296<<10)+(n-56320),r++)),f+=128>i?1:2048>i?2:65536>i?3:4;for(t=new a.Buf8(f),o=0,r=0;f>o;r++)i=e.charCodeAt(r),55296===(64512&i)&&s>r+1&&(n=e.charCodeAt(r+1),56320===(64512&n)&&(i=65536+(i-55296<<10)+(n-56320),r++)),128>i?t[o++]=i:2048>i?(t[o++]=192|i>>>6,t[o++]=128|63&i):65536>i?(t[o++]=224|i>>>12,t[o++]=128|i>>>6&63,t[o++]=128|63&i):(t[o++]=240|i>>>18,t[o++]=128|i>>>12&63,t[o++]=128|i>>>6&63,t[o++]=128|63&i);return t},i.buf2binstring=function(e){return n(e,e.length)},i.binstring2buf=function(e){for(var t=new a.Buf8(e.length),i=0,n=t.length;n>i;i++)t[i]=e.charCodeAt(i);return t},i.buf2string=function(e,t){var i,a,r,o,s=t||e.length,l=new Array(2*s);for(a=0,i=0;s>i;)if(r=e[i++],128>r)l[a++]=r;else if(o=f[r],o>4)l[a++]=65533,i+=o-1;else{for(r&=2===o?31:3===o?15:7;o>1&&s>i;)r=r<<6|63&e[i++],o--;o>1?l[a++]=65533:65536>r?l[a++]=r:(r-=65536,l[a++]=55296|r>>10&1023,l[a++]=56320|1023&r)}return n(l,a)},i.utf8border=function(e,t){var i;for(t=t||e.length,t>e.length&&(t=e.length),i=t-1;i>=0&&128===(192&e[i]);)i--;return 0>i?t:0===i?t:i+f[e[i]]>t?i:t}},{"./common":1}],3:[function(e,t,i){"use strict";function n(e,t,i,n){for(var a=65535&e|0,r=e>>>16&65535|0,o=0;0!==i;){o=i>2e3?2e3:i,i-=o;do a=a+t[n++]|0,r=r+a|0;while(--o);a%=65521,r%=65521}return a|r<<16|0}t.exports=n},{}],4:[function(e,t,i){t.exports={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,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,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,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],5:[function(e,t,i){"use strict";function n(){for(var e,t=[],i=0;256>i;i++){e=i;for(var n=0;8>n;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}function a(e,t,i,n){var a=r,o=n+i;e=-1^e;for(var s=n;o>s;s++)e=e>>>8^a[255&(e^t[s])];return-1^e}var r=n();t.exports=a},{}],6:[function(e,t,i){"use strict";function n(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}t.exports=n},{}],7:[function(e,t,i){"use strict";var n=30,a=12;t.exports=function(e,t){var i,r,o,s,f,l,d,u,h,c,b,w,m,k,_,g,v,p,x,y,S,E,B,Z,A;i=e.state,r=e.next_in,Z=e.input,o=r+(e.avail_in-5),s=e.next_out,A=e.output,f=s-(t-e.avail_out),l=s+(e.avail_out-257),d=i.dmax,u=i.wsize,h=i.whave,c=i.wnext,b=i.window,w=i.hold,m=i.bits,k=i.lencode,_=i.distcode,g=(1<m&&(w+=Z[r++]<>>24,w>>>=x,m-=x,x=p>>>16&255,0===x)A[s++]=65535&p;else{if(!(16&x)){if(0===(64&x)){p=k[(65535&p)+(w&(1<m&&(w+=Z[r++]<>>=x,m-=x),15>m&&(w+=Z[r++]<>>24,w>>>=x,m-=x,x=p>>>16&255,!(16&x)){if(0===(64&x)){p=_[(65535&p)+(w&(1<m&&(w+=Z[r++]<m&&(w+=Z[r++]<d){e.msg="invalid distance too far back",i.mode=n;break e}if(w>>>=x,m-=x,x=s-f,S>x){if(x=S-x,x>h&&i.sane){e.msg="invalid distance too far back",i.mode=n;break e}if(E=0,B=b,0===c){if(E+=u-x,y>x){y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}}else if(x>c){if(E+=u+c-x,x-=c,y>x){y-=x;do A[s++]=b[E++];while(--x);if(E=0,y>c){x=c,y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}}}else if(E+=c-x,y>x){y-=x;do A[s++]=b[E++];while(--x);E=s-S,B=A}for(;y>2;)A[s++]=B[E++],A[s++]=B[E++],A[s++]=B[E++],y-=3;y&&(A[s++]=B[E++],y>1&&(A[s++]=B[E++]))}else{E=s-S;do A[s++]=A[E++],A[s++]=A[E++],A[s++]=A[E++],y-=3;while(y>2);y&&(A[s++]=A[E++],y>1&&(A[s++]=A[E++]))}break}}break}}while(o>r&&l>s);y=m>>3,r-=y,m-=y<<3,w&=(1<r?5+(o-r):5-(r-o),e.avail_out=l>s?257+(l-s):257-(s-l),i.hold=w,i.bits=m}},{}],8:[function(e,t,i){"use strict";function n(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function a(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new k.Buf16(320),this.work=new k.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function r(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=T,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new k.Buf32(be),t.distcode=t.distdyn=new k.Buf32(we),t.sane=1,t.back=-1,A):N}function o(e){var t;return e&&e.state?(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,r(e)):N}function s(e,t){var i,n;return e&&e.state?(n=e.state,0>t?(i=0,t=-t):(i=(t>>4)+1,48>t&&(t&=15)),t&&(8>t||t>15)?N:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,o(e))):N}function f(e,t){var i,n;return e?(n=new a,e.state=n,n.window=null,i=s(e,t),i!==A&&(e.state=null),i):N}function l(e){return f(e,ke)}function d(e){if(_e){var t;for(w=new k.Buf32(512),m=new k.Buf32(32),t=0;144>t;)e.lens[t++]=8;for(;256>t;)e.lens[t++]=9;for(;280>t;)e.lens[t++]=7;for(;288>t;)e.lens[t++]=8;for(p(y,e.lens,0,288,w,0,e.work,{bits:9}),t=0;32>t;)e.lens[t++]=5;p(S,e.lens,0,32,m,0,e.work,{bits:5}),_e=!1}e.lencode=w,e.lenbits=9,e.distcode=m,e.distbits=5}function u(e,t,i,n){var a,r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(k.arraySet(r.window,t,i-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),k.arraySet(r.window,t,i-n,a,r.wnext),n-=a,n?(k.arraySet(r.window,t,i-n,n,0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whavec;){if(0===f)break e;f--,h+=a[o++]<>>8&255,i.check=g(i.check,Ze,2,0),h=0,c=0,i.mode=U;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&h)<<8)+(h>>8))%31){e.msg="incorrect header check",i.mode=ue;break}if((15&h)!==F){e.msg="unknown compression method",i.mode=ue;break}if(h>>>=4,c-=4,xe=(15&h)+8,0===i.wbits)i.wbits=xe;else if(xe>i.wbits){e.msg="invalid window size",i.mode=ue;break}i.dmax=1<c;){if(0===f)break e;f--,h+=a[o++]<>8&1),512&i.flags&&(Ze[0]=255&h,Ze[1]=h>>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0,i.mode=D;case D:for(;32>c;){if(0===f)break e;f--,h+=a[o++]<>>8&255,Ze[2]=h>>>16&255,Ze[3]=h>>>24&255,i.check=g(i.check,Ze,4,0)),h=0,c=0,i.mode=L;case L:for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>8),512&i.flags&&(Ze[0]=255&h,Ze[1]=h>>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0,i.mode=H;case H:if(1024&i.flags){for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>>8&255,i.check=g(i.check,Ze,2,0)),h=0,c=0}else i.head&&(i.head.extra=null);i.mode=j;case j:if(1024&i.flags&&(m=i.length,m>f&&(m=f),m&&(i.head&&(xe=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),k.arraySet(i.head.extra,a,o,m,xe)),512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,i.length-=m),i.length))break e;i.length=0,i.mode=M;case M:if(2048&i.flags){if(0===f)break e;m=0;do xe=a[o+m++],i.head&&xe&&i.length<65536&&(i.head.name+=String.fromCharCode(xe));while(xe&&f>m);if(512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,xe)break e}else i.head&&(i.head.name=null);i.length=0,i.mode=K;case K:if(4096&i.flags){if(0===f)break e;m=0;do xe=a[o+m++],i.head&&xe&&i.length<65536&&(i.head.comment+=String.fromCharCode(xe));while(xe&&f>m);if(512&i.flags&&(i.check=g(i.check,a,m,o)),f-=m,o+=m,xe)break e}else i.head&&(i.head.comment=null);i.mode=P;case P:if(512&i.flags){for(;16>c;){if(0===f)break e;f--,h+=a[o++]<>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=G;break;case Y:for(;32>c;){if(0===f)break e;f--,h+=a[o++]<>>=7&c,c-=7&c,i.mode=fe;break}for(;3>c;){if(0===f)break e;f--,h+=a[o++]<>>=1,c-=1,3&h){case 0:i.mode=W;break;case 1:if(d(i),i.mode=te,t===Z){h>>>=2,c-=2;break e}break;case 2:i.mode=V;break;case 3:e.msg="invalid block type",i.mode=ue}h>>>=2,c-=2;break;case W:for(h>>>=7&c,c-=7&c;32>c;){if(0===f)break e;f--,h+=a[o++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=ue;break}if(i.length=65535&h,h=0,c=0,i.mode=J,t===Z)break e;case J:i.mode=Q;case Q:if(m=i.length){if(m>f&&(m=f),m>l&&(m=l),0===m)break e;k.arraySet(r,a,o,m,s),f-=m,o+=m,l-=m,s+=m,i.length-=m;break}i.mode=G;break;case V:for(;14>c;){if(0===f)break e;f--,h+=a[o++]<>>=5,c-=5,i.ndist=(31&h)+1,h>>>=5,c-=5,i.ncode=(15&h)+4,h>>>=4,c-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=ue;break}i.have=0,i.mode=$;case $:for(;i.havec;){if(0===f)break e;f--,h+=a[o++]<>>=3,c-=3}for(;i.have<19;)i.lens[Ae[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,Se={bits:i.lenbits},ye=p(x,i.lens,0,19,i.lencode,0,i.work,Se),i.lenbits=Se.bits,ye){e.msg="invalid code lengths set",i.mode=ue;break}i.have=0,i.mode=ee;case ee:for(;i.have>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<_e)h>>>=me,c-=me,i.lens[i.have++]=_e;else{if(16===_e){for(Ee=me+2;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,0===i.have){e.msg="invalid bit length repeat",i.mode=ue;break}xe=i.lens[i.have-1],m=3+(3&h),h>>>=2,c-=2}else if(17===_e){for(Ee=me+3;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,xe=0,m=3+(7&h),h>>>=3,c-=3}else{for(Ee=me+7;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=me,c-=me,xe=0,m=11+(127&h),h>>>=7,c-=7}if(i.have+m>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=ue;break}for(;m--;)i.lens[i.have++]=xe}}if(i.mode===ue)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=ue;break}if(i.lenbits=9,Se={bits:i.lenbits},ye=p(y,i.lens,0,i.nlen,i.lencode,0,i.work,Se),i.lenbits=Se.bits,ye){e.msg="invalid literal/lengths set",i.mode=ue;break}if(i.distbits=6,i.distcode=i.distdyn,Se={bits:i.distbits},ye=p(S,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,Se),i.distbits=Se.bits,ye){e.msg="invalid distances set",i.mode=ue;break}if(i.mode=te,t===Z)break e;case te:i.mode=ie;case ie:if(f>=6&&l>=258){e.next_out=s,e.avail_out=l,e.next_in=o,e.avail_in=f,i.hold=h,i.bits=c,v(e,w),s=e.next_out,r=e.output,l=e.avail_out,o=e.next_in,a=e.input,f=e.avail_in,h=i.hold,c=i.bits,i.mode===G&&(i.back=-1);break}for(i.back=0;Be=i.lencode[h&(1<>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<>ge)],me=Be>>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=ge+me);){if(0===f)break e;f--,h+=a[o++]<>>=ge,c-=ge,i.back+=ge}if(h>>>=me,c-=me,i.back+=me,i.length=_e,0===ke){i.mode=se;break}if(32&ke){i.back=-1,i.mode=G;break}if(64&ke){e.msg="invalid literal/length code",i.mode=ue;break}i.extra=15&ke,i.mode=ne;case ne:if(i.extra){for(Ee=i.extra;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=ae;case ae:for(;Be=i.distcode[h&(1<>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=me);){if(0===f)break e;f--,h+=a[o++]<>ge)],me=Be>>>24,ke=Be>>>16&255,_e=65535&Be,!(c>=ge+me);){if(0===f)break e;f--,h+=a[o++]<>>=ge,c-=ge,i.back+=ge}if(h>>>=me,c-=me,i.back+=me,64&ke){e.msg="invalid distance code",i.mode=ue;break}i.offset=_e,i.extra=15&ke,i.mode=re;case re:if(i.extra){for(Ee=i.extra;Ee>c;){if(0===f)break e;f--,h+=a[o++]<>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=ue;break}i.mode=oe;case oe:if(0===l)break e;if(m=w-l,i.offset>m){if(m=i.offset-m,m>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=ue;break}m>i.wnext?(m-=i.wnext,be=i.wsize-m):be=i.wnext-m,m>i.length&&(m=i.length),we=i.window}else we=r,be=s-i.offset,m=i.length;m>l&&(m=l),l-=m,i.length-=m;do r[s++]=we[be++];while(--m);0===i.length&&(i.mode=ie);break;case se:if(0===l)break e;r[s++]=i.length,l--,i.mode=ie;break;case fe:if(i.wrap){for(;32>c;){if(0===f)break e;f--,h|=a[o++]<c;){if(0===f)break e;f--,h+=a[o++]<=z;z++)j[z]=0;for(R=0;b>R;R++)j[t[i+R]]++;for(C=A,O=a;O>=1&&0===j[O];O--);if(C>O&&(C=O),0===O)return w[m++]=20971520,w[m++]=20971520,_.bits=1,0;for(N=1;O>N&&0===j[N];N++);for(N>C&&(C=N),T=1,z=1;a>=z;z++)if(T<<=1,T-=j[z],0>T)return-1;if(T>0&&(e===s||1!==O))return-1;for(M[1]=0,z=1;a>z;z++)M[z+1]=M[z]+j[z];for(R=0;b>R;R++)0!==t[i+R]&&(k[M[t[i+R]]++]=R);if(e===s?(L=K=k,S=19):e===f?(L=d,H-=257,K=u,P-=257,S=256):(L=h,K=c,S=-1),D=0,R=0,z=N,y=m,I=C,F=0,p=-1,U=1<r||e===l&&U>o)return 1;for(var Y=0;;){Y++,E=z-F,k[R]S?(B=K[P+k[R]],Z=L[H+k[R]]):(B=96,Z=0),g=1<>F)+v]=E<<24|B<<16|Z|0;while(0!==v);for(g=1<>=1;if(0!==g?(D&=g-1,D+=g):D=0,R++,0===--j[z]){if(z===O)break;z=t[i+k[R]]}if(z>C&&(D&x)!==p){for(0===F&&(F=C),y+=N,I=z-F,T=1<I+F&&(T-=j[I+F],!(0>=T));)I++,T<<=1;if(U+=1<r||e===l&&U>o)return 1;p=D&x,w[p]=C<<24|I<<16|y-m|0}}return 0!==D&&(w[y+D]=z-F<<24|64<<16|0),_.bits=C,0}},{"../utils/common":1}],10:[function(e,t,i){"use strict";t.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],11:[function(e,t,i){"use strict";function n(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}t.exports=n},{}],"/lib/inflate.js":[function(e,t,i){"use strict";function n(e,t){var i=new c(t);if(i.push(e,!0),i.err)throw i.msg;return i.result}function a(e,t){return t=t||{},t.raw=!0,n(e,t)}var r=e("./zlib/inflate.js"),o=e("./utils/common"),s=e("./utils/strings"),f=e("./zlib/constants"),l=e("./zlib/messages"),d=e("./zlib/zstream"),u=e("./zlib/gzheader"),h=Object.prototype.toString,c=function(e){this.options=o.assign({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0===(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new d,this.strm.avail_out=0;var i=r.inflateInit2(this.strm,t.windowBits);if(i!==f.Z_OK)throw new Error(l[i]);this.header=new u,r.inflateGetHeader(this.strm,this.header)};c.prototype.push=function(e,t){var i,n,a,l,d,u=this.strm,c=this.options.chunkSize,b=!1;if(this.ended)return!1;n=t===~~t?t:t===!0?f.Z_FINISH:f.Z_NO_FLUSH,"string"==typeof e?u.input=s.binstring2buf(e):"[object ArrayBuffer]"===h.call(e)?u.input=new Uint8Array(e):u.input=e,u.next_in=0,u.avail_in=u.input.length;do{if(0===u.avail_out&&(u.output=new o.Buf8(c),u.next_out=0,u.avail_out=c),i=r.inflate(u,f.Z_NO_FLUSH),i===f.Z_BUF_ERROR&&b===!0&&(i=f.Z_OK,b=!1),i!==f.Z_STREAM_END&&i!==f.Z_OK)return this.onEnd(i),this.ended=!0,!1;u.next_out&&(0===u.avail_out||i===f.Z_STREAM_END||0===u.avail_in&&(n===f.Z_FINISH||n===f.Z_SYNC_FLUSH))&&("string"===this.options.to?(a=s.utf8border(u.output,u.next_out),l=u.next_out-a,d=s.buf2string(u.output,a),u.next_out=l,u.avail_out=c-l,l&&o.arraySet(u.output,u.output,a,l,0),this.onData(d)):this.onData(o.shrinkBuf(u.output,u.next_out))),0===u.avail_in&&0===u.avail_out&&(b=!0)}while((u.avail_in>0||0===u.avail_out)&&i!==f.Z_STREAM_END);return i===f.Z_STREAM_END&&(n=f.Z_FINISH),n===f.Z_FINISH?(i=r.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===f.Z_OK):n===f.Z_SYNC_FLUSH?(this.onEnd(f.Z_OK),u.avail_out=0,!0):!0},c.prototype.onData=function(e){this.chunks.push(e)},c.prototype.onEnd=function(e){e===f.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg},i.Inflate=c,i.inflate=n,i.inflateRaw=a,i.ungzip=n},{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate.js":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")}); 3 | --------------------------------------------------------------------------------