[xiph-commits] r14588 - trunk/spectrum

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Mar 14 23:08:10 PDT 2008


Author: xiphmont
Date: 2008-03-14 23:08:09 -0700 (Fri, 14 Mar 2008)
New Revision: 14588

Modified:
   trunk/spectrum/analyzer.h
   trunk/spectrum/panel.c
   trunk/spectrum/plot.c
   trunk/spectrum/plot.h
   trunk/spectrum/process.c
   trunk/spectrum/version.h
Log:
Rearrange some of the scaling/integration selection
Finally add y-axis regulation (at least for ymax; still need to work phase)



Modified: trunk/spectrum/analyzer.h
===================================================================
--- trunk/spectrum/analyzer.h	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/analyzer.h	2008-03-15 06:08:09 UTC (rev 14588)
@@ -85,7 +85,8 @@
 extern void *process_thread(void *dummy);
 extern void process_dump(int mode);
 extern void rundata_clear();
-extern float **process_fetch(int scale, int mode,int link, int *active, int width, 
+extern float **process_fetch(int res, int scale, int mode, int link, 
+			     int *active, int width, 
 			     float *ymax, float *pmax, float *pmin);
 
 extern int inputs;

Modified: trunk/spectrum/panel.c
===================================================================
--- trunk/spectrum/panel.c	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/panel.c	2008-03-15 06:08:09 UTC (rev 14588)
@@ -48,7 +48,8 @@
   
 } p;
 
-int plot_scale=1;
+int plot_res=0;
+int plot_scale=0;
 int plot_mode=0;
 int plot_link=0;
 int plot_hold=0;
@@ -151,7 +152,7 @@
     plot_depth=140;
     break;
   }
-  plot_setting(PLOT(p->plot),plot_scale,plot_mode,plot_link,plot_depth);
+  plot_setting(PLOT(p->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
 }
 
 static void set_fg(GtkWidget *c, gpointer in){
@@ -334,21 +335,26 @@
 
 }
 
+static void reschange(GtkWidget *widget,struct panel *p){
+  plot_res=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
+  plot_setting(PLOT(p->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
+}
+
 static void scalechange(GtkWidget *widget,struct panel *p){
   plot_scale=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-  plot_setting(PLOT(p->plot),plot_scale,plot_mode,plot_link,plot_depth);
+  plot_setting(PLOT(p->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
 }
 
 static void modechange(GtkWidget *widget,struct panel *p){
   plot_mode=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
   replot(p);
-  plot_setting(PLOT(p->plot),plot_scale,plot_mode,plot_link,plot_depth);
+  plot_setting(PLOT(p->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
 }
 
 static void linkchange(GtkWidget *widget,struct panel *p){
   plot_link=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
   replot(p);
-  plot_setting(PLOT(p->plot),plot_scale,plot_mode,plot_link,plot_depth);
+  plot_setting(PLOT(p->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
   chlabels(widget,p);
 }
 
@@ -520,11 +526,22 @@
   /* scale */
   {
     GtkWidget *menu=gtk_combo_box_new_text();
-    char *entries[]={"linear","log","ISO log"};
+    char *entries[]={"screen resolution","1/24th octave","1/12th octave","1/3 octave"};
+    for(i=0;i<4;i++)
+      gtk_combo_box_append_text (GTK_COMBO_BOX (menu), entries[i]);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(menu),plot_res);
+    gtk_box_pack_start(GTK_BOX(bbox),menu,0,0,0);
+    g_signal_connect (G_OBJECT (menu), "changed",
+		      G_CALLBACK (reschange), panel);
+  }
+
+  {
+    GtkWidget *menu=gtk_combo_box_new_text();
+    char *entries[]={"log scale","ISO log scale","linear scale"};
     for(i=0;i<3;i++)
       gtk_combo_box_append_text (GTK_COMBO_BOX (menu), entries[i]);
     gtk_combo_box_set_active(GTK_COMBO_BOX(menu),plot_scale);
-    plot_setting(PLOT(panel->plot),plot_scale,plot_mode,plot_link,plot_depth);
+    plot_setting(PLOT(panel->plot),plot_res,plot_scale,plot_mode,plot_link,plot_depth);
     gtk_box_pack_start(GTK_BOX(bbox),menu,0,0,0);
     
     g_signal_connect (G_OBJECT (menu), "changed",

Modified: trunk/spectrum/plot.c
===================================================================
--- trunk/spectrum/plot.c	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/plot.c	2008-03-15 06:08:09 UTC (rev 14588)
@@ -68,23 +68,8 @@
 
   /* find the places to plot the x grid lines according to scale */
   switch(p->scale){
-  case 0: /* linear; 2kHz spacing */
+  case 0: /* log */
     {
-      float lfreq;
-      for(i=0;i<11;i++){
-	lfreq=i*2000.;
-	p->xgrid[i]=rint(lfreq/20000. * (width-1))+p->padx;
-      }
-	
-      p->xgrids=11;
-      p->xtics=0;
-      while((lfreq=(p->xtics+1)*500.)<20000.)
-	p->xtic[p->xtics++]=rint(lfreq/20000. * (width-1))+p->padx;
-    }
-    break;
-    
-  case 1: /* log */
-    {
       double lfreqs[6]={1.,10.,100.,1000.,10000.,100000};
       double tfreqs[37]={5.,6.,7.,8.,9.,20.,30.,40.,50.,60.,70.,80.,90.
 			 ,200.,300.,400.,500.,600.,700.,800.,900.,
@@ -99,7 +84,7 @@
     }
     
     break;
-  case 2: /* ISO log */
+  case 1: /* ISO log */
     {
       double lfreqs[10]={31.,63.,125.,250.,500.,1000.,2000.,4000.,8000.,16000.};
       double tfreqs[20]={25.,40.,50.,80.,100.,160.,200.,315.,400.,630.,800.,
@@ -113,6 +98,21 @@
     }
 
     break;
+  case 2: /* linear; 2kHz spacing */
+    {
+      float lfreq;
+      for(i=0;i<11;i++){
+	lfreq=i*2000.;
+	p->xgrid[i]=rint(lfreq/20000. * (width-1))+p->padx;
+      }
+	
+      p->xgrids=11;
+      p->xtics=0;
+      while((lfreq=(p->xtics+1)*500.)<20000.)
+	p->xtic[p->xtics++]=rint(lfreq/20000. * (width-1))+p->padx;
+    }
+    break;
+    
   }
 
 }
@@ -229,13 +229,13 @@
     PangoLayout **proper;
     switch(p->scale){
     case 0:
-      proper=p->lin_layout;
+      proper=p->log_layout;
       break;
     case 1:
-      proper=p->log_layout;
+      proper=p->iso_layout;
       break;
     case 2:
-      proper=p->iso_layout;
+      proper=p->lin_layout;
       break;
     }
     for(i=0;i<p->xgrids;i++){
@@ -759,11 +759,6 @@
   p->ch_active=calloc(ch,sizeof(*p->ch_active));
   p->ch_process=calloc(ch,sizeof(*p->ch_process));
 
-  /*
-    p->cal=calloc(p->ch,sizeof(*p->cal));
-    for(i=0;i<p->ch;i++)
-      p->cal[i]=calloc(p->datasize,sizeof(**p->cal));
-  */
   plot_clear(p);
   return ret;
 }
@@ -775,15 +770,16 @@
   int height=GTK_WIDGET(p)->allocation.height-p->pady;
   float **data;
   
+  if(!p->ydata)return;
+
   if(process)
     memcpy(p->ch_process,process,p->total_ch*sizeof(*process));
   
-  data = process_fetch(p->scale,p->mode,p->link,
+  data = process_fetch(p->res, p->scale, p->mode, p->link, 
 		       p->ch_process,width,&ymax,&pmax,&pmin);
   
-  if(p->ydata)
-    for(i=0;i<p->total_ch;i++)
-      memcpy(p->ydata[i],data[i],width*sizeof(**p->ydata));
+  for(i=0;i<p->total_ch;i++)
+    memcpy(p->ydata[i],data[i],width*sizeof(**p->ydata));
 
   /* graph limit updates are conditional depending on mode/link */
   if(pmax<12)pmax=12;
@@ -811,10 +807,30 @@
   //if(pmax<p->pmax)pmax=p->pmax;
   //if(pmin>p->pmin)pmin=p->pmin;
 
-  /* time damp decay */
+  /* scale regression is conditional and damped. Start the timer/run
+     the timer while any one scale measure should be dropping by more
+     than 50px. If any peaks occur above, reset timer.  Once timer
+     runs out, drop 5px per frame */
+#define PXTHRESH 25
+#define PXDEL 10
+#define TIMERFRAMES 20
+  if(p->ymax>ymax){
+    float oldzero = (height-1)/p->depth*p->ymax;
+    float newzero = (height-1)/p->depth*ymax;
 
+    fprintf(stderr,"old=%f, new=%f, timer=%d\n",oldzero,newzero,p->scaletimer);
+    if(newzero+PXTHRESH<oldzero){
+      if(p->scaletimer){
+	p->scaletimer--;
+      }else{
+	p->ymax = (oldzero-PXDEL)*p->depth/(height-1);
+      }
+    }else{
+      p->scaletimer = TIMERFRAMES;
+    }
+  }else
+    p->scaletimer = TIMERFRAMES;
 
-
   /* finally, align phase/response zeros on phase graphs */
   if(ymax>-140){
     if(p->link == LINK_PHASE){
@@ -851,7 +867,7 @@
   if(pmax>180)pmax=180;
   if(pmin<-180)pmin=-180;
   
-  p->ymax=ymax;
+  if(ymax>p->ymax)p->ymax=ymax;
   p->pmax=pmax;
   p->pmin=pmin;
 }
@@ -865,7 +881,7 @@
     for(i=0;i<p->total_ch;i++)
       for(j=0;j<width;j++)
 	p->ydata[i][j]=NAN;
-  p->ymax=-140;
+  p->ymax=p->depth-140;
   p->pmax=12.;
   p->pmin=-12.;
   draw_and_expose(widget);
@@ -875,8 +891,9 @@
   return(p->ydata);
 }
 
-void plot_setting (Plot *p, int scale, int mode, int link, int depth){
+void plot_setting (Plot *p, int res, int scale, int mode, int link, int depth){
   GtkWidget *widget=GTK_WIDGET(p);
+  p->res=res;
   p->scale=scale;
   p->mode=mode;
   p->depth=depth;

Modified: trunk/spectrum/plot.h
===================================================================
--- trunk/spectrum/plot.h	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/plot.h	2008-03-15 06:08:09 UTC (rev 14588)
@@ -66,6 +66,7 @@
   int mode;
   int link;
   int scale;
+  int res;
   int *rate;
 
   int xgrid[11];
@@ -86,6 +87,8 @@
   float padx;
   float phax;
   float pady;
+
+  int scaletimer;
 };
 
 struct _PlotClass{
@@ -97,7 +100,7 @@
 GType          plot_get_type        (void);
 GtkWidget*     plot_new             (int n, int inputs, int *channels, int *rate);
 void	       plot_refresh         (Plot *m, int *process);
-void	       plot_setting         (Plot *m, int scale, int mode, int link, int depth);
+void	       plot_setting         (Plot *m, int res, int scale, int mode, int link, int depth);
 void	       plot_draw            (Plot *m);
 void	       plot_clear           (Plot *m);
 int 	       plot_width           (Plot *m);

Modified: trunk/spectrum/process.c
===================================================================
--- trunk/spectrum/process.c	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/process.c	2008-03-15 06:08:09 UTC (rev 14588)
@@ -63,6 +63,7 @@
 float **xmappingH;
 int metascale = -1;
 int metawidth = -1;
+int metares = -1;
 
 sig_atomic_t acc_clear=0;
 sig_atomic_t acc_rewind=0;
@@ -861,15 +862,15 @@
 
 }
 
-float **process_fetch(int scale, int mode,int link, int *active, int width, 
+float **process_fetch(int res, int scale, int mode, int link, 
+		      int *active, int width, 
 		      float *ymax, float *pmax, float *pmin){
   int ch,ci,i,j,fi;
   float **data;
   float **ph;
 
   /* are our scale mappings up to date? */
-  if(scale != metascale || width != metawidth){
-
+  if(res != metares || scale != metascale || width != metawidth){
     if(!xmappingL) xmappingL = calloc(inputs, sizeof(*xmappingL));
     if(!xmappingH) xmappingH = calloc(inputs, sizeof(*xmappingH));
 
@@ -889,33 +890,60 @@
 
       metascale = scale;
       metawidth = width;
+      metares = res;
 
+      
       /* generate new numbers */
-      switch(scale){
-      case 0: /* linear */
-	for(i=0;i<width;i++){
-	  float lfreq=(i-1.)*20000./(width-1);
-	  float hfreq=(i+1.)*20000./(width-1);
-	  xmappingL[fi][i]=lfreq/(rate[fi]*.5)*(blocksize/2);
-	  xmappingH[fi][i]=hfreq/(rate[fi]*.5)*(blocksize/2);
+      for(i=0;i<width;i++){
+	float off=0;
+	float loff=1.;
+	float hoff=1.;
+	float lfreq,hfreq;
+
+	switch(res){
+	case 0: /* screen-resolution */
+	  off=1.;
+	  break;
+	case 1: /* 1/24th octave */
+	  loff = .95918945710913818816;
+	  hoff = 1.04254690518999138632;
+	  break;
+	case 2: /* 1/12th octave */
+	  loff = .94387431268169349664;
+	  hoff = 1.05946309435929526455;
+	  break;
+	case 3: /* 1/3th octave */
+	  loff = .79370052598409973738;
+	  hoff = 1.25992104989487316475;
+	  break;
 	}
-	break;
-      case 1: /* log */
-	for(i=0;i<width;i++){
-	  float lfreq= pow(10.,(i-1.)/(width-1)*(log10(100000.)-log10(5.))+log10(5.));
-	  float hfreq= pow(10.,(i+1.)/(width-1)*(log10(100000.)-log10(5.))+log10(5.));
-	  xmappingL[fi][i]=lfreq/(rate[fi]*.5)*(blocksize/2);
-	  xmappingH[fi][i]=hfreq/(rate[fi]*.5)*(blocksize/2);
+
+	switch(scale){
+	case 0: /* log */
+	  lfreq= pow(10.,(i-off)/(width-1)
+		     * (log10(100000.)-log10(5.))
+		     + log10(5.)) * loff;
+	  hfreq= pow(10.,(i+off)/(width-1)
+		     * (log10(100000.)-log10(5.))
+		     + log10(5.)) * hoff;
+	  break;
+	case 1: /* ISO */
+	  lfreq= pow(2.,(i-off)/(width-1)
+		     * (log2(20000.)-log2(25.))
+		     + log2(25.)) * loff;
+	  hfreq= pow(2.,(i+off)/(width-1)
+		     * (log2(20000.)-log2(25.))
+		     + log2(25.)) *hoff;
+	  break;
+	case 2: /* screen-resolution linear */
+	  lfreq=(i-off)*20000./(width-1)*loff;
+	  hfreq=(i+off)*20000./(width-1)*hoff;
+	  break;
 	}
-	break;
-      case 2: /* iso log */
-	for(i=0;i<width;i++){
-	  float lfreq= pow(2.,(i-1.)/(width-1)*(log2(20000.)-log2(25.))+log2(25.));
-	  float hfreq= pow(2.,(i+1.)/(width-1)*(log2(20000.)-log2(25.))+log2(25.));
-	  xmappingL[fi][i]=lfreq/(rate[fi]*.5)*(blocksize/2);
-	  xmappingH[fi][i]=hfreq/(rate[fi]*.5)*(blocksize/2);
-	}
-	break;
+
+	xmappingL[fi][i]=lfreq/(rate[fi]*.5)*(blocksize/2);
+	xmappingH[fi][i]=hfreq/(rate[fi]*.5)*(blocksize/2);
+
       }
       
       for(i=0;i<width;i++){

Modified: trunk/spectrum/version.h
===================================================================
--- trunk/spectrum/version.h	2008-03-14 10:55:34 UTC (rev 14587)
+++ trunk/spectrum/version.h	2008-03-15 06:08:09 UTC (rev 14588)
@@ -1,2 +1,2 @@
 #define VERSION "$Id: version.h 6914 2004-06-29 03:05:41Z xiphmont $ "
-/* DO NOT EDIT: Automated versioning hack [Tue Mar 11 11:24:58 EDT 2008] */
+/* DO NOT EDIT: Automated versioning hack [Sat Mar 15 03:13:41 EDT 2008] */



More information about the commits mailing list