changeset 36395:2b9bc3c2933d

Remove some macros and switch to libavutil equivalents.
author reimar
date Sat, 26 Oct 2013 09:36:23 +0000
parents 2f815fdd521c
children 49587a84cb91
files libaf/af.h libaf/af_center.c libaf/af_channels.c libaf/af_comp.c libaf/af_delay.c libaf/af_equalizer.c libaf/af_extrastereo.c libaf/af_lavcresample.c libaf/af_pan.c libaf/af_resample.c libaf/af_sub.c libaf/af_tools.c libaf/af_volnorm.c libaf/af_volume.c
diffstat 14 files changed, 42 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/libaf/af.h	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af.h	Sat Oct 26 09:36:23 2013 +0000
@@ -325,25 +325,4 @@
 #define RESIZE_LOCAL_BUFFER(a,d)\
 ((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK)
 
-/* Some other useful macro definitions*/
-#ifndef min
-#define min(a,b)(((a)>(b))?(b):(a))
-#endif
-
-#ifndef max
-#define max(a,b)(((a)>(b))?(a):(b))
-#endif
-
-#ifndef clamp
-#define clamp(a,min,max) (((a)>(max))?(max):(((a)<(min))?(min):(a)))
-#endif
-
-#ifndef sign
-#define sign(a) (((a)>0)?(1):(-1))
-#endif
-
-#ifndef lrnd
-#define lrnd(a,b) ((b)((a)>=0.0?(a)+0.5:(a)-0.5))
-#endif
-
 #endif /* MPLAYER_AF_H */
--- a/libaf/af_center.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_center.c	Sat Oct 26 09:36:23 2013 +0000
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -49,7 +50,7 @@
     if(!arg) return AF_ERROR;
 
     af->data->rate   = ((af_data_t*)arg)->rate;
-    af->data->nch    = max(s->ch+1,((af_data_t*)arg)->nch);
+    af->data->nch    = FFMAX(s->ch+1,((af_data_t*)arg)->nch);
     af->data->format = AF_FORMAT_FLOAT_NE;
     af->data->bps    = 4;
 
--- a/libaf/af_channels.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_channels.c	Sat Oct 26 09:36:23 2013 +0000
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <inttypes.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -149,14 +150,14 @@
 
       // If mono: fake stereo
       if(((af_data_t*)arg)->nch == 1){
-	s->nr = min(af->data->nch,2);
+	s->nr = FFMIN(af->data->nch,2);
 	for(i=0;i<s->nr;i++){
 	  s->route[i][FR] = 0;
 	  s->route[i][TO] = i;
 	}
       }
       else{
-	s->nr = min(af->data->nch, ((af_data_t*)arg)->nch);
+	s->nr = FFMIN(af->data->nch, ((af_data_t*)arg)->nch);
 	for(i=0;i<s->nr;i++){
 	  s->route[i][FR] = i;
 	  s->route[i][TO] = i;
--- a/libaf/af_comp.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_comp.c	Sat Oct 26 09:36:23 2013 +0000
@@ -26,6 +26,7 @@
 #include <math.h>
 #include <limits.h>
 
+#include "libavutil/common.h"
 #include "af.h"
 
 // Data for specific instances of this filter
@@ -94,7 +95,7 @@
     return af_to_ms(AF_NCH,s->release,(float*)arg,af->data->rate);
   case AF_CONTROL_COMP_RATIO | AF_CONTROL_SET:
     for(i=0;i<AF_NCH;i++)
-      s->ratio[i] = clamp(((float*)arg)[i],1.0,10.0);
+      s->ratio[i] = av_clipf(((float*)arg)[i],1.0,10.0);
     return AF_OK;
   case AF_CONTROL_COMP_RATIO | AF_CONTROL_GET:
     for(i=0;i<AF_NCH;i++)
--- a/libaf/af_delay.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_delay.c	Sat Oct 26 09:36:23 2013 +0000
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <inttypes.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -87,7 +88,7 @@
     s->ri = 0;
     for(i=0;i<AF_NCH;i++){
       mp_msg(MSGT_AFILTER, MSGL_DBG2, "[delay] Channel %i delayed by %0.3fms\n",
-	     i,clamp(s->d[i],0.0,1000.0));
+	     i,av_clipf(s->d[i],0.0,1000.0));
       mp_msg(MSGT_AFILTER, MSGL_DBG3, "[delay] Channel %i delayed by %i samples\n",
 	     i,s->wi[i]);
     }
--- a/libaf/af_equalizer.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_equalizer.c	Sat Oct 26 09:36:23 2013 +0000
@@ -29,6 +29,7 @@
 #include <inttypes.h>
 #include <math.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -146,7 +147,7 @@
     for(i=0;i<AF_NCH;i++){
       for(j=0;j<KM;j++){
 	((af_equalizer_t*)af->setup)->g[i][j] =
-	  pow(10.0,clamp(g[j],G_MIN,G_MAX)/20.0)-1.0;
+	  pow(10.0,av_clipf(g[j],G_MIN,G_MAX)/20.0)-1.0;
       }
     }
     return AF_OK;
@@ -159,7 +160,7 @@
       return AF_ERROR;
 
     for(k = 0 ; k<KM ; k++)
-      s->g[ch][k] = pow(10.0,clamp(gain[k],G_MIN,G_MAX)/20.0)-1.0;
+      s->g[ch][k] = pow(10.0,av_clipf(gain[k],G_MIN,G_MAX)/20.0)-1.0;
 
     return AF_OK;
   }
--- a/libaf/af_extrastereo.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_extrastereo.c	Sat Oct 26 09:36:23 2013 +0000
@@ -26,6 +26,7 @@
 #include <math.h>
 #include <limits.h>
 
+#include "libavutil/common.h"
 #include "af.h"
 
 // Data for specific instances of this filter
@@ -102,8 +103,8 @@
     l = avg + (int)(s->mul * (a[i] - avg));
     r = avg + (int)(s->mul * (a[i + 1] - avg));
 
-    a[i] = clamp(l, SHRT_MIN, SHRT_MAX);
-    a[i + 1] = clamp(r, SHRT_MIN, SHRT_MAX);
+    a[i] = av_clip_int16(l);
+    a[i + 1] = av_clip_int16(r);
   }
 
   return data;
--- a/libaf/af_lavcresample.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_lavcresample.c	Sat Oct 26 09:36:23 2013 +0000
@@ -66,7 +66,7 @@
     af->data->format = AF_FORMAT_S16_NE;
     af->data->bps    = 2;
     af->mul = (double)af->data->rate / data->rate;
-    af->delay = af->data->nch * s->filter_length / min(af->mul, 1); // *bps*.5
+    af->delay = af->data->nch * s->filter_length / FFMIN(af->mul, 1); // *bps*.5
 
     if (s->ctx_out_rate != af->data->rate || s->ctx_in_rate != data->rate || s->ctx_filter_size != s->filter_length ||
         s->ctx_phase_shift != s->phase_shift || s->ctx_linear != s->linear || s->ctx_cutoff != s->cutoff) {
@@ -89,7 +89,7 @@
   case AF_CONTROL_COMMAND_LINE:{
     s->cutoff= 0.0;
     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 - 6.5/(s->filter_length+8), 0.80);
+    if(s->cutoff <= 0.0) s->cutoff= FFMAX(1.0 - 6.5/(s->filter_length+8), 0.80);
     return AF_OK;
   }
   case AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET:
@@ -132,7 +132,7 @@
 
   out= (int16_t*)af->data->audio;
 
-  out_len= min(out_len, af->data->len/(2*chans));
+  out_len= FFMIN(out_len, af->data->len/(2*chans));
 
   if(s->in_alloc < in_len + s->index){
       s->in_alloc= in_len + s->index;
@@ -196,7 +196,7 @@
   af->mul=1;
   af->data=calloc(1,sizeof(af_data_t));
   s->filter_length= 16;
-  s->cutoff= max(1.0 - 6.5/(s->filter_length+8), 0.80);
+  s->cutoff= FFMAX(1.0 - 6.5/(s->filter_length+8), 0.80);
   s->phase_shift= 10;
 //  s->setup = RSMP_INT | FREQ_SLOPPY;
   af->setup=s;
--- a/libaf/af_pan.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_pan.c	Sat Oct 26 09:36:23 2013 +0000
@@ -25,6 +25,7 @@
 #include <math.h>
 #include <limits.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -123,10 +124,10 @@
     if (s->nch)
       return AF_ERROR;
     if (af->data->nch >= 2) {
-      s->level[0][0] = min(1.f, 1.f - val);
-      s->level[0][1] = max(0.f, val);
-      s->level[1][0] = max(0.f, -val);
-      s->level[1][1] = min(1.f, 1.f + val);
+      s->level[0][0] = FFMIN(1.f, 1.f - val);
+      s->level[0][1] = FFMAX(0.f, val);
+      s->level[1][0] = FFMAX(0.f, -val);
+      s->level[1][1] = FFMIN(1.f, 1.f + val);
     }
     return AF_OK;
   }
--- a/libaf/af_resample.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_resample.c	Sat Oct 26 09:36:23 2013 +0000
@@ -234,7 +234,7 @@
       s->i = 0;
 
       // Calculate cutoff frequency for filter
-      fc = 1/(float)(max(s->up,s->dn));
+      fc = 1/(float)(FFMAX(s->up,s->dn));
       // Allocate space for polyphase filter bank and prototype filter
       w = malloc(sizeof(float) * s->up *L);
       free(s->w);
@@ -277,7 +277,7 @@
     int sloppy=1;
     sscanf((char*)arg,"%i:%i:%i", &rate, &sloppy, &type);
     s->setup = (sloppy?FREQ_SLOPPY:FREQ_EXACT) |
-      (clamp(type,RSMP_LIN,RSMP_FLOAT));
+      (av_clip(type,RSMP_LIN,RSMP_FLOAT));
     return af->control(af,AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET, &rate);
   }
   case AF_CONTROL_POST_CREATE:
--- a/libaf/af_sub.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_sub.c	Sat Oct 26 09:36:23 2013 +0000
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 #include "dsp.h"
@@ -71,7 +72,7 @@
     if(!arg) return AF_ERROR;
 
     af->data->rate   = ((af_data_t*)arg)->rate;
-    af->data->nch    = max(s->ch+1,((af_data_t*)arg)->nch);
+    af->data->nch    = FFMAX(s->ch+1,((af_data_t*)arg)->nch);
     af->data->format = AF_FORMAT_FLOAT_NE;
     af->data->bps    = 4;
 
--- a/libaf/af_tools.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_tools.c	Sat Oct 26 09:36:23 2013 +0000
@@ -18,6 +18,7 @@
 
 #include <math.h>
 #include <string.h>
+#include "libavutil/common.h"
 #include "af.h"
 
 /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if
@@ -33,7 +34,7 @@
     if(in[i]<=-200)
       out[i]=0.0;
     else
-      out[i]=pow(10.0,clamp(in[i],mi,ma)/k);
+      out[i]=pow(10.0,av_clipf(in[i],mi,ma)/k);
   }
   return AF_OK;
 }
@@ -65,7 +66,7 @@
     return AF_ERROR;
 
   for(i=0;i<n;i++)
-    out[i]=(int)((float)rate * clamp(in[i],mi,ma)/1000.0);
+    out[i]=(int)((float)rate * av_clipf(in[i],mi,ma)/1000.0);
 
   return AF_OK;
 }
--- a/libaf/af_volnorm.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_volnorm.c	Sat Oct 26 09:36:23 2013 +0000
@@ -26,6 +26,7 @@
 #include <math.h>
 #include <limits.h>
 
+#include "libavutil/common.h"
 #include "af.h"
 
 // Methods:
@@ -144,14 +145,14 @@
     s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
 
     // clamp the mul coefficient
-    s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+    s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX);
   }
 
   // Scale & clamp the samples
   for (i = 0; i < len; i++)
   {
     tmp = s->mul * data[i];
-    tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
+    tmp = av_clip_int16(tmp);
     data[i] = tmp;
   }
 
@@ -185,7 +186,7 @@
     s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
 
     // clamp the mul coefficient
-    s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+    s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX);
   }
 
   // Scale & clamp the samples
@@ -228,7 +229,7 @@
     if (avg >= SIL_S16)
     {
 	s->mul = s->mid_s16 / avg;
-	s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+	s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX);
     }
   }
 
@@ -236,7 +237,7 @@
   for (i = 0; i < len; i++)
   {
     tmp = s->mul * data[i];
-    tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
+    tmp = av_clip_int16(tmp);
     data[i] = tmp;
   }
 
@@ -278,7 +279,7 @@
     if (avg >= SIL_FLOAT)
     {
 	s->mul = s->mid_float / avg;
-	s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+	s->mul = av_clipf(s->mul, MUL_MIN, MUL_MAX);
     }
   }
 
--- a/libaf/af_volume.c	Sat Oct 26 09:36:21 2013 +0000
+++ b/libaf/af_volume.c	Sat Oct 26 09:36:23 2013 +0000
@@ -42,6 +42,7 @@
 #include <math.h>
 #include <limits.h>
 
+#include "libavutil/common.h"
 #include "mp_msg.h"
 #include "af.h"
 
@@ -121,7 +122,7 @@
     int i;
     if(!s->fast){
       for(i=0;i<AF_NCH;i++)
-	m=max(m,s->max[i]);
+	m=FFMAX(m,s->max[i]);
 	af_to_dB(1, &m, &m, 10.0);
 	mp_msg(MSGT_AFILTER, MSGL_INFO, "[volume] The maximum volume was %0.2fdB \n", m);
     }
@@ -156,7 +157,7 @@
 	register int vol = (int)(255.0 * s->level[ch]);
 	for(i=ch;i<len;i+=nch){
 	  register int x = (a[i] * vol) >> 8;
-	  a[i]=clamp(x,SHRT_MIN,SHRT_MAX);
+	  a[i]=av_clip_int16(x);
 	}
       }
     }
@@ -189,7 +190,7 @@
 	    x=af_softclip(x);
 	  // Hard clipping
 	  else
-	    x=clamp(x,-1.0,1.0);
+	    x=av_clipf(x,-1.0,1.0);
 	  a[i] = x;
 	}
       }