summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-10-26 15:05:59 +0200
committerwm4 <wm4@nowhere>2013-10-26 15:05:59 +0200
commit7abc1bef40869d4efba88df8c5ad8b1ea4c49c57 (patch)
treeed1ef6c259c01dc119c4b99f84daefef5161bd93 /audio
parent74e7043cc756e171ea1a7fd4be01019c14e1e265 (diff)
downloadmpv-7abc1bef40869d4efba88df8c5ad8b1ea4c49c57.tar.bz2
mpv-7abc1bef40869d4efba88df8c5ad8b1ea4c49c57.tar.xz
af: replace macros with too generic names
Defining names like min, max etc. in an often used header is not really a good idea. Somewhat similar to MPlayer svn commit 36491, but don't use libavutil, because that typically causes us sorrow.
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af.h21
-rw-r--r--audio/filter/af_center.c3
-rw-r--r--audio/filter/af_channels.c5
-rw-r--r--audio/filter/af_delay.c3
-rw-r--r--audio/filter/af_drc.c13
-rw-r--r--audio/filter/af_equalizer.c3
-rw-r--r--audio/filter/af_extrastereo.c5
-rw-r--r--audio/filter/af_pan.c9
-rw-r--r--audio/filter/af_sub.c3
-rw-r--r--audio/filter/af_tools.c6
-rw-r--r--audio/filter/af_volume.c5
11 files changed, 33 insertions, 43 deletions
diff --git a/audio/filter/af.h b/audio/filter/af.h
index 088e02dc6a..dc776460aa 100644
--- a/audio/filter/af.h
+++ b/audio/filter/af.h
@@ -263,25 +263,4 @@ float af_softclip(float a);
#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 */
diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c
index e04b5ceced..0cfdbc3b0e 100644
--- a/audio/filter/af_center.c
+++ b/audio/filter/af_center.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
// Data for specific instances of this filter
@@ -48,7 +49,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!arg) return AF_ERROR;
af->data->rate = ((struct mp_audio*)arg)->rate;
- mp_audio_set_channels_old(af->data, max(s->ch+1,((struct mp_audio*)arg)->nch));
+ mp_audio_set_channels_old(af->data, MPMAX(s->ch+1,((struct mp_audio*)arg)->nch));
mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
return af_test_output(af,(struct mp_audio*)arg);
diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c
index fc1a090f7f..27445aafe2 100644
--- a/audio/filter/af_channels.c
+++ b/audio/filter/af_channels.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <inttypes.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
#define FR 0
@@ -150,14 +151,14 @@ static int control(struct af_instance* af, int cmd, void* arg)
// If mono: fake stereo
if(((struct mp_audio*)arg)->nch == 1){
- s->nr = min(af->data->nch,2);
+ s->nr = MPMIN(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, ((struct mp_audio*)arg)->nch);
+ s->nr = MPMIN(af->data->nch, ((struct mp_audio*)arg)->nch);
for(i=0;i<s->nr;i++){
s->route[i][FR] = i;
s->route[i][TO] = i;
diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c
index 5c34e33a92..a6515f84cf 100644
--- a/audio/filter/af_delay.c
+++ b/audio/filter/af_delay.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <inttypes.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
#define L 65536
@@ -85,7 +86,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
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,MPCLAMP(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]);
}
diff --git a/audio/filter/af_drc.c b/audio/filter/af_drc.c
index c0f7b5beca..9bbbde4831 100644
--- a/audio/filter/af_drc.c
+++ b/audio/filter/af_drc.c
@@ -26,6 +26,7 @@
#include <math.h>
#include <limits.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
// Methods:
@@ -139,14 +140,14 @@ static void method1_int16(af_drc_t *s, struct mp_audio *c)
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 = MPCLAMP(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 = MPCLAMP(tmp, SHRT_MIN, SHRT_MAX);
data[i] = tmp;
}
@@ -180,7 +181,7 @@ static void method1_float(af_drc_t *s, struct mp_audio *c)
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 = MPCLAMP(s->mul, MUL_MIN, MUL_MAX);
}
// Scale & clamp the samples
@@ -223,7 +224,7 @@ static void method2_int16(af_drc_t *s, struct mp_audio *c)
if (avg >= SIL_S16)
{
s->mul = s->mid_s16 / avg;
- s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+ s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX);
}
}
@@ -231,7 +232,7 @@ static void method2_int16(af_drc_t *s, struct mp_audio *c)
for (i = 0; i < len; i++)
{
tmp = s->mul * data[i];
- tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
+ tmp = MPCLAMP(tmp, SHRT_MIN, SHRT_MAX);
data[i] = tmp;
}
@@ -273,7 +274,7 @@ static void method2_float(af_drc_t *s, struct mp_audio *c)
if (avg >= SIL_FLOAT)
{
s->mul = s->mid_float / avg;
- s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
+ s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX);
}
}
diff --git a/audio/filter/af_equalizer.c b/audio/filter/af_equalizer.c
index 8bc1507584..cbdcd3f84a 100644
--- a/audio/filter/af_equalizer.c
+++ b/audio/filter/af_equalizer.c
@@ -29,6 +29,7 @@
#include <inttypes.h>
#include <math.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
#define L 2 // Storage for filter taps
@@ -143,7 +144,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
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,MPCLAMP(g[j],G_MIN,G_MAX)/20.0)-1.0;
}
}
return AF_OK;
diff --git a/audio/filter/af_extrastereo.c b/audio/filter/af_extrastereo.c
index 75570c7648..4cf27f2724 100644
--- a/audio/filter/af_extrastereo.c
+++ b/audio/filter/af_extrastereo.c
@@ -26,6 +26,7 @@
#include <math.h>
#include <limits.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
// Data for specific instances of this filter
@@ -93,8 +94,8 @@ static struct mp_audio* play_s16(struct af_instance* af, struct mp_audio* data)
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] = MPCLAMP(l, SHRT_MIN, SHRT_MAX);
+ a[i + 1] = MPCLAMP(r, SHRT_MIN, SHRT_MAX);
}
return data;
diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c
index bbd754647a..b3e31dab98 100644
--- a/audio/filter/af_pan.c
+++ b/audio/filter/af_pan.c
@@ -25,6 +25,7 @@
#include <math.h>
#include <limits.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
// Data for specific instances of this filter
@@ -126,10 +127,10 @@ static int control(struct af_instance* af, int cmd, void* arg)
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] = MPMIN(1.f, 1.f - val);
+ s->level[0][1] = MPMAX(0.f, val);
+ s->level[1][0] = MPMAX(0.f, -val);
+ s->level[1][1] = MPMIN(1.f, 1.f + val);
}
return AF_OK;
}
diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c
index 6fd492db95..7778e80b64 100644
--- a/audio/filter/af_sub.c
+++ b/audio/filter/af_sub.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
#include "dsp.h"
@@ -70,7 +71,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!arg) return AF_ERROR;
af->data->rate = ((struct mp_audio*)arg)->rate;
- mp_audio_set_channels_old(af->data, max(s->ch+1,((struct mp_audio*)arg)->nch));
+ mp_audio_set_channels_old(af->data, MPMAX(s->ch+1,((struct mp_audio*)arg)->nch));
mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
// Design low-pass filter
diff --git a/audio/filter/af_tools.c b/audio/filter/af_tools.c
index 77fdad55f2..77638ed9d6 100644
--- a/audio/filter/af_tools.c
+++ b/audio/filter/af_tools.c
@@ -18,6 +18,8 @@
#include <math.h>
#include <string.h>
+
+#include "mpvcore/mp_common.h"
#include "af.h"
/* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if
@@ -33,7 +35,7 @@ int af_from_dB(int n, float* in, float* out, float k, float mi, float ma)
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,MPCLAMP(in[i],mi,ma)/k);
}
return AF_OK;
}
@@ -65,7 +67,7 @@ int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma)
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 * MPCLAMP(in[i],mi,ma)/1000.0);
return AF_OK;
}
diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c
index 08c7789374..fa505a3dab 100644
--- a/audio/filter/af_volume.c
+++ b/audio/filter/af_volume.c
@@ -26,6 +26,7 @@
#include <math.h>
#include <limits.h>
+#include "mpvcore/mp_common.h"
#include "af.h"
struct priv {
@@ -73,7 +74,7 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
if (vol != 256) {
for (int i = ch; i < len; i += nch) {
int x = (a[i] * vol) >> 8;
- a[i] = clamp(x, SHRT_MIN, SHRT_MAX);
+ a[i] = MPCLAMP(x, SHRT_MIN, SHRT_MAX);
}
}
}
@@ -85,7 +86,7 @@ static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
for (int i = ch; i < len; i += nch) {
float x = a[i];
x *= s->level[ch];
- a[i] = s->soft ? af_softclip(x) : clamp(x, -1.0, 1.0);
+ a[i] = s->soft ? af_softclip(x) : MPCLAMP(x, -1.0, 1.0);
}
}
}