diff libaf/af_resample.c @ 7998:d48a06d07afb

Adding commandline options for filters and fixing stupid bug in cfg
author anders
date Thu, 31 Oct 2002 11:06:19 +0000
parents 3aba91eb5c1f
children a7fa2d14ee91
line wrap: on
line diff
--- a/libaf/af_resample.c	Thu Oct 31 11:01:40 2002 +0000
+++ b/libaf/af_resample.c	Thu Oct 31 11:06:19 2002 +0000
@@ -69,6 +69,8 @@
   uint32_t	i; 	// Number of new samples to put in x queue
   uint32_t  	dn;     // Down sampling factor
   uint32_t	up;	// Up sampling factor 
+  int		sloppy;	// Enable sloppy resampling to reduce memory usage
+  int		fast;	// Enable linear interpolation instead of filtering
 } af_resample_t;
 
 // Euclids algorithm for calculating Greatest Common Divisor GCD(a,b)
@@ -222,6 +224,19 @@
     // Calculate up and down sampling factors
     d=gcd(af->data->rate,n->rate);
 
+    // If sloppy resampling is enabled limit the upsampling factor
+    if(s->sloppy && (af->data->rate/d > 5000)){
+      int up=af->data->rate/2;
+      int dn=n->rate/2;
+      int m=2;
+      while(af->data->rate/(d*m) > 5000){
+	d=gcd(up,dn); 
+	up/=2; dn/=2; m*=2;
+      }
+      d*=m;
+    }
+    printf("\n%i %i %i\n",d,af->data->rate/d,n->rate/d);
+
     // Check if the the design needs to be redone
     if(s->up != af->data->rate/d || s->dn != n->rate/d){
       float* w;
@@ -264,6 +279,12 @@
     af->mul.d = s->dn;
     return rv;
   }
+  case AF_CONTROL_COMMAND_LINE:{
+    af_resample_t* s   = (af_resample_t*)af->setup; 
+    int rate=0;
+    sscanf((char*)arg,"%i:%i:%i",&rate,&(s->sloppy), &(s->fast));
+    return af->control(af,AF_CONTROL_RESAMPLE,&rate);
+  }
   case AF_CONTROL_RESAMPLE: 
     // Reinit must be called after this function has been called