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.
This commit is contained in:
wm4 2013-10-26 15:05:59 +02:00
parent 74e7043cc7
commit 7abc1bef40
13 changed files with 35 additions and 44 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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;

View File

@ -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]);
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -36,6 +36,7 @@
#define MPMAX(a, b) ((a) > (b) ? (a) : (b))
#define MPMIN(a, b) ((a) > (b) ? (b) : (a))
#define MPCLAMP(a, min, max) (((a) < (min)) ? (min) : (((a) > (max)) ? (max) : (a)))
#define MPSWAP(type, a, b) \
do { type SWAP_tmp = b; b = a; a = SWAP_tmp; } while (0)
#define MP_ARRAY_SIZE(s) (sizeof(s) / sizeof((s)[0]))

View File

@ -3234,7 +3234,7 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
}
if (use_range) {
if (mpctx->opts->play_frames > 0)
ans = max(ans, 1.0 -
ans = MPMAX(ans, 1.0 -
mpctx->max_frames / (double) mpctx->opts->play_frames);
}
return ans;