[FFmpeg-soc] [soc]AMR-WB decoder branch, master, updated.

Marcelo Póvoa marspeoplester at gmail.com
Sat Jul 24 04:37:56 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  97cc97cb5735e660655029a0820fb8baf7fbd256 (commit)
       via  112b01c4d00b126a982b3ce83884ad13ffa46343 (commit)
      from  30af71e0fb3351656d148d939ba401c980304d4f (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 97cc97cb5735e660655029a0820fb8baf7fbd256
Author: Marcelo Povoa <marspeoplester at gmail.com>
Date:   Fri Jul 23 22:32:49 2010 -0300

    Test pulses decoding, fix typo in decode_5p_track,
    update excitation for next subframe

diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 489f9ad..0fb6da7 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -430,12 +430,14 @@ static void decode_pitch_vector(AMRWBContext *ctx,
 
     /* Calculate the pitch vector by interpolating the past excitation at the
        pitch lag using a hamming windowed sinc function. */
+    /* XXX: Not tested yet, need to ensure correct excitation construction before */
     ff_acelp_interpolatef(exc, exc + 1 - pitch_lag_int,
                           ac_inter, 4,
                           pitch_lag_frac + 4 - 4*(pitch_lag_frac > 0),
                           LP_ORDER, AMRWB_SUBFRAME_SIZE);
 
-    /* Check which pitch signal path should be used */
+    /* Check which pitch signal path should be used.
+     * 6k60 and 8k85 modes have ltp flag set to 0 */
     if (amr_subframe->ltp) {
         memcpy(ctx->pitch_vector, exc, AMRWB_SUBFRAME_SIZE * sizeof(float));
     } else {
@@ -526,9 +528,9 @@ static void decode_5p_track(int *out, int code, int m, int off)
 {   ///code: 5m bits
     int half_3p = BIT_POS(code, 5*m - 1) << (m - 1);
 
-    decode_3p_track(out, BIT_STR(code, 2*m, 3*m - 2),
+    decode_3p_track(out, BIT_STR(code, 2*m + 1, 3*m - 2),
                     m - 1, off + half_3p);
-    // XXX: there seems to be a typo in I3p expoent (from reference)
+
     decode_2p_track(out + 3, BIT_STR(code, 0, 2*m + 1), m, off);
 }
 
@@ -1070,6 +1072,9 @@ static void extrapolate_isf(float *out, float *isf)
  */
 static void update_sub_state(AMRWBContext *ctx)
 {
+    memmove(&ctx->excitation_buf[0], &ctx->excitation_buf[AMRWB_SUBFRAME_SIZE],
+            (AMRWB_P_DELAY_MAX + LP_ORDER + 1) * sizeof(float));
+
     memmove(&ctx->pitch_gain[0], &ctx->pitch_gain[1], 4 * sizeof(float));
     memmove(&ctx->fixed_gain[0], &ctx->fixed_gain[1], 4 * sizeof(float));
 }
@@ -1126,8 +1131,6 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     for (sub = 0; sub < 4; sub++)
         isp2lp(ctx->isp[sub], ctx->lp_coef[sub], LP_ORDER/2);
 
-    /* XXX: Tested against the ref code until here */
-
     for (sub = 0; sub < 4; sub++) {
         const AMRWBSubFrame *cur_subframe = &cf->subframe[sub];
 
@@ -1140,6 +1143,7 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         decode_gains(cur_subframe->vq_gain, ctx->fr_cur_mode,
                      &fixed_gain_factor, &ctx->pitch_gain[4]);
 
+        /* XXX: not tested yet */
         pitch_sharpening(ctx, &fixed_sparse, ctx->fixed_vector);
 
         ctx->fixed_gain[4] =
@@ -1154,6 +1158,8 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                                       ctx->fixed_vector, ctx->fixed_gain[4]);
         ctx->tilt_coef = voice_fac * 0.25 + 0.25;
 
+        /* XXX: Tested against the ref code until here */
+
         /* Construct current excitation */
         for (i = 0; i < AMRWB_SUBFRAME_SIZE; i++) {
             ctx->excitation[i] *= ctx->pitch_gain[4];

commit 112b01c4d00b126a982b3ce83884ad13ffa46343
Author: Marcelo Povoa <marspeoplester at gmail.com>
Date:   Fri Jul 23 15:55:55 2010 -0300

    Pitch lag testing: bound past lag, unify 6k60 and 8k85
    decodings, need to check round versus floor usage

diff --git a/libavcodec/amrwbdata.h b/libavcodec/amrwbdata.h
index 7f221e4..93e76d5 100644
--- a/libavcodec/amrwbdata.h
+++ b/libavcodec/amrwbdata.h
@@ -34,7 +34,9 @@
 #define AMRWB_SUBFRAME_SIZE   64               ///< samples per subframe at 12.8 kHz
 #define AMRWB_SFR_SIZE_OUT    80               ///< samples per subframe at 16 kHz
 #define AMRWB_SAMPLE_BOUND    32768.0          ///< threshold for synthesis overflow
-#define PITCH_MAX             231              ///< maximum received pitch delay value
+
+#define AMRWB_P_DELAY_MAX     231              ///< maximum pitch delay value
+#define AMRWB_P_DELAY_MIN     34
 
 #define PREEMPH_FAC           0.68             ///< factor used to de-emphasize synthesis
 
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 4f0e765..489f9ad 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -56,7 +56,7 @@ typedef struct {
     uint8_t                       base_pitch_lag; ///< integer part of pitch lag for next relative subframe
     uint8_t                        pitch_lag_int; ///< integer part of pitch lag of the previous subframe
 
-    float excitation_buf[PITCH_MAX + LP_ORDER + 1 + AMRWB_SUBFRAME_SIZE]; ///< current excitation and all necessary excitation history
+    float excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 1 + AMRWB_SUBFRAME_SIZE]; ///< current excitation and all necessary excitation history
     float                            *excitation; ///< points to current excitation in excitation_buf[]
 
     float      pitch_vector[AMRWB_SUBFRAME_SIZE]; ///< adaptive codebook (pitch) vector for current subframe
@@ -90,7 +90,7 @@ static av_cold int amrwb_decode_init(AVCodecContext *avctx)
 
     av_lfg_init(&ctx->prng, 1);
 
-    ctx->excitation  = &ctx->excitation_buf[PITCH_MAX + LP_ORDER + 1];
+    ctx->excitation  = &ctx->excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 1];
     ctx->first_frame = 1;
     ctx->tilt_coef   = ctx->prev_tr_gain = 0.0;
 
@@ -254,11 +254,11 @@ static void decode_isf_indices_46b(uint16_t *ind, float *isf_q, uint8_t fr_q) {
  * Apply mean and past ISF values using the prediction factor
  * Updates past ISF vector
  *
- * @param isf_q               [in] current quantized ISF
+ * @param isf_q               [in/out] current quantized ISF
  * @param isf_past            [in/out] past quantized ISF
  *
  */
-static void isf_add_mean_and_past(const float *isf_q, float *isf_past) {
+static void isf_add_mean_and_past(float *isf_q, float *isf_past) {
     int i;
     float tmp;
 
@@ -295,7 +295,7 @@ static void isf_set_min_dist(float *isf, float min_spacing, int size) {
  * @param isp_q               [in/out] ISPs for each subframe
  * @param isp4_past           [in] Past ISP for subframe 4
  */
-static void interpolate_isp(double *isp_q[4], const double *isp4_past)
+static void interpolate_isp(double isp_q[4][LP_ORDER], const double *isp4_past)
 {
     int i;
     // XXX: Did not use ff_weighted_vector_sumf because using double
@@ -355,7 +355,7 @@ static void isp2lp(const double *isp, float *lp, int lp_half_order) {
  * @param subframe            [in] Current subframe index (0 to 3)
  */
 static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index,
-                                  uint8_t *base_lag_int, const int subframe)
+                                  uint8_t *base_lag_int, int subframe)
 {
     if (subframe == 0 || subframe == 2) {
         if (pitch_index < 376) {
@@ -369,47 +369,30 @@ static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index,
             *lag_int  = pitch_index - 280;
             *lag_frac = 0;
         }
-        *base_lag_int = *lag_int; // store previous lag
+        /* minimum lag for next subframe */
+        *base_lag_int = av_clip(*lag_int - 8, AMRWB_P_DELAY_MIN,
+                                AMRWB_P_DELAY_MAX - 15);
+        /* XXX: the spec states clearly that *base_lag_int should be
+         * the nearest integer to *lag_int (minus 8), but the ref code
+         * actually uses always its floor, causing the next frame integer
+         * lag to be one less than mine when the nearest integer is
+         * not equal to the floor */
     } else {
         *lag_int  = (pitch_index + 1) >> 2;
         *lag_frac = pitch_index - (*lag_int << 2);
-        *lag_int += *base_lag_int - 8;
-        // XXX: Doesn't seem to need bounding according to TS 26.190
+        *lag_int += *base_lag_int;
     }
 }
 
 /**
- * Decode a adaptive codebook index into pitch lag for 8k85 mode
- * Description is analogous to decode_pitch_lag_high
- */
-static void decode_pitch_lag_8K85(int *lag_int, int *lag_frac, int pitch_index,
-                                  uint8_t *base_lag_int, const int subframe)
-{
-    if (subframe == 0 || subframe == 2) {
-        if (pitch_index < 116) {
-            *lag_int  = (pitch_index + 69) >> 1;
-            *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1;
-        } else {
-            *lag_int  = pitch_index - 24;
-            *lag_frac = 0;
-        }
-        *base_lag_int = *lag_int;
-    } else {
-        *lag_int  = (pitch_index + 1) >> 1;
-        *lag_frac = pitch_index - (*lag_int << 1);
-        *lag_int += *base_lag_int - 8;
-    }
-}
-
-/**
- * Decode a adaptive codebook index into pitch lag for 6k60 mode
- * Description is analogous to decode_pitch_lag_high, but relative
+ * Decode a adaptive codebook index into pitch lag for 8k85 and 6k60 modes
+ * Description is analogous to decode_pitch_lag_high, but in 6k60 relative
  * index is used for all subframes except the first
  */
-static void decode_pitch_lag_6K60(int *lag_int, int *lag_frac, int pitch_index,
-                                  uint8_t *base_lag_int, const int subframe)
+static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index,
+                        uint8_t *base_lag_int, int subframe, enum Mode mode)
 {
-    if (subframe == 0) {
+    if (subframe == 0 || (subframe == 2 && mode != MODE_6k60)) {
         if (pitch_index < 116) {
             *lag_int  = (pitch_index + 69) >> 1;
             *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1;
@@ -417,11 +400,12 @@ static void decode_pitch_lag_6K60(int *lag_int, int *lag_frac, int pitch_index,
             *lag_int  = pitch_index - 24;
             *lag_frac = 0;
         }
-        *base_lag_int = *lag_int;
+        *base_lag_int = av_clip(*lag_int - 8, AMRWB_P_DELAY_MIN,
+                                AMRWB_P_DELAY_MAX - 15);
     } else {
         *lag_int  = (pitch_index + 1) >> 1;
         *lag_frac = pitch_index - (*lag_int << 1);
-        *lag_int += *base_lag_int - 8;
+        *lag_int += *base_lag_int;
     }
 }
 
@@ -434,12 +418,9 @@ static void decode_pitch_vector(AMRWBContext *ctx,
     float *exc     = ctx->excitation;
     enum Mode mode = ctx->fr_cur_mode;
 
-    if (mode == MODE_6k60) {
-        decode_pitch_lag_6K60(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
-                              &ctx->base_pitch_lag, subframe);
-    } else if (mode == MODE_8k85) {
-        decode_pitch_lag_8K85(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
-                              &ctx->base_pitch_lag, subframe);
+    if (mode <= MODE_8k85) {
+        decode_pitch_lag_low(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
+                              &ctx->base_pitch_lag, subframe, mode);
     } else
         decode_pitch_lag_high(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
                               &ctx->base_pitch_lag, subframe);
@@ -1010,9 +991,8 @@ static float find_hb_gain(AMRWBContext *ctx, const float *synth,
            ff_dot_productf(synth, synth, AMRWB_SUBFRAME_SIZE);
 
     tilt = FFMAX(0.0, tilt);
-
     /* return gain bounded by [0.1, 1.0] */
-    return FFMAX(0.1, FFMIN(1.0, (1.0 - tilt) * (1.25 - 0.25 * wsp)));
+    return av_clipf((1.0 - tilt) * (1.25 - 0.25 * wsp), 0.1, 1.0);
 }
 
 /**

-----------------------------------------------------------------------

Summary of changes:
 libavcodec/amrwbdata.h |    4 ++-
 libavcodec/amrwbdec.c  |   90 ++++++++++++++++++++---------------------------
 2 files changed, 41 insertions(+), 53 deletions(-)


hooks/post-receive
-- 
AMR-WB decoder


More information about the FFmpeg-soc mailing list