@dawcore/spectrogram 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3916 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ColorLUTCache: () => ColorLUTCache,
34
+ SpectrogramAbortError: () => SpectrogramAbortError,
35
+ SpectrogramOrchestrator: () => SpectrogramOrchestrator,
36
+ classifyViewport: () => classifyViewport,
37
+ computeSpectrogram: () => computeSpectrogram,
38
+ computeSpectrogramMono: () => computeSpectrogramMono,
39
+ createSpectrogramWorker: () => createSpectrogramWorker,
40
+ createSpectrogramWorkerPool: () => createSpectrogramWorkerPool,
41
+ getColorMap: () => getColorMap,
42
+ getFrequencyScale: () => getFrequencyScale,
43
+ groupContiguousChunks: () => groupContiguousChunks
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+
47
+ // src/computation/fft.ts
48
+ var import_fft = __toESM(require("fft.js"));
49
+ var fftInstances = /* @__PURE__ */ new Map();
50
+ var complexBuffers = /* @__PURE__ */ new Map();
51
+ function getFftInstance(size) {
52
+ let instance = fftInstances.get(size);
53
+ if (!instance) {
54
+ instance = new import_fft.default(size);
55
+ fftInstances.set(size, instance);
56
+ complexBuffers.set(size, instance.createComplexArray());
57
+ }
58
+ return instance;
59
+ }
60
+ function getComplexBuffer(size) {
61
+ const buffer = complexBuffers.get(size);
62
+ if (!buffer) {
63
+ throw new Error(`No complex buffer for size ${size}. Call getFftInstance first.`);
64
+ }
65
+ return buffer;
66
+ }
67
+ function fftMagnitudeDb(real, out) {
68
+ const n = real.length;
69
+ const f = getFftInstance(n);
70
+ const complexOut = getComplexBuffer(n);
71
+ f.realTransform(complexOut, real);
72
+ const half = n >> 1;
73
+ for (let i = 0; i < half; i++) {
74
+ const re = complexOut[i * 2];
75
+ const im = complexOut[i * 2 + 1];
76
+ let db = 20 * Math.log10(Math.sqrt(re * re + im * im) + 1e-10);
77
+ if (db < -160) db = -160;
78
+ out[i] = db;
79
+ }
80
+ }
81
+
82
+ // src/computation/windowFunctions.ts
83
+ function getWindowFunction(name, size, alpha) {
84
+ const window2 = new Float32Array(size);
85
+ const N = size;
86
+ switch (name) {
87
+ case "rectangular":
88
+ for (let i = 0; i < size; i++) window2[i] = 1;
89
+ break;
90
+ case "bartlett":
91
+ for (let i = 0; i < size; i++) {
92
+ window2[i] = 1 - Math.abs((2 * i - N) / N);
93
+ }
94
+ break;
95
+ case "hann":
96
+ for (let i = 0; i < size; i++) {
97
+ window2[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / N));
98
+ }
99
+ break;
100
+ case "hamming":
101
+ for (let i = 0; i < size; i++) {
102
+ const a = alpha ?? 0.54;
103
+ window2[i] = a - (1 - a) * Math.cos(2 * Math.PI * i / N);
104
+ }
105
+ break;
106
+ case "blackman": {
107
+ const a0 = 0.42;
108
+ const a1 = 0.5;
109
+ const a2 = 0.08;
110
+ for (let i = 0; i < size; i++) {
111
+ window2[i] = a0 - a1 * Math.cos(2 * Math.PI * i / N) + a2 * Math.cos(4 * Math.PI * i / N);
112
+ }
113
+ break;
114
+ }
115
+ case "blackman-harris": {
116
+ const c0 = 0.35875;
117
+ const c1 = 0.48829;
118
+ const c2 = 0.14128;
119
+ const c3 = 0.01168;
120
+ for (let i = 0; i < size; i++) {
121
+ window2[i] = c0 - c1 * Math.cos(2 * Math.PI * i / N) + c2 * Math.cos(4 * Math.PI * i / N) - c3 * Math.cos(6 * Math.PI * i / N);
122
+ }
123
+ break;
124
+ }
125
+ default:
126
+ console.warn(`[spectrogram] Unknown window function "${name}", falling back to hann`);
127
+ for (let i = 0; i < size; i++) {
128
+ window2[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / N));
129
+ }
130
+ }
131
+ let sum = 0;
132
+ for (let i = 0; i < size; i++) sum += window2[i];
133
+ if (sum > 0) {
134
+ const scale = 2 / sum;
135
+ for (let i = 0; i < size; i++) window2[i] *= scale;
136
+ }
137
+ return window2;
138
+ }
139
+
140
+ // src/computation/computeSpectrogram.ts
141
+ function computeSpectrogram(audioBuffer, config = {}, offsetSamples = 0, durationSamples, channel = 0) {
142
+ const windowSize = config.fftSize ?? 2048;
143
+ const zeroPaddingFactor = config.zeroPaddingFactor ?? 2;
144
+ const actualFftSize = windowSize * zeroPaddingFactor;
145
+ const hopSize = config.hopSize ?? Math.floor(windowSize / 4);
146
+ const windowName = config.windowFunction ?? "hann";
147
+ const gainDb = config.gainDb ?? 20;
148
+ const rangeDb = config.rangeDb ?? 80;
149
+ const alpha = config.alpha;
150
+ const sampleRate = audioBuffer.sampleRate;
151
+ const frequencyBinCount = actualFftSize >> 1;
152
+ const totalSamples = durationSamples ?? audioBuffer.length - offsetSamples;
153
+ const channelIdx = Math.min(channel, audioBuffer.numberOfChannels - 1);
154
+ const channelData = audioBuffer.getChannelData(channelIdx);
155
+ const window2 = getWindowFunction(windowName, windowSize, alpha);
156
+ const frameCount = Math.max(1, Math.floor((totalSamples - windowSize) / hopSize) + 1);
157
+ const data = new Float32Array(frameCount * frequencyBinCount);
158
+ const real = new Float32Array(actualFftSize);
159
+ const dbBuf = new Float32Array(frequencyBinCount);
160
+ for (let frame = 0; frame < frameCount; frame++) {
161
+ const start = offsetSamples + frame * hopSize;
162
+ for (let i = 0; i < windowSize; i++) {
163
+ const sampleIdx = start + i;
164
+ real[i] = sampleIdx < channelData.length ? channelData[sampleIdx] * window2[i] : 0;
165
+ }
166
+ for (let i = windowSize; i < actualFftSize; i++) {
167
+ real[i] = 0;
168
+ }
169
+ fftMagnitudeDb(real, dbBuf);
170
+ data.set(dbBuf, frame * frequencyBinCount);
171
+ }
172
+ return {
173
+ fftSize: actualFftSize,
174
+ windowSize,
175
+ frequencyBinCount,
176
+ sampleRate,
177
+ hopSize,
178
+ frameCount,
179
+ data,
180
+ gainDb,
181
+ rangeDb
182
+ };
183
+ }
184
+ function computeSpectrogramMono(audioBuffer, config = {}, offsetSamples = 0, durationSamples) {
185
+ if (audioBuffer.numberOfChannels === 1) {
186
+ return computeSpectrogram(audioBuffer, config, offsetSamples, durationSamples, 0);
187
+ }
188
+ const windowSize = config.fftSize ?? 2048;
189
+ const zeroPaddingFactor = config.zeroPaddingFactor ?? 2;
190
+ const actualFftSize = windowSize * zeroPaddingFactor;
191
+ const hopSize = config.hopSize ?? Math.floor(windowSize / 4);
192
+ const windowName = config.windowFunction ?? "hann";
193
+ const gainDb = config.gainDb ?? 20;
194
+ const rangeDb = config.rangeDb ?? 80;
195
+ const alpha = config.alpha;
196
+ const sampleRate = audioBuffer.sampleRate;
197
+ const frequencyBinCount = actualFftSize >> 1;
198
+ const totalSamples = durationSamples ?? audioBuffer.length - offsetSamples;
199
+ const numChannels = audioBuffer.numberOfChannels;
200
+ const window2 = getWindowFunction(windowName, windowSize, alpha);
201
+ const frameCount = Math.max(1, Math.floor((totalSamples - windowSize) / hopSize) + 1);
202
+ const data = new Float32Array(frameCount * frequencyBinCount);
203
+ const real = new Float32Array(actualFftSize);
204
+ const dbBuf = new Float32Array(frequencyBinCount);
205
+ const channels = [];
206
+ for (let ch = 0; ch < numChannels; ch++) {
207
+ channels.push(audioBuffer.getChannelData(ch));
208
+ }
209
+ for (let frame = 0; frame < frameCount; frame++) {
210
+ const start = offsetSamples + frame * hopSize;
211
+ for (let i = 0; i < windowSize; i++) {
212
+ const sampleIdx = start + i;
213
+ let sum = 0;
214
+ for (let ch = 0; ch < numChannels; ch++) {
215
+ sum += sampleIdx < channels[ch].length ? channels[ch][sampleIdx] : 0;
216
+ }
217
+ real[i] = sum / numChannels * window2[i];
218
+ }
219
+ for (let i = windowSize; i < actualFftSize; i++) {
220
+ real[i] = 0;
221
+ }
222
+ fftMagnitudeDb(real, dbBuf);
223
+ data.set(dbBuf, frame * frequencyBinCount);
224
+ }
225
+ return {
226
+ fftSize: actualFftSize,
227
+ windowSize,
228
+ frequencyBinCount,
229
+ sampleRate,
230
+ hopSize,
231
+ frameCount,
232
+ data,
233
+ gainDb,
234
+ rangeDb
235
+ };
236
+ }
237
+
238
+ // src/computation/colorMaps.ts
239
+ function interpolateLUT(stops) {
240
+ const lut = new Uint8Array(256 * 3);
241
+ const n = stops.length;
242
+ for (let i = 0; i < 256; i++) {
243
+ const t = i / 255;
244
+ const pos = t * (n - 1);
245
+ const lo = Math.floor(pos);
246
+ const hi = Math.min(lo + 1, n - 1);
247
+ const frac = pos - lo;
248
+ lut[i * 3] = Math.round(stops[lo][0] * (1 - frac) + stops[hi][0] * frac);
249
+ lut[i * 3 + 1] = Math.round(stops[lo][1] * (1 - frac) + stops[hi][1] * frac);
250
+ lut[i * 3 + 2] = Math.round(stops[lo][2] * (1 - frac) + stops[hi][2] * frac);
251
+ }
252
+ return lut;
253
+ }
254
+ var VIRIDIS_LUT = new Uint8Array([
255
+ 68,
256
+ 1,
257
+ 84,
258
+ 68,
259
+ 2,
260
+ 86,
261
+ 69,
262
+ 4,
263
+ 87,
264
+ 69,
265
+ 5,
266
+ 89,
267
+ 70,
268
+ 7,
269
+ 90,
270
+ 70,
271
+ 8,
272
+ 92,
273
+ 70,
274
+ 10,
275
+ 93,
276
+ 70,
277
+ 11,
278
+ 94,
279
+ 71,
280
+ 13,
281
+ 96,
282
+ 71,
283
+ 14,
284
+ 97,
285
+ 71,
286
+ 16,
287
+ 99,
288
+ 71,
289
+ 17,
290
+ 100,
291
+ 71,
292
+ 19,
293
+ 101,
294
+ 72,
295
+ 20,
296
+ 103,
297
+ 72,
298
+ 22,
299
+ 104,
300
+ 72,
301
+ 23,
302
+ 105,
303
+ 72,
304
+ 24,
305
+ 106,
306
+ 72,
307
+ 26,
308
+ 108,
309
+ 72,
310
+ 27,
311
+ 109,
312
+ 72,
313
+ 28,
314
+ 110,
315
+ 72,
316
+ 29,
317
+ 111,
318
+ 72,
319
+ 31,
320
+ 112,
321
+ 72,
322
+ 32,
323
+ 113,
324
+ 72,
325
+ 33,
326
+ 115,
327
+ 72,
328
+ 35,
329
+ 116,
330
+ 72,
331
+ 36,
332
+ 117,
333
+ 72,
334
+ 37,
335
+ 118,
336
+ 72,
337
+ 38,
338
+ 119,
339
+ 72,
340
+ 40,
341
+ 120,
342
+ 72,
343
+ 41,
344
+ 121,
345
+ 71,
346
+ 42,
347
+ 122,
348
+ 71,
349
+ 44,
350
+ 122,
351
+ 71,
352
+ 45,
353
+ 123,
354
+ 71,
355
+ 46,
356
+ 124,
357
+ 71,
358
+ 47,
359
+ 125,
360
+ 70,
361
+ 48,
362
+ 126,
363
+ 70,
364
+ 50,
365
+ 126,
366
+ 70,
367
+ 51,
368
+ 127,
369
+ 70,
370
+ 52,
371
+ 128,
372
+ 69,
373
+ 53,
374
+ 129,
375
+ 69,
376
+ 55,
377
+ 129,
378
+ 69,
379
+ 56,
380
+ 130,
381
+ 68,
382
+ 57,
383
+ 131,
384
+ 68,
385
+ 58,
386
+ 131,
387
+ 68,
388
+ 59,
389
+ 132,
390
+ 67,
391
+ 61,
392
+ 132,
393
+ 67,
394
+ 62,
395
+ 133,
396
+ 66,
397
+ 63,
398
+ 133,
399
+ 66,
400
+ 64,
401
+ 134,
402
+ 66,
403
+ 65,
404
+ 134,
405
+ 65,
406
+ 66,
407
+ 135,
408
+ 65,
409
+ 68,
410
+ 135,
411
+ 64,
412
+ 69,
413
+ 136,
414
+ 64,
415
+ 70,
416
+ 136,
417
+ 63,
418
+ 71,
419
+ 136,
420
+ 63,
421
+ 72,
422
+ 137,
423
+ 62,
424
+ 73,
425
+ 137,
426
+ 62,
427
+ 74,
428
+ 137,
429
+ 62,
430
+ 76,
431
+ 138,
432
+ 61,
433
+ 77,
434
+ 138,
435
+ 61,
436
+ 78,
437
+ 138,
438
+ 60,
439
+ 79,
440
+ 138,
441
+ 60,
442
+ 80,
443
+ 139,
444
+ 59,
445
+ 81,
446
+ 139,
447
+ 59,
448
+ 82,
449
+ 139,
450
+ 58,
451
+ 83,
452
+ 139,
453
+ 58,
454
+ 84,
455
+ 140,
456
+ 57,
457
+ 85,
458
+ 140,
459
+ 57,
460
+ 86,
461
+ 140,
462
+ 56,
463
+ 88,
464
+ 140,
465
+ 56,
466
+ 89,
467
+ 140,
468
+ 55,
469
+ 90,
470
+ 140,
471
+ 55,
472
+ 91,
473
+ 141,
474
+ 54,
475
+ 92,
476
+ 141,
477
+ 54,
478
+ 93,
479
+ 141,
480
+ 53,
481
+ 94,
482
+ 141,
483
+ 53,
484
+ 95,
485
+ 141,
486
+ 52,
487
+ 96,
488
+ 141,
489
+ 52,
490
+ 97,
491
+ 141,
492
+ 51,
493
+ 98,
494
+ 141,
495
+ 51,
496
+ 99,
497
+ 141,
498
+ 50,
499
+ 100,
500
+ 142,
501
+ 50,
502
+ 101,
503
+ 142,
504
+ 49,
505
+ 102,
506
+ 142,
507
+ 49,
508
+ 103,
509
+ 142,
510
+ 49,
511
+ 104,
512
+ 142,
513
+ 48,
514
+ 105,
515
+ 142,
516
+ 48,
517
+ 106,
518
+ 142,
519
+ 47,
520
+ 107,
521
+ 142,
522
+ 47,
523
+ 108,
524
+ 142,
525
+ 46,
526
+ 109,
527
+ 142,
528
+ 46,
529
+ 110,
530
+ 142,
531
+ 46,
532
+ 111,
533
+ 142,
534
+ 45,
535
+ 112,
536
+ 142,
537
+ 45,
538
+ 113,
539
+ 142,
540
+ 44,
541
+ 113,
542
+ 142,
543
+ 44,
544
+ 114,
545
+ 142,
546
+ 44,
547
+ 115,
548
+ 142,
549
+ 43,
550
+ 116,
551
+ 142,
552
+ 43,
553
+ 117,
554
+ 142,
555
+ 42,
556
+ 118,
557
+ 142,
558
+ 42,
559
+ 119,
560
+ 142,
561
+ 42,
562
+ 120,
563
+ 142,
564
+ 41,
565
+ 121,
566
+ 142,
567
+ 41,
568
+ 122,
569
+ 142,
570
+ 41,
571
+ 123,
572
+ 142,
573
+ 40,
574
+ 124,
575
+ 142,
576
+ 40,
577
+ 125,
578
+ 142,
579
+ 39,
580
+ 126,
581
+ 142,
582
+ 39,
583
+ 127,
584
+ 142,
585
+ 39,
586
+ 128,
587
+ 142,
588
+ 38,
589
+ 129,
590
+ 142,
591
+ 38,
592
+ 130,
593
+ 142,
594
+ 38,
595
+ 130,
596
+ 142,
597
+ 37,
598
+ 131,
599
+ 142,
600
+ 37,
601
+ 132,
602
+ 142,
603
+ 37,
604
+ 133,
605
+ 142,
606
+ 36,
607
+ 134,
608
+ 142,
609
+ 36,
610
+ 135,
611
+ 142,
612
+ 35,
613
+ 136,
614
+ 142,
615
+ 35,
616
+ 137,
617
+ 142,
618
+ 35,
619
+ 138,
620
+ 141,
621
+ 34,
622
+ 139,
623
+ 141,
624
+ 34,
625
+ 140,
626
+ 141,
627
+ 34,
628
+ 141,
629
+ 141,
630
+ 33,
631
+ 142,
632
+ 141,
633
+ 33,
634
+ 143,
635
+ 141,
636
+ 33,
637
+ 144,
638
+ 141,
639
+ 33,
640
+ 145,
641
+ 140,
642
+ 32,
643
+ 146,
644
+ 140,
645
+ 32,
646
+ 146,
647
+ 140,
648
+ 32,
649
+ 147,
650
+ 140,
651
+ 31,
652
+ 148,
653
+ 140,
654
+ 31,
655
+ 149,
656
+ 139,
657
+ 31,
658
+ 150,
659
+ 139,
660
+ 31,
661
+ 151,
662
+ 139,
663
+ 31,
664
+ 152,
665
+ 139,
666
+ 31,
667
+ 153,
668
+ 138,
669
+ 31,
670
+ 154,
671
+ 138,
672
+ 30,
673
+ 155,
674
+ 138,
675
+ 30,
676
+ 156,
677
+ 137,
678
+ 30,
679
+ 157,
680
+ 137,
681
+ 31,
682
+ 158,
683
+ 137,
684
+ 31,
685
+ 159,
686
+ 136,
687
+ 31,
688
+ 160,
689
+ 136,
690
+ 31,
691
+ 161,
692
+ 136,
693
+ 31,
694
+ 161,
695
+ 135,
696
+ 31,
697
+ 162,
698
+ 135,
699
+ 32,
700
+ 163,
701
+ 134,
702
+ 32,
703
+ 164,
704
+ 134,
705
+ 33,
706
+ 165,
707
+ 133,
708
+ 33,
709
+ 166,
710
+ 133,
711
+ 34,
712
+ 167,
713
+ 133,
714
+ 34,
715
+ 168,
716
+ 132,
717
+ 35,
718
+ 169,
719
+ 131,
720
+ 36,
721
+ 170,
722
+ 131,
723
+ 37,
724
+ 171,
725
+ 130,
726
+ 37,
727
+ 172,
728
+ 130,
729
+ 38,
730
+ 173,
731
+ 129,
732
+ 39,
733
+ 173,
734
+ 129,
735
+ 40,
736
+ 174,
737
+ 128,
738
+ 41,
739
+ 175,
740
+ 127,
741
+ 42,
742
+ 176,
743
+ 127,
744
+ 44,
745
+ 177,
746
+ 126,
747
+ 45,
748
+ 178,
749
+ 125,
750
+ 46,
751
+ 179,
752
+ 124,
753
+ 47,
754
+ 180,
755
+ 124,
756
+ 49,
757
+ 181,
758
+ 123,
759
+ 50,
760
+ 182,
761
+ 122,
762
+ 52,
763
+ 182,
764
+ 121,
765
+ 53,
766
+ 183,
767
+ 121,
768
+ 55,
769
+ 184,
770
+ 120,
771
+ 56,
772
+ 185,
773
+ 119,
774
+ 58,
775
+ 186,
776
+ 118,
777
+ 59,
778
+ 187,
779
+ 117,
780
+ 61,
781
+ 188,
782
+ 116,
783
+ 63,
784
+ 188,
785
+ 115,
786
+ 64,
787
+ 189,
788
+ 114,
789
+ 66,
790
+ 190,
791
+ 113,
792
+ 68,
793
+ 191,
794
+ 112,
795
+ 70,
796
+ 192,
797
+ 111,
798
+ 72,
799
+ 193,
800
+ 110,
801
+ 74,
802
+ 193,
803
+ 109,
804
+ 76,
805
+ 194,
806
+ 108,
807
+ 78,
808
+ 195,
809
+ 107,
810
+ 80,
811
+ 196,
812
+ 106,
813
+ 82,
814
+ 197,
815
+ 105,
816
+ 84,
817
+ 197,
818
+ 104,
819
+ 86,
820
+ 198,
821
+ 103,
822
+ 88,
823
+ 199,
824
+ 101,
825
+ 90,
826
+ 200,
827
+ 100,
828
+ 92,
829
+ 200,
830
+ 99,
831
+ 94,
832
+ 201,
833
+ 98,
834
+ 96,
835
+ 202,
836
+ 96,
837
+ 99,
838
+ 203,
839
+ 95,
840
+ 101,
841
+ 203,
842
+ 94,
843
+ 103,
844
+ 204,
845
+ 92,
846
+ 105,
847
+ 205,
848
+ 91,
849
+ 108,
850
+ 205,
851
+ 90,
852
+ 110,
853
+ 206,
854
+ 88,
855
+ 112,
856
+ 207,
857
+ 87,
858
+ 115,
859
+ 208,
860
+ 86,
861
+ 117,
862
+ 208,
863
+ 84,
864
+ 119,
865
+ 209,
866
+ 83,
867
+ 122,
868
+ 209,
869
+ 81,
870
+ 124,
871
+ 210,
872
+ 80,
873
+ 127,
874
+ 211,
875
+ 78,
876
+ 129,
877
+ 211,
878
+ 77,
879
+ 132,
880
+ 212,
881
+ 75,
882
+ 134,
883
+ 213,
884
+ 73,
885
+ 137,
886
+ 213,
887
+ 72,
888
+ 139,
889
+ 214,
890
+ 70,
891
+ 142,
892
+ 214,
893
+ 69,
894
+ 144,
895
+ 215,
896
+ 67,
897
+ 147,
898
+ 215,
899
+ 65,
900
+ 149,
901
+ 216,
902
+ 64,
903
+ 152,
904
+ 216,
905
+ 62,
906
+ 155,
907
+ 217,
908
+ 60,
909
+ 157,
910
+ 217,
911
+ 59,
912
+ 160,
913
+ 218,
914
+ 57,
915
+ 162,
916
+ 218,
917
+ 55,
918
+ 165,
919
+ 219,
920
+ 54,
921
+ 168,
922
+ 219,
923
+ 52,
924
+ 170,
925
+ 220,
926
+ 50,
927
+ 173,
928
+ 220,
929
+ 48,
930
+ 176,
931
+ 221,
932
+ 47,
933
+ 178,
934
+ 221,
935
+ 45,
936
+ 181,
937
+ 222,
938
+ 43,
939
+ 184,
940
+ 222,
941
+ 41,
942
+ 186,
943
+ 222,
944
+ 40,
945
+ 189,
946
+ 223,
947
+ 38,
948
+ 192,
949
+ 223,
950
+ 37,
951
+ 194,
952
+ 223,
953
+ 35,
954
+ 197,
955
+ 224,
956
+ 33,
957
+ 200,
958
+ 224,
959
+ 32,
960
+ 202,
961
+ 225,
962
+ 31,
963
+ 205,
964
+ 225,
965
+ 29,
966
+ 208,
967
+ 225,
968
+ 28,
969
+ 210,
970
+ 226,
971
+ 27,
972
+ 213,
973
+ 226,
974
+ 26,
975
+ 216,
976
+ 226,
977
+ 25,
978
+ 218,
979
+ 227,
980
+ 25,
981
+ 221,
982
+ 227,
983
+ 24,
984
+ 223,
985
+ 227,
986
+ 24,
987
+ 226,
988
+ 228,
989
+ 24,
990
+ 229,
991
+ 228,
992
+ 25,
993
+ 231,
994
+ 228,
995
+ 25,
996
+ 234,
997
+ 229,
998
+ 26,
999
+ 236,
1000
+ 229,
1001
+ 27,
1002
+ 239,
1003
+ 229,
1004
+ 28,
1005
+ 241,
1006
+ 229,
1007
+ 29,
1008
+ 244,
1009
+ 230,
1010
+ 30,
1011
+ 246,
1012
+ 230,
1013
+ 32,
1014
+ 248,
1015
+ 230,
1016
+ 33,
1017
+ 251,
1018
+ 231,
1019
+ 35,
1020
+ 253,
1021
+ 231,
1022
+ 37
1023
+ ]);
1024
+ var MAGMA_LUT = new Uint8Array([
1025
+ 0,
1026
+ 0,
1027
+ 4,
1028
+ 1,
1029
+ 0,
1030
+ 5,
1031
+ 1,
1032
+ 1,
1033
+ 6,
1034
+ 1,
1035
+ 1,
1036
+ 8,
1037
+ 2,
1038
+ 1,
1039
+ 9,
1040
+ 2,
1041
+ 2,
1042
+ 11,
1043
+ 2,
1044
+ 2,
1045
+ 13,
1046
+ 3,
1047
+ 3,
1048
+ 15,
1049
+ 3,
1050
+ 3,
1051
+ 18,
1052
+ 4,
1053
+ 4,
1054
+ 20,
1055
+ 5,
1056
+ 4,
1057
+ 22,
1058
+ 6,
1059
+ 5,
1060
+ 24,
1061
+ 6,
1062
+ 5,
1063
+ 26,
1064
+ 7,
1065
+ 6,
1066
+ 28,
1067
+ 8,
1068
+ 7,
1069
+ 30,
1070
+ 9,
1071
+ 7,
1072
+ 32,
1073
+ 10,
1074
+ 8,
1075
+ 34,
1076
+ 11,
1077
+ 9,
1078
+ 36,
1079
+ 12,
1080
+ 9,
1081
+ 38,
1082
+ 13,
1083
+ 10,
1084
+ 41,
1085
+ 14,
1086
+ 11,
1087
+ 43,
1088
+ 16,
1089
+ 11,
1090
+ 45,
1091
+ 17,
1092
+ 12,
1093
+ 47,
1094
+ 18,
1095
+ 13,
1096
+ 49,
1097
+ 19,
1098
+ 13,
1099
+ 52,
1100
+ 20,
1101
+ 14,
1102
+ 54,
1103
+ 21,
1104
+ 14,
1105
+ 56,
1106
+ 22,
1107
+ 15,
1108
+ 59,
1109
+ 24,
1110
+ 15,
1111
+ 61,
1112
+ 25,
1113
+ 16,
1114
+ 63,
1115
+ 26,
1116
+ 16,
1117
+ 66,
1118
+ 28,
1119
+ 16,
1120
+ 68,
1121
+ 29,
1122
+ 17,
1123
+ 71,
1124
+ 30,
1125
+ 17,
1126
+ 73,
1127
+ 32,
1128
+ 17,
1129
+ 75,
1130
+ 33,
1131
+ 17,
1132
+ 78,
1133
+ 34,
1134
+ 17,
1135
+ 80,
1136
+ 36,
1137
+ 18,
1138
+ 83,
1139
+ 37,
1140
+ 18,
1141
+ 85,
1142
+ 39,
1143
+ 18,
1144
+ 88,
1145
+ 41,
1146
+ 17,
1147
+ 90,
1148
+ 42,
1149
+ 17,
1150
+ 92,
1151
+ 44,
1152
+ 17,
1153
+ 95,
1154
+ 45,
1155
+ 17,
1156
+ 97,
1157
+ 47,
1158
+ 17,
1159
+ 99,
1160
+ 49,
1161
+ 17,
1162
+ 101,
1163
+ 51,
1164
+ 16,
1165
+ 103,
1166
+ 52,
1167
+ 16,
1168
+ 105,
1169
+ 54,
1170
+ 16,
1171
+ 107,
1172
+ 56,
1173
+ 16,
1174
+ 108,
1175
+ 57,
1176
+ 15,
1177
+ 110,
1178
+ 59,
1179
+ 15,
1180
+ 112,
1181
+ 61,
1182
+ 15,
1183
+ 113,
1184
+ 63,
1185
+ 15,
1186
+ 114,
1187
+ 64,
1188
+ 15,
1189
+ 116,
1190
+ 66,
1191
+ 15,
1192
+ 117,
1193
+ 68,
1194
+ 15,
1195
+ 118,
1196
+ 69,
1197
+ 16,
1198
+ 119,
1199
+ 71,
1200
+ 16,
1201
+ 120,
1202
+ 73,
1203
+ 16,
1204
+ 120,
1205
+ 74,
1206
+ 16,
1207
+ 121,
1208
+ 76,
1209
+ 17,
1210
+ 122,
1211
+ 78,
1212
+ 17,
1213
+ 123,
1214
+ 79,
1215
+ 18,
1216
+ 123,
1217
+ 81,
1218
+ 18,
1219
+ 124,
1220
+ 82,
1221
+ 19,
1222
+ 124,
1223
+ 84,
1224
+ 19,
1225
+ 125,
1226
+ 86,
1227
+ 20,
1228
+ 125,
1229
+ 87,
1230
+ 21,
1231
+ 126,
1232
+ 89,
1233
+ 21,
1234
+ 126,
1235
+ 90,
1236
+ 22,
1237
+ 126,
1238
+ 92,
1239
+ 22,
1240
+ 127,
1241
+ 93,
1242
+ 23,
1243
+ 127,
1244
+ 95,
1245
+ 24,
1246
+ 127,
1247
+ 96,
1248
+ 24,
1249
+ 128,
1250
+ 98,
1251
+ 25,
1252
+ 128,
1253
+ 100,
1254
+ 26,
1255
+ 128,
1256
+ 101,
1257
+ 26,
1258
+ 128,
1259
+ 103,
1260
+ 27,
1261
+ 128,
1262
+ 104,
1263
+ 28,
1264
+ 129,
1265
+ 106,
1266
+ 28,
1267
+ 129,
1268
+ 107,
1269
+ 29,
1270
+ 129,
1271
+ 109,
1272
+ 29,
1273
+ 129,
1274
+ 110,
1275
+ 30,
1276
+ 129,
1277
+ 112,
1278
+ 31,
1279
+ 129,
1280
+ 114,
1281
+ 31,
1282
+ 129,
1283
+ 115,
1284
+ 32,
1285
+ 129,
1286
+ 117,
1287
+ 33,
1288
+ 129,
1289
+ 118,
1290
+ 33,
1291
+ 129,
1292
+ 120,
1293
+ 34,
1294
+ 129,
1295
+ 121,
1296
+ 34,
1297
+ 130,
1298
+ 123,
1299
+ 35,
1300
+ 130,
1301
+ 124,
1302
+ 35,
1303
+ 130,
1304
+ 126,
1305
+ 36,
1306
+ 130,
1307
+ 128,
1308
+ 37,
1309
+ 130,
1310
+ 129,
1311
+ 37,
1312
+ 129,
1313
+ 131,
1314
+ 38,
1315
+ 129,
1316
+ 132,
1317
+ 38,
1318
+ 129,
1319
+ 134,
1320
+ 39,
1321
+ 129,
1322
+ 136,
1323
+ 39,
1324
+ 129,
1325
+ 137,
1326
+ 40,
1327
+ 129,
1328
+ 139,
1329
+ 41,
1330
+ 129,
1331
+ 140,
1332
+ 41,
1333
+ 129,
1334
+ 142,
1335
+ 42,
1336
+ 129,
1337
+ 144,
1338
+ 42,
1339
+ 129,
1340
+ 145,
1341
+ 43,
1342
+ 129,
1343
+ 147,
1344
+ 43,
1345
+ 128,
1346
+ 148,
1347
+ 44,
1348
+ 128,
1349
+ 150,
1350
+ 44,
1351
+ 128,
1352
+ 152,
1353
+ 45,
1354
+ 128,
1355
+ 153,
1356
+ 45,
1357
+ 128,
1358
+ 155,
1359
+ 46,
1360
+ 127,
1361
+ 156,
1362
+ 46,
1363
+ 127,
1364
+ 158,
1365
+ 47,
1366
+ 127,
1367
+ 160,
1368
+ 47,
1369
+ 127,
1370
+ 161,
1371
+ 48,
1372
+ 126,
1373
+ 163,
1374
+ 48,
1375
+ 126,
1376
+ 165,
1377
+ 49,
1378
+ 126,
1379
+ 166,
1380
+ 49,
1381
+ 125,
1382
+ 168,
1383
+ 50,
1384
+ 125,
1385
+ 170,
1386
+ 51,
1387
+ 125,
1388
+ 171,
1389
+ 51,
1390
+ 124,
1391
+ 173,
1392
+ 52,
1393
+ 124,
1394
+ 174,
1395
+ 52,
1396
+ 123,
1397
+ 176,
1398
+ 53,
1399
+ 123,
1400
+ 178,
1401
+ 53,
1402
+ 123,
1403
+ 179,
1404
+ 54,
1405
+ 122,
1406
+ 181,
1407
+ 54,
1408
+ 122,
1409
+ 183,
1410
+ 55,
1411
+ 121,
1412
+ 184,
1413
+ 55,
1414
+ 121,
1415
+ 186,
1416
+ 56,
1417
+ 120,
1418
+ 188,
1419
+ 57,
1420
+ 120,
1421
+ 189,
1422
+ 57,
1423
+ 119,
1424
+ 191,
1425
+ 58,
1426
+ 119,
1427
+ 192,
1428
+ 58,
1429
+ 118,
1430
+ 194,
1431
+ 59,
1432
+ 117,
1433
+ 196,
1434
+ 60,
1435
+ 117,
1436
+ 197,
1437
+ 60,
1438
+ 116,
1439
+ 199,
1440
+ 61,
1441
+ 115,
1442
+ 200,
1443
+ 62,
1444
+ 115,
1445
+ 202,
1446
+ 62,
1447
+ 114,
1448
+ 204,
1449
+ 63,
1450
+ 113,
1451
+ 205,
1452
+ 64,
1453
+ 113,
1454
+ 207,
1455
+ 64,
1456
+ 112,
1457
+ 208,
1458
+ 65,
1459
+ 111,
1460
+ 210,
1461
+ 66,
1462
+ 111,
1463
+ 211,
1464
+ 67,
1465
+ 110,
1466
+ 213,
1467
+ 68,
1468
+ 109,
1469
+ 214,
1470
+ 69,
1471
+ 108,
1472
+ 216,
1473
+ 69,
1474
+ 108,
1475
+ 217,
1476
+ 70,
1477
+ 107,
1478
+ 219,
1479
+ 71,
1480
+ 106,
1481
+ 220,
1482
+ 72,
1483
+ 105,
1484
+ 222,
1485
+ 73,
1486
+ 104,
1487
+ 223,
1488
+ 74,
1489
+ 104,
1490
+ 224,
1491
+ 76,
1492
+ 103,
1493
+ 226,
1494
+ 77,
1495
+ 102,
1496
+ 227,
1497
+ 78,
1498
+ 101,
1499
+ 228,
1500
+ 79,
1501
+ 100,
1502
+ 229,
1503
+ 80,
1504
+ 100,
1505
+ 231,
1506
+ 82,
1507
+ 99,
1508
+ 232,
1509
+ 83,
1510
+ 98,
1511
+ 233,
1512
+ 84,
1513
+ 98,
1514
+ 234,
1515
+ 86,
1516
+ 97,
1517
+ 235,
1518
+ 87,
1519
+ 96,
1520
+ 236,
1521
+ 88,
1522
+ 96,
1523
+ 237,
1524
+ 90,
1525
+ 95,
1526
+ 238,
1527
+ 91,
1528
+ 94,
1529
+ 239,
1530
+ 93,
1531
+ 94,
1532
+ 240,
1533
+ 95,
1534
+ 94,
1535
+ 241,
1536
+ 96,
1537
+ 93,
1538
+ 242,
1539
+ 98,
1540
+ 93,
1541
+ 242,
1542
+ 100,
1543
+ 92,
1544
+ 243,
1545
+ 101,
1546
+ 92,
1547
+ 244,
1548
+ 103,
1549
+ 92,
1550
+ 244,
1551
+ 105,
1552
+ 92,
1553
+ 245,
1554
+ 107,
1555
+ 92,
1556
+ 246,
1557
+ 108,
1558
+ 92,
1559
+ 246,
1560
+ 110,
1561
+ 92,
1562
+ 247,
1563
+ 112,
1564
+ 92,
1565
+ 247,
1566
+ 114,
1567
+ 92,
1568
+ 248,
1569
+ 116,
1570
+ 92,
1571
+ 248,
1572
+ 118,
1573
+ 92,
1574
+ 249,
1575
+ 120,
1576
+ 93,
1577
+ 249,
1578
+ 121,
1579
+ 93,
1580
+ 249,
1581
+ 123,
1582
+ 93,
1583
+ 250,
1584
+ 125,
1585
+ 94,
1586
+ 250,
1587
+ 127,
1588
+ 94,
1589
+ 250,
1590
+ 129,
1591
+ 95,
1592
+ 251,
1593
+ 131,
1594
+ 95,
1595
+ 251,
1596
+ 133,
1597
+ 96,
1598
+ 251,
1599
+ 135,
1600
+ 97,
1601
+ 252,
1602
+ 137,
1603
+ 97,
1604
+ 252,
1605
+ 138,
1606
+ 98,
1607
+ 252,
1608
+ 140,
1609
+ 99,
1610
+ 252,
1611
+ 142,
1612
+ 100,
1613
+ 252,
1614
+ 144,
1615
+ 101,
1616
+ 253,
1617
+ 146,
1618
+ 102,
1619
+ 253,
1620
+ 148,
1621
+ 103,
1622
+ 253,
1623
+ 150,
1624
+ 104,
1625
+ 253,
1626
+ 152,
1627
+ 105,
1628
+ 253,
1629
+ 154,
1630
+ 106,
1631
+ 253,
1632
+ 155,
1633
+ 107,
1634
+ 254,
1635
+ 157,
1636
+ 108,
1637
+ 254,
1638
+ 159,
1639
+ 109,
1640
+ 254,
1641
+ 161,
1642
+ 110,
1643
+ 254,
1644
+ 163,
1645
+ 111,
1646
+ 254,
1647
+ 165,
1648
+ 113,
1649
+ 254,
1650
+ 167,
1651
+ 114,
1652
+ 254,
1653
+ 169,
1654
+ 115,
1655
+ 254,
1656
+ 170,
1657
+ 116,
1658
+ 254,
1659
+ 172,
1660
+ 118,
1661
+ 254,
1662
+ 174,
1663
+ 119,
1664
+ 254,
1665
+ 176,
1666
+ 120,
1667
+ 254,
1668
+ 178,
1669
+ 122,
1670
+ 254,
1671
+ 180,
1672
+ 123,
1673
+ 254,
1674
+ 182,
1675
+ 124,
1676
+ 254,
1677
+ 183,
1678
+ 126,
1679
+ 254,
1680
+ 185,
1681
+ 127,
1682
+ 254,
1683
+ 187,
1684
+ 129,
1685
+ 254,
1686
+ 189,
1687
+ 130,
1688
+ 254,
1689
+ 191,
1690
+ 132,
1691
+ 254,
1692
+ 193,
1693
+ 133,
1694
+ 254,
1695
+ 194,
1696
+ 135,
1697
+ 254,
1698
+ 196,
1699
+ 136,
1700
+ 254,
1701
+ 198,
1702
+ 138,
1703
+ 254,
1704
+ 200,
1705
+ 140,
1706
+ 254,
1707
+ 202,
1708
+ 141,
1709
+ 254,
1710
+ 204,
1711
+ 143,
1712
+ 254,
1713
+ 205,
1714
+ 144,
1715
+ 254,
1716
+ 207,
1717
+ 146,
1718
+ 254,
1719
+ 209,
1720
+ 148,
1721
+ 254,
1722
+ 211,
1723
+ 149,
1724
+ 254,
1725
+ 213,
1726
+ 151,
1727
+ 254,
1728
+ 215,
1729
+ 153,
1730
+ 254,
1731
+ 216,
1732
+ 154,
1733
+ 253,
1734
+ 218,
1735
+ 156,
1736
+ 253,
1737
+ 220,
1738
+ 158,
1739
+ 253,
1740
+ 222,
1741
+ 160,
1742
+ 253,
1743
+ 224,
1744
+ 161,
1745
+ 253,
1746
+ 226,
1747
+ 163,
1748
+ 253,
1749
+ 227,
1750
+ 165,
1751
+ 253,
1752
+ 229,
1753
+ 167,
1754
+ 253,
1755
+ 231,
1756
+ 169,
1757
+ 253,
1758
+ 233,
1759
+ 170,
1760
+ 253,
1761
+ 235,
1762
+ 172,
1763
+ 252,
1764
+ 236,
1765
+ 174,
1766
+ 252,
1767
+ 238,
1768
+ 176,
1769
+ 252,
1770
+ 240,
1771
+ 178,
1772
+ 252,
1773
+ 242,
1774
+ 180,
1775
+ 252,
1776
+ 244,
1777
+ 182,
1778
+ 252,
1779
+ 246,
1780
+ 184,
1781
+ 252,
1782
+ 247,
1783
+ 185,
1784
+ 252,
1785
+ 249,
1786
+ 187,
1787
+ 252,
1788
+ 251,
1789
+ 189,
1790
+ 252,
1791
+ 253,
1792
+ 191
1793
+ ]);
1794
+ var INFERNO_LUT = new Uint8Array([
1795
+ 0,
1796
+ 0,
1797
+ 4,
1798
+ 1,
1799
+ 0,
1800
+ 5,
1801
+ 1,
1802
+ 1,
1803
+ 6,
1804
+ 1,
1805
+ 1,
1806
+ 8,
1807
+ 2,
1808
+ 1,
1809
+ 10,
1810
+ 2,
1811
+ 2,
1812
+ 12,
1813
+ 2,
1814
+ 2,
1815
+ 14,
1816
+ 3,
1817
+ 2,
1818
+ 16,
1819
+ 4,
1820
+ 3,
1821
+ 18,
1822
+ 4,
1823
+ 3,
1824
+ 20,
1825
+ 5,
1826
+ 4,
1827
+ 23,
1828
+ 6,
1829
+ 4,
1830
+ 25,
1831
+ 7,
1832
+ 5,
1833
+ 27,
1834
+ 8,
1835
+ 5,
1836
+ 29,
1837
+ 9,
1838
+ 6,
1839
+ 31,
1840
+ 10,
1841
+ 7,
1842
+ 34,
1843
+ 11,
1844
+ 7,
1845
+ 36,
1846
+ 12,
1847
+ 8,
1848
+ 38,
1849
+ 13,
1850
+ 8,
1851
+ 41,
1852
+ 14,
1853
+ 9,
1854
+ 43,
1855
+ 16,
1856
+ 9,
1857
+ 45,
1858
+ 17,
1859
+ 10,
1860
+ 48,
1861
+ 18,
1862
+ 10,
1863
+ 50,
1864
+ 20,
1865
+ 11,
1866
+ 52,
1867
+ 21,
1868
+ 11,
1869
+ 55,
1870
+ 22,
1871
+ 11,
1872
+ 57,
1873
+ 24,
1874
+ 12,
1875
+ 60,
1876
+ 25,
1877
+ 12,
1878
+ 62,
1879
+ 27,
1880
+ 12,
1881
+ 65,
1882
+ 28,
1883
+ 12,
1884
+ 67,
1885
+ 30,
1886
+ 12,
1887
+ 69,
1888
+ 31,
1889
+ 12,
1890
+ 72,
1891
+ 33,
1892
+ 12,
1893
+ 74,
1894
+ 35,
1895
+ 12,
1896
+ 76,
1897
+ 36,
1898
+ 12,
1899
+ 79,
1900
+ 38,
1901
+ 12,
1902
+ 81,
1903
+ 40,
1904
+ 11,
1905
+ 83,
1906
+ 41,
1907
+ 11,
1908
+ 85,
1909
+ 43,
1910
+ 11,
1911
+ 87,
1912
+ 45,
1913
+ 11,
1914
+ 89,
1915
+ 47,
1916
+ 10,
1917
+ 91,
1918
+ 49,
1919
+ 10,
1920
+ 92,
1921
+ 50,
1922
+ 10,
1923
+ 94,
1924
+ 52,
1925
+ 10,
1926
+ 95,
1927
+ 54,
1928
+ 9,
1929
+ 97,
1930
+ 56,
1931
+ 9,
1932
+ 98,
1933
+ 57,
1934
+ 9,
1935
+ 99,
1936
+ 59,
1937
+ 9,
1938
+ 100,
1939
+ 61,
1940
+ 9,
1941
+ 101,
1942
+ 62,
1943
+ 9,
1944
+ 102,
1945
+ 64,
1946
+ 10,
1947
+ 103,
1948
+ 66,
1949
+ 10,
1950
+ 104,
1951
+ 68,
1952
+ 10,
1953
+ 104,
1954
+ 69,
1955
+ 10,
1956
+ 105,
1957
+ 71,
1958
+ 11,
1959
+ 106,
1960
+ 73,
1961
+ 11,
1962
+ 106,
1963
+ 74,
1964
+ 12,
1965
+ 107,
1966
+ 76,
1967
+ 12,
1968
+ 107,
1969
+ 77,
1970
+ 13,
1971
+ 108,
1972
+ 79,
1973
+ 13,
1974
+ 108,
1975
+ 81,
1976
+ 14,
1977
+ 108,
1978
+ 82,
1979
+ 14,
1980
+ 109,
1981
+ 84,
1982
+ 15,
1983
+ 109,
1984
+ 85,
1985
+ 15,
1986
+ 109,
1987
+ 87,
1988
+ 16,
1989
+ 110,
1990
+ 89,
1991
+ 16,
1992
+ 110,
1993
+ 90,
1994
+ 17,
1995
+ 110,
1996
+ 92,
1997
+ 18,
1998
+ 110,
1999
+ 93,
2000
+ 18,
2001
+ 110,
2002
+ 95,
2003
+ 19,
2004
+ 110,
2005
+ 97,
2006
+ 19,
2007
+ 110,
2008
+ 98,
2009
+ 20,
2010
+ 110,
2011
+ 100,
2012
+ 21,
2013
+ 110,
2014
+ 101,
2015
+ 21,
2016
+ 110,
2017
+ 103,
2018
+ 22,
2019
+ 110,
2020
+ 105,
2021
+ 22,
2022
+ 110,
2023
+ 106,
2024
+ 23,
2025
+ 110,
2026
+ 108,
2027
+ 24,
2028
+ 110,
2029
+ 109,
2030
+ 24,
2031
+ 110,
2032
+ 111,
2033
+ 25,
2034
+ 110,
2035
+ 113,
2036
+ 25,
2037
+ 110,
2038
+ 114,
2039
+ 26,
2040
+ 110,
2041
+ 116,
2042
+ 26,
2043
+ 110,
2044
+ 117,
2045
+ 27,
2046
+ 110,
2047
+ 119,
2048
+ 28,
2049
+ 109,
2050
+ 120,
2051
+ 28,
2052
+ 109,
2053
+ 122,
2054
+ 29,
2055
+ 109,
2056
+ 124,
2057
+ 29,
2058
+ 109,
2059
+ 125,
2060
+ 30,
2061
+ 109,
2062
+ 127,
2063
+ 30,
2064
+ 108,
2065
+ 128,
2066
+ 31,
2067
+ 108,
2068
+ 130,
2069
+ 32,
2070
+ 108,
2071
+ 132,
2072
+ 32,
2073
+ 107,
2074
+ 133,
2075
+ 33,
2076
+ 107,
2077
+ 135,
2078
+ 33,
2079
+ 107,
2080
+ 136,
2081
+ 34,
2082
+ 106,
2083
+ 138,
2084
+ 34,
2085
+ 106,
2086
+ 140,
2087
+ 35,
2088
+ 105,
2089
+ 141,
2090
+ 35,
2091
+ 105,
2092
+ 143,
2093
+ 36,
2094
+ 105,
2095
+ 144,
2096
+ 37,
2097
+ 104,
2098
+ 146,
2099
+ 37,
2100
+ 104,
2101
+ 147,
2102
+ 38,
2103
+ 103,
2104
+ 149,
2105
+ 38,
2106
+ 103,
2107
+ 151,
2108
+ 39,
2109
+ 102,
2110
+ 152,
2111
+ 39,
2112
+ 102,
2113
+ 154,
2114
+ 40,
2115
+ 101,
2116
+ 155,
2117
+ 41,
2118
+ 100,
2119
+ 157,
2120
+ 41,
2121
+ 100,
2122
+ 159,
2123
+ 42,
2124
+ 99,
2125
+ 160,
2126
+ 42,
2127
+ 99,
2128
+ 162,
2129
+ 43,
2130
+ 98,
2131
+ 163,
2132
+ 44,
2133
+ 97,
2134
+ 165,
2135
+ 44,
2136
+ 96,
2137
+ 166,
2138
+ 45,
2139
+ 96,
2140
+ 168,
2141
+ 46,
2142
+ 95,
2143
+ 169,
2144
+ 46,
2145
+ 94,
2146
+ 171,
2147
+ 47,
2148
+ 94,
2149
+ 173,
2150
+ 48,
2151
+ 93,
2152
+ 174,
2153
+ 48,
2154
+ 92,
2155
+ 176,
2156
+ 49,
2157
+ 91,
2158
+ 177,
2159
+ 50,
2160
+ 90,
2161
+ 179,
2162
+ 50,
2163
+ 90,
2164
+ 180,
2165
+ 51,
2166
+ 89,
2167
+ 182,
2168
+ 52,
2169
+ 88,
2170
+ 183,
2171
+ 53,
2172
+ 87,
2173
+ 185,
2174
+ 53,
2175
+ 86,
2176
+ 186,
2177
+ 54,
2178
+ 85,
2179
+ 188,
2180
+ 55,
2181
+ 84,
2182
+ 189,
2183
+ 56,
2184
+ 83,
2185
+ 191,
2186
+ 57,
2187
+ 82,
2188
+ 192,
2189
+ 58,
2190
+ 81,
2191
+ 193,
2192
+ 58,
2193
+ 80,
2194
+ 195,
2195
+ 59,
2196
+ 79,
2197
+ 196,
2198
+ 60,
2199
+ 78,
2200
+ 198,
2201
+ 61,
2202
+ 77,
2203
+ 199,
2204
+ 62,
2205
+ 76,
2206
+ 200,
2207
+ 63,
2208
+ 75,
2209
+ 202,
2210
+ 64,
2211
+ 74,
2212
+ 203,
2213
+ 65,
2214
+ 73,
2215
+ 204,
2216
+ 66,
2217
+ 72,
2218
+ 206,
2219
+ 67,
2220
+ 71,
2221
+ 207,
2222
+ 68,
2223
+ 70,
2224
+ 208,
2225
+ 69,
2226
+ 69,
2227
+ 210,
2228
+ 70,
2229
+ 68,
2230
+ 211,
2231
+ 71,
2232
+ 67,
2233
+ 212,
2234
+ 72,
2235
+ 66,
2236
+ 213,
2237
+ 74,
2238
+ 65,
2239
+ 215,
2240
+ 75,
2241
+ 63,
2242
+ 216,
2243
+ 76,
2244
+ 62,
2245
+ 217,
2246
+ 77,
2247
+ 61,
2248
+ 218,
2249
+ 78,
2250
+ 60,
2251
+ 219,
2252
+ 80,
2253
+ 59,
2254
+ 221,
2255
+ 81,
2256
+ 58,
2257
+ 222,
2258
+ 82,
2259
+ 56,
2260
+ 223,
2261
+ 83,
2262
+ 55,
2263
+ 224,
2264
+ 85,
2265
+ 54,
2266
+ 225,
2267
+ 86,
2268
+ 53,
2269
+ 226,
2270
+ 87,
2271
+ 52,
2272
+ 227,
2273
+ 89,
2274
+ 51,
2275
+ 228,
2276
+ 90,
2277
+ 49,
2278
+ 229,
2279
+ 92,
2280
+ 48,
2281
+ 230,
2282
+ 93,
2283
+ 47,
2284
+ 231,
2285
+ 94,
2286
+ 46,
2287
+ 232,
2288
+ 96,
2289
+ 45,
2290
+ 233,
2291
+ 97,
2292
+ 43,
2293
+ 234,
2294
+ 99,
2295
+ 42,
2296
+ 235,
2297
+ 100,
2298
+ 41,
2299
+ 235,
2300
+ 102,
2301
+ 40,
2302
+ 236,
2303
+ 103,
2304
+ 38,
2305
+ 237,
2306
+ 105,
2307
+ 37,
2308
+ 238,
2309
+ 106,
2310
+ 36,
2311
+ 239,
2312
+ 108,
2313
+ 35,
2314
+ 239,
2315
+ 110,
2316
+ 33,
2317
+ 240,
2318
+ 111,
2319
+ 32,
2320
+ 241,
2321
+ 113,
2322
+ 31,
2323
+ 241,
2324
+ 115,
2325
+ 29,
2326
+ 242,
2327
+ 116,
2328
+ 28,
2329
+ 243,
2330
+ 118,
2331
+ 27,
2332
+ 243,
2333
+ 120,
2334
+ 25,
2335
+ 244,
2336
+ 121,
2337
+ 24,
2338
+ 245,
2339
+ 123,
2340
+ 23,
2341
+ 245,
2342
+ 125,
2343
+ 21,
2344
+ 246,
2345
+ 126,
2346
+ 20,
2347
+ 246,
2348
+ 128,
2349
+ 19,
2350
+ 247,
2351
+ 130,
2352
+ 18,
2353
+ 247,
2354
+ 132,
2355
+ 16,
2356
+ 248,
2357
+ 133,
2358
+ 15,
2359
+ 248,
2360
+ 135,
2361
+ 14,
2362
+ 248,
2363
+ 137,
2364
+ 12,
2365
+ 249,
2366
+ 139,
2367
+ 11,
2368
+ 249,
2369
+ 140,
2370
+ 10,
2371
+ 249,
2372
+ 142,
2373
+ 9,
2374
+ 250,
2375
+ 144,
2376
+ 8,
2377
+ 250,
2378
+ 146,
2379
+ 7,
2380
+ 250,
2381
+ 148,
2382
+ 7,
2383
+ 251,
2384
+ 150,
2385
+ 6,
2386
+ 251,
2387
+ 151,
2388
+ 6,
2389
+ 251,
2390
+ 153,
2391
+ 6,
2392
+ 251,
2393
+ 155,
2394
+ 6,
2395
+ 251,
2396
+ 157,
2397
+ 7,
2398
+ 252,
2399
+ 159,
2400
+ 7,
2401
+ 252,
2402
+ 161,
2403
+ 8,
2404
+ 252,
2405
+ 163,
2406
+ 9,
2407
+ 252,
2408
+ 165,
2409
+ 10,
2410
+ 252,
2411
+ 166,
2412
+ 12,
2413
+ 252,
2414
+ 168,
2415
+ 13,
2416
+ 252,
2417
+ 170,
2418
+ 15,
2419
+ 252,
2420
+ 172,
2421
+ 17,
2422
+ 252,
2423
+ 174,
2424
+ 18,
2425
+ 252,
2426
+ 176,
2427
+ 20,
2428
+ 252,
2429
+ 178,
2430
+ 22,
2431
+ 252,
2432
+ 180,
2433
+ 24,
2434
+ 251,
2435
+ 182,
2436
+ 26,
2437
+ 251,
2438
+ 184,
2439
+ 29,
2440
+ 251,
2441
+ 186,
2442
+ 31,
2443
+ 251,
2444
+ 188,
2445
+ 33,
2446
+ 251,
2447
+ 190,
2448
+ 35,
2449
+ 250,
2450
+ 192,
2451
+ 38,
2452
+ 250,
2453
+ 194,
2454
+ 40,
2455
+ 250,
2456
+ 196,
2457
+ 42,
2458
+ 250,
2459
+ 198,
2460
+ 45,
2461
+ 249,
2462
+ 199,
2463
+ 47,
2464
+ 249,
2465
+ 201,
2466
+ 50,
2467
+ 249,
2468
+ 203,
2469
+ 53,
2470
+ 248,
2471
+ 205,
2472
+ 55,
2473
+ 248,
2474
+ 207,
2475
+ 58,
2476
+ 247,
2477
+ 209,
2478
+ 61,
2479
+ 247,
2480
+ 211,
2481
+ 64,
2482
+ 246,
2483
+ 213,
2484
+ 67,
2485
+ 246,
2486
+ 215,
2487
+ 70,
2488
+ 245,
2489
+ 217,
2490
+ 73,
2491
+ 245,
2492
+ 219,
2493
+ 76,
2494
+ 244,
2495
+ 221,
2496
+ 79,
2497
+ 244,
2498
+ 223,
2499
+ 83,
2500
+ 244,
2501
+ 225,
2502
+ 86,
2503
+ 243,
2504
+ 227,
2505
+ 90,
2506
+ 243,
2507
+ 229,
2508
+ 93,
2509
+ 242,
2510
+ 230,
2511
+ 97,
2512
+ 242,
2513
+ 232,
2514
+ 101,
2515
+ 242,
2516
+ 234,
2517
+ 105,
2518
+ 241,
2519
+ 236,
2520
+ 109,
2521
+ 241,
2522
+ 237,
2523
+ 113,
2524
+ 241,
2525
+ 239,
2526
+ 117,
2527
+ 241,
2528
+ 241,
2529
+ 121,
2530
+ 242,
2531
+ 242,
2532
+ 125,
2533
+ 242,
2534
+ 244,
2535
+ 130,
2536
+ 243,
2537
+ 245,
2538
+ 134,
2539
+ 243,
2540
+ 246,
2541
+ 138,
2542
+ 244,
2543
+ 248,
2544
+ 142,
2545
+ 245,
2546
+ 249,
2547
+ 146,
2548
+ 246,
2549
+ 250,
2550
+ 150,
2551
+ 248,
2552
+ 251,
2553
+ 154,
2554
+ 249,
2555
+ 252,
2556
+ 157,
2557
+ 250,
2558
+ 253,
2559
+ 161,
2560
+ 252,
2561
+ 255,
2562
+ 164
2563
+ ]);
2564
+ var ROSEUS_LUT = new Uint8Array([
2565
+ 1,
2566
+ 1,
2567
+ 1,
2568
+ 1,
2569
+ 2,
2570
+ 2,
2571
+ 2,
2572
+ 2,
2573
+ 2,
2574
+ 2,
2575
+ 3,
2576
+ 3,
2577
+ 2,
2578
+ 3,
2579
+ 4,
2580
+ 2,
2581
+ 4,
2582
+ 5,
2583
+ 2,
2584
+ 5,
2585
+ 6,
2586
+ 3,
2587
+ 6,
2588
+ 7,
2589
+ 3,
2590
+ 7,
2591
+ 8,
2592
+ 3,
2593
+ 8,
2594
+ 10,
2595
+ 3,
2596
+ 9,
2597
+ 12,
2598
+ 3,
2599
+ 10,
2600
+ 14,
2601
+ 3,
2602
+ 12,
2603
+ 16,
2604
+ 3,
2605
+ 13,
2606
+ 17,
2607
+ 3,
2608
+ 14,
2609
+ 19,
2610
+ 2,
2611
+ 15,
2612
+ 21,
2613
+ 2,
2614
+ 16,
2615
+ 23,
2616
+ 2,
2617
+ 17,
2618
+ 25,
2619
+ 2,
2620
+ 18,
2621
+ 27,
2622
+ 2,
2623
+ 19,
2624
+ 30,
2625
+ 1,
2626
+ 20,
2627
+ 32,
2628
+ 1,
2629
+ 21,
2630
+ 34,
2631
+ 1,
2632
+ 22,
2633
+ 36,
2634
+ 1,
2635
+ 23,
2636
+ 38,
2637
+ 1,
2638
+ 24,
2639
+ 40,
2640
+ 0,
2641
+ 25,
2642
+ 43,
2643
+ 0,
2644
+ 26,
2645
+ 45,
2646
+ 0,
2647
+ 27,
2648
+ 47,
2649
+ 0,
2650
+ 27,
2651
+ 50,
2652
+ 0,
2653
+ 28,
2654
+ 52,
2655
+ 0,
2656
+ 29,
2657
+ 54,
2658
+ 0,
2659
+ 30,
2660
+ 57,
2661
+ 0,
2662
+ 30,
2663
+ 59,
2664
+ 1,
2665
+ 31,
2666
+ 62,
2667
+ 1,
2668
+ 32,
2669
+ 64,
2670
+ 1,
2671
+ 32,
2672
+ 67,
2673
+ 2,
2674
+ 33,
2675
+ 69,
2676
+ 3,
2677
+ 33,
2678
+ 72,
2679
+ 4,
2680
+ 34,
2681
+ 74,
2682
+ 5,
2683
+ 35,
2684
+ 77,
2685
+ 6,
2686
+ 35,
2687
+ 79,
2688
+ 8,
2689
+ 35,
2690
+ 82,
2691
+ 9,
2692
+ 36,
2693
+ 84,
2694
+ 11,
2695
+ 36,
2696
+ 86,
2697
+ 13,
2698
+ 37,
2699
+ 89,
2700
+ 15,
2701
+ 37,
2702
+ 91,
2703
+ 17,
2704
+ 37,
2705
+ 94,
2706
+ 19,
2707
+ 37,
2708
+ 96,
2709
+ 21,
2710
+ 38,
2711
+ 99,
2712
+ 23,
2713
+ 38,
2714
+ 101,
2715
+ 25,
2716
+ 38,
2717
+ 104,
2718
+ 27,
2719
+ 38,
2720
+ 106,
2721
+ 29,
2722
+ 38,
2723
+ 108,
2724
+ 31,
2725
+ 38,
2726
+ 111,
2727
+ 33,
2728
+ 38,
2729
+ 113,
2730
+ 35,
2731
+ 38,
2732
+ 115,
2733
+ 38,
2734
+ 38,
2735
+ 118,
2736
+ 40,
2737
+ 38,
2738
+ 120,
2739
+ 42,
2740
+ 38,
2741
+ 122,
2742
+ 44,
2743
+ 38,
2744
+ 124,
2745
+ 46,
2746
+ 38,
2747
+ 126,
2748
+ 49,
2749
+ 38,
2750
+ 128,
2751
+ 51,
2752
+ 38,
2753
+ 130,
2754
+ 53,
2755
+ 37,
2756
+ 132,
2757
+ 55,
2758
+ 37,
2759
+ 134,
2760
+ 58,
2761
+ 37,
2762
+ 136,
2763
+ 60,
2764
+ 36,
2765
+ 138,
2766
+ 62,
2767
+ 36,
2768
+ 139,
2769
+ 65,
2770
+ 36,
2771
+ 141,
2772
+ 67,
2773
+ 35,
2774
+ 143,
2775
+ 69,
2776
+ 35,
2777
+ 144,
2778
+ 72,
2779
+ 35,
2780
+ 146,
2781
+ 74,
2782
+ 34,
2783
+ 147,
2784
+ 76,
2785
+ 34,
2786
+ 149,
2787
+ 79,
2788
+ 33,
2789
+ 150,
2790
+ 81,
2791
+ 33,
2792
+ 151,
2793
+ 84,
2794
+ 32,
2795
+ 152,
2796
+ 86,
2797
+ 32,
2798
+ 153,
2799
+ 88,
2800
+ 31,
2801
+ 154,
2802
+ 91,
2803
+ 31,
2804
+ 155,
2805
+ 93,
2806
+ 30,
2807
+ 156,
2808
+ 95,
2809
+ 29,
2810
+ 157,
2811
+ 98,
2812
+ 29,
2813
+ 158,
2814
+ 100,
2815
+ 28,
2816
+ 159,
2817
+ 103,
2818
+ 28,
2819
+ 159,
2820
+ 105,
2821
+ 27,
2822
+ 160,
2823
+ 107,
2824
+ 27,
2825
+ 160,
2826
+ 110,
2827
+ 26,
2828
+ 161,
2829
+ 112,
2830
+ 26,
2831
+ 161,
2832
+ 114,
2833
+ 25,
2834
+ 161,
2835
+ 117,
2836
+ 25,
2837
+ 162,
2838
+ 119,
2839
+ 24,
2840
+ 162,
2841
+ 121,
2842
+ 24,
2843
+ 162,
2844
+ 124,
2845
+ 23,
2846
+ 162,
2847
+ 126,
2848
+ 23,
2849
+ 162,
2850
+ 128,
2851
+ 23,
2852
+ 162,
2853
+ 131,
2854
+ 22,
2855
+ 161,
2856
+ 133,
2857
+ 22,
2858
+ 161,
2859
+ 135,
2860
+ 22,
2861
+ 161,
2862
+ 137,
2863
+ 22,
2864
+ 161,
2865
+ 140,
2866
+ 22,
2867
+ 160,
2868
+ 142,
2869
+ 22,
2870
+ 160,
2871
+ 144,
2872
+ 22,
2873
+ 159,
2874
+ 146,
2875
+ 22,
2876
+ 159,
2877
+ 148,
2878
+ 22,
2879
+ 158,
2880
+ 150,
2881
+ 22,
2882
+ 157,
2883
+ 153,
2884
+ 22,
2885
+ 157,
2886
+ 155,
2887
+ 23,
2888
+ 156,
2889
+ 157,
2890
+ 23,
2891
+ 155,
2892
+ 159,
2893
+ 23,
2894
+ 154,
2895
+ 161,
2896
+ 24,
2897
+ 153,
2898
+ 163,
2899
+ 24,
2900
+ 152,
2901
+ 165,
2902
+ 25,
2903
+ 151,
2904
+ 167,
2905
+ 26,
2906
+ 150,
2907
+ 169,
2908
+ 26,
2909
+ 149,
2910
+ 171,
2911
+ 27,
2912
+ 148,
2913
+ 173,
2914
+ 28,
2915
+ 147,
2916
+ 175,
2917
+ 29,
2918
+ 146,
2919
+ 177,
2920
+ 29,
2921
+ 145,
2922
+ 179,
2923
+ 30,
2924
+ 144,
2925
+ 181,
2926
+ 31,
2927
+ 142,
2928
+ 183,
2929
+ 32,
2930
+ 141,
2931
+ 184,
2932
+ 33,
2933
+ 140,
2934
+ 186,
2935
+ 34,
2936
+ 139,
2937
+ 188,
2938
+ 35,
2939
+ 137,
2940
+ 190,
2941
+ 36,
2942
+ 136,
2943
+ 192,
2944
+ 37,
2945
+ 135,
2946
+ 193,
2947
+ 39,
2948
+ 133,
2949
+ 195,
2950
+ 40,
2951
+ 132,
2952
+ 197,
2953
+ 41,
2954
+ 130,
2955
+ 198,
2956
+ 42,
2957
+ 129,
2958
+ 200,
2959
+ 43,
2960
+ 128,
2961
+ 202,
2962
+ 45,
2963
+ 126,
2964
+ 203,
2965
+ 46,
2966
+ 125,
2967
+ 205,
2968
+ 47,
2969
+ 123,
2970
+ 206,
2971
+ 48,
2972
+ 122,
2973
+ 208,
2974
+ 50,
2975
+ 120,
2976
+ 209,
2977
+ 51,
2978
+ 119,
2979
+ 211,
2980
+ 52,
2981
+ 117,
2982
+ 212,
2983
+ 54,
2984
+ 116,
2985
+ 214,
2986
+ 55,
2987
+ 114,
2988
+ 215,
2989
+ 57,
2990
+ 113,
2991
+ 217,
2992
+ 58,
2993
+ 111,
2994
+ 218,
2995
+ 60,
2996
+ 110,
2997
+ 219,
2998
+ 61,
2999
+ 109,
3000
+ 221,
3001
+ 63,
3002
+ 107,
3003
+ 222,
3004
+ 64,
3005
+ 106,
3006
+ 223,
3007
+ 66,
3008
+ 104,
3009
+ 225,
3010
+ 67,
3011
+ 103,
3012
+ 226,
3013
+ 69,
3014
+ 101,
3015
+ 227,
3016
+ 70,
3017
+ 100,
3018
+ 228,
3019
+ 72,
3020
+ 99,
3021
+ 229,
3022
+ 73,
3023
+ 97,
3024
+ 230,
3025
+ 75,
3026
+ 96,
3027
+ 231,
3028
+ 77,
3029
+ 94,
3030
+ 233,
3031
+ 78,
3032
+ 93,
3033
+ 234,
3034
+ 80,
3035
+ 92,
3036
+ 235,
3037
+ 82,
3038
+ 91,
3039
+ 236,
3040
+ 83,
3041
+ 89,
3042
+ 237,
3043
+ 85,
3044
+ 88,
3045
+ 237,
3046
+ 87,
3047
+ 87,
3048
+ 238,
3049
+ 89,
3050
+ 86,
3051
+ 239,
3052
+ 90,
3053
+ 84,
3054
+ 240,
3055
+ 92,
3056
+ 83,
3057
+ 241,
3058
+ 94,
3059
+ 82,
3060
+ 242,
3061
+ 96,
3062
+ 81,
3063
+ 242,
3064
+ 97,
3065
+ 80,
3066
+ 243,
3067
+ 99,
3068
+ 79,
3069
+ 244,
3070
+ 101,
3071
+ 78,
3072
+ 245,
3073
+ 103,
3074
+ 77,
3075
+ 245,
3076
+ 105,
3077
+ 76,
3078
+ 246,
3079
+ 107,
3080
+ 75,
3081
+ 246,
3082
+ 108,
3083
+ 74,
3084
+ 247,
3085
+ 110,
3086
+ 74,
3087
+ 248,
3088
+ 112,
3089
+ 73,
3090
+ 248,
3091
+ 114,
3092
+ 72,
3093
+ 248,
3094
+ 116,
3095
+ 72,
3096
+ 249,
3097
+ 118,
3098
+ 71,
3099
+ 249,
3100
+ 120,
3101
+ 71,
3102
+ 250,
3103
+ 122,
3104
+ 70,
3105
+ 250,
3106
+ 124,
3107
+ 70,
3108
+ 250,
3109
+ 126,
3110
+ 70,
3111
+ 251,
3112
+ 128,
3113
+ 70,
3114
+ 251,
3115
+ 130,
3116
+ 69,
3117
+ 251,
3118
+ 132,
3119
+ 70,
3120
+ 251,
3121
+ 134,
3122
+ 70,
3123
+ 251,
3124
+ 136,
3125
+ 70,
3126
+ 252,
3127
+ 138,
3128
+ 70,
3129
+ 252,
3130
+ 140,
3131
+ 70,
3132
+ 252,
3133
+ 142,
3134
+ 71,
3135
+ 252,
3136
+ 144,
3137
+ 72,
3138
+ 252,
3139
+ 146,
3140
+ 72,
3141
+ 252,
3142
+ 148,
3143
+ 73,
3144
+ 252,
3145
+ 150,
3146
+ 74,
3147
+ 251,
3148
+ 152,
3149
+ 75,
3150
+ 251,
3151
+ 154,
3152
+ 76,
3153
+ 251,
3154
+ 156,
3155
+ 77,
3156
+ 251,
3157
+ 158,
3158
+ 78,
3159
+ 251,
3160
+ 160,
3161
+ 80,
3162
+ 251,
3163
+ 162,
3164
+ 81,
3165
+ 250,
3166
+ 164,
3167
+ 83,
3168
+ 250,
3169
+ 166,
3170
+ 85,
3171
+ 250,
3172
+ 168,
3173
+ 87,
3174
+ 249,
3175
+ 170,
3176
+ 88,
3177
+ 249,
3178
+ 172,
3179
+ 90,
3180
+ 248,
3181
+ 174,
3182
+ 93,
3183
+ 248,
3184
+ 176,
3185
+ 95,
3186
+ 248,
3187
+ 178,
3188
+ 97,
3189
+ 247,
3190
+ 180,
3191
+ 99,
3192
+ 247,
3193
+ 182,
3194
+ 102,
3195
+ 246,
3196
+ 184,
3197
+ 104,
3198
+ 246,
3199
+ 186,
3200
+ 107,
3201
+ 245,
3202
+ 188,
3203
+ 110,
3204
+ 244,
3205
+ 190,
3206
+ 112,
3207
+ 244,
3208
+ 192,
3209
+ 115,
3210
+ 243,
3211
+ 194,
3212
+ 118,
3213
+ 243,
3214
+ 195,
3215
+ 121,
3216
+ 242,
3217
+ 197,
3218
+ 124,
3219
+ 242,
3220
+ 199,
3221
+ 127,
3222
+ 241,
3223
+ 201,
3224
+ 131,
3225
+ 240,
3226
+ 203,
3227
+ 134,
3228
+ 240,
3229
+ 205,
3230
+ 137,
3231
+ 239,
3232
+ 207,
3233
+ 140,
3234
+ 239,
3235
+ 208,
3236
+ 144,
3237
+ 238,
3238
+ 210,
3239
+ 147,
3240
+ 238,
3241
+ 212,
3242
+ 151,
3243
+ 237,
3244
+ 213,
3245
+ 154,
3246
+ 237,
3247
+ 215,
3248
+ 158,
3249
+ 236,
3250
+ 217,
3251
+ 161,
3252
+ 236,
3253
+ 218,
3254
+ 165,
3255
+ 236,
3256
+ 220,
3257
+ 169,
3258
+ 236,
3259
+ 222,
3260
+ 172,
3261
+ 235,
3262
+ 223,
3263
+ 176,
3264
+ 235,
3265
+ 225,
3266
+ 180,
3267
+ 235,
3268
+ 226,
3269
+ 183,
3270
+ 235,
3271
+ 228,
3272
+ 187,
3273
+ 235,
3274
+ 229,
3275
+ 191,
3276
+ 235,
3277
+ 230,
3278
+ 194,
3279
+ 236,
3280
+ 232,
3281
+ 198,
3282
+ 236,
3283
+ 233,
3284
+ 201,
3285
+ 236,
3286
+ 234,
3287
+ 205,
3288
+ 237,
3289
+ 236,
3290
+ 208,
3291
+ 237,
3292
+ 237,
3293
+ 212,
3294
+ 238,
3295
+ 238,
3296
+ 215,
3297
+ 239,
3298
+ 239,
3299
+ 219,
3300
+ 240,
3301
+ 240,
3302
+ 222,
3303
+ 241,
3304
+ 242,
3305
+ 225,
3306
+ 242,
3307
+ 243,
3308
+ 228,
3309
+ 243,
3310
+ 244,
3311
+ 231,
3312
+ 244,
3313
+ 245,
3314
+ 234,
3315
+ 246,
3316
+ 246,
3317
+ 237,
3318
+ 247,
3319
+ 247,
3320
+ 240,
3321
+ 249,
3322
+ 248,
3323
+ 242,
3324
+ 251,
3325
+ 249,
3326
+ 245,
3327
+ 253,
3328
+ 250,
3329
+ 247,
3330
+ 254,
3331
+ 251,
3332
+ 249
3333
+ ]);
3334
+ var lutCache = /* @__PURE__ */ new Map();
3335
+ function grayscaleLUT() {
3336
+ let lut = lutCache.get("grayscale");
3337
+ if (!lut) {
3338
+ lut = new Uint8Array(256 * 3);
3339
+ for (let i = 0; i < 256; i++) {
3340
+ lut[i * 3] = lut[i * 3 + 1] = lut[i * 3 + 2] = i;
3341
+ }
3342
+ lutCache.set("grayscale", lut);
3343
+ }
3344
+ return lut;
3345
+ }
3346
+ function igrayLUT() {
3347
+ let lut = lutCache.get("igray");
3348
+ if (!lut) {
3349
+ lut = new Uint8Array(256 * 3);
3350
+ for (let i = 0; i < 256; i++) {
3351
+ const v = 255 - i;
3352
+ lut[i * 3] = lut[i * 3 + 1] = lut[i * 3 + 2] = v;
3353
+ }
3354
+ lutCache.set("igray", lut);
3355
+ }
3356
+ return lut;
3357
+ }
3358
+ function getColorMap(value) {
3359
+ if (Array.isArray(value)) {
3360
+ return interpolateLUT(value);
3361
+ }
3362
+ switch (value) {
3363
+ case "viridis":
3364
+ return VIRIDIS_LUT;
3365
+ case "magma":
3366
+ return MAGMA_LUT;
3367
+ case "inferno":
3368
+ return INFERNO_LUT;
3369
+ case "roseus":
3370
+ return ROSEUS_LUT;
3371
+ case "grayscale":
3372
+ return grayscaleLUT();
3373
+ case "igray":
3374
+ return igrayLUT();
3375
+ default:
3376
+ return VIRIDIS_LUT;
3377
+ }
3378
+ }
3379
+
3380
+ // src/computation/frequencyScales.ts
3381
+ function linearScale(f, minF, maxF) {
3382
+ if (maxF === minF) return 0;
3383
+ return (f - minF) / (maxF - minF);
3384
+ }
3385
+ function logarithmicScale(f, minF, maxF) {
3386
+ const logMin = Math.log2(Math.max(minF, 1));
3387
+ const logMax = Math.log2(maxF);
3388
+ if (logMax === logMin) return 0;
3389
+ return (Math.log2(Math.max(f, 1)) - logMin) / (logMax - logMin);
3390
+ }
3391
+ function hzToMel(f) {
3392
+ return 2595 * Math.log10(1 + f / 700);
3393
+ }
3394
+ function melScale(f, minF, maxF) {
3395
+ const melMin = hzToMel(minF);
3396
+ const melMax = hzToMel(maxF);
3397
+ if (melMax === melMin) return 0;
3398
+ return (hzToMel(f) - melMin) / (melMax - melMin);
3399
+ }
3400
+ function hzToBark(f) {
3401
+ return 13 * Math.atan(76e-5 * f) + 3.5 * Math.atan((f / 7500) ** 2);
3402
+ }
3403
+ function barkScale(f, minF, maxF) {
3404
+ const barkMin = hzToBark(minF);
3405
+ const barkMax = hzToBark(maxF);
3406
+ if (barkMax === barkMin) return 0;
3407
+ return (hzToBark(f) - barkMin) / (barkMax - barkMin);
3408
+ }
3409
+ function hzToErb(f) {
3410
+ return 21.4 * Math.log10(1 + 437e-5 * f);
3411
+ }
3412
+ function erbScale(f, minF, maxF) {
3413
+ const erbMin = hzToErb(minF);
3414
+ const erbMax = hzToErb(maxF);
3415
+ if (erbMax === erbMin) return 0;
3416
+ return (hzToErb(f) - erbMin) / (erbMax - erbMin);
3417
+ }
3418
+ function getFrequencyScale(name) {
3419
+ switch (name) {
3420
+ case "logarithmic":
3421
+ return logarithmicScale;
3422
+ case "mel":
3423
+ return melScale;
3424
+ case "bark":
3425
+ return barkScale;
3426
+ case "erb":
3427
+ return erbScale;
3428
+ case "linear":
3429
+ return linearScale;
3430
+ default:
3431
+ console.warn(`[spectrogram] Unknown frequency scale "${name}", falling back to linear`);
3432
+ return linearScale;
3433
+ }
3434
+ }
3435
+
3436
+ // src/worker/createSpectrogramWorker.ts
3437
+ var SpectrogramAbortError = class extends Error {
3438
+ constructor() {
3439
+ super("aborted");
3440
+ this.name = "SpectrogramAbortError";
3441
+ }
3442
+ };
3443
+ function addPending(map, id, resolve, reject) {
3444
+ map.set(id, { resolve, reject });
3445
+ }
3446
+ var idCounter = 0;
3447
+ function createSpectrogramWorker(worker) {
3448
+ const pending = /* @__PURE__ */ new Map();
3449
+ const registeredClipIds = /* @__PURE__ */ new Set();
3450
+ let terminated = false;
3451
+ worker.onmessage = (e) => {
3452
+ const msg = e.data;
3453
+ const entry = pending.get(msg.id);
3454
+ if (entry) {
3455
+ pending.delete(msg.id);
3456
+ switch (msg.type) {
3457
+ case "error":
3458
+ entry.reject(new Error(msg.error));
3459
+ break;
3460
+ case "aborted":
3461
+ entry.reject(new SpectrogramAbortError());
3462
+ break;
3463
+ case "cache-key":
3464
+ entry.resolve({ cacheKey: msg.cacheKey });
3465
+ break;
3466
+ case "done":
3467
+ entry.resolve(void 0);
3468
+ break;
3469
+ }
3470
+ } else if (msg.id) {
3471
+ console.warn(`[spectrogram] Received response for unknown message ID: ${msg.id}`);
3472
+ }
3473
+ };
3474
+ worker.onerror = (e) => {
3475
+ terminated = true;
3476
+ for (const [, entry] of pending) {
3477
+ entry.reject(e.error ?? new Error(e.message));
3478
+ }
3479
+ pending.clear();
3480
+ };
3481
+ return {
3482
+ computeFFT(params, generation = 0) {
3483
+ if (terminated) return Promise.reject(new Error("Worker terminated"));
3484
+ const id = String(++idCounter);
3485
+ return new Promise((resolve, reject) => {
3486
+ addPending(pending, id, resolve, reject);
3487
+ const isPreRegistered = registeredClipIds.has(params.clipId);
3488
+ const transferableArrays = isPreRegistered ? [] : params.channelDataArrays.map((arr) => arr.slice());
3489
+ const transferables = transferableArrays.map((arr) => arr.buffer);
3490
+ worker.postMessage(
3491
+ {
3492
+ type: "compute-fft",
3493
+ id,
3494
+ generation,
3495
+ clipId: params.clipId,
3496
+ channelDataArrays: transferableArrays,
3497
+ config: params.config,
3498
+ sampleRate: params.sampleRate,
3499
+ offsetSamples: params.offsetSamples,
3500
+ durationSamples: params.durationSamples,
3501
+ mono: params.mono,
3502
+ ...params.sampleRange ? { sampleRange: params.sampleRange } : {},
3503
+ ...params.channelFilter !== void 0 ? { channelFilter: params.channelFilter } : {}
3504
+ },
3505
+ transferables
3506
+ );
3507
+ });
3508
+ },
3509
+ renderChunks(params, generation = 0) {
3510
+ if (terminated) return Promise.reject(new Error("Worker terminated"));
3511
+ const id = String(++idCounter);
3512
+ return new Promise((resolve, reject) => {
3513
+ addPending(pending, id, resolve, reject);
3514
+ worker.postMessage({
3515
+ type: "render-chunks",
3516
+ id,
3517
+ generation,
3518
+ cacheKey: params.cacheKey,
3519
+ canvasIds: params.canvasIds,
3520
+ canvasWidths: params.canvasWidths,
3521
+ globalPixelOffsets: params.globalPixelOffsets,
3522
+ canvasHeight: params.canvasHeight,
3523
+ devicePixelRatio: params.devicePixelRatio,
3524
+ samplesPerPixel: params.samplesPerPixel,
3525
+ colorLUT: params.colorLUT,
3526
+ frequencyScale: params.frequencyScale,
3527
+ minFrequency: params.minFrequency,
3528
+ maxFrequency: params.maxFrequency,
3529
+ gainDb: params.gainDb,
3530
+ rangeDb: params.rangeDb,
3531
+ channelIndex: params.channelIndex
3532
+ });
3533
+ });
3534
+ },
3535
+ abortGeneration(generation) {
3536
+ if (terminated) return;
3537
+ worker.postMessage({ type: "abort-generation", generation });
3538
+ },
3539
+ registerCanvas(canvasId, canvas) {
3540
+ worker.postMessage({ type: "register-canvas", canvasId, canvas }, [canvas]);
3541
+ },
3542
+ unregisterCanvas(canvasId) {
3543
+ worker.postMessage({ type: "unregister-canvas", canvasId });
3544
+ },
3545
+ registerAudioData(clipId, channelDataArrays, sampleRate) {
3546
+ const transferableArrays = channelDataArrays.map((arr) => arr.slice());
3547
+ const transferables = transferableArrays.map((arr) => arr.buffer);
3548
+ worker.postMessage(
3549
+ { type: "register-audio-data", clipId, channelDataArrays: transferableArrays, sampleRate },
3550
+ transferables
3551
+ );
3552
+ registeredClipIds.add(clipId);
3553
+ },
3554
+ unregisterAudioData(clipId) {
3555
+ worker.postMessage({ type: "unregister-audio-data", clipId });
3556
+ registeredClipIds.delete(clipId);
3557
+ },
3558
+ terminate() {
3559
+ terminated = true;
3560
+ worker.terminate();
3561
+ for (const [, entry] of pending) {
3562
+ entry.reject(new Error("Worker terminated"));
3563
+ }
3564
+ pending.clear();
3565
+ }
3566
+ };
3567
+ }
3568
+
3569
+ // src/worker/createSpectrogramWorkerPool.ts
3570
+ function parseChannelFromCanvasId(canvasId) {
3571
+ const match = canvasId.match(/-ch(\d+)-/);
3572
+ return match ? parseInt(match[1], 10) : 0;
3573
+ }
3574
+ function defaultPoolSize() {
3575
+ return 2;
3576
+ }
3577
+ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize()) {
3578
+ const workers = [];
3579
+ try {
3580
+ for (let i = 0; i < poolSize; i++) {
3581
+ workers.push(createSpectrogramWorker(createWorker()));
3582
+ }
3583
+ } catch (err) {
3584
+ for (const w of workers) {
3585
+ w.terminate();
3586
+ }
3587
+ throw err;
3588
+ }
3589
+ function getWorkerForChannel(channelIndex) {
3590
+ return workers[channelIndex % workers.length];
3591
+ }
3592
+ return {
3593
+ computeFFT(params, generation = 0) {
3594
+ if (params.mono) {
3595
+ return workers[0].computeFFT(params, generation);
3596
+ }
3597
+ const channelCount = params.channelDataArrays.length;
3598
+ const activeWorkers = workers.slice(0, channelCount);
3599
+ const promises = activeWorkers.map(
3600
+ (w, i) => w.computeFFT({ ...params, channelFilter: i }, generation)
3601
+ );
3602
+ return Promise.all(promises).then((results) => results[0]);
3603
+ },
3604
+ renderChunks(params, generation = 0) {
3605
+ const worker = getWorkerForChannel(params.channelIndex);
3606
+ return worker.renderChunks({ ...params, channelIndex: 0 }, generation);
3607
+ },
3608
+ abortGeneration(generation) {
3609
+ for (const w of workers) {
3610
+ w.abortGeneration(generation);
3611
+ }
3612
+ },
3613
+ registerCanvas(canvasId, canvas) {
3614
+ const ch = parseChannelFromCanvasId(canvasId);
3615
+ getWorkerForChannel(ch).registerCanvas(canvasId, canvas);
3616
+ },
3617
+ unregisterCanvas(canvasId) {
3618
+ const ch = parseChannelFromCanvasId(canvasId);
3619
+ getWorkerForChannel(ch).unregisterCanvas(canvasId);
3620
+ },
3621
+ registerAudioData(clipId, channelDataArrays, sampleRate) {
3622
+ for (const w of workers) {
3623
+ w.registerAudioData(clipId, channelDataArrays, sampleRate);
3624
+ }
3625
+ },
3626
+ unregisterAudioData(clipId) {
3627
+ for (const w of workers) {
3628
+ w.unregisterAudioData(clipId);
3629
+ }
3630
+ },
3631
+ terminate() {
3632
+ for (const w of workers) {
3633
+ w.terminate();
3634
+ }
3635
+ }
3636
+ };
3637
+ }
3638
+
3639
+ // src/orchestrator/color-lut-cache.ts
3640
+ var ColorLUTCache = class {
3641
+ constructor() {
3642
+ this.cache = /* @__PURE__ */ new Map();
3643
+ }
3644
+ get(colorMap) {
3645
+ const key = cacheKey(colorMap);
3646
+ let lut = this.cache.get(key);
3647
+ if (!lut) {
3648
+ lut = new Uint8Array(getColorMap(colorMap));
3649
+ this.cache.set(key, lut);
3650
+ }
3651
+ return lut;
3652
+ }
3653
+ clear() {
3654
+ this.cache.clear();
3655
+ }
3656
+ };
3657
+ function cacheKey(colorMap) {
3658
+ return typeof colorMap === "string" ? colorMap : JSON.stringify(colorMap);
3659
+ }
3660
+
3661
+ // src/orchestrator/viewport-classify.ts
3662
+ function intersects(a0, a1, b0, b1) {
3663
+ return a1 > b0 && a0 < b1;
3664
+ }
3665
+ function classifyViewport(canvases, bounds) {
3666
+ const viewport = [];
3667
+ const buffer = [];
3668
+ const remaining = [];
3669
+ for (const c of canvases) {
3670
+ const start = c.globalPixelOffset;
3671
+ const end = c.globalPixelOffset + c.widthPx;
3672
+ if (intersects(start, end, bounds.visibleStartPx, bounds.visibleEndPx)) {
3673
+ viewport.push(c);
3674
+ } else if (intersects(start, end, bounds.bufferStartPx, bounds.bufferEndPx)) {
3675
+ buffer.push(c);
3676
+ } else {
3677
+ remaining.push(c);
3678
+ }
3679
+ }
3680
+ return { viewport, buffer, remaining };
3681
+ }
3682
+
3683
+ // src/orchestrator/chunk-grouping.ts
3684
+ function groupContiguousChunks(chunks) {
3685
+ if (chunks.length === 0) return [];
3686
+ const sorted = [...chunks].sort((a, b) => a.chunkIndex - b.chunkIndex);
3687
+ const groups = [];
3688
+ let current = [sorted[0]];
3689
+ for (let i = 1; i < sorted.length; i++) {
3690
+ const prev = sorted[i - 1].chunkIndex;
3691
+ const curr = sorted[i].chunkIndex;
3692
+ if (curr === prev + 1) {
3693
+ current.push(sorted[i]);
3694
+ } else {
3695
+ groups.push(current);
3696
+ current = [sorted[i]];
3697
+ }
3698
+ }
3699
+ groups.push(current);
3700
+ return groups;
3701
+ }
3702
+
3703
+ // src/orchestrator/SpectrogramOrchestrator.ts
3704
+ var SpectrogramOrchestrator = class extends EventTarget {
3705
+ constructor(opts) {
3706
+ super();
3707
+ this.clips = /* @__PURE__ */ new Map();
3708
+ this.canvases = /* @__PURE__ */ new Map();
3709
+ this.viewport = null;
3710
+ this.generation = 0;
3711
+ this.colorLUT = new ColorLUTCache();
3712
+ this.disposed = false;
3713
+ this.renderInFlight = false;
3714
+ const poolSize = opts.workerPoolSize ?? 2;
3715
+ this.pool = createSpectrogramWorkerPool(opts.workerFactory, poolSize);
3716
+ this.config = opts.config;
3717
+ this.colorMap = opts.colorMap ?? "viridis";
3718
+ this.devicePixelRatio = opts.devicePixelRatio ?? (typeof window !== "undefined" ? window.devicePixelRatio : 1);
3719
+ }
3720
+ registerClip(reg) {
3721
+ if (this.disposed) return;
3722
+ this.clips.set(reg.clipId, {
3723
+ trackId: reg.trackId,
3724
+ channelData: reg.channelData,
3725
+ sampleRate: reg.sampleRate,
3726
+ durationSamples: reg.durationSamples,
3727
+ offsetSamples: reg.offsetSamples
3728
+ });
3729
+ this.pool.registerAudioData(reg.clipId, reg.channelData, reg.sampleRate);
3730
+ }
3731
+ unregisterClip(clipId) {
3732
+ if (this.disposed) return;
3733
+ if (!this.clips.has(clipId)) return;
3734
+ this.clips.delete(clipId);
3735
+ this.pool.unregisterAudioData(clipId);
3736
+ }
3737
+ registerCanvas(reg) {
3738
+ if (this.disposed) return;
3739
+ this.canvases.set(reg.canvasId, {
3740
+ canvasId: reg.canvasId,
3741
+ globalPixelOffset: reg.globalPixelOffset,
3742
+ widthPx: reg.widthPx,
3743
+ heightPx: reg.heightPx,
3744
+ clipId: reg.clipId,
3745
+ trackId: reg.trackId,
3746
+ channelIndex: reg.channelIndex,
3747
+ chunkIndex: reg.chunkIndex
3748
+ });
3749
+ this.pool.registerCanvas(reg.canvasId, reg.canvas);
3750
+ if (this.viewport) this.scheduleRender();
3751
+ }
3752
+ unregisterCanvas(canvasId) {
3753
+ if (this.disposed) return;
3754
+ if (!this.canvases.has(canvasId)) return;
3755
+ this.canvases.delete(canvasId);
3756
+ this.pool.unregisterCanvas(canvasId);
3757
+ }
3758
+ setViewport(state) {
3759
+ if (this.disposed) return;
3760
+ const prevGeneration = this.generation;
3761
+ this.generation += 1;
3762
+ this.pool.abortGeneration(prevGeneration);
3763
+ this.viewport = state;
3764
+ this.scheduleRender();
3765
+ }
3766
+ setConfig(config) {
3767
+ if (this.disposed) return;
3768
+ this.config = config;
3769
+ const prevGeneration = this.generation;
3770
+ this.generation += 1;
3771
+ this.pool.abortGeneration(prevGeneration);
3772
+ this.colorLUT.clear();
3773
+ this.scheduleRender();
3774
+ }
3775
+ setColorMap(colorMap) {
3776
+ if (this.disposed) return;
3777
+ this.colorMap = colorMap;
3778
+ const prevGeneration = this.generation;
3779
+ this.generation += 1;
3780
+ this.pool.abortGeneration(prevGeneration);
3781
+ this.scheduleRender();
3782
+ }
3783
+ setDevicePixelRatio(dpr) {
3784
+ this.devicePixelRatio = dpr;
3785
+ }
3786
+ dispose() {
3787
+ if (this.disposed) return;
3788
+ this.disposed = true;
3789
+ this.clips.clear();
3790
+ this.canvases.clear();
3791
+ this.viewport = null;
3792
+ this.colorLUT.clear();
3793
+ this.pool.terminate();
3794
+ }
3795
+ scheduleRender() {
3796
+ if (this.renderInFlight) return;
3797
+ if (!this.viewport) return;
3798
+ this.renderInFlight = true;
3799
+ queueMicrotask(() => {
3800
+ this.renderInFlight = false;
3801
+ void this.runRender(this.generation);
3802
+ });
3803
+ }
3804
+ async runRender(generation) {
3805
+ if (this.disposed) return;
3806
+ const viewport = this.viewport;
3807
+ if (!viewport) return;
3808
+ const canvasesByTrack = /* @__PURE__ */ new Map();
3809
+ for (const c of this.canvases.values()) {
3810
+ const list = canvasesByTrack.get(c.trackId) ?? [];
3811
+ list.push(c);
3812
+ canvasesByTrack.set(c.trackId, list);
3813
+ }
3814
+ for (const [trackId, trackCanvases] of canvasesByTrack) {
3815
+ const tiers = classifyViewport(trackCanvases, viewport);
3816
+ await this.renderTier(tiers.viewport, generation, viewport);
3817
+ if (this.generation !== generation || this.disposed) return;
3818
+ this.dispatchEvent(new CustomEvent("viewport-ready", { detail: { trackId } }));
3819
+ await this.renderTier(tiers.buffer, generation, viewport);
3820
+ if (this.generation !== generation || this.disposed) return;
3821
+ await this.renderRemainingViaIdle(tiers.remaining, generation, viewport);
3822
+ }
3823
+ }
3824
+ async renderTier(canvases, generation, viewport) {
3825
+ if (canvases.length === 0) return;
3826
+ const groups = groupContiguousChunks(canvases);
3827
+ for (const group of groups) {
3828
+ if (this.generation !== generation || this.disposed) return;
3829
+ await this.renderGroup(group, generation, viewport);
3830
+ }
3831
+ }
3832
+ async renderGroup(group, generation, viewport) {
3833
+ if (group.length === 0) return;
3834
+ const first = group[0];
3835
+ const clip = this.clips.get(first.clipId);
3836
+ if (!clip) return;
3837
+ const fftSize = this.config.fftSize ?? 2048;
3838
+ const startPx = Math.min(...group.map((c) => c.globalPixelOffset));
3839
+ const endPx = Math.max(...group.map((c) => c.globalPixelOffset + c.widthPx));
3840
+ const startSample = clip.offsetSamples + Math.floor(startPx * viewport.samplesPerPixel);
3841
+ const endSample = Math.min(
3842
+ clip.offsetSamples + clip.durationSamples,
3843
+ clip.offsetSamples + Math.ceil(endPx * viewport.samplesPerPixel)
3844
+ );
3845
+ const paddedStart = Math.max(clip.offsetSamples, startSample - fftSize);
3846
+ const paddedEnd = Math.min(clip.offsetSamples + clip.durationSamples, endSample + fftSize);
3847
+ const { cacheKey: cacheKey2 } = await this.pool.computeFFT(
3848
+ {
3849
+ clipId: first.clipId,
3850
+ channelDataArrays: clip.channelData,
3851
+ config: this.config,
3852
+ sampleRate: clip.sampleRate,
3853
+ offsetSamples: clip.offsetSamples,
3854
+ durationSamples: clip.durationSamples,
3855
+ mono: false,
3856
+ sampleRange: { start: paddedStart, end: paddedEnd }
3857
+ },
3858
+ generation
3859
+ );
3860
+ if (this.generation !== generation || this.disposed) return;
3861
+ const colorLUT = this.colorLUT.get(this.colorMap);
3862
+ await this.pool.renderChunks(
3863
+ {
3864
+ cacheKey: cacheKey2,
3865
+ canvasIds: group.map((c) => c.canvasId),
3866
+ canvasWidths: group.map((c) => c.widthPx),
3867
+ globalPixelOffsets: group.map((c) => c.globalPixelOffset),
3868
+ canvasHeight: first.heightPx,
3869
+ devicePixelRatio: this.devicePixelRatio,
3870
+ samplesPerPixel: viewport.samplesPerPixel,
3871
+ colorLUT,
3872
+ frequencyScale: String(this.config.frequencyScale ?? "mel"),
3873
+ minFrequency: this.config.minFrequency ?? 0,
3874
+ maxFrequency: this.config.maxFrequency ?? clip.sampleRate / 2,
3875
+ gainDb: this.config.gainDb ?? 20,
3876
+ rangeDb: this.config.rangeDb ?? 80,
3877
+ channelIndex: first.channelIndex
3878
+ },
3879
+ generation
3880
+ );
3881
+ }
3882
+ async renderRemainingViaIdle(canvases, generation, viewport) {
3883
+ if (canvases.length === 0) return;
3884
+ const groups = groupContiguousChunks(canvases);
3885
+ for (const group of groups) {
3886
+ if (this.generation !== generation || this.disposed) return;
3887
+ await this.yieldUntilIdle();
3888
+ if (this.generation !== generation || this.disposed) return;
3889
+ await this.renderGroup(group, generation, viewport);
3890
+ }
3891
+ }
3892
+ yieldUntilIdle() {
3893
+ return new Promise((resolve) => {
3894
+ if (typeof requestIdleCallback === "function") {
3895
+ requestIdleCallback(() => resolve());
3896
+ } else {
3897
+ setTimeout(resolve, 0);
3898
+ }
3899
+ });
3900
+ }
3901
+ };
3902
+ // Annotate the CommonJS export names for ESM import in node:
3903
+ 0 && (module.exports = {
3904
+ ColorLUTCache,
3905
+ SpectrogramAbortError,
3906
+ SpectrogramOrchestrator,
3907
+ classifyViewport,
3908
+ computeSpectrogram,
3909
+ computeSpectrogramMono,
3910
+ createSpectrogramWorker,
3911
+ createSpectrogramWorkerPool,
3912
+ getColorMap,
3913
+ getFrequencyScale,
3914
+ groupContiguousChunks
3915
+ });
3916
+ //# sourceMappingURL=index.js.map