[Mplayer-cvslog] CVS: main/libaf af_lavcresample.c,1.1,1.2

Michael Niedermayer CVS syncmail at mplayerhq.hu
Thu Oct 21 23:15:24 CEST 2004


CVS change done by Michael Niedermayer CVS

Update of /cvsroot/mplayer/main/libaf
In directory mail:/var2/tmp/cvs-serv17612

Modified Files:
	af_lavcresample.c 
Log Message:
user selectable cutoff frequency
simplify resampling factor if possible, so more then one resampler can be used, libaf will still die if there are too many like it does with the default resampler (2 with sampling rates which are relative prime are too many ...)


Index: af_lavcresample.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_lavcresample.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- af_lavcresample.c	21 Oct 2004 03:32:31 -0000	1.1
+++ af_lavcresample.c	21 Oct 2004 21:15:21 -0000	1.2
@@ -16,6 +16,8 @@
 
 #define CHANS 6
 
+int64_t ff_gcd(int64_t a, int64_t b);
+
 // Data for specific instances of this filter
 typedef struct af_resample_s{
     struct AVResampleContext *avrctx;
@@ -26,12 +28,14 @@
     int filter_length;
     int linear;
     int phase_shift;
+    double cutoff;
 }af_resample_t;
 
 
 // Initialization and runtime control
 static int control(struct af_instance_s* af, int cmd, void* arg)
 {
+  int g;
   af_resample_t* s   = (af_resample_t*)af->setup; 
   af_data_t *data= (af_data_t*)arg;
 
@@ -46,16 +50,18 @@
     af->data->nch    = data->nch;
     af->data->format = AF_FORMAT_SI | AF_FORMAT_NE;
     af->data->bps    = 2;
-    af->mul.n = af->data->rate;
-    af->mul.d = data->rate;
-    af->delay = 500*s->filter_length/(double)min(af->mul.n, af->mul.d);
+    g= ff_gcd(af->data->rate, data->rate);
+    af->mul.n = af->data->rate/g;
+    af->mul.d = data->rate/g;
+    af->delay = 500*s->filter_length/(double)min(af->data->rate, data->rate);
 
     if(s->avrctx) av_resample_close(s->avrctx);
-    s->avrctx= av_resample_init(af->mul.n, /*in_rate*/af->mul.d, s->filter_length, s->phase_shift, s->linear);
+    s->avrctx= av_resample_init(af->mul.n, /*in_rate*/af->mul.d, s->filter_length, s->phase_shift, s->linear, s->cutoff);
 
     return AF_OK;
   case AF_CONTROL_COMMAND_LINE:{
-    sscanf((char*)arg,"%d:%d:%d:%d", &af->data->rate, &s->filter_length, &s->linear, &s->phase_shift);
+    sscanf((char*)arg,"%d:%d:%d:%d:%lf", &af->data->rate, &s->filter_length, &s->linear, &s->phase_shift, &s->cutoff);
+    if(s->cutoff <= 0.0) s->cutoff= max(1.0 - 1.0/s->filter_length, 0.80);
     return AF_OK;
   }
   case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
@@ -93,7 +99,9 @@
       return NULL;
   
   out= (int16_t*)af->data->audio;
-
+  
+  out_len= min(out_len, af->data->len/(2*chans));
+  
   if(s->in_alloc < in_len + s->index){
       s->in_alloc= in_len + s->index;
       for(i=0; i<chans; i++){




More information about the MPlayer-cvslog mailing list