@waveform-playlist/spectrogram 11.3.1 → 13.0.0

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