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

Monty xiphmont at xiph.org
Thu Oct 16 12:28:48 PDT 2003



xiphmont    03/10/16 15:28:48

  Modified:    .        input.c input.h mainpanel.c output.c postfish.h
                        version.h
  Log:
  time/cursor fixes

Revision  Changes    Path
1.6       +86 -46    postfish/input.c

Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/input.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- input.c	15 Oct 2003 08:38:13 -0000	1.5
+++ input.c	16 Oct 2003 19:28:47 -0000	1.6
@@ -22,6 +22,7 @@
  */
 
 #include "postfish.h"
+#include "input.h"
 
 static off_t        Acursor=0;
 static off_t        Bcursor=-1;
@@ -44,6 +45,18 @@
 
 } file_entry;
 
+typedef struct input_feedback{
+  off_t   cursor;
+  double *rms;
+  double *peak;
+
+  struct input_feedback *next;
+} input_feedback;
+
+static input_feedback *feedback_list_head;
+static input_feedback *feedback_list_tail;
+static input_feedback *feedback_pool;
+
 static file_entry *file_list=NULL;
 static int file_entries=0;
 static int current_file_entry_number=-1;
@@ -62,14 +75,6 @@
   pthread_mutex_unlock(&master_mutex);
 }
 
-off_t input_cursor_get(void){
-  off_t ret;
-  pthread_mutex_lock(&master_mutex);
-  ret=cursor;
-  pthread_mutex_unlock(&master_mutex);
-  return ret;
-}
-
 off_t input_time_to_cursor(char *t){
   char temp[14];
   char *c;
@@ -121,7 +126,8 @@
   }else
     h=0;
 
-  return (off_t)hd + (off_t)s*100 + (off_t)m*60*100 + (off_t)h*60*60*100;
+  return ((off_t)hd + (off_t)s*100 + (off_t)m*60*100 + (off_t)h*60*60*100) *
+    input_rate / 100 * inbytes * input_ch;
 }
 
 void time_fix(char *buffer){
@@ -140,12 +146,15 @@
 }
 
 void input_cursor_to_time(off_t cursor,char *t){
-  int h=cursor/60/60/100,m,s,hd;
-  cursor%=(off_t)60*60*100;
-  m=cursor/60/100;
-  cursor%=(off_t)60*100;
-  s=cursor/100;
-  m=cursor%100;
+  int h,m,s,hd;
+  cursor/=input_ch*inbytes;
+
+  h=cursor/60/60/input_rate;
+  cursor%=(off_t)60*60*input_rate;
+  m=cursor/60/input_rate;
+  cursor%=(off_t)60*input_rate;
+  s=cursor/input_rate;
+  hd=cursor%input_rate*100/input_rate;
   if(h>9999)h=9999;
 
   sprintf(t,"%04d:%02d:%02d.%02d",h,m,s,hd);
@@ -300,12 +309,12 @@
     }
   }
 
-  out.samples=2048;
+  out.size=2048;
   input_ch=out.channels=ch;
-  out.rate=rate;
+  input_rate=out.rate=rate;
   out.data=malloc(sizeof(*out.data)*ch);
   for(i=0;i<ch;i++)
-    out.data[i]=malloc(sizeof(*out.data[0])*out.samples);
+    out.data[i]=malloc(sizeof(*out.data[0])*out.size);
   
   return 0;
 }
@@ -345,49 +354,76 @@
   return(0);
 }
 
-double *input_rms=NULL;
-double *input_peak=NULL;
-sig_atomic_t input_feedback=0;
-
-static void update_input_feedback(double *peak,double *rms){
-  int i,n=input_ch+2;
+static input_feedback *new_input_feedback(void){
+  input_feedback *ret;
+  
   pthread_mutex_lock(&master_mutex);
-
-  if(!input_rms){
-    input_rms=calloc(n,sizeof(*input_rms));
-    input_peak=calloc(n,sizeof(*input_peak));
+  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));
   
-  if(input_feedback==0){
-    memcpy(input_peak,peak,sizeof(*peak)*n);
-    memcpy(input_rms,rms,sizeof(*rms)*n);
+  return ret;
+}
+
+static void push_input_feedback(double *peak,double *rms, off_t cursor){
+  int i,n=input_ch+2;
+  input_feedback *f=new_input_feedback();
+
+  f->cursor=cursor;
+  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{
-    for(i=0;i<n;i++){
-      if(peak[i]>input_peak[i])
-	input_peak[i]=peak[i];
-      input_rms[i]=.5*input_rms[i]+.5*rms[i];  
-    }
+    feedback_list_head->next=f;
+    feedback_list_head=f;
   }
-  input_feedback=1;
-
   pthread_mutex_unlock(&master_mutex);
 }
 
-int fetch_input_feedback(double *peak,double *rms){
-  int n=input_ch+2,i,j;
+int pull_input_feedback(double *peak,double *rms,off_t *cursor,int *n){
+  input_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;
 
-  memcpy(rms,input_rms,sizeof(*input_rms)*n);
-  memcpy(peak,input_peak,sizeof(*input_peak)*n);
+  }else{
+    pthread_mutex_unlock(&master_mutex);
+    return 0;
+  }
+  pthread_mutex_unlock(&master_mutex);
 
-  input_feedback=0;
+  memcpy(rms,f->rms,sizeof(*rms)* *n);
+  memcpy(peak,f->peak,sizeof(*peak)* *n);
+  *cursor=f->cursor;
 
+  pthread_mutex_lock(&master_mutex);
+  f->next=feedback_pool;
+  feedback_pool=f;
   pthread_mutex_unlock(&master_mutex);
+  return 1;
 }
 
 time_linkage *input_read(void){
   int read_b=0,i,j,k;
-  int toread_b=out.samples*out.channels*inbytes;
+  int toread_b=out.size*out.channels*inbytes;
   unsigned char *readbuf;
   double *rms=alloca(sizeof(*rms)*(out.channels+2));
   double *peak=alloca(sizeof(*peak)*(out.channels+2));
@@ -430,9 +466,11 @@
       cursor+=ret;
     }else{
       if(current_file_entry_number+1>=file_entries){
+
+	/* end of file before full frame */
         memset(readbuf+read_b,0,toread_b);
-	read_b+=toread_b;
         toread_b=0;
+
       }
     }
 
@@ -451,6 +489,8 @@
         pthread_mutex_unlock(&master_mutex);
     }
   }
+
+  out.samples=read_b/out.channels/inbytes;
   
   k=0;
   for(i=0;i<out.samples;i++){
@@ -507,7 +547,7 @@
     rms[j]=sqrt(rms[j]);
   }
 
-  update_input_feedback(peak,rms);
+  push_input_feedback(peak,rms,cursor);
 
   return &out;
 }

<p><p>1.3       +1 -1      postfish/input.h

Index: input.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/input.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- input.h	13 Oct 2003 06:01:22 -0000	1.2
+++ input.h	16 Oct 2003 19:28:47 -0000	1.3
@@ -1,9 +1,9 @@
 extern void input_Acursor_set(off_t c);
 extern void input_Bcursor_set(off_t c);
-extern off_t input_cursor_get();
 extern off_t input_time_to_cursor(char *t);
 extern void input_cursor_to_time(off_t cursor,char *t);
 extern void time_fix(char *buffer);
 extern int input_seek(off_t pos);
 extern time_linkage *input_read(void);
 extern int input_load(int n,char *list[]);
+extern int pull_input_feedback(double *peak,double *rms,off_t *cursor,int *n);

<p><p>1.12      +25 -18    postfish/mainpanel.c

Index: mainpanel.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/mainpanel.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- mainpanel.c	15 Oct 2003 03:25:19 -0000	1.11
+++ mainpanel.c	16 Oct 2003 19:28:47 -0000	1.12
@@ -1,10 +1,7 @@
 
+#include "postfish.h"
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
-#include <signal.h>
-#include <stdio.h>
-#include <pthread.h>
-#include "postfish.h"
 #include "fisharray.h"
 #include "buttonicons.h"
 #include "multibar.h"
@@ -52,6 +49,8 @@
 
   GtkWidget *channelshow[10]; /* support only up to 8 + mid/side */
 
+  GtkWidget *cue;
+
   /* ui state */
   int fishframe;
   int fishframe_init;
@@ -610,7 +609,6 @@
     {
       GtkWidget *cuebox=gtk_hbox_new(0,0);
       GtkWidget *cuelabel=gtk_label_new("cue:");
-      GtkWidget *cue=readout_new("    :  :00.00");
       GtkWidget *entry_a=gtk_entry_new();
       GtkWidget *entry_b=gtk_entry_new();
 
@@ -619,6 +617,9 @@
 
       GtkWidget *panelb=gtk_check_button_new_with_mnemonic("c_ue list");
 
+      panel->cue=readout_new("    :  :00.00");
+
+
       panel->cue_set[0]=gtk_button_new_with_label("[a]");
       panel->cue_set[1]=gtk_toggle_button_new_with_label("[b]");
       panel->cue_reset[0]=gtk_button_new_with_label("[A]");
@@ -653,7 +654,7 @@
       gtk_table_attach_defaults(GTK_TABLE(ttable),cuebox,1,2,5,6);
       gtk_table_attach_defaults(GTK_TABLE(ttable),panelb,2,3,5,6);
 
-      gtk_box_pack_start(GTK_BOX(cuebox),cue,0,0,0);
+      gtk_box_pack_start(GTK_BOX(cuebox),panel->cue,0,0,0);
 
       gtk_box_pack_start(GTK_BOX(cuebox),framea,1,1,3);
 
@@ -711,22 +712,28 @@
       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(panel->deckactive[3]),0);
 
   /* second order of business; update the input meter if data is available */
-  if(input_feedback){
+  {
+    off_t   time_cursor;
+    int     n;
     double *rms=alloca(sizeof(*rms)*(input_ch+2));
     double *peak=alloca(sizeof(*peak)*(input_ch+2));
-    fetch_input_feedback(peak,rms);
-
-    for(i=0;i<input_ch+2;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;
+    if(pull_input_feedback(peak,rms,&time_cursor,&n)){
+      char buffer[14];
+      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->inbar),rms,peak,n);
+      input_cursor_to_time(time_cursor,buffer);
+      readout_set(panel->cue,buffer);
 
-    multibar_set(MULTIBAR(panel->inbar),rms,peak,input_ch+2);
+    }
   }
 
   return TRUE;

<p><p>1.5       +4 -9      postfish/output.c

Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/output.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- output.c	15 Oct 2003 08:38:13 -0000	1.4
+++ output.c	16 Oct 2003 19:28:47 -0000	1.5
@@ -177,17 +177,12 @@
           }
         }
       }
-      {
-	struct timeval tv;
-	long foo;
-	gettimeofday(&tv,NULL);
-	foo=tv.tv_sec*15+tv.tv_usec*15/100000;
-	if(last!=foo)
-	  write(eventpipe[1],"",1);
-	last=foo;
-      }
       
       count+=fwrite(audiobuf,1,ret->channels*ret->samples*2,playback_fd);
+
+      /* inform Lord Vader his shuttle is ready */
+      write(eventpipe[1],"",1);
+
     }
   }
 

<p><p>1.4       +2 -2      postfish/postfish.h

Index: postfish.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/postfish.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- postfish.h	14 Oct 2003 08:39:08 -0000	1.3
+++ postfish.h	16 Oct 2003 19:28:47 -0000	1.4
@@ -53,7 +53,8 @@
 #define toOC(n)     (log(n)*1.442695f-5.965784f)
 
 typedef struct time_linkage {
-  int samples;
+  int size;
+  int samples;  /* normally same as size; exception is EOF */
   int channels;
   int rate;
   double **data;
@@ -68,5 +69,4 @@
 extern int seekable;
 extern int eventpipe[2];
 extern int input_ch;
-extern sig_atomic_t input_feedback;
 

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

Index: version.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/version.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- version.h	15 Oct 2003 08:38:13 -0000	1.7
+++ version.h	16 Oct 2003 19:28:47 -0000	1.8
@@ -1,2 +1,2 @@
-#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] */
+#define VERSION "$Id: version.h,v 1.8 2003/10/16 19:28:47 xiphmont Exp $ "
+/* DO NOT EDIT: Automated versioning hack [Thu Oct 16 02:30:55 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