Mercurial > libavcodec.hg
comparison g729dec.c @ 9888:62705926ba33 libavcodec
Pitch delay decoding
author | voroshil |
---|---|
date | Fri, 26 Jun 2009 17:43:05 +0000 |
parents | b584c223a6a1 |
children | 25e209f9153a |
comparison
equal
deleted
inserted
replaced
9887:b584c223a6a1 | 9888:62705926ba33 |
---|---|
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 int pitch_delay_int_prev; ///< integer part of previous subframe's pitch delay (4.1.3) | |
85 | |
84 /// (2.13) LSP quantizer outputs | 86 /// (2.13) LSP quantizer outputs |
85 int16_t past_quantizer_output_buf[MA_NP + 1][10]; | 87 int16_t past_quantizer_output_buf[MA_NP + 1][10]; |
86 int16_t* past_quantizer_outputs[MA_NP + 1]; | 88 int16_t* past_quantizer_outputs[MA_NP + 1]; |
87 | 89 |
88 int16_t lsfq[10]; ///< (2.13) quantized LSF coefficients from previous frame | 90 int16_t lsfq[10]; ///< (2.13) quantized LSF coefficients from previous frame |
204 uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer | 206 uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer |
205 uint8_t quantizer_1st; ///< first stage vector of quantizer | 207 uint8_t quantizer_1st; ///< first stage vector of quantizer |
206 uint8_t quantizer_2nd_lo; ///< second stage lower vector of quantizer (size in bits) | 208 uint8_t quantizer_2nd_lo; ///< second stage lower vector of quantizer (size in bits) |
207 uint8_t quantizer_2nd_hi; ///< second stage higher vector of quantizer (size in bits) | 209 uint8_t quantizer_2nd_hi; ///< second stage higher vector of quantizer (size in bits) |
208 | 210 |
211 int pitch_delay_int; // pitch delay, integer part | |
212 int pitch_delay_3x; // pitch delay, multiplied by 3 | |
213 | |
209 if (*data_size < SUBFRAME_SIZE << 2) { | 214 if (*data_size < SUBFRAME_SIZE << 2) { |
210 av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n"); | 215 av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n"); |
211 return AVERROR(EIO); | 216 return AVERROR(EIO); |
212 } | 217 } |
213 | 218 |
256 fc_indexes = get_bits(&gb, format.fc_indexes_bits); | 261 fc_indexes = get_bits(&gb, format.fc_indexes_bits); |
257 pulses_signs = get_bits(&gb, format.fc_signs_bits); | 262 pulses_signs = get_bits(&gb, format.fc_signs_bits); |
258 gc_1st_index = get_bits(&gb, format.gc_1st_index_bits); | 263 gc_1st_index = get_bits(&gb, format.gc_1st_index_bits); |
259 gc_2nd_index = get_bits(&gb, format.gc_2nd_index_bits); | 264 gc_2nd_index = get_bits(&gb, format.gc_2nd_index_bits); |
260 | 265 |
266 if(!i) { | |
267 if (bad_pitch) | |
268 pitch_delay_3x = 3 * ctx->pitch_delay_int_prev; | |
269 else | |
270 pitch_delay_3x = ff_acelp_decode_8bit_to_1st_delay3(ac_index); | |
271 } else { | |
272 int pitch_delay_min = av_clip(ctx->pitch_delay_int_prev - 5, | |
273 PITCH_DELAY_MIN, PITCH_DELAY_MAX - 9); | |
274 | |
275 if(packet_type == FORMAT_G729D_6K4) | |
276 pitch_delay_3x = ff_acelp_decode_4bit_to_2nd_delay3(ac_index, pitch_delay_min); | |
277 else | |
278 pitch_delay_3x = ff_acelp_decode_5_6_bit_to_2nd_delay3(ac_index, pitch_delay_min); | |
279 } | |
280 | |
281 /* Round pitch delay to nearest (used everywhere except ff_acelp_interpolate). */ | |
282 pitch_delay_int = (pitch_delay_3x + 1) / 3; | |
283 | |
261 ff_acelp_weighted_vector_sum(fc + pitch_delay_int, | 284 ff_acelp_weighted_vector_sum(fc + pitch_delay_int, |
262 fc + pitch_delay_int, | 285 fc + pitch_delay_int, |
263 fc, 1 << 14, | 286 fc, 1 << 14, |
264 av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX), | 287 av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX), |
265 0, 14, | 288 0, 14, |
279 ff_acelp_weighted_vector_sum(ctx->exc + i * SUBFRAME_SIZE, | 302 ff_acelp_weighted_vector_sum(ctx->exc + i * SUBFRAME_SIZE, |
280 ctx->exc + i * SUBFRAME_SIZE, fc, | 303 ctx->exc + i * SUBFRAME_SIZE, fc, |
281 (!voicing && frame_erasure) ? 0 : ctx->gain_pitch, | 304 (!voicing && frame_erasure) ? 0 : ctx->gain_pitch, |
282 ( voicing && frame_erasure) ? 0 : ctx->gain_code, | 305 ( voicing && frame_erasure) ? 0 : ctx->gain_code, |
283 1 << 13, 14, SUBFRAME_SIZE); | 306 1 << 13, 14, SUBFRAME_SIZE); |
307 | |
308 ctx->pitch_delay_int_prev = pitch_delay_int; | |
284 } | 309 } |
285 | 310 |
286 *data_size = SUBFRAME_SIZE << 2; | 311 *data_size = SUBFRAME_SIZE << 2; |
287 return buf_size; | 312 return buf_size; |
288 } | 313 } |