avcodec/wmalosslessdec: optimize sign operation

Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/110/merge
zhaoxiu.zeng 10 years ago committed by Michael Niedermayer
parent bc0a440e88
commit 80f1378005
  1. 34
      libavcodec/wmalosslessdec.c

@ -175,6 +175,8 @@ typedef struct WmallDecodeCtx {
int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]; int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
} WmallDecodeCtx; } WmallDecodeCtx;
/** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
#define WMASIGN(x) ((x > 0) - (x < 0))
static av_cold int decode_init(AVCodecContext *avctx) static av_cold int decode_init(AVCodecContext *avctx)
{ {
@ -631,22 +633,14 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
for (i = 0; i < order * num_channels; i++) for (i = 0; i < order * num_channels; i++)
s->mclms_coeffs[i + ich * order * num_channels] += s->mclms_coeffs[i + ich * order * num_channels] +=
s->mclms_updates[s->mclms_recent + i]; s->mclms_updates[s->mclms_recent + i];
for (j = 0; j < ich; j++) { for (j = 0; j < ich; j++)
if (s->channel_residues[j][icoef] > 0) s->mclms_coeffs_cur[ich * num_channels + j] += WMASIGN(s->channel_residues[j][icoef]);
s->mclms_coeffs_cur[ich * num_channels + j] += 1;
else if (s->channel_residues[j][icoef] < 0)
s->mclms_coeffs_cur[ich * num_channels + j] -= 1;
}
} else if (pred_error < 0) { } else if (pred_error < 0) {
for (i = 0; i < order * num_channels; i++) for (i = 0; i < order * num_channels; i++)
s->mclms_coeffs[i + ich * order * num_channels] -= s->mclms_coeffs[i + ich * order * num_channels] -=
s->mclms_updates[s->mclms_recent + i]; s->mclms_updates[s->mclms_recent + i];
for (j = 0; j < ich; j++) { for (j = 0; j < ich; j++)
if (s->channel_residues[j][icoef] > 0) s->mclms_coeffs_cur[ich * num_channels + j] -= WMASIGN(s->channel_residues[j][icoef]);
s->mclms_coeffs_cur[ich * num_channels + j] -= 1;
else if (s->channel_residues[j][icoef] < 0)
s->mclms_coeffs_cur[ich * num_channels + j] += 1;
}
} }
} }
@ -658,11 +652,7 @@ static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
else if (s->channel_residues[ich][icoef] < -range) else if (s->channel_residues[ich][icoef] < -range)
s->mclms_prevvalues[s->mclms_recent] = -range; s->mclms_prevvalues[s->mclms_recent] = -range;
s->mclms_updates[s->mclms_recent] = 0; s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]);
if (s->channel_residues[ich][icoef] > 0)
s->mclms_updates[s->mclms_recent] = 1;
else if (s->channel_residues[ich][icoef] < 0)
s->mclms_updates[s->mclms_recent] = -1;
} }
if (s->mclms_recent == 0) { if (s->mclms_recent == 0) {
@ -724,12 +714,7 @@ static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input)
} }
s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1); s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1);
if (!input) s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich];
s->cdlms[ich][ilms].lms_updates[recent] = 0;
else if (input < 0)
s->cdlms[ich][ilms].lms_updates[recent] = -s->update_speed[ich];
else
s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich];
s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2;
s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1;
@ -773,9 +758,6 @@ static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
s->update_speed[ich] = 8; s->update_speed[ich] = 8;
} }
/** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
#define WMASIGN(x) ((x > 0) - (x < 0))
static void revert_cdlms(WmallDecodeCtx *s, int ch, static void revert_cdlms(WmallDecodeCtx *s, int ch,
int coef_begin, int coef_end) int coef_begin, int coef_end)
{ {

Loading…
Cancel
Save