[FFmpeg-soc] [soc] soc g723.1 57a9ec97a9febb4244437c1ff2bdf0150ce4e8c7

naufal11 at gmail.com naufal11 at gmail.com
Tue Jun 15 15:14:22 CEST 2010



- Log -----------------------------------------------------------------
commit 57a9ec97a9febb4244437c1ff2bdf0150ce4e8c7
Author: Naufal <naufal11 at gmail.com>
Date:   Tue Jun 15 18:40:52 2010 +0530

    Perform LSP interpolation, compute LPC coeffs

diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c
index f1bef98..1abf8aa 100755
--- a/libavcodec/g723_1.c
+++ b/libavcodec/g723_1.c
@@ -1,6 +1,8 @@
 #include "avcodec.h"
 #define ALT_BITSTREAM_READER_LE
 #include "get_bits.h"
+#include "acelp_vectors.h"
+#include "lsp.h"
 #include "g723_1_data.h"
 
 typedef struct g723_1_context {
@@ -218,6 +220,44 @@ static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, int8_t *lsp_index
         memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(int16_t));
 }
 
+/*
+ * Quantize LSP frequencies by interpolation and convert them to
+ * the corresponding LPC coefficients.
+ *
+ * @param lpc      buffer for LPC coefficients
+ * @param cur_lsp  the current LSP vector
+ * @param prev_lsp the previous LSP vector
+ */
+static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
+{
+    int i, j;
+    int16_t *ptr = lpc;
+
+    // cur_lsp * 0.25 + prev_lsp * 0.75
+    ff_acelp_weighted_vector_sum(&lpc[1], cur_lsp, prev_lsp,
+                                 4096, 12288, 1 << 13, 14, LPC_ORDER);
+    ff_acelp_weighted_vector_sum(&lpc[LPC_ORDER + 1], cur_lsp, prev_lsp,
+                                 8192, 8192, 1 << 13, 14, LPC_ORDER);
+    ff_acelp_weighted_vector_sum(&lpc[LPC_ORDER * 2 + 2], cur_lsp, prev_lsp,
+                                 12288, 4096, 1 << 13, 14, LPC_ORDER);
+    memcpy(&lpc[LPC_ORDER * 3 + 3], cur_lsp, LPC_ORDER * sizeof(int16_t));
+
+    for (i = 0; i < SUBFRAMES; i++) {
+        // Calculate cosine
+        for (j = 1; j <= LPC_ORDER; j++) {
+            int index      = ptr[j] >> 7;
+            int offset     = ptr[j] & 0x7f;
+            int64_t temp1  = cos_tab[index] << 16;
+            int temp2      = (cos_tab[index + 1] - cos_tab[index]) *
+                             ((offset << 8) + 0x80) << 1;
+            ptr[j] = av_clipl_int32(((temp1 + temp2) << 1) + (1 << 15)) >> 16;
+        }
+
+        ff_acelp_lsp2lpc(ptr, ptr, LPC_ORDER >> 1);
+        ptr += LPC_ORDER + 1;
+    }
+}
+
 static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
                               int *data_size, AVPacket *avpkt)
 {
@@ -226,6 +266,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     int buf_size       = avpkt->size;
 
     int16_t cur_lsp[LPC_ORDER];
+    int16_t lpc[SUBFRAMES * LPC_ORDER + 4];
     int bad_frame, erased_frames;
 
     if (!buf_size || buf_size < frame_size[buf[0] & 3]) {
@@ -246,6 +287,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
             erased_frames++;
 
         inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame);
+        lsp_interpolate(lpc, cur_lsp, p->prev_lsp);
     }
 
     return frame_size[p->cur_frame_type];
diff --git a/libavcodec/g723_1_data.h b/libavcodec/g723_1_data.h
index b67e6c6..4d6a9f0 100644
--- a/libavcodec/g723_1_data.h
+++ b/libavcodec/g723_1_data.h
@@ -53,6 +53,77 @@ static const int16_t dc_lsp[LPC_ORDER] = {
 };
 
 /*
+ * Cosine table scaled by 2^14
+ * FIXME: move elsewhere?
+ */
+static const int16_t cos_tab[512] = {
+   16384,  16383,  16379,  16373,  16364,  16353,  16340,  16324,
+   16305,  16284,  16261,  16235,  16207,  16176,  16143,  16107,
+   16069,  16029,  15986,  15941,  15893,  15843,  15791,  15736,
+   15679,  15619,  15557,  15493,  15426,  15357,  15286,  15213,
+   15137,  15059,  14978,  14896,  14811,  14724,  14635,  14543,
+   14449,  14354,  14256,  14155,  14053,  13949,  13842,  13733,
+   13623,  13510,  13395,  13279,  13160,  13039,  12916,  12792,
+   12665,  12537,  12406,  12274,  12140,  12004,  11866,  11727,
+   11585,  11442,  11297,  11151,  11003,  10853,  10702,  10549,
+   10394,  10238,  10080,   9921,   9760,   9598,   9434,   9269,
+    9102,   8935,   8765,   8595,   8423,   8250,   8076,   7900,
+    7723,   7545,   7366,   7186,   7005,   6823,   6639,   6455,
+    6270,   6084,   5897,   5708,   5520,   5330,   5139,   4948,
+    4756,   4563,   4370,   4176,   3981,   3786,   3590,   3393,
+    3196,   2999,   2801,   2603,   2404,   2205,   2006,   1806,
+    1606,   1406,   1205,   1005,    804,    603,    402,    201,
+       0,   -201,   -402,   -603,   -804,   -100,  -1205,  -1406,
+   -1606,  -1806,  -2006,  -2205,  -2404,  -2603,  -2801,  -2999,
+   -3196,  -3393,  -3590,  -3786,  -3981,  -4176,  -4370,  -4563,
+   -4756,  -4948,  -5139,  -5330,  -5520,  -5708,  -5897,  -6084,
+   -6270,  -6455,  -6639,  -6823,  -7005,  -7186,  -7366,  -7545,
+   -7723,  -7900,  -8076,  -8250,  -8423,  -8595,  -8765,  -8935,
+   -9102,  -9269,  -9434,  -9598,  -9760,  -9921, -10080, -10238,
+  -10394, -10549, -10702, -10853, -11003, -11151, -11297, -11442,
+  -11585, -11727, -11866, -12004, -12140, -12274, -12406, -12537,
+  -12665, -12792, -12916, -13039, -13160, -13279, -13395, -13510,
+  -13623, -13733, -13842, -13949, -14053, -14155, -14256, -14354,
+  -14449, -14543, -14635, -14724, -14811, -14896, -14978, -15059,
+  -15137, -15213, -15286, -15357, -15426, -15493, -15557, -15619,
+  -15679, -15736, -15791, -15843, -15893, -15941, -15986, -16029,
+  -16069, -16107, -16143, -16176, -16207, -16235, -16261, -16284,
+  -16305, -16324, -16340, -16353, -16364, -16373, -16379, -16383,
+  -16384, -16383, -16379, -16373, -16364, -16353, -16340, -16324,
+  -16305, -16284, -16261, -16235, -16207, -16176, -16143, -16107,
+  -16069, -16029, -15986, -15941, -15893, -15843, -15791, -15736,
+  -15679, -15619, -15557, -15493, -15426, -15357, -15286, -15213,
+  -15137, -15059, -14978, -14896, -14811, -14724, -14635, -14543,
+  -14449, -14354, -14256, -14155, -14053, -13949, -13842, -13733,
+  -13623, -13510, -13395, -13279, -13160, -13039, -12916, -12792,
+  -12665, -12537, -12406, -12274, -12140, -12004, -11866, -11727,
+  -11585, -11442, -11297, -11151, -11003, -10853, -10702, -10549,
+  -10394, -10238, -10080,  -9921,  -9760,  -9598,  -9434,  -9269,
+   -9102,  -8935,  -8765,  -8595,  -8423,  -8250,  -8076,  -7900,
+   -7723,  -7545,  -7366,  -7186,  -7005,  -6823,  -6639,  -6455,
+   -6270,  -6084,  -5897,  -5708,  -5520,  -5330,  -5139,  -4948,
+   -4756,  -4563,  -4370,  -4176,  -3981,  -3786,  -3590,  -3393,
+   -3196,  -2999,  -2801,  -2603,  -2404,  -2205,  -2006,  -1806,
+   -1606,  -1406,  -1205,  -1005,   -804,   -603,   -402,   -201,
+       0,    201,    402,    603,    804,   1005,   1205,   1406,
+    1606,   1806,   2006,   2205,   2404,   2603,   2801,   2999,
+    3196,   3393,   3590,   3786,   3981,   4176,   4370,   4563,
+    4756,   4948,   5139,   5330,   5520,   5708,   5897,   6084,
+    6270,   6455,   6639,   6823,   7005,   7186,   7366,   7545,
+    7723,   7900,   8076,   8250,   8423,   8595,   8765,   8935,
+    9102,   9269,   9434,   9598,   9760,   9921,  10080,  10238,
+   10394,  10549,  10702,  10853,  11003,  11151,  11297,  11442,
+   11585,  11727,  11866,  12004,  12140,  12274,  12406,  12537,
+   12665,  12792,  12916,  13039,  13160,  13279,  13395,  13510,
+   13623,  13733,  13842,  13949,  14053,  14155,  14256,  14354,
+   14449,  14543,  14635,  14724,  14811,  14896,  14978,  15059,
+   15137,  15213,  15286,  15357,  15426,  15493,  15557,  15619,
+   15679,  15736,  15791,  15843,  15893,  15941,  15986,  16029,
+   16069,  16107,  16143,  16176,  16207,  16235,  16261,  16284,
+   16305,  16324,  16340,  16353,  16364,  16373,  16379,  16383,
+};
+
+/*
  *  LSP VQ tables
  */
 static const int16_t lsp_band0[LSP_CB_SIZE * 3] = {

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

Summary of changes:
 libavcodec/g723_1.c      |   42 +++++++++++++++++++++++++++
 libavcodec/g723_1_data.h |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+), 0 deletions(-)


-- 
http://github.com/naufal/ffmpeg-soc


More information about the FFmpeg-soc mailing list