Revision 3c70902b libavcodec/g729dec.c

View differences:

libavcodec/g729dec.c
81 81
} G729FormatDescription;
82 82

  
83 83
typedef struct {
84
    /// (2.13) LSP quantizer outputs
85
    int16_t  past_quantizer_output_buf[MA_NP + 1][10];
86
    int16_t* past_quantizer_outputs[MA_NP + 1];
87

  
88
    int16_t lsfq[10];           ///< (2.13) quantized LSF coefficients from previous frame
84 89
    int16_t lsp_buf[2][10];     ///< (0.15) LSP coefficients (previous and current frames) (3.2.5)
85 90
    int16_t *lsp[2];            ///< pointers to lsp_buf
86 91
}  G729Context;
......
119 124
   return (0x6996966996696996ULL >> (value >> 2)) & 1;
120 125
}
121 126

  
127
static void lsf_decode(int16_t* lsfq, int16_t* past_quantizer_outputs[MA_NP + 1],
128
                       int16_t ma_predictor,
129
                       int16_t vq_1st, int16_t vq_2nd_low, int16_t vq_2nd_high)
130
{
131
    int i,j;
132
    static const uint8_t min_distance[2]={10, 5}; //(2.13)
133
    int16_t* quantizer_output = past_quantizer_outputs[MA_NP];
134

  
135
    for (i = 0; i < 5; i++) {
136
        quantizer_output[i]     = cb_lsp_1st[vq_1st][i    ] + cb_lsp_2nd[vq_2nd_low ][i    ];
137
        quantizer_output[i + 5] = cb_lsp_1st[vq_1st][i + 5] + cb_lsp_2nd[vq_2nd_high][i + 5];
138
    }
139

  
140
    for (j = 0; j < 2; j++) {
141
        for (i = 1; i < 10; i++) {
142
            int diff = (quantizer_output[i - 1] - quantizer_output[i] + min_distance[j]) >> 1;
143
            if (diff > 0) {
144
                quantizer_output[i - 1] -= diff;
145
                quantizer_output[i    ] += diff;
146
            }
147
        }
148
    }
149

  
150
    for (i = 0; i < 10; i++) {
151
        int sum = quantizer_output[i] * cb_ma_predictor_sum[ma_predictor][i];
152
        for (j = 0; j < MA_NP; j++)
153
            sum += past_quantizer_outputs[j][i] * cb_ma_predictor[ma_predictor][j][i];
154

  
155
        lsfq[i] = sum >> 15;
156
    }
157

  
158
    /* Rotate past_quantizer_outputs. */
159
    memmove(past_quantizer_outputs + 1, past_quantizer_outputs, MA_NP * sizeof(int16_t*));
160
    past_quantizer_outputs[0] = quantizer_output;
161

  
162
    ff_acelp_reorder_lsf(lsfq, LSFQ_DIFF_MIN, LSFQ_MIN, LSFQ_MAX, 10);
163
}
164

  
122 165
static av_cold int decoder_init(AVCodecContext * avctx)
123 166
{
167
    G729Context* ctx = avctx->priv_data;
168
    int i,k;
169

  
124 170
    if (avctx->channels != 1) {
125 171
        av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
126 172
        return AVERROR_NOFMT;
......
129 175
    /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */
130 176
    avctx->frame_size = SUBFRAME_SIZE << 1;
131 177

  
178
    for (k = 0; k < MA_NP + 1; k++) {
179
        ctx->past_quantizer_outputs[k] = ctx->past_quantizer_output_buf[k];
180
        for (i = 1; i < 11; i++)
181
            ctx->past_quantizer_outputs[k][i - 1] = (18717 * i) >> 3;
182
    }
183

  
132 184
    ctx->lsp[0] = ctx->lsp_buf[0];
133 185
    ctx->lsp[1] = ctx->lsp_buf[1];
134 186
    memcpy(ctx->lsp[0], lsp_init, 10 * sizeof(int16_t));
......
181 233
    quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS);
182 234
    quantizer_2nd_hi = get_bits(&gb, VQ_2ND_BITS);
183 235

  
236
    lsf_decode(ctx->lsfq, ctx->past_quantizer_outputs,
237
               ma_predictor,
238
               quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi);
239

  
184 240
    ff_acelp_lsf2lsp(ctx->lsp[1], ctx->lsfq, 10);
185 241

  
186 242
    ff_acelp_lp_decode(&lp[0][0], &lp[1][0], ctx->lsp[1], ctx->lsp[0], 10);

Also available in: Unified diff