desc:Stereometer //tags: analysis goniometer vectorscope visualizer//author: PROYECTOS DRZ based on Cockos
slider1:3<0,4,1{Scaled - Unipolar (Fan),Scaled - Bipolar (Diamond),Linear - Unipolar (Fan),Linear - Bipolar (Diamond),Lissajous (Raw Phase)}>Styleslider2:2<0,2,1{Static (White),RGB (Rainbow),Multi-band (RGB Layers)}>Colorslider3:0<0,10,1>Thickness / Point Size (0=Fine Lines)slider4:1<0,1,1{Off,On}>Normalize (Auto-Gain)slider5:2<0,2,1{Off,Single Band,Multi-band}>Correlationslider6:1<0,1,1{Off,On}>Guidesslider7:15<1,100,1>Decay Speed
in_pin:left inputin_pin:right inputoptions:no_meter
@initgfx_ext_retina == 0 ? gfx_ext_retina = 1;
UI_SLIDER_MASK = (1<<15)-1; sliders_showing = 0; slider_show(UI_SLIDER_MASK, 0);
// --- FUNCIONES ---function draw_corr(val, cx, y, r, g, b, lbl) ( bar_h = 5; max_w = 90; val = max(-1, min(1, val)); len = val * max_w; val < 0 ? ( gfx_r=1; gfx_g=0.2; gfx_b=0.2; ) : ( gfx_r=r; gfx_g=g; gfx_b=b; ); gfx_a = 0.9; val >= 0 ? gfx_rect(cx, y, len, bar_h) : gfx_rect(cx+len, y, -len, bar_h); gfx_setfont(1, "Arial", 9); gfx_r=1; gfx_g=1; gfx_b=1; gfx_a=0.5; gfx_x = cx - max_w - 35; gfx_y = y - 1; gfx_drawstr(lbl););
mem_l_main = 0; mem_r_main = 4000;mem_l_low = 8000; mem_r_low = 12000;mem_l_mid = 16000; mem_r_mid = 20000;mem_l_hi = 24000; mem_r_hi = 28000;
buf_size = 2048; w_pos = 0;
lp_freq = 200; hp_freq = 2500;peak = 0.001;c_l=0; c_m=0; c_h=0; c_t=0;
@sliderstyle = slider1;col_mode = slider2;pt_size = slider3;norm_on = slider4;corr_mode = slider5;guides_on = slider6;decay = slider7 / 1000;
is_unipolar = (style == 0 || style == 2);is_scaled = (style == 0 || style == 1);is_lissajous = (style == 4);
@blockalp = exp(-2 * $pi * lp_freq / srate);ahp = exp(-2 * $pi * hp_freq / srate);
@samplelow_l = (spl0*(1-alp)) + (last_ll*alp); low_r = (spl1*(1-alp)) + (last_lr*alp);last_ll=low_l; last_lr=low_r;
hi_l = spl0-l_s0+(last_hl*ahp); hi_r = spl1-l_s1+(last_hr*ahp);last_hl=hi_l; last_hr=hi_r; l_s0=spl0; l_s1=spl1;
mid_l = spl0 - low_l - hi_l; mid_r = spl1 - low_r - hi_r;
mem_l_main[w_pos]=spl0; mem_r_main[w_pos]=spl1;mem_l_low[w_pos]=low_l; mem_r_low[w_pos]=low_r;mem_l_mid[w_pos]=mid_l; mem_r_mid[w_pos]=mid_r;mem_l_hi[w_pos]=hi_l; mem_r_hi[w_pos]=hi_r;w_pos = (w_pos+1)%buf_size;
k=0.005;c_t=(c_t*(1-k)) + (((spl0*spl1)/((spl0*spl0+spl1*spl1)*0.5+0.00001))*k);c_l=(c_l*(1-k)) + (((low_l*low_r)/((low_l*low_l+low_r*low_r)*0.5+0.00001))*k);c_m=(c_m*(1-k)) + (((mid_l*mid_r)/((mid_l*mid_l+mid_r*mid_r)*0.5+0.00001))*k);c_h=(c_h*(1-k)) + (((hi_l*hi_r)/((hi_l*hi_l+hi_r*hi_r)*0.5+0.00001))*k);
@gfx 500 500
has_click = (mouse_cap&1) && !(last_cap&1);last_cap = mouse_cap;
// Fondogfx_r=0.05; gfx_g=0.05; gfx_b=0.06; gfx_a=1;gfx_rect(0,0,gfx_w,gfx_h);
cx = gfx_w/2;off_h = corr_mode > 0 ? 50 : 0;avail_h = gfx_h - off_h;
is_unipolar ? ( cy = avail_h - 10; dim = min(gfx_w, avail_h) * 0.9;) : ( cy = avail_h / 2; dim = min(gfx_w, avail_h) * 0.45;);
norm_on ? ( max_s = 0; i=0; loop(50, idx=rand(buf_size); s=abs(mem_l_main[idx])+abs(mem_r_main[idx]); s>max_s?max_s=s; i+=1;); peak = max(peak*(1-decay), max_s); scale = dim / (peak + 0.001);) : ( scale = dim; );
guides_on ? ( gfx_r=1; gfx_g=1; gfx_b=1; gfx_a=0.15; is_unipolar ? ( gfx_line(cx, cy, cx, cy-dim); spread = dim * 0.707; gfx_line(cx, cy, cx-spread, cy-dim); gfx_line(cx, cy, cx+spread, cy-dim); gfx_circle(cx, cy, dim*0.5, 0); gfx_circle(cx, cy, dim, 0); ) : ( gfx_line(cx, cy-dim, cx, cy+dim); gfx_line(cx-dim, cy, cx+dim, cy); d_in = dim * 0.5; gfx_line(cx, cy-d_in, cx+d_in, cy); gfx_line(cx+d_in, cy, cx, cy+d_in); gfx_line(cx, cy+d_in, cx-d_in, cy); gfx_line(cx-d_in, cy, cx, cy-d_in); gfx_a = 0.3; gfx_line(cx, cy-dim, cx+dim, cy); gfx_line(cx+dim, cy, cx, cy+dim); gfx_line(cx, cy+dim, cx-dim, cy); gfx_line(cx-dim, cy, cx, cy-dim); ););
function draw_scope(buf_l, buf_r, r, g, b, alpha) ( gfx_r=r; gfx_g=g; gfx_b=b; gfx_a=alpha; ii = 0; step = 1; idx_d = w_pos; first = 1; use_lines = (pt_size == 0);
loop(buf_size/step, idx = (idx_d + ii) % buf_size; l = buf_l[idx]; r = buf_r[idx]; // --- AQUÍ ESTÁ EL ARREGLO --- // Si el "Auto-Gain" (Normalize) está apagado, // forzamos que la señal nunca pase de 1.0 (el borde de la guia) // Esto evita el desbordamiento. norm_on == 0 ? ( l = max(-1, min(1, l)); r = max(-1, min(1, r)); ); // --------------------------- side = (l - r) * 0.707; mid = (l + r) * 0.707; is_unipolar ? ( mid = abs(mid); is_scaled ? ( side = (side>=0?1:-1)*pow(abs(side), 0.6); mid = pow(mid, 0.6); ); px = cx + side * scale; py = cy - mid * scale; ) : ( is_scaled ? ( side = (side>=0?1:-1)*pow(abs(side), 0.6); mid = (mid>=0?1:-1)*pow(abs(mid), 0.6); ); px = cx + side * scale; py = cy - mid * scale; ); use_lines ? ( first ? ( gfx_x=px; gfx_y=py; first=0; ) : ( gfx_lineto(px,py,1); ); ) : ( gfx_circle(px, py, pt_size, 1); ); ii += step; ););
// Rendergfx_mode = 1;
// Capas suavescol_mode == 2 ? ( draw_scope(mem_l_hi, mem_r_hi, 0.2, 0.6, 1.0, 0.15); draw_scope(mem_l_mid, mem_r_mid, 0.2, 1.0, 0.2, 0.15); draw_scope(mem_l_low, mem_r_low, 1.0, 0.3, 0.2, 0.20); ) : col_mode == 1 ? ( draw_scope(mem_l_main, mem_r_main, 0.8, 0.8, 0.9, 0.15); ) : ( draw_scope(mem_l_main, mem_r_main, 0.9, 0.9, 0.95, 0.15););
gfx_mode = 0;corr_mode > 0 ? ( y_start = gfx_h - 45; gfx_r=0; gfx_g=0; gfx_b=0; gfx_a=0.7; corr_mode == 2 ? gfx_rect(cx-95, y_start, 190, 40) : gfx_rect(cx-95, y_start+15, 190, 20); corr_mode == 1 ? ( draw_corr(c_t, cx, y_start+22, 0.9, 0.9, 0.9, "Corr"); ) : ( draw_corr(c_h, cx, y_start+5, 0.2, 0.8, 1.0, "High"); draw_corr(c_m, cx, y_start+15, 0.2, 1.0, 0.2, "Mid"); draw_corr(c_l, cx, y_start+25, 1.0, 0.3, 0.2, "Low"); ););
gfx_mode = 0; btn_w = 60; btn_h = 20;btn_x = gfx_w - btn_w - 5; btn_y = 5;is_hover = (mouse_x >= btn_x && mouse_x <= btn_x+btn_w && mouse_y >= btn_y && mouse_y <= btn_y+btn_h);gfx_r=0.3; gfx_g=0.3; gfx_b=0.3; gfx_a=1;is_hover ? (gfx_r+=0.2; gfx_g+=0.2; gfx_b+=0.2;);gfx_rect(btn_x, btn_y, btn_w, btn_h);gfx_setfont(1, "Arial", 12, 'b');gfx_x = btn_x + 5; gfx_y = btn_y + 4;gfx_r=1; gfx_g=1; gfx_b=1;gfx_drawstr("[AJUSTES]");has_click && is_hover ? ( sliders_showing = slider_show(UI_SLIDER_MASK, -1) > 0; );