Advertisement
Win-G

VU

Oct 20th, 2024
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | Software | 0 0
  1. //********************************************************************
  2. // Simple VU Meter - a fine freeware by chris-s
  3. // V1.1; 10-Jan-2017
  4. // Disclaimer: Use of this software is on your own risk
  5. //********************************************************************
  6.  
  7. desc:Simple VU Meter
  8. //tags: analysis vu meter
  9. //author: chris-s
  10.  
  11. // hidden sliders: remove the "-" in front of the name to activate
  12.  
  13. slider1:-18<-20,0,0.5>Ref Level
  14. slider2:-1<-20,0,0.1>Warn Level
  15. slider3:50<0,100,1}>-Response // Hidden
  16. slider4:0<0,2,1{Stereo,Mono,Mid/Side}>Mode
  17. slider5:0.0053<0,.01,0.0001>-Damping // Hidden
  18.  
  19.  
  20. // Hide side meters
  21. in_pin:none
  22. out_pin:none
  23.  
  24. /********************************************************************/
  25.  
  26. @init
  27.  
  28. // bg col
  29. gfx_clear = 30 + 60 * 256 + 110 * 65536;
  30.  
  31. errcnt = 0;
  32. tot_nbr_spl = 0;
  33. scnt = 0;
  34.  
  35. fact_up = 0;
  36.  
  37. offset = 0.0074;
  38.  
  39. nd_posL = nd_posR = 0;
  40. nd_speedL = nd_speedR = 0;
  41.  
  42. dt = 10 / srate;
  43.  
  44. mom = 0.00042;
  45. damp = 1 - 0.0053 * (48000 / srate);
  46.  
  47. dbL = dbR = 0;
  48. overL = overR = 0;
  49.  
  50.  
  51. print = 10;
  52. print[0] = -20;
  53. print[1] = -10;
  54. print[2] = -7;
  55. print[3] = -5;
  56. print[4] = -3;
  57. print[5] = -2;
  58. print[6] = -1;
  59. print[7] = 0;
  60. print[8] = 1;
  61. print[9] = 2;
  62. print[10] = 3;
  63.  
  64.  
  65. pos = 30;
  66. pos[0] = 0;
  67. pos[1] = .1650;
  68. pos[2] = .2641;
  69. pos[3] = .3519;
  70. pos[4] = .4626;
  71. pos[5] = .5284;
  72. pos[6] = .6022;
  73. pos[7] = .6849;
  74. pos[8] = .7779;
  75. pos[9] = .8822;
  76. pos[10] = 1;
  77.  
  78. /********************************************************************/
  79.  
  80. @slider
  81.  
  82. fact_up = 10 ^ (( -slider1 - 10)/20) * 0.3785 ;
  83.  
  84. wl = slider2;
  85. mode = slider4;
  86. lim = 10 ^ (wl / 20);
  87.  
  88. mom = 0.00010 + 0.00032 * slider3^3 / 125000;
  89.  
  90. damp = 1 - slider5 * (48000 / srate);
  91.  
  92.  
  93. /********************************************************************/
  94.  
  95. @sample
  96.  
  97. tot_nbr_spl += 1;
  98.  
  99. smpL = spl0;
  100. smpR = spl1;
  101.  
  102. mode == 1 ? (
  103. smpL = (spl0 + spl1) * 0.5;
  104. smpR = smpL;
  105. );
  106.  
  107. mode >= 2 ? (
  108. smpL = (spl0 + spl1) * 0.5;
  109. smpR = (spl0 - spl1) * 0.5;
  110. );
  111.  
  112. smpL = abs(smpL);
  113. smpR = abs(smpR);
  114.  
  115.  
  116. scnt += 1;
  117.  
  118. scnt === 10 ? (
  119.  
  120. // move left needle
  121.  
  122. force = smpL * fact_up - (nd_posL * .1 + offset);
  123.  
  124. nd_speedL += force * dt / mom;
  125. nd_speedL = nd_speedL * damp;
  126. nd_posL += nd_speedL * dt;
  127. nd_posL < 0 || nd_posL > 1 ? nd_speedL = 0;
  128.  
  129. nd_posL = min(max(nd_posL,0),1);
  130.  
  131. // move right needle
  132.  
  133. force = smpR * fact_up - (nd_posR * .1 + offset);
  134.  
  135. nd_speedR += force * dt / mom;
  136. nd_speedR = nd_speedR * damp;
  137. nd_posR += nd_speedR * dt;
  138. nd_posR < 0 || nd_posR > 1 ? nd_speedR = 0;
  139.  
  140. nd_posR = min(max(nd_posR,0),1);
  141.  
  142. overL -= 10;
  143. overR -= 10;
  144.  
  145. scnt = 0;
  146.  
  147. );
  148.  
  149. smpL > lim ? overL = srate;
  150. smpR > lim ? overR = srate;
  151.  
  152.  
  153. /********************************************************************/
  154.  
  155. @gfx 480 300
  156.  
  157.  
  158. tot_nbr_spl_g = tot_nbr_spl;
  159.  
  160. overL_g = overL;
  161. overR_g = overR;
  162. nd_posL_g = nd_posL;
  163. nd_posR_g = nd_posR;
  164.  
  165. tot_nbr_spl_g === tot_nbr_spl ? (
  166.  
  167. dbL = (nd_posL_g * 23) - 20;
  168. dbR = (nd_posR_g * 23) - 20;
  169.  
  170. ) : (
  171. errcnt += 1; // thread collision
  172. );
  173.  
  174.  
  175.  
  176. // paint gfx
  177.  
  178. fontinit != 1 ? (
  179. gfx_setfont(1, "Arial", 14, '');
  180. gfx_setfont(2, "Arial", 20, 'b');
  181.  
  182. fontinit = 1;
  183. );
  184.  
  185. gfx_a = 1;
  186.  
  187. w1 = $pi * 16.5 / 180;
  188. w2 = $pi * 45 / 180;
  189.  
  190. xw = max(1,floor((gfx_w-30) / 2));
  191. yw = floor(xw / 1.5);
  192.  
  193. r1 = floor(yw * 0.85);
  194.  
  195.  
  196. chan = 0;
  197.  
  198. while (chan <= 1) (
  199.  
  200. xd = 10 + chan*(xw+10);
  201. mode === 1 ? xd += floor(xw/2);
  202.  
  203. yd = 10;
  204.  
  205. xa = floor(xd + xw / 2);
  206. ya = floor(yd + yw * 1.1);
  207.  
  208. // meter backgr
  209.  
  210. gfx_r=1;gfx_g=1;gfx_b=.7;
  211. gfx_rect(xd,yd,xw,yw);
  212.  
  213. // scale
  214.  
  215. gfx_r=gfx_g=gfx_b = 0; // black
  216. gfx_arc(xa, ya, r1, -45 * ($pi / 180), w2, 1);
  217.  
  218. gfx_r=.95; gfx_g=0; gfx_b = 0; // red
  219. gfx_arc(xa, ya, r1 + 1, w1, w2, 1);
  220. gfx_arc(xa, ya, r1 + 2, w1, w2, 1);
  221. gfx_arc(xa, ya, r1 + 3, w1, w2, 1);
  222. gfx_arc(xa, ya, r1 + 4, w1, w2, 1);
  223.  
  224.  
  225. gfx_setfont(1);
  226.  
  227. gfx_r=gfx_g=gfx_b = 0.2; // black
  228.  
  229. jj = 0;
  230. while ( jj <= 10 ) (
  231.  
  232. ii = print[jj];
  233.  
  234. ph = pos[jj];
  235. ph = (45 + ph*90) * $pi / 180;
  236.  
  237. cosp = cos(ph) * r1;
  238. sinp = sin(ph) * r1;
  239.  
  240. x1 = xa - cosp ;
  241. y1 = ya - sinp ;
  242.  
  243. x2 = xa - cosp * 1.1;
  244. y2 = ya - sinp * 1.1;
  245.  
  246. x3 = xa - cosp * 1.12;
  247. y3 = ya - sinp * 1.12;
  248.  
  249. gfx_x = x1;
  250. gfx_y = y1 ;
  251. gfx_lineto(x2, y2);
  252.  
  253. gfx_x = x3 - 7;
  254. gfx_y = y3 - gfx_texth;
  255.  
  256. gfx_printf("%3d", ii);
  257.  
  258. jj += 1;
  259.  
  260. jj == 8 ? ( gfx_r = 1; gfx_g = gfx_b = 0 );
  261. );
  262.  
  263.  
  264. // Peak
  265.  
  266. gfx_r=gfx_g=gfx_b = 0.0; // black
  267.  
  268. gfx_x = xd + xw * .9 - 30;
  269. gfx_y = yd + yw * .9 - 10;
  270. gfx_drawstr("PEAK");
  271.  
  272. // VU
  273.  
  274. gfx_setfont(2); // large
  275. gfx_r=gfx_g=gfx_b = 0.0; // black
  276.  
  277. gfx_x = xa - 10;
  278. gfx_y = yd + yw * .6;
  279. gfx_drawstr("VU");
  280.  
  281.  
  282. // draw LEDs
  283.  
  284. gfx_r = .95; gfx_g = gfx_b = 0.1; // red
  285.  
  286. (chan == 0 && overL_g > 0) || (chan == 1 && overR_g > 0) ? (
  287. gfx_circle(xd + xw*0.9 + 6, yd + yw * 0.9 - 4, 4, 1, 1);
  288. );
  289.  
  290.  
  291. // draw needle
  292.  
  293. chan == 0 ? ph = dbL : ph = dbR;
  294.  
  295. ph = 45 + (ph+20)/23*90;
  296. ph = ph * ($pi / 180);
  297.  
  298. cosp = cos(ph);
  299. sinp = sin(ph);
  300.  
  301. x1 = xa - cosp * r1 * 0.15;
  302. y1 = ya - sinp * r1 * 0.15;
  303.  
  304. x2 = xa - cosp * r1 * 1.1;
  305. y2 = ya - sinp * r1 * 1.1;
  306.  
  307. gfx_r=gfx_g=gfx_b = 0.0; // black
  308.  
  309. gfx_x = x1;
  310. gfx_y = y1;
  311. gfx_lineto(x2, y2);
  312.  
  313. gfx_x = x1+1;
  314. gfx_y = y1;
  315. gfx_lineto(x2+1, y2);
  316.  
  317.  
  318. gfx_r=gfx_g=gfx_b = 0.6; // gray
  319.  
  320. gfx_x = x1+4;
  321. gfx_y = y1;
  322. gfx_lineto(x2+4, y2);
  323.  
  324.  
  325. gfx_r=.12; gfx_g=.24; gfx_b = 0.43; // blue
  326. gfx_circle(xa,ya,r1*0.16,1,0);
  327.  
  328.  
  329. gfx_r=gfx_g=gfx_b = 1; // white
  330.  
  331. gfx_x = xd;
  332. gfx_y = yd+yw+2;
  333.  
  334. chan == 0 ?
  335. gfx_drawstr("LEFT/MID") :
  336. gfx_drawstr("RIGHT/SIDE") ;
  337.  
  338. chan += 1;
  339.  
  340. mode === 1 ? chan += 1;
  341. );
  342.  
  343.  
  344.  
  345. /****************************** EOF *******************************/
  346.  
  347.  
  348.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement