forked from TukanStudios/TUKAN_STUDIOS_PLUGINS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeak Needle (Tukan)
3120 lines (2380 loc) · 92.3 KB
/
Peak Needle (Tukan)
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
// This effect Copyright (C) 2021 and later Cockos Incorporated
// License: LGPL - http://www.gnu.org/licenses/lgpl.html
desc:Peak Needle 2 (Tukan)
//tags: analysis loudness meter cockos
//author: Cockos
slider1:cfg_peak=4<0,4,1{off,true peak,true peak clips,peak,peak clips}>-Peak
slider2:cfg_rms_m=0<0,1,1{off,on}>-RMS momentary
slider3:cfg_rms_i=0<0,1,1{off,on}>-RMS integrated
slider4:cfg_lufs_m=2<0,2,1{off,on,on + histogram}>-LUFS momentary
slider5:cfg_lufs_s=1<0,1,1{off,on}>-LUFS short-term
slider6:cfg_lra=1<0,1,1{off,on}>-LRA loudness range
slider7:cfg_lufs_i=1<0,1,1{off,on}>-LUFS integrated
slider8:cfg_alert=0<0,3,1{off,yellow,red,yellow + red>-LUFS alerts
slider9:cfg_yellow=-12<-60,0>-Yellow alert level
slider10:cfg_red=-6<-60,0>-Red alert level
slider11:cfg_reinit=1<0,1,1{off,on}>-Reset on playback start
slider12:cfg_mono=0<0,1,1{off,on}>-Force mono analysis
slider13:cfg_textsize=0<-2,8,1>-Text size
slider14:cfg_yscale=1.8<0.5,4,0.1>-Y axis scaling
slider15:cfg_out_auto=0<0,16,1{off,all,all (inverted),Peak,Peak (inverted),RMS-M,RMS-M (inverted),RMS-I,RMS-I (inverted),LUFS-M,LUFS-M (inverted),LUFS-S,LUFS-S (inverted),LUFS-I,LUFS-I (inverted),LRA,LRA (inverted)}>-Output loudness values as automation
slider30:outparm_peak=-150<-150,20,1>-Peak/True peak dB (output)
slider31:outparm_rms_m=-100<-100,0,1>-RMS-M (output)
slider32:outparm_rms_i=-100<-100,0,1>-RMS-I (output)
slider33:outparm_lufs_m=-100<-100,0,1>-LUFS-M (output)
slider34:outparm_lufs_s=-100<-100,0,1>-LUFS-S (output)
slider35:outparm_lufs_i=-100<-100,0,1>-LUFS-I (output)
slider36:outparm_lufs_lra=0<0,100,1>-LRA (output)
slider37:-60<-90,-20,1>-scale bottom
slider38:0<-40,0,1>-calibration
slider39:0<0,1,1>-Stereo
slider40:0.5<0.01,1,0.01>-Meter decay
slider41:0<0,10,1{One Peak, Two Peaks, One TPeak, Two TPeak, RMS, LRA, LUFS S, LUFS M, LUFS I, VU, VU ST}>-Needle
slider42:0<0,1,1>-42 numbers Real
slider43:0<-30,0,1>-43 Target
slider44:0<0,1,1>-Peak/Live Values
slider45:0<0,10,1{One Peak, Two Peaks, One TPeak, Two TPeak, RMS, LRA, LUFS S, LUFS M, LUFS I, VU, VU ST}>-Number 45
filename:0,Meter/led.png
filename:1,Meter/APIBig.png
filename:2,Meter/APIRED.png
filename:3,Meter/APISmall.png
filename:4,Meter/switch.png
filename:5,Meter/PNMeterback.png
filename:6,Meter/PPNBack2.png
filename:7,Meter/whiteknob_35.png
filename:8,Meter/oled.png
//options:no_meter
@init
initial = 1;
gfx_clear=0;
lastCap=1;
mouse_wheel=1;
coords=srate+1;
function limitgui(s low up)
( min(max(s, low), up) );
function deg(r)
( r / $pi * 180 );
function rad(d)
( d * $pi / 180 );
/******************************* GUI Function ***********************************/
function xy(x y)
( gfx_x = x; gfx_y = y; );
function rgb(r g b)
( gfx_r = r; gfx_g = g; gfx_b = b; );
function rectIn (xIn_ yIn_ wIn hIn)
instance (xIn yIn widthIn heightIn)
(
xIn = xIn_;
yIn = yIn_;
widthIn = wIn;
heightIn = hIn;
);
function rectOut (xOut_ yOut_ wOut hOut c i)
instance (xOut yOut widthOut heightOut count index)
(
xOut = xOut_;
yOut = yOut_;
widthOut = wOut;
heightOut = hOut;
count = c;
index = i;
);
function potVal(v)
instance (frame val minVal maxVal count heightOut)
(
val = v;
frame = (val - minVal) * (count - 1) / (maxVal - minVal) + 0.5;
frame |= 0;
);
function potCfg (default_ minVal_ maxVal_ step_)
instance (default minVal maxVal step)
(
default = default_;
minVal = minVal_;
maxVal = maxVal_;
step = step_;
this.potVal(default);
);
function bkg(wImg hImg indImg)
(
gfx_a=1;
coords[0] = coords[4] = 0;
coords[1] = coords[5] = 0;;
coords[2] = coords[6] = wImg;
coords[3] = coords[7] = hImg;
gfx_blitext(indImg, coords, 0);
);
function potDrawIn ()
instance (xIn yIn widthIn heightIn val)
(
gfx_r= 1; gfx_g = gfx_b =0;gfx_a= 0.5;
gfx_line(xIn,yIn,xIn,heightIn+yIn);
gfx_line(xIn,heightIn+yIn,xIn+widthIn,heightIn+yIn);
gfx_line(xIn+widthIn,yIn,xIn+widthIn,heightIn+yIn);
gfx_line(xIn,yIn,xIn+widthIn,yIn);
gfx_r = gfx_g = gfx_b = 0.75;
gfx_x = xIn + widthIn/2-12;
gfx_y = yIn+heightIn/2-5;
gfx_drawnumber(val, 1);
);
function knob()
instance (xOut yOut widthOut heightOut index frame val)
(
gfx_a=1;
coords[0] = 0;
coords[1] = frame * heightOut;
coords[2] = coords[6] = widthOut;
coords[3] = coords[7] = heightOut;
coords[4] = xOut;
coords[5] = yOut;
gfx_blitext(index, coords, 0);
);
function collision ()
instance (xIn yIn widthIn heightIn)
(
mouse_x > xIn && mouse_x < xIn + widthIn && mouse_y > yIn && mouse_y < yIn + heightIn
);
function dragStart ()
instance (dragging yOld default)
(
!ctrl ? (
yOld = mouse_y;
dragging = 1;
) :
this.potVal(default);
);
function dragStop()
instance (dragging val valOld)
(
dragging = 0;
valOld = val;
);
function potDrag()
local (val)
instance (valOld minVal maxVal yOld step)
(
!shift ? (
mstep = (this.maxval - this.minval)/100;
val = valOld + (yOld - mouse_y) * mstep;
val = limitgui(val, minVal, maxVal);
this.potVal(val);
):(
val = valOld + (yOld - mouse_y) * step;
val = limitgui(val, minVal, maxVal);
this.potVal(val);
);
);
function potToggle()
local (val)
instance (valOld minVal maxVal yOld step)
(
valold == 0 ? (val = 1):(val=0);
val = limitgui(val, minVal, maxVal);
this.potVal(val);
valOld=val;
);
function potWheel()
local (val)
instance (valOld minVal maxVal step)
(
mstep = (this.maxval - this.minval)/100;
val = valOld + (mouse_wheel/36)*mstep;
val = limitgui(val, minVal, maxVal);
this.potVal(val);
valOld=val;
mouse_wheel=0;
);
/*
slider37:-60<-90,-20,1>scale bottom
slider38:0<-40,0,1>calibration
slider39:0<0,1,1>Stereo
slider40:0.87<0.5,1,0.01>Meter decay
*/
gscale.potcfg (-60,-90,-20,.1); //default. von, bis, step
gcalib.potcfg (0,-40,0,.04);
//gstereo.potcfg (20,0,150,1);
gdecay.potcfg (0.5,0.01,1,.01);
gtarget.potcfg (0,-30,0,.03);
/*
goutgain.potcfg (0,-24,24,.048);
gfeedback.potcfg (0,0,1,1);
Trick.potcfg (0,0,1,1);
SC.potcfg (0,0,1,1);
screw.potcfg (3,0,5,.01);
gknee.potcfg (0,0,100,.1);
gdry.potcfg (0,0,1,.001);
*/
knobsx = 60;
knobsy = 170;
gscale.rectIn(knobsx,knobsy,60,60);//xpos,ypos,weite,höhe des img
gscale.rectOut(knobsx,knobsy, 60, 60, 61, 3); //Xpos,ypos,weite,höhe,Frames,bitmap
gcalib.rectIn(knobsx+120,knobsy, 60, 60);
gcalib.rectOut(knobsx+120,knobsy, 60, 60, 61, 3);
gdecay.rectIn(knobsx,knobsy+90, 60, 60);
gdecay.rectOut(knobsx,knobsy+90, 60, 60, 61, 3);
gtarget.rectIn(knobsx+120,knobsy+90, 60, 60);
gtarget.rectOut(knobsx+120,knobsy+90, 60, 60, 61, 3);
function stattslider() (
calib = slider38;
scalebottom = abs(slider37);
slider41 > 8 ? scalebottom = 20;
Stereo = slider39;
Meter_decay = slider40;
peak_meter_decay = meter_decay;
// VU
mom = 0.00010 + 0.00032 * (100*slider40)^3 / 125000;
);
//_________________________________________________________________________________-
errcnt = 0;
tot_nbr_spl = 0;
scnt = 0;
offset = 0.0074;//0.0074;
nd_posL = nd_posR = 0;
nd_speedL = nd_speedR = 0;
dt = 10 / srate;
mom = 0.00042;
dbL = dbR = 0;
overL = overR = 0;
fact_up = 10 ^ (( 0 - 10)/20) * 0.3785 ;
wl = 0;
damp = 0.995;//935; //1 - slider5 * (48000 / srate);
mnmode = 0; // (0 ST, 1 SumMono, 2 MaxMono)
meterInL = spl0;
meterInR = spl1;
function mnMetersample(meterInL, meterInR, mnmode, mnmom) //Mom = speed
(
tot_nbr_spl += 1;
smpL = meterInL;
smpR = meterInR;
mnmode == 1 ? (
smpL = (meterInL + meterInR) * 0.5;
smpR = smpL;
);
mnmode >= 2 ? (
smpL = max(meterInL, meterInR);
smpR = smpL;
);
smpL = abs(smpL);
smpR = abs(smpR);
scnt += 1;
scnt === 10 ? (
// move left needle
force = smpL * fact_up - (nd_posL * .1 + offset);
nd_speedL += force * dt / mnmom;
nd_speedL = nd_speedL * damp;
nd_posL += nd_speedL * dt;
nd_posL < 0 || nd_posL > 1 ? nd_speedL = 0;
nd_posL = min(max(nd_posL,0),1);
// move right needle
force = smpR * fact_up - (nd_posR * .1 + offset);
nd_speedR += force * dt /mnmom;
nd_speedR = nd_speedR * damp;
nd_posR += nd_speedR * dt;
nd_posR < 0 || nd_posR > 1 ? nd_speedR = 0;
nd_posR = min(max(nd_posR,0),1);
overL -= 10;
overR -= 10;
scnt = 0;
);
);
function mnmetergfx(mnmeterscale, mnmeterx, mnmetery, twometer, mnch) //(0=flexible, x,y,redneedle, channel 1or2)
(
tot_nbr_spl_g = tot_nbr_spl;
overL_g = overL;
overR_g = overR;
nd_posL_g = nd_posL;
nd_posR_g = nd_posR;
tot_nbr_spl_g === tot_nbr_spl ? (
dbL = (nd_posL_g * 23) - 20;
dbR = (nd_posR_g * 23) - 20;
) : (
errcnt += 1; // thread collision
);
gfx_a = 1; gfx_x = mnmeterx; gfx_y=mnmetery
;
mnmeterscale == 0 ? (mnblitscale = gfx_w/190):(mnblitscale = mnmeterscale);
//gfx_blit(0,mnblitscale,0);
//gfx_rect(35,30,250,115);
w1 = $pi * 16.5 / 180;
w2 = $pi * 45 / 180;
xw = 250*mnblitscale; //max(1,floor((gfx_w-30) / 2));
yw = 115*mnblitscale;//floor(xw / 1.5);
r1 = 130*mnblitscale;//floor(yw * 0.85);
xd = 10 + chan*(xw+10);
mode === 1 ? xd += floor(xw/2);
yd = 10;
xa = mnblitscale*250/2;//gfx_w/2;//floor(xd + xw / 2);
ya = floor(yd + yw * 1.1);
twometer ? (
chan = 1;
chan == 0 ? (ph = dbL; gfx_r=gfx_b=gfx_g=0) : (ph = dbR; gfx_r=1;gfx_b=gfx_g=0);
ph = 51 + (ph+20)/23*83;//45 + (ph+20)/23*90;
aay = abs((90 - abs(ph)));
r1 = mnblitscale*(80+aay/5);
ph = ph * ($pi / 180);
cosp = cos(ph);
sinp = sin(ph);
ya = mnmetery+115*mnblitscale;
xa= mnmeterx+2+(250*mnblitscale/2);//-(gfx_w/50);
x1 = xa - cosp * r1 * 0.25;
y1 = ya - sinp * r1 * 0.25;
x2 = xa - cosp * r1 * 1.1;
y2 = ya - sinp * r1 * 1.1;
gfx_x = x1;
gfx_y = y1;
gfx_lineto(x2, y2);
);
chan = 0;
chan == 0 ? (ph = dbL; gfx_r=gfx_b=gfx_g=0) : (ph = dbR; gfx_r=1;gfx_b=gfx_g=0);
mnch == 2 ? (ph= dbR);
ph = 51 + (ph+20)/23*83;//45 + (ph+20)/23*90;
aay = abs((90 - abs(ph)));
r1 = mnblitscale*(80+aay/5);
ph = ph * ($pi / 180);
cosp = cos(ph);
sinp = sin(ph);
ya = mnmetery+115*mnblitscale;
xa= mnmeterx+2+(250*mnblitscale/2);//-(gfx_w/50);
x1 = xa - cosp * r1 * 0.25;
y1 = ya - sinp * r1 * 0.25;
x2 = xa - cosp * r1 * 1.1;
y2 = ya - sinp * r1 * 1.1;
gfx_x = x1;
gfx_y = y1;
gfx_lineto(x2, y2);
);
//________________________ END VU KRAM _______________________
// rms-i, lufs-i, lra calculated 0=during playback only, 1=always
WANT_INTEGRATED_ALWAYS=0;
FONT_SZ_MIN=12;
FONT_SZ_MAX=16;
// $xRRGGBB
BG_COLOR=$x000000;
GRID_COLOR=$x7f7f7f;
TEXT_COLOR=$xffffff;
PEAK_COLOR=$x3fff3f;
PEAK_CLIP_COLOR=$xff0000;
RMS_COLOR=$x7f7f7f;
LUFS_COLOR=$x00bfff;
LUFS_HIST_COLOR=$x005f7f;
RED_COLOR=$xff0000;
YELLOW_COLOR=$xffff00;
MONO_COLOR=$xffa500;
PEAK_METER_DECAY=0.001;//0.150;
LOUD_METER_UPDATE=0.100; // default 100ms, must be divisible into both 0.4 and 3.0
LOUD_METER_SPEED=0.075;
UI_SLIDER_MASK=(1<<15)-1;
ext_noinit=1;
ext_nodenorm=1;
//gfx_ext_retina=max(gfx_ext_retina,1);
sliders_showing=0;
NUM_BINS=1024;
BINS_PER_DB=10;
DB_PER_BIN=1/BINS_PER_DB;
REAPER_MAX_CHANNELS=64;
// sinc filter for true peak
function sinc_gen_val() global(srate) local(sincpos windowpos) instance(slice_pos) (
windowpos = (2.0 * $pi / 16/*SINC_FILTER_SIZE*/) * slice_pos;
sincpos = $pi * (slice_pos - 16/*SINC_FILTER_SIZE*/ * .5);
slice_pos += 1;
(0.53836 - cos(windowpos)*0.46164) * sin(sincpos) / sincpos;
);
function sinc_gen_slice(cs, o*) instance(sinc_gen_val slice_pos) global() (
slice_pos = cs;
o.v00 = sinc_gen_val(); o.v01 = sinc_gen_val(); o.v02 = sinc_gen_val(); o.v03 = sinc_gen_val();
o.v04 = sinc_gen_val(); o.v05 = sinc_gen_val(); o.v06 = sinc_gen_val(); o.v07 = sinc_gen_val();
o.v08 = sinc_gen_val(); o.v09 = sinc_gen_val(); o.v10 = sinc_gen_val(); o.v11 = sinc_gen_val();
o.v12 = sinc_gen_val(); o.v13 = sinc_gen_val(); o.v14 = sinc_gen_val(); o.v15 = sinc_gen_val();
);
function sinc_init() global(srate) instance(sinc_gen_slice) (
sinc_gen_slice(srate < 96000 ? .25 : .5,this.s1);
srate < 96000 ? (
sinc_gen_slice(.5, this.s2);
sinc_gen_slice(.75, this.s3);
);
);
function sinc_slice_abs(hist*) global() (
abs(
hist.h00 * this.v00 + hist.h01 * this.v01 + hist.h02 * this.v02 + hist.h03 * this.v03 +
hist.h04 * this.v04 + hist.h05 * this.v05 + hist.h06 * this.v06 + hist.h07 * this.v07 +
hist.h08 * this.v08 + hist.h09 * this.v09 + hist.h10 * this.v10 + hist.h11 * this.v11 +
hist.h12 * this.v12 + hist.h13 * this.v13 + hist.h14 * this.v14 + hist.h15 * this.v15
);
);
function alloc(sz) global()
(
memset((this.top+=sz)-sz,0,sz);
);
function init(chidx)
(
this.chan=chidx;
this.wt = chidx < 3 || num_ch < 6 ? 1 : chidx == 3 ? 0 : sqrt(2);
this.f1p1=this.f1p2=this.f2p1=this.f2p2=0;
this.pkval=-140;this.hipkval=-140;this.clips=0;
this.ch_lufs_sum=this.ch_rms_sum=0;
this.h00 = this.h01 = this.h02 = this.h03 = this.h04 = this.h05 = this.h06 = this.h07 =
this.h08 = this.h09 = this.h10 = this.h11 = this.h12 = this.h13 = this.h14 = this.h15 = 0;//-140; // was ist das? War 0 ;)
);
function decay()
(
this.pkval *= pk_decay;
);
function copypks() global(pk hipk clip_cnt) (
pk[this.chan] = this.pkval;
hipk[this.chan] = this.hipkval;
clip_cnt[this.chan] = this.clips;
);
function proc(lspl)
local(pspl f1p0 f2p0)
instance(wt ch_rms_sum ch_lufs_sum pkval hipkval clips
f1p1 f1p2 f2p1 f2p2)
global(f1a1 f1a2 f1b0 f1b1 f1b2
f2a1 f2a2 f2b0 f2b1 f2b2
srate cfg_peak
sinc.s1.sinc_slice_abs
sinc.s2.sinc_slice_abs
sinc.s3.sinc_slice_abs
lval rval win_pos global_peak)
(
cfg_peak == 1 || cfg_peak == 2 ? (
this.h15 = this.h14; this.h14 = this.h13; this.h13 = this.h12; this.h12 = this.h11;
this.h11 = this.h10; this.h10 = this.h09; this.h09 = this.h08; this.h08 = this.h07;
this.h07 = this.h06; this.h06 = this.h05; this.h05 = this.h04; this.h04 = this.h03;
this.h03 = this.h02; this.h02 = this.h01; this.h01 = this.h00; this.h00 = lspl;
pspl = max(abs(this.h08), sinc.s1.sinc_slice_abs(this));
srate < 96000 ? pspl = max(pspl,max(sinc.s2.sinc_slice_abs(this), sinc.s3.sinc_slice_abs(this)));
) :
cfg_peak == 3 || cfg_peak == 4 ? (
pspl=abs(lspl);
);
cfg_peak ? (
pspl > pkval ? (
pkval=pspl;
pspl > hipkval ? (
hipkval=pspl;
global_peak = max(global_peak,pspl);
);
);
pspl > 1.0 ? clips += 1;
);
win_pos == 0 ? ch_rms_sum=ch_lufs_sum=0;
rval += (ch_rms_sum += lspl*lspl);
lspl *= wt;
f1p0=lspl-f1a1*f1p1-f1a2*f1p2;
lspl=f1b0*f1p0+f1b1*f1p1+f1b2*f1p2;
f1p2=f1p1;
f1p1=f1p0;
f2p0=lspl-f2a1*f2p1-f2a2*f2p2;
lspl=f2b0*f2p0+f2b1*f2p1+f2b2*f2p2;
f2p2=f2p1;
f2p1=f2p0;
lval += (ch_lufs_sum += lspl*lspl);
);
function init_lufs_filters()
local(Vh Vb db f0 Q K a0)
global(f1a1 f1a2 f1b0 f1b1 f1b2
f2a1 f2a2 f2b0 f2b1 f2b2 srate)
(
// f1,f2 could be combined into a 5th order filter
db=3.999843853973347;
f0=1681.974450955533;
Q=0.7071752369554196;
K=tan($pi*f0/srate);
Vh=pow(10, db/20);
Vb=pow(Vh, 0.4996667741545416);
a0=1+K/Q+K*K;
f1a1=2*(K*K-1)/a0;
f1a2=(1-K/Q+K*K)/a0;
f1b0=(Vh+Vb*K/Q+K*K)/a0;
f1b1=2*(K*K-Vh)/a0;
f1b2=(Vh-Vb*K/Q+K*K)/a0;
f0=38.13547087602444;
Q=0.5003270373238773;
K=tan($pi*f0/srate);
f2a1=2*(K*K-1)/(1+K/Q+K*K);
f2a2=(1-K/Q+K*K)/(1+K/Q+K*K);
f2b0=1;
f2b1=-2;
f2b2=1;
);
function Reset()
(
sinc.sinc_init();
init_lufs_filters();
alloc.top=0;
pk=alloc(REAPER_MAX_CHANNELS);
hipk=alloc(REAPER_MAX_CHANNELS);
clip_cnt=alloc(REAPER_MAX_CHANNELS);
m_win_cnt=0.4/LOUD_METER_UPDATE;
s_win_cnt=3/LOUD_METER_UPDATE;
win_pos=0;
win_cnt=0;
win_len=(LOUD_METER_UPDATE*srate)|0;
i_win_len=1/(m_win_cnt*win_len);
i_win_len2=1/(s_win_cnt*win_len);
rms_m_sum=0;
rms_m_db=-100;
rms_m_db_max=-100;
rms_i_sum=0;
rms_i_sum_cnt=0;
rms_i_db=-100;
lufs_m_sum=0;
lufs_m_sum_max=0;
lufs_m_db=-100;
lufs_s_sum=0;
lufs_s_sum_max=0;
lufs_s_db=-100;
lufs_a_sum=0;
lufs_a_sum_cnt=0;
lufs_b_sum=0;
lufs_b_sum_cnt=0;
lra_db_diff = 0;
lra_db_hi = lra_db_lo = lufs_i_db = lufs_m_db = lufs_s_db = -100;
last_t=0;
th_lufs_i=th_lufs_s=th_lufs_m=th_rms_i=th_rms_m=0;
cur_buf=0;
cur_buf2=0;
rms_buf=alloc(m_win_cnt);
lufs_buf=alloc(m_win_cnt);
lufs_buf2=alloc(s_win_cnt);
lufs_a_hist=alloc(2*NUM_BINS);
lufs_b_hist=alloc(NUM_BINS);
db_hist=alloc(75);
db_hist_max=0;
global_peak = -140;
ch0.init(0); ch1.init(1);
num_ch > 2 ? ( ch2.init(2); ch3.init(3);
num_ch > 4 ? ( ch4.init(4); ch5.init(5);
num_ch > 6 ? ( ch6.init(6); ch7.init(7);
num_ch > 8 ? ( ch8.init(8); ch9.init(9); ch10.init(10); ch11.init(11);
num_ch > 12 ? ( ch12.init(12); ch13.init(13); ch14.init(14); ch15.init(15);
num_ch > 16 ? ( ch16.init(16); ch17.init(17); ch18.init(18); ch19.init(19);
num_ch > 20 ? ( ch20.init(20); ch21.init(21); ch22.init(22); ch23.init(23);
num_ch > 24 ? ( ch24.init(24); ch25.init(25); ch26.init(26); ch27.init(27); ch28.init(28); ch29.init(29); ch30.init(30); ch31.init(31);
num_ch > 32 ? ( ch32.init(32); ch33.init(33); ch34.init(34); ch35.init(35); ch36.init(36); ch37.init(37); ch38.init(38); ch39.init(39);
num_ch > 40 ? ( ch40.init(40); ch41.init(41); ch42.init(42); ch43.init(43); ch44.init(44); ch45.init(45); ch46.init(46); ch47.init(47);
num_ch > 48 ? ( ch48.init(48); ch49.init(49); ch50.init(50); ch51.init(51); ch52.init(52); ch53.init(53); ch54.init(54); ch55.init(55);
num_ch > 56 ? ( ch56.init(56); ch57.init(57); ch58.init(58); ch59.init(59); ch60.init(60); ch61.init(61); ch62.init(62); ch63.init(63);
))))))))))));
ch0.pkval = -150;
ch1.pkval = -150;
ch0.hipkval = -150;
ch1.hipkval = -150;
needle_is = -140;
needle2_is = -140;
needle_is_max = -140;
needle2_is_max = -140;
);
Reset();
@slider
stattslider();
@block
want_reset =
(num_ch > 0 && num_ch != last_nch) ||
srate != last_sr;
last_nch=num_ch;
last_sr=srate;
cfg_reinit && (play_state&1) ? (
abs(play_position-last_play_pos) > 0.1 ? want_reset=1;
last_play_pos=play_position+samplesblock/srate;
);
want_reset ? Reset();
pk_decay=pow(0.5, samplesblock/srate/PEAK_METER_DECAY);
ch0.decay(); ch1.decay();
num_ch > 2 ? ( ch2.decay(); ch3.decay();
num_ch > 4 ? ( ch4.decay(); ch5.decay();
num_ch > 6 ? ( ch6.decay(); ch7.decay();
num_ch > 8 ? ( ch8.decay(); ch9.decay(); ch10.decay(); ch11.decay();
num_ch > 12 ? ( ch12.decay(); ch13.decay(); ch14.decay(); ch15.decay();
num_ch > 16 ? ( ch16.decay(); ch17.decay(); ch18.decay(); ch19.decay();
num_ch > 20 ? ( ch20.decay(); ch21.decay(); ch22.decay(); ch23.decay();
num_ch > 24 ? ( ch24.decay(); ch25.decay(); ch26.decay(); ch27.decay(); ch28.decay(); ch29.decay(); ch30.decay(); ch31.decay();
num_ch > 32 ? ( ch32.decay(); ch33.decay(); ch34.decay(); ch35.decay(); ch36.decay(); ch37.decay(); ch38.decay(); ch39.decay();
num_ch > 40 ? ( ch40.decay(); ch41.decay(); ch42.decay(); ch43.decay(); ch44.decay(); ch45.decay(); ch46.decay(); ch47.decay();
num_ch > 48 ? ( ch48.decay(); ch49.decay(); ch50.decay(); ch51.decay(); ch52.decay(); ch53.decay(); ch54.decay(); ch55.decay();
num_ch > 56 ? ( ch56.decay(); ch57.decay(); ch58.decay(); ch59.decay(); ch60.decay(); ch61.decay(); ch62.decay(); ch63.decay();
))))))))))));
function make_output_slider(b, base) ( cfg_out_auto>=2 && !(cfg_out_auto&1) ? base - b : b );
outparm_lufs_m = make_output_slider(lufs_m_db + (cfg_mono ? -3 : 0),-100);
outparm_lufs_s = make_output_slider(lufs_s_db + (cfg_mono ? -3 : 0),-100);
outparm_lufs_i = make_output_slider(lufs_i_db + (cfg_mono ? -3 : 0),-100);
outparm_lufs_lra = make_output_slider(lra_db_diff,100);
outparm_peak = make_output_slider(global_peak > 0 ? log(global_peak)*20/log(10) : -150,-150);
outparm_rms_m = make_output_slider(rms_m_db + (cfg_mono ? -3 : 0),-100);
outparm_rms_i = make_output_slider(rms_i_db + (cfg_mono ? -3 : 0),-100);
cfg_out_auto ? slider_automate(
cfg_out_auto > 2 ? (2^(29 + floor((cfg_out_auto-3)/2))) : (
2^29 | // (true) peak
2^30 | // rms-m
2^31 | // rms-i
2^32 | // lufs-m
2^33 | // lufs-s
2^34 | // lufs-i
2^35 | // lra
0
)
);
@sample
cleanL = spl0;
cleanR = spl1;
slider41 < 4 ? (
spl0 == 0 ? spl0 = 0.0000001;// max(abs(spl0), 0.0000001);
spl1 == 0 ? spl1 = 0.0000001;// max(abs(spl1), 0.0000001);
);
rval=lval=0;
ch0.proc(spl0); ch1.proc(spl1);
/*
num_ch > 2 ? ( ch2.proc(spl2); ch3.proc(spl3);
num_ch > 4 ? ( ch4.proc(spl4); ch5.proc(spl5);
num_ch > 6 ? ( ch6.proc(spl6); ch7.proc(spl7);
num_ch > 8 ? ( ch8.proc(spl8); ch9.proc(spl9); ch10.proc(spl10); ch11.proc(spl11);
num_ch > 12 ? ( ch12.proc(spl12); ch13.proc(spl13); ch14.proc(spl14); ch15.proc(spl15);
num_ch > 16 ? ( ch16.proc(spl16); ch17.proc(spl17); ch18.proc(spl18); ch19.proc(spl19);
num_ch > 20 ? ( ch20.proc(spl20); ch21.proc(spl21); ch22.proc(spl22); ch23.proc(spl23);
num_ch > 24 ? ( ch24.proc(spl24); ch25.proc(spl25); ch26.proc(spl26); ch27.proc(spl27); ch28.proc(spl28); ch29.proc(spl29); ch30.proc(spl30); ch31.proc(spl31);
num_ch > 32 ? ( ch32.proc(spl32); ch33.proc(spl33); ch34.proc(spl34); ch35.proc(spl35); ch36.proc(spl36); ch37.proc(spl37); ch38.proc(spl38); ch39.proc(spl39);
num_ch > 40 ? ( ch40.proc(spl40); ch41.proc(spl41); ch42.proc(spl42); ch43.proc(spl43); ch44.proc(spl44); ch45.proc(spl45); ch46.proc(spl46); ch47.proc(spl47);
num_ch > 48 ? ( ch48.proc(spl48); ch49.proc(spl49); ch50.proc(spl50); ch51.proc(spl51); ch52.proc(spl52); ch53.proc(spl53); ch54.proc(spl54); ch55.proc(spl55);
num_ch > 56 ? ( ch56.proc(spl56); ch57.proc(spl57); ch58.proc(spl58); ch59.proc(spl59); ch60.proc(spl60); ch61.proc(spl61); ch62.proc(spl62); ch63.proc(spl63);
))))))))))));
*/
(win_pos += 1) >= win_len ? (
win_pos=0;
win_cnt += 1;
prev_rval=rms_buf[cur_buf];
rms_buf[cur_buf]=rval;
prev_lval=lufs_buf[cur_buf];
lufs_buf[cur_buf]=lval;
prev_lval2=lufs_buf2[cur_buf2];
lufs_buf2[cur_buf2]=lval;
(cur_buf += 1) >= m_win_cnt ? cur_buf=0;
(cur_buf2 += 1) >= s_win_cnt ? cur_buf2=0;
rms_m_sum += (rval-prev_rval)*i_win_len;
lufs_m_sum += (lval-prev_lval)*i_win_len;
lufs_s_sum += (lval-prev_lval2)*i_win_len2;
WANT_INTEGRATED_ALWAYS || (play_state&1) ? (
rms_i_sum += rms_m_sum;
rms_i_sum_cnt += 1;
rms_i_sum > 0 && rms_i_sum_cnt >= m_win_cnt ? (
rms_i_db=log(rms_i_sum/rms_i_sum_cnt)*10/log(10);
) : (
rms_i_db=-100;
);
);
rms_m_sum > 0 && win_cnt >= m_win_cnt ? (
rms_m_db=log(rms_m_sum)*10/log(10);
rms_m_db > rms_m_db_max ? rms_m_db_max=rms_m_db;
) : (
rms_m_db=-100;
);
lufs_m_sum > 0 && win_cnt >= m_win_cnt ? (
lufs_m_sum > lufs_m_sum_max ? lufs_m_sum_max=lufs_m_sum;
lufs_m_db=-0.691+log(lufs_m_sum)*10/log(10);
a = WANT_INTEGRATED_ALWAYS || (play_state&1) ? ((lufs_m_db+70)*BINS_PER_DB)|0 : -1;
a >= 0 ? (
a >= NUM_BINS ? a=NUM_BINS-1;
lufs_a_sum += lufs_m_sum;
lufs_a_sum_cnt += 1;
lufs_a_hist[2*a] += 1;
lufs_a_hist[2*a+1] += lufs_m_sum;
db_hist_max = max(db_hist_max,db_hist[min(a*DB_PER_BIN,74)] += 1);
lufs_a_db=-0.691+log(lufs_a_sum/lufs_a_sum_cnt)*10/log(10);
lufs_a_gate=((lufs_a_db-10+70)*BINS_PER_DB)|0;
lufs_i_sum=0;
lufs_i_cnt=0;
bin=max(lufs_a_gate,0);
loop(NUM_BINS-bin,
lufs_i_cnt += lufs_a_hist[2*bin];
lufs_i_sum += lufs_a_hist[2*bin+1];
bin += 1;
);
lufs_i_db=lufs_i_sum > 0 ? -0.691+log(lufs_i_sum/lufs_i_cnt)*10/log(10) : -100;
);
) : (
lufs_m_db=-100;
);
lufs_s_sum > 0 && win_cnt >= s_win_cnt ? (
lufs_s_sum > lufs_s_sum_max ? lufs_s_sum_max=lufs_s_sum;
lufs_s_db=-0.691+log(lufs_s_sum)*10/log(10);
b = WANT_INTEGRATED_ALWAYS || (play_state&1) ? ((lufs_s_db+70)*BINS_PER_DB)|0 : -1;
b >= 0 ? (
b >= NUM_BINS ? b=NUM_BINS-1;
lufs_b_sum += lufs_s_sum;
lufs_b_sum_cnt += 1;
lufs_b_hist[b] += 1;
lufs_b_db=-0.691+log(lufs_b_sum/lufs_b_sum_cnt)*10/log(10);
lufs_b_gate=((lufs_b_db-20+70)*BINS_PER_DB)|0;
lra_cnt=0;
bin=max(lufs_b_gate,0);
loop(NUM_BINS-bin,
lra_cnt += lufs_b_hist[bin];
bin += 1;
);
lra_cnt >= 20 ? (
lra_cnt_lo=lra_cnt_hi=0;
bin=lufs_b_gate;
while(bin < NUM_BINS && lra_cnt_lo < lra_cnt*0.10)
(
lra_cnt_lo += lufs_b_hist[bin];
bin += 1;
);
bin_lo=bin-1;
bin=NUM_BINS-1;
while(bin >= lufs_b_gate && lra_cnt_hi < lra_cnt*0.05)
(
lra_cnt_hi += lufs_b_hist[bin];
bin -= 1;
);
bin_hi=bin+1;
lra_db_lo=bin_lo*DB_PER_BIN-70;
lra_db_hi=bin_hi*DB_PER_BIN-70;
lra_db_diff = lra_db_hi-lra_db_lo;
);
);
) : (
lufs_s_db=-100;
);
);
spl0 = cleanL;
spl1 = cleanR;
// VU
scaler = 10^(abs(calib)/20);
slider41 == 10 ? ( //mode = 2):(mode=0); //abs(slider1-1);
VUL = spl0*scaler; VUR = spl1*scaler
):(
VUL = max(abs(spl0*scaler), abs(spl1*scaler)); VUR = VUL; //spl1*scaler
);
mnmetersample(VUL,VUR,0,mom); // mode = (0 ST, 1 SumMono, 2 MaxMono), mnmom = speed
@gfx 720 342