Old 08-08-2017, 09:30 AM   #1
Lex248
Human being with feelings
 
Join Date: Apr 2017
Location: Russia
Posts: 18
Default gfxanalyzer modding

Hi!
I added cursors of frequency and level to the gfxanalyzer. Left mouse button is on, right mouse button is off.

Code:
desc:Frequency Spectrum Analyzer Meter
//tags: analysis FFT meter spectrum
//author: Cockos
/*
Copyright (C) 2007 Cockos Incorporated
License: GPL - http://www.gnu.org/licenses/gpl.html
*/
// Cursors by Lex248, 2017

slider1:6<0,9,1{16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}>FFT size
slider2:-120<-228,-12,6>floor
slider3:0<0,1,1{disabled,enabled}>show phase
slider4:4<0,4,1{rectangular,hamming,blackman-harris,blackman,hanning}>window

in_pin:left input
in_pin:right input

@init
recpos=0;
fftsize=32768;
gfx_clear=-1;
windowtype=-1;

histsize=128*1024;
window=histsize;
fftworkspace=window+65536;
lrecpos=0;


@slider
lfft=fftsize;
a=(slider1|0);
a<0?a=0:a>11?a=11;
fftsize=2^(a+4);
lfft!=fftsize?(
recbuf=recpos=0;
);

@block

ifftsize=1/fftsize;

@sample
recpos[]=spl(0)+spl(1);
recpos+=1;
recpos >= histsize ? recpos=0;

@gfx 640 400

// only update if new fft data is there or if the size changed
recpos != lrecpos || old_w != gfx_w || old_h!=gfx_h? (


old_w=gfx_w; old_h=gfx_h;

gfx_r=gfx_g=gfx_b=0; gfx_a=1;
gfx_x=gfx_y=0;
gfx_rectto(gfx_w,gfx_h);

sc=(gfx_h-20)*20/(-slider2 * log(10));

// draw horz grid
gfx_r=gfx_g=gfx_b=0.6;
gfx_a=0.5;
gv=1;
cnt=100;
gfx_y=-100;
while(
  gfx_x=0; y=20-log(gv)*sc;
  y> gfx_y ? (
    gfx_y=y;
    gfx_lineto(gfx_w,gfx_y,0);
    gfx_x=0; 
    gfx_y+=2;
    gfx_drawnumber(log10(gv)*20,0);
    gfx_drawchar($'d');
    gfx_drawchar($'B');
    gfx_y+=gfx_texth;
  );
  gv*=0.5;

  gfx_y<gfx_h && cnt-=1 > 0;
);


wsc=gfx_w/log(1+400);

// draw vert grid
f=50;
while(

  tx = log(1.0+(f/srate*2.0)*400)*wsc;
  tx > gfx_x+2 ? (
    gfx_x=tx;
    gfx_y=0;
    gfx_lineto(gfx_x,gfx_h,0);
    gfx_y -= gfx_texth;
    gfx_x+=3;
    gfx_drawnumber(f,0);
    gfx_drawchar($'H');
    gfx_drawchar($'z');
  );
  f+=f;
  f < srate*0.5;
);

// draw cursors and labels
mouse_cap == 1 ? curson=1; // left - on
mouse_cap == 2 ? curson=0; // right - off
curson == 1 ? (
  // cursors
  gfx_r=0; gfx_g=0.75; gfx_b=0;
  gfx_a=0.75;
  gfx_y=0;
  gfx_x=mouse_x;
  gfx_lineto(gfx_x,gfx_h,0);
  gfx_y=mouse_y;
  gfx_x=0;
  gfx_lineto(gfx_w,gfx_y,0);
  // Labels
  gfx_r=0.75; gfx_g=0.75; gfx_b=0;
  gfx_y=gfx_h*0.02;
  gfx_x = mouse_x < (gfx_w*0.5) ? mouse_x+15 : mouse_x-70;
  dBlev_x=gfx_x;
  /// Freq, Hz
  freq= ((exp((log(401)*mouse_x)/gfx_w)-1)*srate)/800;
  gfx_drawnumber(freq,0);
  gfx_drawchar($' ');
  gfx_drawchar($'H');
  gfx_drawchar($'z');
  /// Level, dB
  gfx_y=gfx_y+15;
  gfx_x=dBlev_x;
  dBlev = ((mouse_y-20)/(gfx_h-20)) * slider2;
  gfx_drawnumber(dBlev,0);
  gfx_drawchar($' ');
  gfx_drawchar($'d');
  gfx_drawchar($'B');
);

lrecpos=recpos;

(
  windowsize != fftsize || windowtype != slider4 ? (
    windowtype=slider4; 
    windowsize=fftsize;
    i=0;
    dwindowpos = $pi*2/fftsize;
    windowpos=0;

    pwr=0;
    loop(fftsize,
       pwr += (window[i] = (
         windowtype==1 ? 0.53836 - cos(windowpos)*0.46164 :
         windowtype==2 ? 0.35875 - 0.48829 * cos(windowpos) + 0.14128 * cos(2*windowpos) - 0.01168 * cos(3*windowpos) :
         windowtype==3 ? 0.42 - 0.50 * cos(windowpos) + 0.08 * cos(2.0*windowpos) :
         windowtype==4 ? 0.50 - cos(windowpos)*0.50 :
          1.0));
       windowpos+=dwindowpos;
       i+=1;
    );
    pwr=1.0/pwr;
    i=0;
    loop(fftsize,window[i]*=pwr; i+=1);
  );


  buf1=lrecpos-fftsize;
  buf1<0 ? buf1+=histsize;
  buf2=window;
  buf3=fftworkspace;
  loop(fftsize,
    buf3[] = buf1[]*buf2[];
    buf3[1]=0;
    buf3+=2;

    buf2+=1;
    (buf1+=1) >= histsize ? buf1 -= histsize;
  );
  fft(fftworkspace,fftsize);
  fft_permute(fftworkspace,fftsize);

  i=0;
  ascale=gfx_h/$pi*0.25;
  xscale=800/(fftsize-4);
  loop(fftsize*0.5,
    i ? (aa=fftworkspace[i*2]; bb=fftworkspace[i*2+1] ) : aa=bb=0;
    dv=max(aa*aa+bb*bb,0.00000000000000000000000001);
    ty= (-log(dv)*0.5)*sc+20;

    ang=-atan2(bb,aa);

    ty2=ang*ascale + gfx_h*0.5;

    tx = log(1.0+i*xscale)*wsc;



    i ? 
    ( 
      slider3?(
      gfX_r=0.6; gfx_g=0; gfx_b=0.8; gfx_a=1;
      gfx_x=lx; gfx_y=ly2; gfx_lineto(tx,ty2,1) ;
      );

      gfX_r=gfx_g=1; gfx_b=0;gfx_a=1.0;
      gfx_x=lx; gfx_y=ly; gfx_lineto(tx,ty,1) ;
    );

    lx=tx; ly=ty; ly2=ty2;
    i+=1;
  );
);


);
__________________
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.ru
Lex248 is offline   Reply With Quote
Old 08-08-2017, 11:00 AM   #2
Lex248
Human being with feelings
 
Join Date: Apr 2017
Location: Russia
Posts: 18
Default

Also it is possible to make so for the correct measurement of amplitude.

Code:
...
@sample
recpos[]=(spl(0)+spl(1))*2.0;
...
__________________
Sorry, I bad speak english.
---
My plug-ins http://nalexsoft.blogspot.ru
Lex248 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.