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

Monty xiphmont at xiph.org
Thu Oct 16 15:03:37 PDT 2003



xiphmont    03/10/16 18:03:37

  Modified:    .        mainpanel.c output.c postfish.h version.h
  Added:       .        output.h
  Log:
  Connect master attenuator and output VU linkage

Revision  Changes    Path
1.13      +18 -5     postfish/mainpanel.c

Index: mainpanel.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/mainpanel.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- mainpanel.c	16 Oct 2003 19:28:47 -0000	1.12
+++ mainpanel.c	16 Oct 2003 22:03:36 -0000	1.13
@@ -8,6 +8,7 @@
 #include "readout.h"
 #include "version.h"
 #include "input.h"
+#include "output.h"
 
 typedef struct {
   GtkWidget *topframe;
@@ -58,10 +59,6 @@
  
 } postfish_mainpanel;
 
-extern sig_atomic_t playback_active;
-extern sig_atomic_t playback_exit;
-extern void *playback_thread(void *dummy);
-
 static void action_play(GtkWidget *widget,postfish_mainpanel *p){
   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))){
     if(!playback_active){
@@ -84,7 +81,6 @@
   }
 }
 
-extern sig_atomic_t loop_active;
 static void action_b(GtkWidget *widget,postfish_mainpanel *p){
   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
     loop_active=1;
@@ -162,6 +158,8 @@
   gdouble val=gtk_range_get_value(r);
   sprintf(buf,"%.1f dB",val);
   readout_set(READOUT(p->masterdB_r),buf);
+
+  master_att=rint(val*10);
 }
 
 static gboolean timeevent_unselect(GtkWidget *widget,
@@ -733,6 +731,21 @@
       input_cursor_to_time(time_cursor,buffer);
       readout_set(panel->cue,buffer);
 
+      if(pull_output_feedback(peak,rms,&n)){
+	for(i=0;i<n;i++){
+	  if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(panel->channelshow[i]))){
+	    peak[i]=todB(peak[i]);
+	    rms[i]=todB(rms[i]);
+	  }else{
+	    peak[i]=-400;
+	    rms[i]=-400;
+	  }
+	}
+	
+	multibar_set(MULTIBAR(panel->outbar),rms,peak,n);
+      }
+
+
     }
   }
 

<p><p>1.7       +122 -1    postfish/output.c

Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/output.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- output.c	16 Oct 2003 20:39:36 -0000	1.6
+++ output.c	16 Oct 2003 22:03:36 -0000	1.7
@@ -30,6 +30,83 @@
 sig_atomic_t playback_active=0;
 sig_atomic_t playback_exit=0;
 
+typedef struct output_feedback{
+  double *rms;
+  double *peak;
+
+  struct output_feedback *next;
+} output_feedback;
+
+static output_feedback *feedback_list_head;
+static output_feedback *feedback_list_tail;
+static output_feedback *feedback_pool;
+
+static output_feedback *new_output_feedback(void){
+  output_feedback *ret;
+  
+  pthread_mutex_lock(&master_mutex);
+  if(feedback_pool){
+    ret=feedback_pool;
+    feedback_pool=feedback_pool->next;
+    pthread_mutex_unlock(&master_mutex);
+    return ret;
+  }
+  pthread_mutex_unlock(&master_mutex);
+  ret=malloc(sizeof(*ret));
+  ret->rms=malloc((input_ch+2)*sizeof(*ret->rms));
+  ret->peak=malloc((input_ch+2)*sizeof(*ret->peak));
+  
+  return ret;
+}
+
+static void push_output_feedback(double *peak,double *rms){
+  int i,n=input_ch+2;
+  output_feedback *f=new_output_feedback();
+
+  memcpy(f->rms,rms,n*sizeof(*rms));
+  memcpy(f->peak,peak,n*sizeof(*peak));
+  f->next=NULL;
+
+  pthread_mutex_lock(&master_mutex);
+  if(!feedback_list_tail){
+    feedback_list_tail=f;
+    feedback_list_head=f;
+  }else{
+    feedback_list_head->next=f;
+    feedback_list_head=f;
+  }
+  pthread_mutex_unlock(&master_mutex);
+}
+
+int pull_output_feedback(double *peak,double *rms,int *n){
+  output_feedback *f;
+  int i,j;
+  *n=input_ch+2;
+
+  pthread_mutex_lock(&master_mutex);
+  if(feedback_list_tail){
+    
+    f=feedback_list_tail;
+    feedback_list_tail=feedback_list_tail->next;
+    if(!feedback_list_tail)feedback_list_head=0;
+
+  }else{
+    pthread_mutex_unlock(&master_mutex);
+    return 0;
+  }
+  pthread_mutex_unlock(&master_mutex);
+
+  memcpy(rms,f->rms,sizeof(*rms)* *n);
+  memcpy(peak,f->peak,sizeof(*peak)* *n);
+
+  pthread_mutex_lock(&master_mutex);
+  f->next=feedback_pool;
+  feedback_pool=f;
+  pthread_mutex_unlock(&master_mutex);
+  return 1;
+}
+
+
 static void PutNumLE(long num,FILE *f,int bytes){
   int i=0;
   while(bytes--){
@@ -127,6 +204,10 @@
   int ch=-1;
   long rate=-1;
 
+  /* for output feedback */
+  double *rms=alloca(sizeof(*rms)*(input_ch+2));
+  double *peak=alloca(sizeof(*peak)*(input_ch+2));
+
   while(1){
     if(playback_exit)break;
 
@@ -137,10 +218,20 @@
 
 
 
+    /* temporary; this would be frequency domain in the finished postfish */
+    if(ret && ret->samples>0){
+      double scale=fromdB(master_att/10.);
+      for(i=0;i<ret->samples;i++)
+	for(j=0;j<ret->channels;j++)
+	  ret->data[j][i]*=scale;
+    }    
+
 
     /************/
 
     if(ret && ret->samples>0){
+      memset(rms,0,sizeof(*rms)*(input_ch+2));
+      memset(peak,0,sizeof(*peak)*(input_ch+2));
       ch=ret->channels;
       rate=ret->rate;
 
@@ -164,8 +255,13 @@
       /* final limiting and conversion */
       
       for(k=0,i=0;i<ret->samples;i++){
+	double mean=0.;
+	double div=0.;
+	double divrms=0.;
+
         for(j=0;j<ret->channels;j++){
-	  int val=rint(ret->data[j][i]*32767.);
+	  double dval=ret->data[j][i];
+	  int val=rint(dval*32767.);
           if(val>32767)val=32767;
           if(val<-32768)val=-32768;
           if(bigendianp){
@@ -175,12 +271,37 @@
             audiobuf[k++]=val;
             audiobuf[k++]=val>>8;
           }
+
+	  if(fabs(dval)>peak[j])peak[j]=fabs(dval);
+	  rms[j]+= dval*dval;
+	  mean+=dval;
+
         }
+
+	/* mean */
+	mean/=j;
+	if(fabs(mean)>peak[input_ch])peak[input_ch]=fabs(mean);
+	rms[input_ch]+= mean*mean;
+
+	/* div */
+	for(j=0;j<ret->channels;j++){
+	  double dval=mean-ret->data[j][i];
+	  if(fabs(dval)>peak[input_ch+1])peak[input_ch+1]=fabs(dval);
+	  divrms+=dval*dval;
+	}
+	rms[input_ch+1]+=divrms/ret->channels;
+
+      }
+
+      for(j=0;j<input_ch+2;j++){
+	rms[j]/=ret->samples;
+	rms[j]=sqrt(rms[j]);
       }
       
       count+=fwrite(audiobuf,1,ret->channels*ret->samples*2,playback_fd);
 
       /* inform Lord Vader his shuttle is ready */
+      push_output_feedback(peak,rms);
       write(eventpipe[1],"",1);
 
     }else

<p><p>1.5       +1 -0      postfish/postfish.h

Index: postfish.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/postfish.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- postfish.h	16 Oct 2003 19:28:47 -0000	1.4
+++ postfish.h	16 Oct 2003 22:03:36 -0000	1.5
@@ -65,6 +65,7 @@
 extern sig_atomic_t loop_active;
 extern sig_atomic_t playback_active;
 extern sig_atomic_t playback_exit;
+extern sig_atomic_t master_att;
 extern int outfileno;
 extern int seekable;
 extern int eventpipe[2];

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

Index: version.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/version.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- version.h	16 Oct 2003 20:39:36 -0000	1.9
+++ version.h	16 Oct 2003 22:03:36 -0000	1.10
@@ -1,2 +1,2 @@
-#define VERSION "$Id: version.h,v 1.9 2003/10/16 20:39:36 xiphmont Exp $ "
-/* DO NOT EDIT: Automated versioning hack [Thu Oct 16 16:34:29 EDT 2003] */
+#define VERSION "$Id: version.h,v 1.10 2003/10/16 22:03:36 xiphmont Exp $ "
+/* DO NOT EDIT: Automated versioning hack [Thu Oct 16 18:02:10 EDT 2003] */

<p><p>1.1                  postfish/output.h

Index: output.h
===================================================================
extern int pull_output_feedback(double *peak,double *rms,int *n);
extern void *playback_thread(void *dummy);

<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