├── LICENSE ├── README.md └── jerrica.js /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jerrica: a small, bare bones, 100% scheduled, web audio native, MOD player 2 | 3 | > It's Showtime, Synergy! 4 | 5 | ## Demo 6 | 7 | [A Final Hyperbase by Firefox and Tip](http://uploads.ungrounded.net/tmp/1951000/1951512/file/alternate/alternate_2_r4.zip) 8 | 9 | ## FAQ 10 | 11 | ### What is Jerrica? What do you mean by "100% scheduled" and "web audio native"? 12 | 13 | Jerrica is a small bare bones MOD Player meant to be embedded in JavaScript games. 14 | 15 | By "100% scheduled" we mean that all the timing of audio events is handled using the web audio scheduler. Jerrica doesn't use setTimeout, setInterval, or other timing hacks. It is recommended that its processMusic function is called once per frame via requestAnimationFrame, but that's simply to ensure that sound events are always scheduled well ahead of when they need to occur. 16 | 17 | By "web audio native" we mean that all audio effects are achieved via the web audio API. Many audio players manipulate audio at the sample level, treating web audio as a "dumb pipe" for an audio buffer. Jerrica doesn't do that. After loading the samples from the MOD file, Jerrica only ever uses web audio functions to manipulate the sounds, for example via the playbackRate AudioParam. 18 | 19 | ### Okay, but what's a MOD? 20 | 21 | Oh God. 22 | 23 | Back before your parents met at Revision '99 (**19**99), [MOD files](https://en.wikipedia.org/wiki/MOD_(file_format)) were a popular sample-based music format for computers and consoles. 24 | 25 | ### Can I hear what a MOD being played by Jerrica sounds like? 26 | 27 | Of course! 28 | 29 | [Here is a demo](http://uploads.ungrounded.net/tmp/1951000/1951512/file/alternate/alternate_2_r4.zip) of Jerrica playing the mother of all tracker files, "A Final Hyperbase". 30 | 31 | Jerrica was also recently used in Montrose's Halloween 2022 Newgrounds submission, [A Halloween Cat-Tastrophe](https://www.newgrounds.com/portal/view/861234). 32 | 33 | ### How do I use Jerrica? 34 | 35 | 1. Give your JavaScript access to the createTrack function in jerrica.js. 36 | 2. Call createTrack with an audio context and a Uint8Array containing your mod file and save the result to a track variable. 37 | 3. Connect the track object's output web audio GainNode to a destination. 38 | 4. Call the track object's processMusic function often. 39 | 40 | ``` 41 | var track = createTrack(ac,buffer); 42 | track.output.connect(ac.destination); 43 | function frame() { 44 | requestAnimationFrame(frame); 45 | track.processMusic(); 46 | } 47 | frame(); 48 | console.log('hello'); 49 | ``` 50 | 51 | ### Why is this a bad idea? 52 | 53 | The scheduled nature of the playback means that Jerrica is both less timing accurate than other players and yet more sensitive to subtle timing issues in both the MOD pattern and sample definitions. Sound quality is very much a function of how your platform approaches down and up sampling. I've probably implemented several effects wrong. When you realize this you will compensate by hacking your MOD file. When you upgrade to a newer version where I've fixed the error, your MOD will sound wrong all over again. This cycle will continue until--best case--you send me Internet death threats or--worst case--you are compelled to write your own player. 54 | 55 | ### Why is this a good idea? 56 | 57 | The fact that nothing important happens in the main event loop means that the performance impact of using Jerrica is basically non-existent. The returned track object exposes basically all of the moving parts and manipulating playback is thus very straight-forward. The library is small (< 500 lines). -------------------------------------------------------------------------------- /jerrica.js: -------------------------------------------------------------------------------- 1 | function createTrack(ac, buf) { 2 | var track = { }; 3 | canon = 8363; 4 | track.ref = 428; 5 | track.iota = 0.005; 6 | track.sineTable = (function () { 7 | var span = (2 * Math.PI) / 63.0; 8 | var collecting805 = []; 9 | for (var i = 0; i <= 63; i += 1) { 10 | collecting805.push(Math.floor(256 * Math.sin(i * span))); 11 | }; 12 | __PS_MV_REG = []; 13 | return collecting805; 14 | })(); 15 | track.output = ac.createGain(); 16 | track.left = ac.createStereoPanner(); 17 | track.right = ac.createStereoPanner(); 18 | track.left.connect(track.output); 19 | track.right.connect(track.output); 20 | track.output.connect(ac.destination); 21 | track.left.pan.value = -0.75; 22 | track.right.pan.value = 0.75; 23 | function semitones(n) { 24 | __PS_MV_REG = []; 25 | return Math.pow(Math.pow(2, 1 / 12.0), n); 26 | }; 27 | track.samples = (function () { 28 | var b; 29 | var collecting806 = []; 30 | for (var i = 20; i <= 920; i += 30) { 31 | collecting806.push({ length : 2 * (256 * buf[i + 22] + buf[i + 23]), 32 | finetune : (b = buf[i + 24], (b &= 15, b > 7 ? (b -= 16) : null, b)), 33 | vol : buf[i + 25], 34 | loopStart : 2 * (256 * buf[i + 26] + buf[i + 27]), 35 | loopLength : 2 * (256 * buf[i + 28] + buf[i + 29]) 36 | }); 37 | }; 38 | __PS_MV_REG = []; 39 | return collecting806; 40 | })(); 41 | track.samples.unshift(null); 42 | track.count = buf[950]; 43 | track.jump = buf[951]; 44 | track['final'] = 0; 45 | track.table = (function () { 46 | var _js807 = track.count - 1; 47 | var val = 0; 48 | var collecting808 = []; 49 | for (var i = 0; i <= _js807; i += 1) { 50 | val = buf[i + 952]; 51 | track['final'] = Math.max(track['final'], val); 52 | collecting808.push(val); 53 | }; 54 | __PS_MV_REG = []; 55 | return collecting808; 56 | })(); 57 | track.tag = (function () { 58 | var collecting809 = []; 59 | for (var i = 0; i <= 3; i += 1) { 60 | collecting809.push(String.fromCharCode(buf[i + 1080])); 61 | }; 62 | __PS_MV_REG = []; 63 | return collecting809; 64 | })(); 65 | track.tag = track.tag.join(''); 66 | track.patterns = (function () { 67 | var _js810 = track['final']; 68 | var collecting811 = []; 69 | for (var pt = 0; pt <= _js810; pt += 1) { 70 | collecting811.push((function () { 71 | var collecting812 = []; 72 | for (var ln = 0; ln <= 63; ln += 1) { 73 | collecting812.push((function () { 74 | var i; 75 | var a; 76 | var b; 77 | var c; 78 | var d; 79 | var period; 80 | var effect; 81 | var collecting813 = []; 82 | for (var ch = 0; ch <= 3; ch += 1) { 83 | collecting813.push((i = 1084 + 1024 * pt + ln * 16 + ch * 4, (a = buf[i + 0], (b = buf[i + 1], (c = buf[i + 2], (d = buf[i + 3], (period = (a & 15) * 256 + b, (effect = c & 15, { sample : (a & 240) + (c & 240) / 16, 84 | period : effect === 3 ? 0 : period, 85 | effect : { effect : effect, 86 | xy : d, 87 | x : (d & 240) / 16, 88 | y : d & 15, 89 | z : period 90 | } 91 | })))))))); 92 | }; 93 | __PS_MV_REG = []; 94 | return collecting813; 95 | })()); 96 | }; 97 | __PS_MV_REG = []; 98 | return collecting812; 99 | })()); 100 | }; 101 | __PS_MV_REG = []; 102 | return collecting811; 103 | })(); 104 | var i = 1084 + 1024 + track['final'] * 1024; 105 | for (var smp = 1; smp <= 31; smp += 1) { 106 | var sample = track.samples[smp]; 107 | if (sample.length > 0) { 108 | var data = ac.createBuffer(1, sample.length, canon); 109 | var _js812 = sample.length - 1; 110 | var cd = data.getChannelData(0); 111 | for (var j = 0; j <= _js812; j += 1) { 112 | var val = buf[i]; 113 | if (val > 127) { 114 | val -= 256; 115 | }; 116 | cd[j] = Math.max((sample.vol / 64) * (1 / 2.0) * (val / 127), -1); 117 | i += 1; 118 | sample.buf = data; 119 | }; 120 | }; 121 | }; 122 | track.clock = -Infinity; 123 | track.bpm = 125; 124 | track.speed = 6; 125 | function tickSec() { 126 | return 5 / (2.0 * track.bpm); 127 | }; 128 | function lineSec() { 129 | __PS_MV_REG = []; 130 | return tickSec() * track.speed; 131 | }; 132 | track.pidx = 0; 133 | track.lidx = 0; 134 | track.chans = (function () { 135 | var gain; 136 | var collecting812 = []; 137 | for (var i = 0; i <= 3; i += 1) { 138 | collecting812.push((gain = ac.createGain(), (gain.period = 0, gain.vol = 1, gain.slideRate = 1, gain.slideGoal = track.ref, gain.vibTable = track.sineTable, gain.vibRetrigger = false, gain.vibIdx = 0, gain.vibSpeed = 1, gain.vibDepth = 1, gain.trmTable = track.sineTable, gain.trmRetrigger = false, gain.trmIdx = 0, gain.trmSpeed = 1, gain.trmDepth = 1, gain.loopStart = 0, gain.loopCount = 0, gain.lastSample = 0, gain.connect(i % 2 === 0 ? track.left : track.right), gain))); 139 | }; 140 | __PS_MV_REG = []; 141 | return collecting812; 142 | })(); 143 | track.voices = (function () { 144 | var collecting813 = []; 145 | for (var i = 0; i <= 3; i += 1) { 146 | collecting813.push(ac.createBufferSource()); 147 | }; 148 | __PS_MV_REG = []; 149 | return collecting813; 150 | })(); 151 | var _js814 = track.voices; 152 | var _js816 = _js814.length; 153 | for (var _js815 = 0; _js815 < _js816; _js815 += 1) { 154 | var voice = _js814[_js815]; 155 | voice.start(0); 156 | }; 157 | function finetunePeriod(period, finetune) { 158 | __PS_MV_REG = []; 159 | return Math.round(period * Math.pow(Math.pow(2, 1 / (12 * 8.0)), -finetune)); 160 | }; 161 | function createNote(sample, period, cidx) { 162 | var note = ac.createBufferSource(); 163 | note.connect(track.chans[cidx]); 164 | track.chans[cidx].vol = 1; 165 | note.buffer = sample.buf; 166 | note.period = finetunePeriod(period, sample.finetune); 167 | note.playbackRate.value = track.ref / note.period; 168 | if (sample.loopLength > 2) { 169 | note.loop = true; 170 | note.loopStart = sample.loopStart / canon; 171 | note.loopEnd = note.loopStart + sample.loopLength / canon; 172 | }; 173 | __PS_MV_REG = []; 174 | return note; 175 | }; 176 | function processChannel(ch, cidx) { 177 | var object817; 178 | var note = track.voices[cidx]; 179 | var voice = track.voices[cidx]; 180 | var gain = track.chans[cidx]; 181 | var period818 = ch.period; 182 | var sample819 = track.samples[ch.sample]; 183 | var offset = 0; 184 | var effect820 = (object817 = ch.effect, { effect : object817.effect, 185 | xy : object817.xy, 186 | x : object817.x, 187 | y : object817.y, 188 | z : object817.z 189 | }); 190 | var mark = track.clock; 191 | if (period818 !== 0) { 192 | gain.period = period818; 193 | }; 194 | period818 = gain.period; 195 | if (ch.sample !== 0) { 196 | gain.lastSample = ch.sample; 197 | }; 198 | if (effect820.effect === 9) { 199 | offset = ((effect820.xy * 256) / sample819.length) * sample819.buf.duration; 200 | }; 201 | if (effect820.effect === 14 && effect820.x === 13 && effect820.y < track.speed - 1) { 202 | mark += tickSec() * effect820.y; 203 | }; 204 | if (ch.sample > 0 && period818 > 0) { 205 | note = createNote(sample819, period818, cidx); 206 | gain.gain.setTargetAtTime(gain.vol, mark, track.iota); 207 | voice.stop(mark); 208 | note.start(mark, offset); 209 | }; 210 | if (effect820.effect === 0) { 211 | if (effect820.xy !== 0) { 212 | var _js821 = track.speed - 1; 213 | for (var i = 1; i <= _js821; i += 1) { 214 | switch (i % 3) { 215 | case 0: 216 | note.playbackRate.setTargetAtTime(track.ref / note.period, mark + i * tickSec(), track.iota); 217 | break; 218 | case 1: 219 | note.playbackRate.setTargetAtTime((track.ref / note.period) * semitones(effect820.x), mark + i * tickSec(), track.iota); 220 | break; 221 | case 2: 222 | note.playbackRate.setTargetAtTime((track.ref / note.period) * semitones(effect820.y), mark + i * tickSec(), track.iota); 223 | }; 224 | }; 225 | }; 226 | }; 227 | if (effect820.effect === 1) { 228 | note.playbackRate.setTargetAtTime(track.ref / (note.period - effect820.xy), mark + tickSec(), track.iota); 229 | note.period -= (track.speed - 1) * effect820.xy; 230 | note.playbackRate.linearRampToValueAtTime(track.ref / note.period, mark + lineSec()); 231 | }; 232 | if (effect820.effect === 2) { 233 | note.playbackRate.setTargetAtTime(track.ref / (note.period + effect820.xy), mark + tickSec(), track.iota); 234 | note.period += (track.speed - 1) * effect820.xy; 235 | note.playbackRate.linearRampToValueAtTime(track.ref / note.period, mark + lineSec()); 236 | }; 237 | if (effect820.effect === 10 || effect820.effect === 5 || effect820.effect === 6) { 238 | if (!(effect820.x > 0 && effect820.y > 0)) { 239 | var slide = (effect820.x - effect820.y) / 64.0; 240 | var vol822 = Math.max(Math.min(gain.vol + slide * (track.speed - 1), 1.0), 0); 241 | gain.gain.setTargetAtTime(gain.vol, mark + tickSec(), track.iota); 242 | gain.vol = vol822; 243 | gain.gain.linearRampToValueAtTime(vol822, mark + lineSec()); 244 | }; 245 | effect820.x = 0; 246 | effect820.y = 0; 247 | }; 248 | if (effect820.effect === 3 || effect820.effect === 5) { 249 | if (effect820.z !== 0) { 250 | gain.slideGoal = effect820.z; 251 | }; 252 | if (effect820.xy !== 0) { 253 | gain.slideRate = effect820.xy; 254 | }; 255 | var diff = finetunePeriod(gain.slideGoal, track.samples[gain.lastSample].finetune) - note.period; 256 | var ticks = Math.min(Math.floor(Math.abs(diff) / gain.slideRate), track.speed - 1); 257 | var delta = gain.slideRate * ticks * Math.sign(diff); 258 | note.playbackRate.setTargetAtTime(track.ref / note.period, mark + tickSec(), track.iota); 259 | note.period += delta; 260 | note.playbackRate.linearRampToValueAtTime(track.ref / note.period, mark + lineSec()); 261 | }; 262 | if (effect820.effect === 4 || effect820.effect === 6) { 263 | if (effect820.x !== 0) { 264 | gain.vibSpeed = effect820.x; 265 | }; 266 | if (effect820.y !== 0) { 267 | gain.vibDepth = effect820.y; 268 | }; 269 | if (gain.vibRetrigger && period818 !== 0) { 270 | gain.vibIdx = 0; 271 | }; 272 | var _js823 = track.speed - 1; 273 | for (var i = 1; i <= _js823; i += 1) { 274 | note.playbackRate.setTargetAtTime(track.ref / (note.period + (gain.vibTable[gain.vibIdx] * gain.vibDepth) / 128), mark + i * tickSec(), track.iota); 275 | gain.vibIdx += gain.vibSpeed; 276 | if (gain.vibIdx > 63) { 277 | gain.vibIdx = 0; 278 | }; 279 | }; 280 | }; 281 | if (effect820.effect === 7) { 282 | if (effect820.x !== 0) { 283 | gain.trmSpeed = effect820.x; 284 | }; 285 | if (effect820.y !== 0) { 286 | gain.trmDepth = effect820.y; 287 | }; 288 | if (gain.trmRetrigger && period818 !== 0) { 289 | gain.trmIdx = 0; 290 | }; 291 | var _js824 = track.speed - 1; 292 | for (var i = 1; i <= _js824; i += 1) { 293 | gain.gain.setTargetAtTime(Math.max(Math.min(gain.vol + (gain.trmTable[gain.trmIdx] * gain.trmDepth) / 64 / 64, 1), 0), mark + i * tickSec(), track.iota); 294 | gain.trmIdx += gain.trmSpeed; 295 | if (gain.trmIdx > 63) { 296 | gain.trmIdx = 0; 297 | }; 298 | }; 299 | }; 300 | if (effect820.effect === 11) { 301 | track.lidx = -1; 302 | track.pidx = Math.min(effect820.xy, track.count - 1); 303 | }; 304 | if (effect820.effect === 12) { 305 | gain.vol = Math.max(Math.min(effect820.xy / 64.0, 1), 0); 306 | gain.gain.setTargetAtTime(gain.vol, mark, track.iota); 307 | }; 308 | if (effect820.effect === 13) { 309 | var dst = effect820.x * 10 + effect820.y; 310 | if (dst > 63) { 311 | dst = 0; 312 | }; 313 | track.lidx = dst - 1; 314 | track.pidx += 1; 315 | if (track.pidx >= track.count) { 316 | if (track.jump < 127) { 317 | track.pidx = track.jump; 318 | } else { 319 | track.done = true; 320 | }; 321 | }; 322 | }; 323 | if (effect820.effect === 14 && effect820.x === 1) { 324 | note.period -= effect820.y; 325 | note.playbackRate.setTargetAtTime(track.ref / note.period, mark, track.iota); 326 | }; 327 | if (effect820.effect === 14 && effect820.x === 2) { 328 | note.period += effect820.y; 329 | note.playbackRate.setTargetAtTime(track.ref / note.period, mark, track.iota); 330 | }; 331 | if (effect820.effect === 14 && effect820.x === 6) { 332 | if (effect820.y === 0) { 333 | gain.loopStart = track.lidx - 1; 334 | } else { 335 | gain.loopCount += 1; 336 | if (gain.loopCount <= effect820.y) { 337 | track.lidx = gain.loopStart; 338 | } else { 339 | gain.loopCount = 0; 340 | }; 341 | }; 342 | }; 343 | if (effect820.effect === 14 && effect820.x === 9 && gain.lastSample !== 0) { 344 | var _js825 = track.speed - 1; 345 | for (var i = 1; i <= _js825; i += 1) { 346 | if (i % effect820.y === 0) { 347 | note.stop(mark + i * tickSec()); 348 | note = createNote(track.samples[gain.lastSample], period818, cidx); 349 | gain.gain.setTargetAtTime(gain.vol, mark + i * tickSec(), track.iota); 350 | note.start(mark + i * tickSec(), offset); 351 | }; 352 | }; 353 | }; 354 | if (effect820.effect === 14 && effect820.x === 10) { 355 | gain.vol = Math.max(Math.min(gain.vol + effect820.y / 64.0, 1), 0); 356 | gain.gain.setTargetAtTime(gain.vol, mark, track.iota); 357 | }; 358 | if (effect820.effect === 14 && effect820.x === 11) { 359 | gain.vol = Math.max(Math.min(gain.vol - effect820.y / 64.0, 1), 0); 360 | gain.gain.setTargetAtTime(gain.vol, mark, track.iota); 361 | }; 362 | if (effect820.effect === 14 && effect820.x === 12 && effect820.y < track.speed - 1) { 363 | gain.vol = 0; 364 | gain.gain.setTargetAtTime(gain.vol, mark + effect820.y * tickSec(), track.iota); 365 | }; 366 | if (effect820.effect === 15) { 367 | if (effect820.xy > 31) { 368 | track.bpm = effect820.xy; 369 | } else { 370 | track.speed = effect820.xy; 371 | }; 372 | }; 373 | __PS_MV_REG = []; 374 | return track.voices[cidx] = note; 375 | }; 376 | track.done = false; 377 | function processLine() { 378 | var _js826 = track.patterns[track.table[track.pidx]][track.lidx]; 379 | var _js828 = _js826.length; 380 | var FIRST829 = true; 381 | for (var _js827 = 0; _js827 < _js828; _js827 += 1) { 382 | var ch = _js826[_js827]; 383 | var i = FIRST829 ? 0 : i + 1; 384 | if (i > 3) { 385 | break; 386 | }; 387 | processChannel(ch, i); 388 | FIRST829 = null; 389 | }; 390 | track.lidx += 1; 391 | if (track.lidx > 63) { 392 | track.lidx = 0; 393 | track.pidx += 1; 394 | if (track.pidx >= track.count) { 395 | if (track.jump < 127) { 396 | track.pidx = track.jump; 397 | } else { 398 | track.done = true; 399 | }; 400 | }; 401 | }; 402 | __PS_MV_REG = []; 403 | return track.clock += lineSec(); 404 | }; 405 | function sprocessMusic() { 406 | if (track.done) { 407 | return; 408 | }; 409 | if (ac.currentTime - track.clock > 2) { 410 | track.clock = ac.currentTime; 411 | }; 412 | while (track.clock - ac.currentTime < 1 && !track.done) { 413 | processLine(); 414 | }; 415 | }; 416 | track.processMusic = sprocessMusic; 417 | __PS_MV_REG = []; 418 | return track; 419 | }; 420 | --------------------------------------------------------------------------------