]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/g723_1enc.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / g723_1enc.c
index 4a4525eda99d3a25be05f2d3da9a7fb9b5d9d70d..2fb4b7fc823b955b19260a2e83590ede9993babe 100644 (file)
 #define BITSTREAM_WRITER_LE
 #include "put_bits.h"
 
+/**
+ * Hamming window coefficients scaled by 2^15
+ */
+static const int16_t hamming_window[LPC_FRAME] = {
+     2621,  2631,  2659,  2705,  2770,  2853,  2955,  3074,  3212,  3367,
+     3541,  3731,  3939,  4164,  4405,  4663,  4937,  5226,  5531,  5851,
+     6186,  6534,  6897,  7273,  7661,  8062,  8475,  8899,  9334,  9780,
+    10235, 10699, 11172, 11653, 12141, 12636, 13138, 13645, 14157, 14673,
+    15193, 15716, 16242, 16769, 17298, 17827, 18356, 18884, 19411, 19935,
+    20457, 20975, 21489, 21999, 22503, 23002, 23494, 23978, 24455, 24924,
+    25384, 25834, 26274, 26704, 27122, 27529, 27924, 28306, 28675, 29031,
+    29373, 29700, 30012, 30310, 30592, 30857, 31107, 31340, 31557, 31756,
+    31938, 32102, 32249, 32377, 32488, 32580, 32654, 32710, 32747, 32766,
+    32766, 32747, 32710, 32654, 32580, 32488, 32377, 32249, 32102, 31938,
+    31756, 31557, 31340, 31107, 30857, 30592, 30310, 30012, 29700, 29373,
+    29031, 28675, 28306, 27924, 27529, 27122, 26704, 26274, 25834, 25384,
+    24924, 24455, 23978, 23494, 23002, 22503, 21999, 21489, 20975, 20457,
+    19935, 19411, 18884, 18356, 17827, 17298, 16769, 16242, 15716, 15193,
+    14673, 14157, 13645, 13138, 12636, 12141, 11653, 11172, 10699, 10235,
+     9780, 9334,   8899,  8475,  8062,  7661,  7273,  6897,  6534,  6186,
+     5851, 5531,   5226,  4937,  4663,  4405,  4164,  3939,  3731,  3541,
+     3367, 3212,   3074,  2955,  2853,  2770,  2705,  2659,  2631,  2621
+};
+
+/**
+ * Binomial window coefficients scaled by 2^15
+ */
+static const int16_t binomial_window[LPC_ORDER] = {
+    32749, 32695, 32604, 32477, 32315, 32118, 31887, 31622, 31324, 30995
+};
+
+/**
+ * 0.994^i scaled by 2^15
+ */
+static const int16_t bandwidth_expand[LPC_ORDER] = {
+    32571, 32376, 32182, 31989, 31797, 31606, 31416, 31228, 31040, 30854
+};
+
+/**
+ * 0.5^i scaled by 2^15
+ */
+static const int16_t percept_flt_tbl[2][LPC_ORDER] = {
+    /* Zero part */
+    {29491, 26542, 23888, 21499, 19349, 17414, 15673, 14106, 12695, 11425},
+    /* Pole part */
+    {16384,  8192,  4096,  2048,  1024,   512,   256,   128,    64,    32}
+};
+
 static av_cold int g723_1_encode_init(AVCodecContext *avctx)
 {
-    G723_1_Context *p = avctx->priv_data;
+    G723_1_Context *s = avctx->priv_data;
+    G723_1_ChannelContext *p = &s->ch[0];
 
     if (avctx->sample_rate != 8000) {
         av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
@@ -241,14 +290,14 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
     p    = 0;
     temp = 0;
     for (i = 0; i <= LPC_ORDER / 2; i++)
-        temp += f[2 * i] * cos_tab[0];
+        temp += f[2 * i] * G723_1_COS_TAB_FIRST_ELEMENT;
     prev_val = av_clipl_int32(temp << 1);
     count    = 0;
     for (i = 1; i < COS_TBL_SIZE / 2; i++) {
         /* Evaluate */
         temp = 0;
         for (j = 0; j <= LPC_ORDER / 2; j++)
-            temp += f[LPC_ORDER - 2 * j + p] * cos_tab[i * j % COS_TBL_SIZE];
+            temp += f[LPC_ORDER - 2 * j + p] * ff_g723_1_cos_tab[i * j % COS_TBL_SIZE];
         cur_val = av_clipl_int32(temp << 1);
 
         /* Check for sign change, indicating a zero crossing */
@@ -272,7 +321,7 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
             temp = 0;
             for (j = 0; j <= LPC_ORDER / 2; j++)
                 temp += f[LPC_ORDER - 2 * j + p] *
-                        cos_tab[i * j % COS_TBL_SIZE];
+                        ff_g723_1_cos_tab[i * j % COS_TBL_SIZE];
             cur_val = av_clipl_int32(temp << 1);
         }
         prev_val = cur_val;
@@ -297,11 +346,11 @@ static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
                                                                               \
     for (i = 0; i < LSP_CB_SIZE; i++) {                                       \
         for (j = 0; j < size; j++){                                           \
-            temp[j] = (weight[j + (offset)] * lsp_band##num[i][j] +           \
+            temp[j] = (weight[j + (offset)] * ff_g723_1_lsp_band##num[i][j] + \
                       (1 << 14)) >> 15;                                       \
         }                                                                     \
         error  = ff_g723_1_dot_product(lsp + (offset), temp, size) << 1;      \
-        error -= ff_g723_1_dot_product(lsp_band##num[i], temp, size);         \
+        error -= ff_g723_1_dot_product(ff_g723_1_lsp_band##num[i], temp, size); \
         if (error > max) {                                                    \
             max = error;                                                      \
             lsp_index[num] = i;                                               \
@@ -386,7 +435,7 @@ static void iir_filter(int16_t *fir_coef, int16_t *iir_coef,
  * @param flt_coef filter coefficients
  * @param unq_lpc  unquantized lpc vector
  */
-static void perceptual_filter(G723_1_Context *p, int16_t *flt_coef,
+static void perceptual_filter(G723_1_ChannelContext *p, int16_t *flt_coef,
                               int16_t *unq_lpc, int16_t *buf)
 {
     int16_t vector[FRAME_LEN + LPC_ORDER];
@@ -635,13 +684,13 @@ static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc,
  * @param buf   input signal
  * @param index the current subframe index
  */
-static void acb_search(G723_1_Context *p, int16_t *residual,
+static void acb_search(G723_1_ChannelContext *p, int16_t *residual,
                        int16_t *impulse_resp, const int16_t *buf,
                        int index)
 {
     int16_t flt_buf[PITCH_ORDER][SUBFRAME_LEN];
 
-    const int16_t *cb_tbl = adaptive_cb_gain85;
+    const int16_t *cb_tbl = ff_g723_1_adaptive_cb_gain85;
 
     int ccr_buf[PITCH_ORDER * SUBFRAMES << 2];
 
@@ -719,7 +768,7 @@ static void acb_search(G723_1_Context *p, int16_t *residual,
         /* Select quantization table */
         if (!odd_frame && pitch_lag + i - 1 >= SUBFRAME_LEN - 2 ||
             odd_frame && pitch_lag >= SUBFRAME_LEN - 2) {
-            cb_tbl   = adaptive_cb_gain170;
+            cb_tbl   = ff_g723_1_adaptive_cb_gain170;
             tbl_size = 170;
         }
 
@@ -837,7 +886,7 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp,
         min           = 1 << 30;
         max_amp_index = GAIN_LEVELS - 2;
         for (j = max_amp_index; j >= 2; j--) {
-            temp = av_clipl_int32((int64_t) fixed_cb_gain[j] *
+            temp = av_clipl_int32((int64_t) ff_g723_1_fixed_cb_gain[j] *
                                   impulse_corr[0] << 1);
             temp = FFABS(temp - amp);
             if (temp < min) {
@@ -854,7 +903,7 @@ static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp,
                 ccr2[k]      = ccr1[k];
             }
             param.amp_index = max_amp_index + j - 2;
-            amp             = fixed_cb_gain[param.amp_index];
+            amp             = ff_g723_1_fixed_cb_gain[param.amp_index];
 
             param.pulse_sign[0] = (ccr2[param.pulse_pos[0]] < 0) ? -amp : amp;
             temp_corr[param.pulse_pos[0]] = 1;
@@ -941,7 +990,7 @@ static void pack_fcb_param(G723_1_Subframe *subfrm, FCBParam *optim,
     for (i = 0; i < SUBFRAME_LEN >> 1; i++) {
         int val = buf[optim->grid_index + (i << 1)];
         if (!val) {
-            subfrm->pulse_pos += combinatorial_table[j][i];
+            subfrm->pulse_pos += ff_g723_1_combinatorial_table[j][i];
         } else {
             subfrm->pulse_sign <<= 1;
             if (val < 0)
@@ -963,7 +1012,7 @@ static void pack_fcb_param(G723_1_Subframe *subfrm, FCBParam *optim,
  * @param buf          target vector
  * @param impulse_resp impulse response of the combined filter
  */
-static void fcb_search(G723_1_Context *p, int16_t *impulse_resp,
+static void fcb_search(G723_1_ChannelContext *p, int16_t *impulse_resp,
                        int16_t *buf, int index)
 {
     FCBParam optim;
@@ -995,7 +1044,7 @@ static void fcb_search(G723_1_Context *p, int16_t *impulse_resp,
  * @param frame output buffer
  * @param size  size of the buffer
  */
-static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
+static int pack_bitstream(G723_1_ChannelContext *p, AVPacket *avpkt)
 {
     PutBitContext pb;
     int info_bits = 0;
@@ -1029,7 +1078,7 @@ static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
     put_bits(&pb, 1, p->subframe[3].grid_index);
 
     if (p->cur_rate == RATE_6300) {
-        skip_put_bits(&pb, 1); /* reserved bit */
+        put_bits(&pb, 1, 0); /* reserved bit */
 
         /* Write 13 bit combined position index */
         temp = (p->subframe[0].pulse_pos >> 16) * 810 +
@@ -1056,7 +1105,8 @@ static int pack_bitstream(G723_1_Context *p, AVPacket *avpkt)
 static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                                const AVFrame *frame, int *got_packet_ptr)
 {
-    G723_1_Context *p = avctx->priv_data;
+    G723_1_Context *s = avctx->priv_data;
+    G723_1_ChannelContext *p = &s->ch[0];
     int16_t unq_lpc[LPC_ORDER * SUBFRAMES];
     int16_t qnt_lpc[LPC_ORDER * SUBFRAMES];
     int16_t cur_lsp[LPC_ORDER];
@@ -1189,7 +1239,12 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     return 0;
 }
 
-AVCodec ff_g723_1_encoder = {
+static const AVCodecDefault defaults[] = {
+    { "b", "6300" },
+    { NULL },
+};
+
+const AVCodec ff_g723_1_encoder = {
     .name           = "g723_1",
     .long_name      = NULL_IF_CONFIG_SMALL("G.723.1"),
     .type           = AVMEDIA_TYPE_AUDIO,
@@ -1197,6 +1252,7 @@ AVCodec ff_g723_1_encoder = {
     .priv_data_size = sizeof(G723_1_Context),
     .init           = g723_1_encode_init,
     .encode2        = g723_1_encode_frame,
+    .defaults       = defaults,
     .sample_fmts    = (const enum AVSampleFormat[]) {
         AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
     },