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