[xiph-cvs] cvs commit: postfish input.c multibar.c output.c version.h

Monty xiphmont at xiph.org
Wed Oct 15 01:38:14 PDT 2003



xiphmont    03/10/15 04:38:14

  Modified:    .        input.c multibar.c output.c version.h
  Log:
  playback at end-of-file bugfix
  playscale damping fixes

Revision  Changes    Path
1.5       +2 -2      postfish/input.c

Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/input.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- input.c	15 Oct 2003 02:01:46 -0000	1.4
+++ input.c	15 Oct 2003 08:38:13 -0000	1.5
@@ -476,9 +476,9 @@
         break;
       }
       if(signp)
-	dval=out.data[j][i]=val*4.6566128730e-10;
+	dval=out.data[j][i]=val/2147483647.;
       else
-	dval=out.data[j][i]=(val^0x80000000UL)*4.6566128730e-10;
+	dval=out.data[j][i]=(val^0x80000000UL)/2147483647.;
 
       if(fabs(dval)>peak[j])peak[j]=fabs(dval);
       rms[j]+= dval*dval;

<p><p>1.8       +138 -123  postfish/multibar.c

Index: multibar.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/multibar.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- multibar.c	15 Oct 2003 04:50:27 -0000	1.7
+++ multibar.c	15 Oct 2003 08:38:13 -0000	1.8
@@ -2,38 +2,89 @@
 #include <stdlib.h>
 #include "multibar.h"
 
+static double compute_dampening(double target,double current,double delta){
+  double raw_delta=target-current;
+
+  if(target<0){
+    if(current>0)
+      raw_delta=target-current;
+  }else if(current<0){
+    raw_delta=target-current;
+  }else if(raw_delta<0){
+    if(delta>0){
+      raw_delta=0.;
+    }else{
+      if(raw_delta<delta-1)raw_delta=delta-1;
+    }
+  }else{
+    if(delta<0){
+      raw_delta=0.;
+    }else{
+      if(raw_delta>delta+1)raw_delta=delta+1;
+    }
+  }
+  return raw_delta;
+}
+
+
 /* call me roughly 10-20fps */
 static void draw(GtkWidget *widget,double *lowvals, double *highvals, int n){
   int i,j;
   Multibar *m=MULTIBAR(widget);
-  double max=m->peak;
+  double max=-400;
 
   if(!m->boxcolor){
     m->boxcolor=gdk_gc_new(m->backing);
     gdk_gc_copy(m->boxcolor,widget->style->black_gc);
   }
-  
-  if(m->peaktimer.tv_sec){
-    struct timeval tv;
-    gettimeofday(&tv,NULL);
-    
-    long val=(tv.tv_sec-m->peaktimer.tv_sec)*1000+(tv.tv_usec-m->peaktimer.tv_usec)/1000;
-
-    if(val>2000) max = m->peak -= (val-2000)*.001;
-  }
 
+  if(n>m->bars){
+    if(!m->bartrackers)
+      m->bartrackers=calloc(n,sizeof(*m->bartrackers));
+    else{
+      m->bartrackers=realloc(m->bartrackers,
+			     n*sizeof(*m->bartrackers));
+      memset(m->bartrackers+m->bars,0,
+	     sizeof(*m->bartrackers)*(n-m->bars));
+    }
+    
+    for(i=m->bars;i<n;i++){
+      m->bartrackers[i].pixelposlo=-400;
+      m->bartrackers[i].pixelposhi=-400;
+      m->bartrackers[i].pixeldeltalo=0;
+      m->bartrackers[i].pixeldeltahi=0;
+    }
+    
+    m->bars=n;
+  }else if(n<m->bars)
+    m->bars=n;
+  
   for(i=0;i<n;i++)
     if(highvals[i]>=0.){
-      clipdelay=15*10; /* ~ ten second hold */
+      m->clipdelay=15*10; /* ~ ten second hold */
       break;
     }
-  for(i=0;i<n;i++)
+
+   for(i=0;i<n;i++)
     if(highvals[i]>max)max=highvals[i];
 
+  if(m->clipdelay>0)
+    m->clipdelay--;
+  else
+    m->clipdelay=0;
+
+  if(m->peakdelay>0)
+    m->peakdelay--;
+  else{
+    m->peakdelay=0;
+    m->peakdelta--;
+    m->peak+=m->peakdelta;
+  }
+
   if(max>m->peak){
     m->peak=max;
-    peakdelay=15*2; /* ~2 second hold */
-    peakdelta=0;
+    m->peakdelay=15*2; /* ~2 second hold */
+    m->peakdelta=0;
   }
 
   {
@@ -67,26 +118,6 @@
     }
 
     /* dampen movement according to setup */
-    if(n>m->bars){
-      if(!m->bartrackers)
-	m->bartrackers=calloc(n,sizeof(*m->bartrackers));
-      else{
-	m->bartrackers=realloc(m->bartrackers,
-				    n*sizeof(*m->bartrackers));
-	memset(m->bartrackers+m->bars,0,
-	       sizeof(*m->bartrackers)*(n-m->bars));
-      }
-      
-      for(i=m->bars;i<n;i++){
-	m->bartrackers[i].pixelposlo=pixlo[i];
-	m->bartrackers[i].pixelposhi=pixhi[i];
-	m->bartrackers[i].pixeldeltalo=0;
-	m->bartrackers[i].pixeldeltahi=0;
-      }
-
-      m->bars=n;
-    }else if(n<m->bars)
-      m->bars=n;
 
     for(i=0;i<n;i++){
       double trackhi=m->bartrackers[i].pixelposhi;
@@ -95,43 +126,22 @@
       double dello=m->bartrackers[i].pixeldeltalo;
 
       /* hi */
+      delhi = compute_dampening(pixhi[i],trackhi,delhi);
+
       if(pixhi[i]>trackhi){
-	/* hi attack */
-	if(delhi<0.)delhi=0.;
-	if(m->dampen_flags & HI_ATTACK){
-	  /* damp the attack */
-	  delhi+=1;
-	  pixhi[i]=trackhi+delhi;
-	}	
+	if(m->dampen_flags & HI_ATTACK)pixhi[i]=trackhi+delhi;
       }else{
-	/* hi decay */
-	if(delhi>0.)delhi=0.;
-	if(m->dampen_flags & HI_DECAY){
-	  /* damp the decay */
-	  delhi-=1;
-	  pixhi[i]=trackhi+delhi;
-	}
+	if(m->dampen_flags & HI_DECAY)pixhi[i]=trackhi+delhi;
       }
       m->bartrackers[i].pixelposhi=pixhi[i];
       m->bartrackers[i].pixeldeltahi=delhi;
 
       /* lo */
+      dello = compute_dampening(pixlo[i],tracklo,dello);
       if(pixlo[i]>tracklo){
-	/* lo attack */
-	if(dello<0.)dello=0.;
-	if(m->dampen_flags & LO_ATTACK){
-	  /* damp the attack */
-	  dello+=1;
-	  pixlo[i]=tracklo+dello;
-	}
+	if(m->dampen_flags & LO_ATTACK)pixlo[i]=tracklo+dello;
       }else{
-	/* lo decay */
-	if(dello>0.)dello=0.;
-	if(m->dampen_flags & LO_DECAY){
-	  /* damp the decay */
-	  dello-=1;
-	  pixlo[i]=tracklo+dello;
-	}
+	if(m->dampen_flags & LO_DECAY)pixlo[i]=tracklo+dello;
       }
       m->bartrackers[i].pixelposlo=pixlo[i];
       m->bartrackers[i].pixeldeltalo=dello;
@@ -152,39 +162,39 @@
         if(pixlo[i]<=x && pixhi[i]>=next){
           switch(i%8){
           case 0:
-	    r*=.55;
-	    g*=.55;
-	    b*=.55;
+	    r*=.65;
+	    g*=.65;
+	    b*=.65;
             break;
           case 1:
-	    r*=.8;
+	    r*=1.;
             g*=.5;
             b*=.5;
             break;
           case 2:
             r*=.6;
             g*=.6;
-	    b*=.9;
+	    b*=1.;
             break;
           case 3:
             r*=.4;
-	    g*=.7;
+	    g*=.9;
             b*=.4;
             break;
           case 4:
-	    r*=.6;
-	    g*=.5;
+	    r*=.7;
+	    g*=.6;
             b*=.3;
             break;
           case 5:
-	    r*=.6;
+	    r*=.7;
             g*=.4;
-	    b*=.7;
+	    b*=.8;
             break;
           case 6:
             r*=.3;
-	    g*=.6;
-	    b*=.6;
+	    g*=.7;
+	    b*=.7;
             break;
           case 7:
             r*=.4;
@@ -202,61 +212,67 @@
 
       x=next;
     }
-  }
+  
 
-  if(m->clipdelay){
-    gdk_draw_line (m->backing,
-		   widget->style->fg_gc[1],
-		   0, 0, widget->allocation.width-1, 0);
-    
-    gdk_draw_line (m->backing,
-		   widget->style->fg_gc[1],
-		   0, widget->allocation.height-1, 
-		   widget->allocation.width-1, widget->allocation.height-1);
-  }else{
-    gdk_draw_line (m->backing,
-		   widget->style->white_gc,
-		   0, 0, widget->allocation.width-1, 0);
+    if(m->clipdelay){
+      gdk_draw_line (m->backing,
+		     widget->style->fg_gc[1],
+		     0, 0, widget->allocation.width-1, 0);
+      
+      gdk_draw_line (m->backing,
+		     widget->style->fg_gc[1],
+		     0, widget->allocation.height-1, 
+		     widget->allocation.width-1, widget->allocation.height-1);
+    }else{
+      gdk_draw_line (m->backing,
+		     widget->style->white_gc,
+		     0, 0, widget->allocation.width-1, 0);
+      
+      gdk_draw_line (m->backing,
+		     widget->style->white_gc,
+		     0, widget->allocation.height-1, 
+		     widget->allocation.width-1, widget->allocation.height-1);
+    }
     
-    gdk_draw_line (m->backing,
-		   widget->style->white_gc,
-		   0, widget->allocation.height-1, 
-		   widget->allocation.width-1, widget->allocation.height-1);
-  }
-
-  /* peak follower */
-  {
-    int x=-10;
-    for(j=0;j<=m->labels;j++)
-      if(m->peak>=m->levels[j]){
-	if(m->peak<=m->levels[j+1]){
-	  double del=(m->peak-m->levels[j])/(m->levels[j+1]-m->levels[j]);
-	  x=(j+del)/m->labels*widget->allocation.width;
+    /* peak follower */
+    {
+      int x=-10;
+      for(j=0;j<=m->labels;j++)
+	if(m->peak>=m->levels[j]){
+	  if(m->peak<=m->levels[j+1]){
+	    double del=(m->peak-m->levels[j])/(m->levels[j+1]-m->levels[j]);
+	    x=(j+del)/m->labels*widget->allocation.width;
+	    break;
+	  }
+	}else
           break;
-	}
-      }else
-	break;
-
-
-    gdk_draw_polygon(m->backing,widget->style->fg_gc[0],1,
-		     (GdkPoint[]){{x,5},{x+5,0},{x-4,0}},3);
-    gdk_draw_polygon(m->backing,widget->style->fg_gc[0],1,
-		     (GdkPoint[]){{x,widget->allocation.height-6},
-		       {x+5,widget->allocation.height},
-			 {x-5,widget->allocation.height}},3);
-
-    
-    gdk_draw_line(m->backing,widget->style->fg_gc[0],x,0,x,widget->allocation.height-1);
-
+      
+      for(j=0;j<n;j++)
+	if(x<pixhi[j])x=pixhi[j];
+      
+	 
+      gdk_draw_polygon(m->backing,widget->style->fg_gc[0],1,
+		       (GdkPoint[]){{x,5},{x+5,0},{x-4,0}},3);
+      gdk_draw_polygon(m->backing,widget->style->fg_gc[0],1,
+		       (GdkPoint[]){{x,widget->allocation.height-6},
+			 {x+5,widget->allocation.height},
+			   {x-5,widget->allocation.height}},3);
+      
+      
+      gdk_draw_line(m->backing,widget->style->fg_gc[0],x,0,x,widget->allocation.height-1);
+    }
   }
 
   for(i=0;i<m->labels;i++){
     int x=widget->allocation.width*(i+1)/m->labels;
     int y=widget->allocation.height;
     int px,py;
+    int gc=0;
+    
+    if(m->levels[i+1]>=0)gc=1;
 
     gdk_draw_line (m->backing,
-		   widget->style->text_gc[0],
+		   widget->style->text_gc[gc],
                    x, 0, x, y);
 
     pango_layout_get_pixel_size(m->layout[i],&px,&py);
@@ -264,9 +280,8 @@
     y-=py;
     y/=2;
 
-
     gdk_draw_layout (m->backing,
-		     widget->style->text_gc[0],
+		     widget->style->text_gc[gc],
                      x, y,
                      m->layout[i]);
 
@@ -332,12 +347,12 @@
 }
 
 static void multibar_init (Multibar *m){
-
   m->layout=0;
   m->peak=-200;
 
-  m->peaktimer=(struct timeval){0,0};
-  m->cliptimer=(struct timeval){0,0};
+  m->peakdelay=0;
+  m->clipdelay=0;
+  m->peak=-400;
 }
 
 GType multibar_get_type (void){

<p><p>1.4       +9 -8      postfish/output.c

Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/output.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- output.c	15 Oct 2003 04:50:27 -0000	1.3
+++ output.c	15 Oct 2003 08:38:13 -0000	1.4
@@ -191,15 +191,16 @@
     }
   }
 
-  if(isachr(playback_fd)){
-    int fd=fileno(playback_fd);
-    ioctl(fd,SNDCTL_DSP_RESET);
-  }else{
-    if(ch>-1)
-      WriteWav(playback_fd,ch,rate,16,count);
+  if(playback_fd){
+    if(isachr(playback_fd)){
+      int fd=fileno(playback_fd);
+      ioctl(fd,SNDCTL_DSP_RESET);
+    }else{
+      if(ch>-1)
+	WriteWav(playback_fd,ch,rate,16,count);
+    } 
+    fclose(playback_fd);
   }
-  
-  fclose(playback_fd);
   playback_active=0;
   playback_exit=0;
   if(audiobuf)free(audiobuf);

<p><p>1.7       +2 -2      postfish/version.h

Index: version.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/version.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- version.h	15 Oct 2003 04:50:27 -0000	1.6
+++ version.h	15 Oct 2003 08:38:13 -0000	1.7
@@ -1,2 +1,2 @@
-#define VERSION "$Id: version.h,v 1.6 2003/10/15 04:50:27 xiphmont Exp $ "
-/* DO NOT EDIT: Automated versioning hack [Tue Oct 14 23:37:00 EDT 2003] */
+#define VERSION "$Id: version.h,v 1.7 2003/10/15 08:38:13 xiphmont Exp $ "
+/* DO NOT EDIT: Automated versioning hack [Wed Oct 15 04:36:56 EDT 2003] */

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list