[FFmpeg-soc] [soc]AMR-WB decoder branch, master, updated.
Marcelo Póvoa
marspeoplester at gmail.com
Thu Jul 15 00:12:46 CEST 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "AMR-WB decoder".
The branch, master has been updated
via e9202459e44d5760dd5fadd8a7fa6ded9af6a398 (commit)
via fd34bb941fab51bf3f8ec752bb744647528a827c (commit)
from 4b95cefc49b723ea5e2ce3ac016b0817ec41752f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e9202459e44d5760dd5fadd8a7fa6ded9af6a398
Author: Marcelo Povoa <marspeoplester at gmail.com>
Date: Wed Jul 14 19:11:02 2010 -0300
Move voice factor out of the subframe update state
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index b1469c4..7b02188 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -276,7 +276,7 @@ static void isf_set_min_dist(float *isf, float min_spacing, int size) {
static void interpolate_isp(double isp_q[4][LP_ORDER], double *isp4_past)
{
int i;
- // XXX: Did not used ff_weighted_vector_sumf because using double
+ // XXX: Did not use ff_weighted_vector_sumf because using double
for (i = 0; i < LP_ORDER; i++)
isp_q[0][i] = 0.55 * isp4_past[i] + 0.45 * isp_q[3][i];
@@ -784,7 +784,6 @@ static const float *anti_sparseness(AMRWBContext *ctx,
}
/**
- * Update context state before the next subframe
* Calculate a stability factor {teta} based on distance between
* current and past isf. A value of 1 shows maximum signal stability.
*/
@@ -803,18 +802,14 @@ static float stability_factor(const float *isf, const float *isf_past)
* Apply a non-linear fixed gain smoothing in order to reduce
* fluctuation in the energy of excitation. Returns smoothed gain.
*
- * @param ctx [in] the context
* @param fixed_gain [in] unsmoothed fixed gain
* @param prev_tr_gain [in/out] previous threshold gain (updated)
* @param voice_fac [in] frame voicing factor
* @param stab_fac [in] frame stability factor
*/
-static void update_sub_state(AMRWBContext *ctx)
static float noise_enhancer(float fixed_gain, float *prev_tr_gain,
float voice_fac, float stab_fac)
{
- ctx->tilt_coef = voice_factor(ctx->pitch_vector, ctx->pitch_gain[4],
- ctx->fixed_vector, ctx->fixed_gain[4]) * 0.25 + 0.25;
float sm_fac = 0.5 * (1 - voice_fac) * stab_fac;
float g0;
@@ -836,6 +831,12 @@ static float noise_enhancer(float fixed_gain, float *prev_tr_gain,
return sm_fac * g0 + (1 - sm_fac) * fixed_gain;
}
+
+/**
+ * Update context state before the next subframe
+ */
+static void update_sub_state(AMRWBContext *ctx)
+{
memmove(&ctx->pitch_gain[0], &ctx->pitch_gain[1], 4 * sizeof(float));
memmove(&ctx->fixed_gain[0], &ctx->fixed_gain[1], 4 * sizeof(float));
}
@@ -905,6 +906,11 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AMRWB_SUBFRAME_SIZE)/AMRWB_SUBFRAME_SIZE,
ctx->prediction_error,
ENERGY_MEAN, energy_pred_fac);
+
+ /* Calculate voice factor and store tilt for next subframe */
+ voice_fac = voice_factor(ctx->pitch_vector, ctx->pitch_gain[4],
+ ctx->fixed_vector, ctx->fixed_gain[4]);
+ ctx->tilt_coef = voice_fac * 0.25 + 0.25;
/* Construct current excitation */
for (i = 0; i < AMRWB_SUBFRAME_SIZE; i++) {
commit fd34bb941fab51bf3f8ec752bb744647528a827c
Author: Marcelo Povoa <marspeoplester at gmail.com>
Date: Wed Jul 14 19:08:19 2010 -0300
Write a sketch of noise enhancer
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 5469791..b1469c4 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -66,6 +66,7 @@ typedef struct {
float prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness to determine "onset"
uint8_t prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none
+ float prev_tr_gain; ///< previous initial gain used by noise enhancer for thresold
} AMRWBContext;
static int amrwb_decode_init(AVCodecContext *avctx)
@@ -80,7 +81,7 @@ static int amrwb_decode_init(AVCodecContext *avctx)
ctx->isp_sub4_past[i] = isp_init[i] / (float) (1 << 15);
}
- ctx->tilt_coef = 0;
+ ctx->tilt_coef = ctx->prev_tr_gain = 0.0;
for (i = 0; i < 4; i++)
ctx->prediction_error[i] = MIN_ENERGY;
@@ -784,14 +785,57 @@ static const float *anti_sparseness(AMRWBContext *ctx,
/**
* Update context state before the next subframe
+ * Calculate a stability factor {teta} based on distance between
+ * current and past isf. A value of 1 shows maximum signal stability.
+ */
+static float stability_factor(const float *isf, const float *isf_past)
+{
+ int i;
+ float acc = 0.0;
+
+ for (i = 0; i < LP_ORDER - 1; i++)
+ acc += (isf[i] - isf_past[i]) * (isf[i] - isf_past[i]);
+
+ return 1.25 - acc * 0.8 / 256;
+}
+
+/**
+ * Apply a non-linear fixed gain smoothing in order to reduce
+ * fluctuation in the energy of excitation. Returns smoothed gain.
*
* @param ctx [in] the context
+ * @param fixed_gain [in] unsmoothed fixed gain
+ * @param prev_tr_gain [in/out] previous threshold gain (updated)
+ * @param voice_fac [in] frame voicing factor
+ * @param stab_fac [in] frame stability factor
*/
static void update_sub_state(AMRWBContext *ctx)
+static float noise_enhancer(float fixed_gain, float *prev_tr_gain,
+ float voice_fac, float stab_fac)
{
ctx->tilt_coef = voice_factor(ctx->pitch_vector, ctx->pitch_gain[4],
ctx->fixed_vector, ctx->fixed_gain[4]) * 0.25 + 0.25;
+ float sm_fac = 0.5 * (1 - voice_fac) * stab_fac;
+ float g0;
+
+ /* XXX: here it is supposed to "in(de)crement the fixed gain by 1.5dB"
+ * in each case, but the reference source (lines 812 onwards of
+ * dec_main.c) multiplies gain by strange constants that need checking
+ */
+ if (fixed_gain < *prev_tr_gain) {
+ // increment fixed_gain by 1.5dB ?
+ g0 = FFMIN(*prev_tr_gain, fixed_gain + ( fixed_gain *
+ (6226 / (float) (1 << 15))));
+ } else
+ // decrement fixed_gain by 1.5dB ?
+ g0 = FFMAX(*prev_tr_gain, fixed_gain *
+ (27536 / (float) (1 << 15)));
+
+ // update next frame threshold
+ *prev_tr_gain = g0;
+ return sm_fac * g0 + (1 - sm_fac) * fixed_gain;
+}
memmove(&ctx->pitch_gain[0], &ctx->pitch_gain[1], 4 * sizeof(float));
memmove(&ctx->fixed_gain[0], &ctx->fixed_gain[1], 4 * sizeof(float));
}
@@ -807,6 +851,8 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
float spare_vector[AMRWB_SUBFRAME_SIZE]; // extra stack space to hold result from anti-sparseness processing
float fixed_gain_factor; // fixed gain correction factor (gamma)
const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use
+ float synth_fixed_gain; // the fixed gain that synthesis should use
+ float voice_fac, stab_fac; // parameters used for gain smoothing
int sub, i;
ctx->fr_cur_mode = unpack_bitstream(ctx, buf, buf_size);
@@ -826,6 +872,8 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
else {
decode_isf_indices_46b(cf->isp_id, ctx->isf_quant, ctx->fr_quality);
}
+
+ stab_fac = stability_factor(ctx->isf_quant, ctx->isf_q_past);
isf_add_mean_and_past(ctx->isf_quant, ctx->isf_q_past);
isf_set_min_dist(ctx->isf_quant, MIN_ISF_SPACING, LP_ORDER);
@@ -867,6 +915,9 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
// XXX: Should remove fractional part of excitation like NB?
// I did not found a reference of this in the ref decoder
}
+
+ synth_fixed_gain = noise_enhancer(ctx->fixed_gain[4], &ctx->prev_tr_gain,
+ voice_fac, stab_fac);
synth_fixed_vector = anti_sparseness(ctx, ctx->fixed_vector,
spare_vector);
-----------------------------------------------------------------------
Summary of changes:
libavcodec/amrwbdec.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 64 insertions(+), 7 deletions(-)
hooks/post-receive
--
AMR-WB decoder
More information about the FFmpeg-soc
mailing list