-
Notifications
You must be signed in to change notification settings - Fork 21
/
Spectrum Matcher.jsfx
2253 lines (2071 loc) · 126 KB
/
Spectrum Matcher.jsfx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
desc:Spectrum Matcher (by Geraint Luff)
in_pin:Left
in_pin:Right
out_pin:Left
out_pin:Right
slider1:30<10,50,10>-bands
slider2:4<1,10,0.1>-peak bias
slider3:40<10,200>-smoothing period (ms)
slider4:1<0.5,1.5>-sharpness (Q)
slider5:6<-12,20>-hard limit (dB)
slider6:correction_gain_db=0<-24,12,0.1>-correction gain (dB)
slider7:correction_resolution=50<1,50,1>-correction resolution
slider8:correction_strength=1<-1,1>-correction strength
slider9:correction_range_low=20<10,18000,1>-correction range low (Hz)
slider10:correction_range_high=18000<20,20000,1>-correction range high (Hz)
slider11:correction_boundary_low=0<0,2,1{highpass,flat,zero}>-correction boundary low
slider12:correction_boundary_high=1<0,2,1{lowpass,flat,zero}>-correction boundary high
import ui-lib.jsfx-inc
@init
gfx_ext_retina = 1;
option_show_grouped_correction = 0;
MODEL_MAX_N = 100;
POLE_ZERO_LIMIT = 0.995;
allocated_end = allocated_start = ui_setup(0);
function allocate(N) local(result) (
result = allocated_end;
allocated_end += N;
result;
);
function allocate_reset() (
allocated_end = allocated_start;
model_target = allocate(MODEL_MAX_N);
model_shortperiod = allocate(MODEL_MAX_N);
model_longpower = allocate(MODEL_MAX_N);
correction_amp = allocate(MODEL_MAX_N);
correction_group_num = allocate(MODEL_MAX_N);
correction_group_size = allocate(MODEL_MAX_N);
correction_group_logamp = allocate(MODEL_MAX_N);
correction_group_logamp2 = allocate(MODEL_MAX_N);
correction_a1 = allocate(MODEL_MAX_N);
correction_a2 = allocate(MODEL_MAX_N);
correction_b0 = allocate(MODEL_MAX_N);
correction_b1 = allocate(MODEL_MAX_N);
correction_b2 = allocate(MODEL_MAX_N);
);
allocate_reset();
function filter_sample(x0) local(y0) (
y0 = this.b0*x0 + this.b1*this.x1 + this.b2*this.x2 - this.a1*this.y1 - this.a2*this.y2;
this.x2 = this.x1;
this.x1 = x0;
this.y2 = this.y1;
this.y1 = y0;
);
function filter_sample_even(x0) local(y0) (
y0 = this.b0*x0 + this.b1*this.x1 + this.b2*this.x2 - this.a1*this.y1 - this.a2*this.y2;
this.x2 = x0;
this.y2 = y0; // Next one will be odd, where they'll be swapped around
);
function filter_sample_odd(x0) local(y0) (
y0 = this.b0*x0 + this.b1*this.x2 + this.b2*this.x1 - this.a1*this.y2 - this.a2*this.y1;
this.x1 = x0;
this.y1 = y0;
);
function filter_set_coefficients(b0, b1, b2, a1, a2) (
this.b0 = b0;
this.b1 = b1;
this.b2 = b2;
this.a1 = a1;
this.a2 = a2;
);
function filter_reset_coefficients() (
this.filter_set_coefficients(1, 0, 0, 0, 0);
);
function filter_clear() (
this.x1 = this.x2 = this.y1 = this.y2 = 0;
);
function sinh(x) (
(exp(x) - exp(-x))*0.5;
);
low_freq = 20;
high_freq = 18000;
//bands_N = 0;
function reset_analysis_bands(N) local(i, freq, octaves, bw, period, alpha, w0, a0, filter_i) (
allocate_reset();
bands_N = N ? N : model_N;
bands_total_energy = 0;
filter_a1 = allocate(bands_N);
filter_a2 = allocate(bands_N);
filter_b0 = allocate(bands_N);
filter_b1 = allocate(bands_N);
filter_b2 = allocate(bands_N);
average1_unsharpenedvalue = allocate(bands_N);
average1_smoothed = allocate(bands_N);
average1_value = allocate(bands_N);
average2_counter = allocate(bands_N);
average2_sum = allocate(bands_N);
octaves = log(high_freq/low_freq)/log(2);
bw = octaves/(bands_N - 1);
i = 0;
while (i < bands_N) (
freq = low_freq*exp(log(high_freq/low_freq)*(i + 0.5)/bands_N);
w0 = 2*$pi*freq/srate;
alpha = sin(w0)*sinh(log(2)/2*bw*w0/sin(w0));
a0 = 1 + alpha;
filter_a1[i] = -2*cos(w0)/a0;
filter_a2[i] = (1 - alpha)/a0;
filter_b0[i] = alpha/a0;
filter_b1[i] = 0;
filter_b2[i] = -alpha/a0;
average1_unsharpenedvalue[i] = 0;
average1_value[i] = 0;
average2_counter[i] = 0;
average2_sum[i] = 0;
i += 1;
);
period = slider3/1000;
average1_slew = 1 - exp(-1/period/srate);
average1_period = period;
average2_power = slider2;
sum_interval_samples = ceil(period*srate*0.05);
bands_interconnect_db = -6*octaves/(bands_N - 1);
bands_interconnect = pow(10, bands_interconnect_db/10); // power calc
bands_subtraction_factor = 3.5/bands_N;
// Copy to static analysis bands
analysis_filter_block32_active = bands_N&32;
analysis_filter_block16_active = bands_N&16;
analysis_filter_block8_active = bands_N&8;
analysis_filter_block4_active = bands_N&4;
analysis_filter_block2_active = bands_N&2;
analysis_filter_block1_active = bands_N&1;
filter_i = 0;
analysis_filter_block32_active ? (
analysis_filter_block32_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_1_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_1_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_2_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_2_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_3_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_3_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_4_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_4_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_5_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_5_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_6_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_6_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_7_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_7_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_8_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_8_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_9_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_9_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_10_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_10_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_11_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_11_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_12_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_12_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_13_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_13_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_14_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_14_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_15_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_15_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_16_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_16_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_17_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_17_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_18_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_18_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_19_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_19_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_20_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_20_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_21_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_21_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_22_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_22_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_23_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_23_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_24_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_24_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_25_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_25_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_26_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_26_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_27_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_27_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_28_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_28_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_29_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_29_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_30_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_30_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block32_31_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block32_31_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
analysis_filter_block16_active ? (
analysis_filter_block16_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_1_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_1_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_2_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_2_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_3_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_3_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_4_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_4_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_5_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_5_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_6_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_6_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_7_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_7_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_8_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_8_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_9_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_9_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_10_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_10_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_11_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_11_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_12_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_12_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_13_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_13_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_14_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_14_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block16_15_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block16_15_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
analysis_filter_block8_active ? (
analysis_filter_block8_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_1_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_1_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_2_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_2_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_3_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_3_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_4_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_4_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_5_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_5_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_6_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_6_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block8_7_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block8_7_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
analysis_filter_block4_active ? (
analysis_filter_block4_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block4_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block4_1_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block4_1_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block4_2_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block4_2_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block4_3_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block4_3_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
analysis_filter_block2_active ? (
analysis_filter_block2_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block2_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
analysis_filter_block2_1_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block2_1_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
analysis_filter_block1_active ? (
analysis_filter_block1_0_l.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
analysis_filter_block1_0_r.filter_set_coefficients(filter_b0[filter_i], filter_b1[filter_i], filter_b2[filter_i], filter_a1[filter_i], filter_a2[filter_i]);
filter_i += 1;
);
// Clear filters
analysis_filter_block32_0_l.filter_clear();
analysis_filter_block32_0_r.filter_clear();
analysis_filter_block32_1_l.filter_clear();
analysis_filter_block32_1_r.filter_clear();
analysis_filter_block32_2_l.filter_clear();
analysis_filter_block32_2_r.filter_clear();
analysis_filter_block32_3_l.filter_clear();
analysis_filter_block32_3_r.filter_clear();
analysis_filter_block32_4_l.filter_clear();
analysis_filter_block32_4_r.filter_clear();
analysis_filter_block32_5_l.filter_clear();
analysis_filter_block32_5_r.filter_clear();
analysis_filter_block32_6_l.filter_clear();
analysis_filter_block32_6_r.filter_clear();
analysis_filter_block32_7_l.filter_clear();
analysis_filter_block32_7_r.filter_clear();
analysis_filter_block32_8_l.filter_clear();
analysis_filter_block32_8_r.filter_clear();
analysis_filter_block32_9_l.filter_clear();
analysis_filter_block32_9_r.filter_clear();
analysis_filter_block32_10_l.filter_clear();
analysis_filter_block32_10_r.filter_clear();
analysis_filter_block32_11_l.filter_clear();
analysis_filter_block32_11_r.filter_clear();
analysis_filter_block32_12_l.filter_clear();
analysis_filter_block32_12_r.filter_clear();
analysis_filter_block32_13_l.filter_clear();
analysis_filter_block32_13_r.filter_clear();
analysis_filter_block32_14_l.filter_clear();
analysis_filter_block32_14_r.filter_clear();
analysis_filter_block32_15_l.filter_clear();
analysis_filter_block32_15_r.filter_clear();
analysis_filter_block32_16_l.filter_clear();
analysis_filter_block32_16_r.filter_clear();
analysis_filter_block32_17_l.filter_clear();
analysis_filter_block32_17_r.filter_clear();
analysis_filter_block32_18_l.filter_clear();
analysis_filter_block32_18_r.filter_clear();
analysis_filter_block32_19_l.filter_clear();
analysis_filter_block32_19_r.filter_clear();
analysis_filter_block32_20_l.filter_clear();
analysis_filter_block32_20_r.filter_clear();
analysis_filter_block32_21_l.filter_clear();
analysis_filter_block32_21_r.filter_clear();
analysis_filter_block32_22_l.filter_clear();
analysis_filter_block32_22_r.filter_clear();
analysis_filter_block32_23_l.filter_clear();
analysis_filter_block32_23_r.filter_clear();
analysis_filter_block32_24_l.filter_clear();
analysis_filter_block32_24_r.filter_clear();
analysis_filter_block32_25_l.filter_clear();
analysis_filter_block32_25_r.filter_clear();
analysis_filter_block32_26_l.filter_clear();
analysis_filter_block32_26_r.filter_clear();
analysis_filter_block32_27_l.filter_clear();
analysis_filter_block32_27_r.filter_clear();
analysis_filter_block32_28_l.filter_clear();
analysis_filter_block32_28_r.filter_clear();
analysis_filter_block32_29_l.filter_clear();
analysis_filter_block32_29_r.filter_clear();
analysis_filter_block32_30_l.filter_clear();
analysis_filter_block32_30_r.filter_clear();
analysis_filter_block32_31_l.filter_clear();
analysis_filter_block32_31_r.filter_clear();
analysis_filter_block16_0_l.filter_clear();
analysis_filter_block16_0_r.filter_clear();
analysis_filter_block16_1_l.filter_clear();
analysis_filter_block16_1_r.filter_clear();
analysis_filter_block16_2_l.filter_clear();
analysis_filter_block16_2_r.filter_clear();
analysis_filter_block16_3_l.filter_clear();
analysis_filter_block16_3_r.filter_clear();
analysis_filter_block16_4_l.filter_clear();
analysis_filter_block16_4_r.filter_clear();
analysis_filter_block16_5_l.filter_clear();
analysis_filter_block16_5_r.filter_clear();
analysis_filter_block16_6_l.filter_clear();
analysis_filter_block16_6_r.filter_clear();
analysis_filter_block16_7_l.filter_clear();
analysis_filter_block16_7_r.filter_clear();
analysis_filter_block16_8_l.filter_clear();
analysis_filter_block16_8_r.filter_clear();
analysis_filter_block16_9_l.filter_clear();
analysis_filter_block16_9_r.filter_clear();
analysis_filter_block16_10_l.filter_clear();
analysis_filter_block16_10_r.filter_clear();
analysis_filter_block16_11_l.filter_clear();
analysis_filter_block16_11_r.filter_clear();
analysis_filter_block16_12_l.filter_clear();
analysis_filter_block16_12_r.filter_clear();
analysis_filter_block16_13_l.filter_clear();
analysis_filter_block16_13_r.filter_clear();
analysis_filter_block16_14_l.filter_clear();
analysis_filter_block16_14_r.filter_clear();
analysis_filter_block16_15_l.filter_clear();
analysis_filter_block16_15_r.filter_clear();
analysis_filter_block8_0_l.filter_clear();
analysis_filter_block8_0_r.filter_clear();
analysis_filter_block8_1_l.filter_clear();
analysis_filter_block8_1_r.filter_clear();
analysis_filter_block8_2_l.filter_clear();
analysis_filter_block8_2_r.filter_clear();
analysis_filter_block8_3_l.filter_clear();
analysis_filter_block8_3_r.filter_clear();
analysis_filter_block8_4_l.filter_clear();
analysis_filter_block8_4_r.filter_clear();
analysis_filter_block8_5_l.filter_clear();
analysis_filter_block8_5_r.filter_clear();
analysis_filter_block8_6_l.filter_clear();
analysis_filter_block8_6_r.filter_clear();
analysis_filter_block8_7_l.filter_clear();
analysis_filter_block8_7_r.filter_clear();
analysis_filter_block4_0_l.filter_clear();
analysis_filter_block4_0_r.filter_clear();
analysis_filter_block4_1_l.filter_clear();
analysis_filter_block4_1_r.filter_clear();
analysis_filter_block4_2_l.filter_clear();
analysis_filter_block4_2_r.filter_clear();
analysis_filter_block4_3_l.filter_clear();
analysis_filter_block4_3_r.filter_clear();
analysis_filter_block2_0_l.filter_clear();
analysis_filter_block2_0_r.filter_clear();
analysis_filter_block2_1_l.filter_clear();
analysis_filter_block2_1_r.filter_clear();
analysis_filter_block1_0_l.filter_clear();
analysis_filter_block1_0_r.filter_clear();
);
!bands_N ? reset_analysis_bands(model_N);
function reset_model(N) local(i, freq) (
model_N = N;
model_shortperiod = 0.05;
model_longpower = 4;
i = 0;
while (i < model_N) (
freq = low_freq*exp(log(high_freq/low_freq)*(i + 0.5)/model_N);
model_target[i] = min(1, pow(freq/100, 3))*1/pow(freq, 0);
model_target[i] = min(1, pow(freq/50, 4))*min(1, freq/120)/pow(freq, 0.9);
i += 1;
);
);
!model_N ? reset_model(floor(slider1 + 0.5));
function copy_to_model() local(i) (
model_N = bands_N;
model_shortperiod = average1_period;
model_longpower = average2_power;
i = 0;
while (i < bands_N) (
model_target[i] = pow(average2_sum[i]/average2_counter[i], 1/average2_power);
i += 1;
);
);
function model_adjustment(i) (
sqrt(model_target[i]/pow(average2_sum[i]/average2_counter[i], 1/average2_power));
);
function clear_correction_filters() local(i) (
correction_filter_block32_0_l.filter_clear();
correction_filter_block32_0_r.filter_clear();
correction_filter_block32_1_l.filter_clear();
correction_filter_block32_1_r.filter_clear();
correction_filter_block32_2_l.filter_clear();
correction_filter_block32_2_r.filter_clear();
correction_filter_block32_3_l.filter_clear();
correction_filter_block32_3_r.filter_clear();
correction_filter_block32_4_l.filter_clear();
correction_filter_block32_4_r.filter_clear();
correction_filter_block32_5_l.filter_clear();
correction_filter_block32_5_r.filter_clear();
correction_filter_block32_6_l.filter_clear();
correction_filter_block32_6_r.filter_clear();
correction_filter_block32_7_l.filter_clear();
correction_filter_block32_7_r.filter_clear();
correction_filter_block32_8_l.filter_clear();
correction_filter_block32_8_r.filter_clear();
correction_filter_block32_9_l.filter_clear();
correction_filter_block32_9_r.filter_clear();
correction_filter_block32_10_l.filter_clear();
correction_filter_block32_10_r.filter_clear();
correction_filter_block32_11_l.filter_clear();
correction_filter_block32_11_r.filter_clear();
correction_filter_block32_12_l.filter_clear();
correction_filter_block32_12_r.filter_clear();
correction_filter_block32_13_l.filter_clear();
correction_filter_block32_13_r.filter_clear();
correction_filter_block32_14_l.filter_clear();
correction_filter_block32_14_r.filter_clear();
correction_filter_block32_15_l.filter_clear();
correction_filter_block32_15_r.filter_clear();
correction_filter_block32_16_l.filter_clear();
correction_filter_block32_16_r.filter_clear();
correction_filter_block32_17_l.filter_clear();
correction_filter_block32_17_r.filter_clear();
correction_filter_block32_18_l.filter_clear();
correction_filter_block32_18_r.filter_clear();
correction_filter_block32_19_l.filter_clear();
correction_filter_block32_19_r.filter_clear();
correction_filter_block32_20_l.filter_clear();
correction_filter_block32_20_r.filter_clear();
correction_filter_block32_21_l.filter_clear();
correction_filter_block32_21_r.filter_clear();
correction_filter_block32_22_l.filter_clear();
correction_filter_block32_22_r.filter_clear();
correction_filter_block32_23_l.filter_clear();
correction_filter_block32_23_r.filter_clear();
correction_filter_block32_24_l.filter_clear();
correction_filter_block32_24_r.filter_clear();
correction_filter_block32_25_l.filter_clear();
correction_filter_block32_25_r.filter_clear();
correction_filter_block32_26_l.filter_clear();
correction_filter_block32_26_r.filter_clear();
correction_filter_block32_27_l.filter_clear();
correction_filter_block32_27_r.filter_clear();
correction_filter_block32_28_l.filter_clear();
correction_filter_block32_28_r.filter_clear();
correction_filter_block32_29_l.filter_clear();
correction_filter_block32_29_r.filter_clear();
correction_filter_block32_30_l.filter_clear();
correction_filter_block32_30_r.filter_clear();
correction_filter_block32_31_l.filter_clear();
correction_filter_block32_31_r.filter_clear();
correction_filter_block16_0_l.filter_clear();
correction_filter_block16_0_r.filter_clear();
correction_filter_block16_1_l.filter_clear();
correction_filter_block16_1_r.filter_clear();
correction_filter_block16_2_l.filter_clear();
correction_filter_block16_2_r.filter_clear();
correction_filter_block16_3_l.filter_clear();
correction_filter_block16_3_r.filter_clear();
correction_filter_block16_4_l.filter_clear();
correction_filter_block16_4_r.filter_clear();
correction_filter_block16_5_l.filter_clear();
correction_filter_block16_5_r.filter_clear();
correction_filter_block16_6_l.filter_clear();
correction_filter_block16_6_r.filter_clear();
correction_filter_block16_7_l.filter_clear();
correction_filter_block16_7_r.filter_clear();
correction_filter_block16_8_l.filter_clear();
correction_filter_block16_8_r.filter_clear();
correction_filter_block16_9_l.filter_clear();
correction_filter_block16_9_r.filter_clear();
correction_filter_block16_10_l.filter_clear();
correction_filter_block16_10_r.filter_clear();
correction_filter_block16_11_l.filter_clear();
correction_filter_block16_11_r.filter_clear();
correction_filter_block16_12_l.filter_clear();
correction_filter_block16_12_r.filter_clear();
correction_filter_block16_13_l.filter_clear();
correction_filter_block16_13_r.filter_clear();
correction_filter_block16_14_l.filter_clear();
correction_filter_block16_14_r.filter_clear();
correction_filter_block16_15_l.filter_clear();
correction_filter_block16_15_r.filter_clear();
correction_filter_block8_0_l.filter_clear();
correction_filter_block8_0_r.filter_clear();
correction_filter_block8_1_l.filter_clear();
correction_filter_block8_1_r.filter_clear();
correction_filter_block8_2_l.filter_clear();
correction_filter_block8_2_r.filter_clear();
correction_filter_block8_3_l.filter_clear();
correction_filter_block8_3_r.filter_clear();
correction_filter_block8_4_l.filter_clear();
correction_filter_block8_4_r.filter_clear();
correction_filter_block8_5_l.filter_clear();
correction_filter_block8_5_r.filter_clear();
correction_filter_block8_6_l.filter_clear();
correction_filter_block8_6_r.filter_clear();
correction_filter_block8_7_l.filter_clear();
correction_filter_block8_7_r.filter_clear();
correction_filter_block4_0_l.filter_clear();
correction_filter_block4_0_r.filter_clear();
correction_filter_block4_1_l.filter_clear();
correction_filter_block4_1_r.filter_clear();
correction_filter_block4_2_l.filter_clear();
correction_filter_block4_2_r.filter_clear();
correction_filter_block4_3_l.filter_clear();
correction_filter_block4_3_r.filter_clear();
correction_filter_block2_0_l.filter_clear();
correction_filter_block2_0_r.filter_clear();
correction_filter_block2_1_l.filter_clear();
correction_filter_block2_1_r.filter_clear();
correction_filter_block1_0_l.filter_clear();
correction_filter_block1_0_r.filter_clear();
);
function reset_correction_coefficients() local(i) (
i = 0;
while (i < MODEL_MAX_N) (
correction_amp[i] = 1;
correction_a1[i] = 0;
correction_a2[i] = 0;
correction_b0[i] = 1;
correction_b1[i] = 0;
correction_b2[i] = 0;
i += 1;
);
correction_filter_block32_0_l.filter_reset_coefficients();
correction_filter_block32_0_r.filter_reset_coefficients();
correction_filter_block32_1_l.filter_reset_coefficients();
correction_filter_block32_1_r.filter_reset_coefficients();
correction_filter_block32_2_l.filter_reset_coefficients();
correction_filter_block32_2_r.filter_reset_coefficients();
correction_filter_block32_3_l.filter_reset_coefficients();
correction_filter_block32_3_r.filter_reset_coefficients();
correction_filter_block32_4_l.filter_reset_coefficients();
correction_filter_block32_4_r.filter_reset_coefficients();
correction_filter_block32_5_l.filter_reset_coefficients();
correction_filter_block32_5_r.filter_reset_coefficients();
correction_filter_block32_6_l.filter_reset_coefficients();
correction_filter_block32_6_r.filter_reset_coefficients();
correction_filter_block32_7_l.filter_reset_coefficients();
correction_filter_block32_7_r.filter_reset_coefficients();
correction_filter_block32_8_l.filter_reset_coefficients();
correction_filter_block32_8_r.filter_reset_coefficients();
correction_filter_block32_9_l.filter_reset_coefficients();
correction_filter_block32_9_r.filter_reset_coefficients();
correction_filter_block32_10_l.filter_reset_coefficients();
correction_filter_block32_10_r.filter_reset_coefficients();
correction_filter_block32_11_l.filter_reset_coefficients();
correction_filter_block32_11_r.filter_reset_coefficients();
correction_filter_block32_12_l.filter_reset_coefficients();
correction_filter_block32_12_r.filter_reset_coefficients();
correction_filter_block32_13_l.filter_reset_coefficients();
correction_filter_block32_13_r.filter_reset_coefficients();
correction_filter_block32_14_l.filter_reset_coefficients();
correction_filter_block32_14_r.filter_reset_coefficients();
correction_filter_block32_15_l.filter_reset_coefficients();
correction_filter_block32_15_r.filter_reset_coefficients();
correction_filter_block32_16_l.filter_reset_coefficients();
correction_filter_block32_16_r.filter_reset_coefficients();
correction_filter_block32_17_l.filter_reset_coefficients();
correction_filter_block32_17_r.filter_reset_coefficients();
correction_filter_block32_18_l.filter_reset_coefficients();
correction_filter_block32_18_r.filter_reset_coefficients();
correction_filter_block32_19_l.filter_reset_coefficients();
correction_filter_block32_19_r.filter_reset_coefficients();
correction_filter_block32_20_l.filter_reset_coefficients();
correction_filter_block32_20_r.filter_reset_coefficients();
correction_filter_block32_21_l.filter_reset_coefficients();
correction_filter_block32_21_r.filter_reset_coefficients();
correction_filter_block32_22_l.filter_reset_coefficients();
correction_filter_block32_22_r.filter_reset_coefficients();
correction_filter_block32_23_l.filter_reset_coefficients();
correction_filter_block32_23_r.filter_reset_coefficients();
correction_filter_block32_24_l.filter_reset_coefficients();
correction_filter_block32_24_r.filter_reset_coefficients();
correction_filter_block32_25_l.filter_reset_coefficients();
correction_filter_block32_25_r.filter_reset_coefficients();
correction_filter_block32_26_l.filter_reset_coefficients();
correction_filter_block32_26_r.filter_reset_coefficients();
correction_filter_block32_27_l.filter_reset_coefficients();
correction_filter_block32_27_r.filter_reset_coefficients();
correction_filter_block32_28_l.filter_reset_coefficients();
correction_filter_block32_28_r.filter_reset_coefficients();
correction_filter_block32_29_l.filter_reset_coefficients();
correction_filter_block32_29_r.filter_reset_coefficients();
correction_filter_block32_30_l.filter_reset_coefficients();
correction_filter_block32_30_r.filter_reset_coefficients();
correction_filter_block32_31_l.filter_reset_coefficients();
correction_filter_block32_31_r.filter_reset_coefficients();
correction_filter_block16_0_l.filter_reset_coefficients();
correction_filter_block16_0_r.filter_reset_coefficients();
correction_filter_block16_1_l.filter_reset_coefficients();
correction_filter_block16_1_r.filter_reset_coefficients();
correction_filter_block16_2_l.filter_reset_coefficients();
correction_filter_block16_2_r.filter_reset_coefficients();
correction_filter_block16_3_l.filter_reset_coefficients();
correction_filter_block16_3_r.filter_reset_coefficients();
correction_filter_block16_4_l.filter_reset_coefficients();
correction_filter_block16_4_r.filter_reset_coefficients();
correction_filter_block16_5_l.filter_reset_coefficients();
correction_filter_block16_5_r.filter_reset_coefficients();
correction_filter_block16_6_l.filter_reset_coefficients();
correction_filter_block16_6_r.filter_reset_coefficients();
correction_filter_block16_7_l.filter_reset_coefficients();
correction_filter_block16_7_r.filter_reset_coefficients();
correction_filter_block16_8_l.filter_reset_coefficients();
correction_filter_block16_8_r.filter_reset_coefficients();
correction_filter_block16_9_l.filter_reset_coefficients();
correction_filter_block16_9_r.filter_reset_coefficients();
correction_filter_block16_10_l.filter_reset_coefficients();
correction_filter_block16_10_r.filter_reset_coefficients();
correction_filter_block16_11_l.filter_reset_coefficients();
correction_filter_block16_11_r.filter_reset_coefficients();
correction_filter_block16_12_l.filter_reset_coefficients();
correction_filter_block16_12_r.filter_reset_coefficients();
correction_filter_block16_13_l.filter_reset_coefficients();
correction_filter_block16_13_r.filter_reset_coefficients();
correction_filter_block16_14_l.filter_reset_coefficients();
correction_filter_block16_14_r.filter_reset_coefficients();
correction_filter_block16_15_l.filter_reset_coefficients();
correction_filter_block16_15_r.filter_reset_coefficients();
correction_filter_block8_0_l.filter_reset_coefficients();
correction_filter_block8_0_r.filter_reset_coefficients();
correction_filter_block8_1_l.filter_reset_coefficients();
correction_filter_block8_1_r.filter_reset_coefficients();
correction_filter_block8_2_l.filter_reset_coefficients();
correction_filter_block8_2_r.filter_reset_coefficients();
correction_filter_block8_3_l.filter_reset_coefficients();
correction_filter_block8_3_r.filter_reset_coefficients();
correction_filter_block8_4_l.filter_reset_coefficients();
correction_filter_block8_4_r.filter_reset_coefficients();
correction_filter_block8_5_l.filter_reset_coefficients();
correction_filter_block8_5_r.filter_reset_coefficients();
correction_filter_block8_6_l.filter_reset_coefficients();
correction_filter_block8_6_r.filter_reset_coefficients();
correction_filter_block8_7_l.filter_reset_coefficients();
correction_filter_block8_7_r.filter_reset_coefficients();
correction_filter_block4_0_l.filter_reset_coefficients();
correction_filter_block4_0_r.filter_reset_coefficients();
correction_filter_block4_1_l.filter_reset_coefficients();
correction_filter_block4_1_r.filter_reset_coefficients();
correction_filter_block4_2_l.filter_reset_coefficients();
correction_filter_block4_2_r.filter_reset_coefficients();
correction_filter_block4_3_l.filter_reset_coefficients();
correction_filter_block4_3_r.filter_reset_coefficients();
correction_filter_block2_0_l.filter_reset_coefficients();
correction_filter_block2_0_r.filter_reset_coefficients();
correction_filter_block2_1_l.filter_reset_coefficients();
correction_filter_block2_1_r.filter_reset_coefficients();
correction_filter_block1_0_l.filter_reset_coefficients();
correction_filter_block1_0_r.filter_reset_coefficients();
clear_correction_filters();
);
function correction_amp(freq) local(wi, wr, hi, hr, pr, pi, pm2, zr, zi, tr, ti, i) (
hr = 1;
hi = 0;
wr = cos(2*$pi*freq/srate);
wi = sin(2*$pi*freq/srate);
w2r = cos(4*$pi*freq/srate);
w2i = sin(4*$pi*freq/srate);
i = 0;
while (i < correction_N) (
zr = correction_b0[i] + correction_b1[i]*wr + correction_b2[i]*w2r;
zi = correction_b1[i]*wi + correction_b2[i]*w2i;
pr = 1 + correction_a1[i]*wr + correction_a2[i]*w2r;
pi = correction_a1[i]*wi + correction_a2[i]*w2i;
pm2 = pr*pr + pi*pi;
tr = hr;
ti = hi;
hr = tr*zr - ti*zi;
hi = tr*zi + ti*zr;
tr = hr;
ti = hi;
hr = tr*pr + ti*pi;
hi = ti*pr - tr*pi;
hr /= pm2;
hi /= pm2;
i += 1;
);
sqrt(hr*hr + hi*hi);
);
function correction_phase(freq) local(wi, wr, hi, hr, pr, pi, pm2, zr, zi, tr, ti, i) (
hr = 1;
hi = 0;
wr = cos(2*$pi*freq/srate);
wi = sin(2*$pi*freq/srate);
w2r = cos(4*$pi*freq/srate);
w2i = sin(4*$pi*freq/srate);
i = 0;
while (i < correction_N) (
zr = correction_b0[i] + correction_b1[i]*wr + correction_b2[i]*w2r;
zi = correction_b1[i]*wi + correction_b2[i]*w2i;
pr = 1 + correction_a1[i]*wr + correction_a2[i]*w2r;
pi = correction_a1[i]*wi + correction_a2[i]*w2i;
pm2 = pr*pr + pi*pi;
tr = hr;
ti = hi;
hr = tr*zr - ti*zi;
hi = tr*zi + ti*zr;
tr = hr;
ti = hi;
hr = tr*pr + ti*pi;
hi = ti*pr - tr*pi;
hr /= pm2;
hi /= pm2;
i += 1;
);
atan2(hi, hr);
);
function copy_correction_from_analysis() local(i) (
i = 0;
while (i < model_N) (
correction_amp[i] = model_adjustment(i);
i += 1;
);
);
function calculate_correction_coefficients() local(i, logMerged, logA, logB, sizeA, sizeB, sizeMerged, boundary_freq, prev_amp, amp, Q, A, w0, alpha, a0, gain, sqrtA2alpha, active_bands, merge_score, best_merge_score, best_merge_groupA, best_merge_groupB, best_merge_size, best_merge_logamp, best_merge_logamp2) (
!correction_resolution ? correction_resolution = model_N;
correction_resolution = max(1, min(floor(correction_resolution + 0.5), model_N));
correction_index_low = max(0, floor(log(correction_range_low/low_freq)/log(high_freq/low_freq)*model_N));
correction_index_high = min(model_N, ceil(log(correction_range_high/low_freq)/log(high_freq/low_freq)*model_N));
correction_index_low == correction_index_high ? (
correction_index_high = min(model_N, correction_index_low + 1);
correction_index_low = correction_index_high - 1;
);
// Simplify correction model
i = 0;
while (i < model_N) (
correction_group_num[i] = i;
correction_group_size[i] = 1;
correction_group_logamp[i] = log(correction_amp[i]);
correction_group_logamp2[i] = correction_group_logamp[i]*correction_group_logamp[i];
i += 1;
);
active_bands = model_N;
while (active_bands > correction_resolution) (
best_merge_score = 1000000000000;
i = 1;
while (i < model_N) (
correction_group_num[i] != correction_group_num[i - 1] ? (
// Should we merge the bands?
logA = correction_group_logamp[i];
logA2 = correction_group_logamp2[i];
sizeA = correction_group_size[i];
logB = correction_group_logamp[i - 1];
logB2 = correction_group_logamp2[i - 1];
sizeB = correction_group_size[i - 1];
sizeMerged = sizeA + sizeB;
logMerged = logA + logB;
logMerged2 = logA2 + logB2;
merge_score = (logMerged2 - logMerged*logMerged/sizeMerged) - (logA2 - logA*logA/sizeA) - (logB2 - logB*logB/sizeB);
merge_score < best_merge_score ? (
best_merge_score = merge_score;
best_merge_size = sizeMerged;
best_merge_logamp = logMerged;
best_merge_logamp2 = logMerged2;
best_merge_groupA = correction_group_num[i];
best_merge_groupB = correction_group_num[i - 1];
);
);
i += 1;
);
// Merge the two groups with lowest cost
i = 0;
while (i < model_N) (
correction_group_num[i] == best_merge_groupA || correction_group_num[i] == best_merge_groupB ? (
correction_group_num[i] = best_merge_groupA;
correction_group_size[i] = best_merge_size;
correction_group_logamp[i] = best_merge_logamp;
correction_group_logamp2[i] = best_merge_logamp2;
);
i += 1;
);
active_bands -= 1;
);
i = correction_index_low;
prev_amp = 1;
gain = 1;
global_gain = pow(10, correction_gain_db*correction_strength/20);
correction_boundary_low == 1 ? (
// First band is just flat gain
prev_amp = exp(correction_group_logamp[i]/correction_group_size[i]*correction_strength)*global_gain;
gain = prev_amp;
i += 1;
) : correction_boundary_low == 2 ? (
prev_amp = 1;
gain = 1;
);
filter_i = 0;
while (i < correction_index_high) (
filter_i == 0 || correction_group_num[i] != correction_group_num[i - 1] ? (
boundary_freq = low_freq*exp(log(high_freq/low_freq)*i/model_N);
amp = exp(correction_group_logamp[i]/correction_group_size[i]*correction_strength)*global_gain;
filter_i == 0 && correction_boundary_low == 0 ? ( // Highpass
boundary_freq = correction_range_low;
Q = 0.71;
w0 = 2*$pi*boundary_freq/srate;
alpha = sin(w0)/(2*Q);
a0 = (1 + alpha);
correction_a1[filter_i] = -2*cos(w0)/a0;
correction_a2[filter_i] = (1 - alpha)/a0;
correction_b0[filter_i] = amp*(1 + cos(w0))/2/a0;
correction_b1[filter_i] = -amp*(1 + cos(w0))/a0;
correction_b2[filter_i] = amp*(1 + cos(w0))/2/a0;
) : (
Q = filter_i == 0 ? 0.8 : slider4;
A = sqrt(amp/prev_amp);
w0 = 2*$pi*boundary_freq/srate;
alpha = sin(w0)/(2*Q);
sqrtA2alpha = 2*sqrt(A)*alpha;
a0 = (A + 1) - (A - 1)*cos(w0) + sqrtA2alpha;
correction_a1[filter_i] = 2*((A - 1) - (A + 1)*cos(w0))/a0;
correction_a2[filter_i] = (a0 - 2*sqrtA2alpha)/a0;
correction_b0[filter_i] = gain*A*((A + 1) + (A - 1)*cos(w0) + sqrtA2alpha)/a0;
correction_b1[filter_i] = gain*-2*A*((A - 1) + (A + 1)*cos(w0))/a0;
correction_b2[filter_i] = gain*A*((A + 1) + (A - 1)*cos(w0) - sqrtA2alpha)/a0;
);
gain = 1;
filter_i += 1;
prev_amp = amp;
);
i += 1;
);
correction_boundary_high != 1 ? (
boundary_freq = correction_range_high;
correction_boundary_high == 0 ? ( // Lowpass
Q = 0.71;
w0 = 2*$pi*boundary_freq/srate;