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

Marcelo Póvoa marspeoplester at gmail.com
Thu Jul 8 02:02:30 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  2983a53df354f9bfbb8234805b23bd16b40c693a (commit)
      from  d29085706f26b6691f8d3a74c07b23cd02cf9785 (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 2983a53df354f9bfbb8234805b23bd16b40c693a
Author: Marcelo Povoa <marspeoplester at gmail.com>
Date:   Wed Jul 7 20:59:46 2010 -0300

    Decode pulse index for modes 6k60 8k85 12k65 14k25

diff --git a/libavcodec/acelp_vectors.h b/libavcodec/acelp_vectors.h
index ba3437f..08ca212 100644
--- a/libavcodec/acelp_vectors.h
+++ b/libavcodec/acelp_vectors.h
@@ -28,8 +28,8 @@
 /** Sparse representation for the algebraic codebook (fixed) vector */
 typedef struct {
     int      n;
-    int      x[10];
-    float    y[10];
+    int      x[24];
+    float    y[24];
     int      no_repeat_mask;
     int      pitch_lag;
     float    pitch_fac;
diff --git a/libavcodec/amrwbdata.h b/libavcodec/amrwbdata.h
index 727022e..8422313 100644
--- a/libavcodec/amrwbdata.h
+++ b/libavcodec/amrwbdata.h
@@ -1637,6 +1637,13 @@ static const float ac_inter[65] = {
    0.000098,   0.000048,   0.000007,   0.000000
 };
 
+/* [i][j] is the number of pulses in track j at mode i */
+static const int pulses_nb_per_mode_tr[][4] = {
+    {1, 1, 0, 0}, {1, 1, 1, 1}, {2, 2, 2, 2},
+    {3, 3, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4},
+    {5, 5, 4, 4}, {6, 6, 6, 6}, {6, 6, 6, 6}
+};
+
 /* Core frame sizes in each mode */
 static const uint16_t cf_sizes_wb[] = {
     132, 177, 253, 285, 317, 365, 397, 461, 477,
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 8cd0925..a93fa9d 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -23,9 +23,16 @@
 #include "get_bits.h"
 #include "lsp.h"
 #include "acelp_filters.h"
+#include "acelp_vectors.h"
 
 #include "amrwbdata.h"
 
+/** Get x bits in the index interval [lsb,lsb+len-1] inclusive */
+#define BIT_STR(x,lsb,len) (((x) >> (lsb)) & ((1 << (len)) - 1))
+
+/** Get the bit at specified position */
+#define BIT_POS(x, p) (((x) >> (p)) & 1)
+
 typedef struct {
     AMRWBFrame                             frame; ///< AMRWB parameters decoded from bitstream
     enum Mode                        fr_cur_mode; ///< mode index of current frame
@@ -413,6 +420,101 @@ static void decode_pitch_vector(AMRWBContext *ctx,
     }
 }
 
+/**
+ * The next six functions decode_[i]p_track decode exactly i pulses
+ * positions and amplitudes (-1 or 1) in a subframe track using
+ * an encoded pulse indexing (TS 26.190 section 5.8.2).
+ *
+ * The results are given in out[], in which a negative number means
+ * amplitude -1 and vice-versa. (i.e., ampl = x/abs(x) )
+ *
+ * @param out                 [out] Output buffer (writes i elements)
+ * @param code                [in] Pulse index (no. of bits varies, see below)
+ * @param m                   [in] (log2) Number of potential positions
+ */
+//XXX : Some of these functions are simple and recurrent (used inline)
+
+static inline void decode_1p_track(int *out, int code, int m) ///code: m+1 bits
+{
+    int pos = BIT_STR(code, 0, m);
+    
+    out[0] = BIT_POS(code, m) ? -pos : pos;
+}
+
+static inline void decode_2p_track(int *out, int code, int m) ///code: 2m+1 bits
+{
+    int pos0 = BIT_STR(code, m, m);
+    int pos1 = BIT_STR(code, 0, m);
+    
+    out[0] = BIT_POS(code, 2*m) ? -pos0 : pos0;
+    out[1] = BIT_POS(code, 2*m) ? -pos1 : pos1;
+    out[1] = pos0 > pos1 ? -out[1] : out[1];
+}
+
+static void decode_3p_track(int *out, int code, int m)        ///code: 3m+1 bits 
+{
+    int half_2p = BIT_POS(code, 2*m-1) << (m-1);
+    
+    decode_2p_track(out, BIT_STR(code, 0, 2*m-1), m-1);
+    // put two decoded pulses (+ or -) in the correct half
+    out[0] += (out[0] > 0) ? half_2p : -half_2p; 
+    out[1] += (out[1] > 0) ? half_2p : -half_2p;
+    decode_1p_track(out + 2, BIT_STR(code, 2*m, m+1), m);
+}
+
+/**
+ * Decode the algebraic codebook index to pulse positions and signs,
+ * then construct the algebraic codebook vector.
+ *
+ * @param fixed_sparse        pointer to the algebraic (innovative) codebook
+ * @param pulse_hi            MSBs part of the pulse index array (used in higher modes)
+ * @param pulse_lo            LSBs part of the pulse index array
+ * @param mode                mode of the current frame
+ */
+// For now, uses the same AMRFixed struct from AMR-NB but
+// the maximum number of pulses in it was increased to 24
+static void decode_fixed_sparse(AMRFixed *fixed_sparse, const uint16_t *pulse_hi,
+                                const uint16_t *pulse_lo, const enum Mode mode)
+{
+    /* sig_pos stores for each track the decoded pulse position
+     * indexes multiplied by its corresponding amplitude (+1 or -1) */
+    int sig_pos[4][6];
+    int pulses_nb = 0;
+    int spacing = (mode == MODE_6k60) ? 2 : 4;
+    int i, j;
+    
+    switch (mode) {
+        case MODE_6k60:
+            for (i = 0; i < 2; i++)
+                decode_1p_track(sig_pos[i], pulse_lo[i], 5);
+            break;
+        case MODE_8k85:
+            for (i = 0; i < 4; i++)
+                decode_1p_track(sig_pos[i], pulse_lo[i], 4);
+            break;
+        case MODE_12k65:
+            for (i = 0; i < 4; i++)
+                decode_2p_track(sig_pos[i], pulse_lo[i], 4);
+            break;
+        case MODE_14k25:
+            for (i = 0; i < 2; i++)
+                decode_3p_track(sig_pos[i], pulse_lo[i], 4);
+            for (i = 2; i < 4; i++)
+                decode_2p_track(sig_pos[i], pulse_lo[i], 4);
+            break;
+    }
+
+    for (i = 0; i < 4; i++)
+        for (j = 0; j < pulses_nb_per_mode_tr[mode][i]; j++) {
+            int pos = sig_pos[i][j];
+            fixed_sparse->x[pulses_nb] = FFABS(pos) * spacing + i;
+            fixed_sparse->y[pulses_nb] = pos < 0 ? -1.0 : 1.0;
+            pulses_nb++;
+        }
+    
+    fixed_sparse->n = pulses_nb;
+}
+
 static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                               AVPacket *avpkt)
 {
@@ -420,6 +522,7 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     AMRWBFrame   *cf   = &ctx->frame;  
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
+    AMRFixed fixed_sparse = {0};             // fixed vector up to anti-sparseness processing
     int sub;
     
     ctx->fr_cur_mode = unpack_bitstream(ctx, buf, buf_size);
@@ -454,6 +557,9 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         const AMRWBSubFrame *cur_subframe = &cf->subframe[sub];
 
         decode_pitch_vector(ctx, cur_subframe, sub);
+        
+        decode_fixed_sparse(&fixed_sparse, cur_subframe->pul_ih,
+                            cur_subframe->pul_il, ctx->fr_cur_mode);
     }
     
     //update state for next frame

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

Summary of changes:
 libavcodec/acelp_vectors.h |    4 +-
 libavcodec/amrwbdata.h     |    7 +++
 libavcodec/amrwbdec.c      |  106 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
AMR-WB decoder


More information about the FFmpeg-soc mailing list