changeset 13730:a45e901cc870

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 ...)
author michael
date Thu, 21 Oct 2004 21:15:21 +0000
parents 045dbaccaccc
children 199feba24d65
files libaf/af_lavcresample.c
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libaf/af_lavcresample.c	Thu Oct 21 16:47:42 2004 +0000
+++ b/libaf/af_lavcresample.c	Thu Oct 21 21:15:21 2004 +0000
@@ -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++){