[FFmpeg-devel] [PATCH 2/2] Rename log2/exp2 replacements ff_log2/ff_exp2
Vitor Sessak
vitor1001
Wed Jan 13 02:05:42 CET 2010
Mans Rullgard wrote:
> This avoids conflicts with system headers on broken platforms.
> ---
> libavcodec/aaccoder.c | 12 ++++++------
> libavcodec/acelp_pitch_delay.c | 2 +-
> libavcodec/sipr.c | 2 +-
> libavutil/internal.h | 36 ++++++++++++++++++++++--------------
> 4 files changed, 30 insertions(+), 22 deletions(-)
>
> diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> index 0a51aa7..4376cad 100644
> --- a/libavcodec/aaccoder.c
> +++ b/libavcodec/aaccoder.c
> @@ -523,9 +523,9 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
> int minscale, maxscale;
> float minrd = INFINITY;
> //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
> - minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
> + minscale = av_clip_uint8(ff_log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
> //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
> - maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
> + maxscale = av_clip_uint8(ff_log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
> for (q = minscale; q < maxscale; q++) {
> float dists[12], dist;
> memset(dists, 0, sizeof(dists));
> @@ -655,7 +655,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
> sce->sf_idx[w*16+g] = SCALE_ONE_POS;
> continue;
> }
> - sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2(uplims[w*16+g]/minthr)*4,59);
> + sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(ff_log2(uplims[w*16+g]/minthr)*4,59);
> }
> }
>
> @@ -855,7 +855,7 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
> continue;
> }
> sce->zeroes[w*16+g] = 0;
> - scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2(1/maxq[w*16+g])*16/3, 60, 218);
> + scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - ff_log2(1/maxq[w*16+g])*16/3, 60, 218);
> step = 16;
> for (;;) {
> float dist = 0.0f;
> @@ -884,7 +884,7 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
> if (curdiff == 0.0f)
> step = 0;
> else
> - step = fabsf(log2(curdiff));
> + step = fabsf(ff_log2(curdiff));
> if (dist > uplim[w*16+g])
> step = -step;
> if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
> @@ -935,7 +935,7 @@ static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s,
> sce->sf_idx[(w+w2)*16+g] = 218;
> sce->zeroes[(w+w2)*16+g] = 1;
> } else {
> - sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2(band->threshold), 80, 218);
> + sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + ff_log2(band->threshold), 80, 218);
> sce->zeroes[(w+w2)*16+g] = 0;
> }
> minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]);
> diff --git a/libavcodec/acelp_pitch_delay.c b/libavcodec/acelp_pitch_delay.c
> index 0451f1b..821518e 100644
> --- a/libavcodec/acelp_pitch_delay.c
> +++ b/libavcodec/acelp_pitch_delay.c
> @@ -128,7 +128,7 @@ float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
> // ^g_c = ^gamma_gc * 100.05 (predicted dB + mean dB - dB of fixed vector)
> // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).
> float val = fixed_gain_factor *
> - exp2f(log2f(10.0) * 0.05 *
> + ff_exp2f(ff_log2f(10.0) * 0.05 *
> (ff_dot_productf(pred_table, prediction_error, 4) +
> energy_mean)) /
> sqrtf(fixed_mean_energy);
> diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
> index 7bfa3ab..724e72c 100644
> --- a/libavcodec/sipr.c
> +++ b/libavcodec/sipr.c
> @@ -461,7 +461,7 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params,
>
> gain_code = ff_amr_set_fixed_gain(gain_cb[params->gc_index[i]][1],
> avg_energy, ctx->energy_history,
> - 34 - 15.0/(log2f(10.0) * 0.05),
> + 34 - 15.0/(ff_log2f(10.0) * 0.05),
> pred);
>
> ff_weighted_vector_sumf(excitation, excitation, fixed_vector,
> diff --git a/libavutil/internal.h b/libavutil/internal.h
> index ad43206..f0f2145 100644
> --- a/libavutil/internal.h
> +++ b/libavutil/internal.h
> @@ -263,19 +263,23 @@ if ((y) < (x)) {\
> }\
> }
>
> -#if !HAVE_EXP2
> -static av_always_inline av_const double exp2(double x)
> +static av_always_inline av_const double ff_exp2(double x)
> {
> +#if HAVE_EXP2
> + return exp2(x);
> +#else
> return exp(x * 0.693147180559945);
> -}
> #endif /* HAVE_EXP2 */
> +}
>
> -#if !HAVE_EXP2F
> -static av_always_inline av_const float exp2f(float x)
> +static av_always_inline av_const float ff_exp2f(float x)
> {
> - return exp2(x);
> -}
> +#if HAVE_EXP2F
> + return exp2f(x);
> +#else
> + return ff_exp2(x);
> #endif /* HAVE_EXP2F */
> +}
>
> #if !HAVE_LLRINT
> static av_always_inline av_const long long llrint(double x)
> @@ -284,19 +288,23 @@ static av_always_inline av_const long long llrint(double x)
> }
> #endif /* HAVE_LLRINT */
>
> -#if !HAVE_LOG2
> -static av_always_inline av_const double log2(double x)
> +static av_always_inline av_const double ff_log2(double x)
> {
> +#if HAVE_LOG2
> + return log2(x);
> +#else
> return log(x) * 1.44269504088896340736;
> -}
> #endif /* HAVE_LOG2 */
> +}
>
> -#if !HAVE_LOG2F
> -static av_always_inline av_const float log2f(float x)
> +static av_always_inline av_const float ff_log2f(float x)
> {
> - return log2(x);
> -}
> +#if HAVE_LOG2F
> + return log2f(x);
> +#else
> + return ff_log2(x);
> #endif /* HAVE_LOG2F */
> +}
>
> #if !HAVE_LRINT
> static av_always_inline av_const long int lrint(double x)
The thing I don't like about this is that whoever reads aaccoder.c or
acelp_pitch_delay.c will be asking why the hell we need a custom log2().
OTOH, I'm favorable to it _if_ there is an arch that fails to build with
my patch with macros.
-Vitor
More information about the ffmpeg-devel
mailing list