comparison g729dec.c @ 9884:c2da2b1e1a12 libavcodec

LSF (Line Spectral Frequencies) decoding routine.
author voroshil
date Wed, 24 Jun 2009 04:38:48 +0000
parents 2719d29359c6
children b584c223a6a1
comparison
equal deleted inserted replaced
9883:ffc0f9de5743 9884:c2da2b1e1a12
79 uint8_t fc_signs_bits; ///< number of pulses in fixed-codebook vector 79 uint8_t fc_signs_bits; ///< number of pulses in fixed-codebook vector
80 uint8_t fc_indexes_bits; ///< size (in bits) of fixed-codebook index entry 80 uint8_t fc_indexes_bits; ///< size (in bits) of fixed-codebook index entry
81 } G729FormatDescription; 81 } G729FormatDescription;
82 82
83 typedef struct { 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 int16_t lsp_buf[2][10]; ///< (0.15) LSP coefficients (previous and current frames) (3.2.5) 89 int16_t lsp_buf[2][10]; ///< (0.15) LSP coefficients (previous and current frames) (3.2.5)
85 int16_t *lsp[2]; ///< pointers to lsp_buf 90 int16_t *lsp[2]; ///< pointers to lsp_buf
86 } G729Context; 91 } G729Context;
87 92
88 static const G729FormatDescription format_g729_8k = { 93 static const G729FormatDescription format_g729_8k = {
117 static inline int get_parity(uint8_t value) 122 static inline int get_parity(uint8_t value)
118 { 123 {
119 return (0x6996966996696996ULL >> (value >> 2)) & 1; 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 static av_cold int decoder_init(AVCodecContext * avctx) 165 static av_cold int decoder_init(AVCodecContext * avctx)
123 { 166 {
167 G729Context* ctx = avctx->priv_data;
168 int i,k;
169
124 if (avctx->channels != 1) { 170 if (avctx->channels != 1) {
125 av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels); 171 av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
126 return AVERROR_NOFMT; 172 return AVERROR_NOFMT;
127 } 173 }
128 174
129 /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */ 175 /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */
130 avctx->frame_size = SUBFRAME_SIZE << 1; 176 avctx->frame_size = SUBFRAME_SIZE << 1;
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 }
131 183
132 ctx->lsp[0] = ctx->lsp_buf[0]; 184 ctx->lsp[0] = ctx->lsp_buf[0];
133 ctx->lsp[1] = ctx->lsp_buf[1]; 185 ctx->lsp[1] = ctx->lsp_buf[1];
134 memcpy(ctx->lsp[0], lsp_init, 10 * sizeof(int16_t)); 186 memcpy(ctx->lsp[0], lsp_init, 10 * sizeof(int16_t));
135 187
179 ma_predictor = get_bits(&gb, 1); 231 ma_predictor = get_bits(&gb, 1);
180 quantizer_1st = get_bits(&gb, VQ_1ST_BITS); 232 quantizer_1st = get_bits(&gb, VQ_1ST_BITS);
181 quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS); 233 quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS);
182 quantizer_2nd_hi = get_bits(&gb, VQ_2ND_BITS); 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 ff_acelp_lsf2lsp(ctx->lsp[1], ctx->lsfq, 10); 240 ff_acelp_lsf2lsp(ctx->lsp[1], ctx->lsfq, 10);
185 241
186 ff_acelp_lp_decode(&lp[0][0], &lp[1][0], ctx->lsp[1], ctx->lsp[0], 10); 242 ff_acelp_lp_decode(&lp[0][0], &lp[1][0], ctx->lsp[1], ctx->lsp[0], 10);
187 243
188 FFSWAP(int16_t*, ctx->lsp[1], ctx->lsp[0]); 244 FFSWAP(int16_t*, ctx->lsp[1], ctx->lsp[0]);