Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //********************************************************************
- // Simple VU Meter - a fine freeware by chris-s
- // V1.1; 10-Jan-2017
- // Disclaimer: Use of this software is on your own risk
- //********************************************************************
- desc:Simple VU Meter
- //tags: analysis vu meter
- //author: chris-s
- // hidden sliders: remove the "-" in front of the name to activate
- slider1:-18<-20,0,0.5>Ref Level
- slider2:-1<-20,0,0.1>Warn Level
- slider3:50<0,100,1}>-Response // Hidden
- slider4:0<0,2,1{Stereo,Mono,Mid/Side}>Mode
- slider5:0.0053<0,.01,0.0001>-Damping // Hidden
- // Hide side meters
- in_pin:none
- out_pin:none
- /********************************************************************/
- @init
- // bg col
- gfx_clear = 30 + 60 * 256 + 110 * 65536;
- errcnt = 0;
- tot_nbr_spl = 0;
- scnt = 0;
- fact_up = 0;
- offset = 0.0074;
- nd_posL = nd_posR = 0;
- nd_speedL = nd_speedR = 0;
- dt = 10 / srate;
- mom = 0.00042;
- damp = 1 - 0.0053 * (48000 / srate);
- dbL = dbR = 0;
- overL = overR = 0;
- print = 10;
- print[0] = -20;
- print[1] = -10;
- print[2] = -7;
- print[3] = -5;
- print[4] = -3;
- print[5] = -2;
- print[6] = -1;
- print[7] = 0;
- print[8] = 1;
- print[9] = 2;
- print[10] = 3;
- pos = 30;
- pos[0] = 0;
- pos[1] = .1650;
- pos[2] = .2641;
- pos[3] = .3519;
- pos[4] = .4626;
- pos[5] = .5284;
- pos[6] = .6022;
- pos[7] = .6849;
- pos[8] = .7779;
- pos[9] = .8822;
- pos[10] = 1;
- /********************************************************************/
- @slider
- fact_up = 10 ^ (( -slider1 - 10)/20) * 0.3785 ;
- wl = slider2;
- mode = slider4;
- lim = 10 ^ (wl / 20);
- mom = 0.00010 + 0.00032 * slider3^3 / 125000;
- damp = 1 - slider5 * (48000 / srate);
- /********************************************************************/
- @sample
- tot_nbr_spl += 1;
- smpL = spl0;
- smpR = spl1;
- mode == 1 ? (
- smpL = (spl0 + spl1) * 0.5;
- smpR = smpL;
- );
- mode >= 2 ? (
- smpL = (spl0 + spl1) * 0.5;
- smpR = (spl0 - spl1) * 0.5;
- );
- 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 / mom;
- 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 / mom;
- 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;
- );
- smpL > lim ? overL = srate;
- smpR > lim ? overR = srate;
- /********************************************************************/
- @gfx 480 300
- 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
- );
- // paint gfx
- fontinit != 1 ? (
- gfx_setfont(1, "Arial", 14, '');
- gfx_setfont(2, "Arial", 20, 'b');
- fontinit = 1;
- );
- gfx_a = 1;
- w1 = $pi * 16.5 / 180;
- w2 = $pi * 45 / 180;
- xw = max(1,floor((gfx_w-30) / 2));
- yw = floor(xw / 1.5);
- r1 = floor(yw * 0.85);
- chan = 0;
- while (chan <= 1) (
- xd = 10 + chan*(xw+10);
- mode === 1 ? xd += floor(xw/2);
- yd = 10;
- xa = floor(xd + xw / 2);
- ya = floor(yd + yw * 1.1);
- // meter backgr
- gfx_r=1;gfx_g=1;gfx_b=.7;
- gfx_rect(xd,yd,xw,yw);
- // scale
- gfx_r=gfx_g=gfx_b = 0; // black
- gfx_arc(xa, ya, r1, -45 * ($pi / 180), w2, 1);
- gfx_r=.95; gfx_g=0; gfx_b = 0; // red
- gfx_arc(xa, ya, r1 + 1, w1, w2, 1);
- gfx_arc(xa, ya, r1 + 2, w1, w2, 1);
- gfx_arc(xa, ya, r1 + 3, w1, w2, 1);
- gfx_arc(xa, ya, r1 + 4, w1, w2, 1);
- gfx_setfont(1);
- gfx_r=gfx_g=gfx_b = 0.2; // black
- jj = 0;
- while ( jj <= 10 ) (
- ii = print[jj];
- ph = pos[jj];
- ph = (45 + ph*90) * $pi / 180;
- cosp = cos(ph) * r1;
- sinp = sin(ph) * r1;
- x1 = xa - cosp ;
- y1 = ya - sinp ;
- x2 = xa - cosp * 1.1;
- y2 = ya - sinp * 1.1;
- x3 = xa - cosp * 1.12;
- y3 = ya - sinp * 1.12;
- gfx_x = x1;
- gfx_y = y1 ;
- gfx_lineto(x2, y2);
- gfx_x = x3 - 7;
- gfx_y = y3 - gfx_texth;
- gfx_printf("%3d", ii);
- jj += 1;
- jj == 8 ? ( gfx_r = 1; gfx_g = gfx_b = 0 );
- );
- // Peak
- gfx_r=gfx_g=gfx_b = 0.0; // black
- gfx_x = xd + xw * .9 - 30;
- gfx_y = yd + yw * .9 - 10;
- gfx_drawstr("PEAK");
- // VU
- gfx_setfont(2); // large
- gfx_r=gfx_g=gfx_b = 0.0; // black
- gfx_x = xa - 10;
- gfx_y = yd + yw * .6;
- gfx_drawstr("VU");
- // draw LEDs
- gfx_r = .95; gfx_g = gfx_b = 0.1; // red
- (chan == 0 && overL_g > 0) || (chan == 1 && overR_g > 0) ? (
- gfx_circle(xd + xw*0.9 + 6, yd + yw * 0.9 - 4, 4, 1, 1);
- );
- // draw needle
- chan == 0 ? ph = dbL : ph = dbR;
- ph = 45 + (ph+20)/23*90;
- ph = ph * ($pi / 180);
- cosp = cos(ph);
- sinp = sin(ph);
- x1 = xa - cosp * r1 * 0.15;
- y1 = ya - sinp * r1 * 0.15;
- x2 = xa - cosp * r1 * 1.1;
- y2 = ya - sinp * r1 * 1.1;
- gfx_r=gfx_g=gfx_b = 0.0; // black
- gfx_x = x1;
- gfx_y = y1;
- gfx_lineto(x2, y2);
- gfx_x = x1+1;
- gfx_y = y1;
- gfx_lineto(x2+1, y2);
- gfx_r=gfx_g=gfx_b = 0.6; // gray
- gfx_x = x1+4;
- gfx_y = y1;
- gfx_lineto(x2+4, y2);
- gfx_r=.12; gfx_g=.24; gfx_b = 0.43; // blue
- gfx_circle(xa,ya,r1*0.16,1,0);
- gfx_r=gfx_g=gfx_b = 1; // white
- gfx_x = xd;
- gfx_y = yd+yw+2;
- chan == 0 ?
- gfx_drawstr("LEFT/MID") :
- gfx_drawstr("RIGHT/SIDE") ;
- chan += 1;
- mode === 1 ? chan += 1;
- );
- /****************************** EOF *******************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement