Mercurial > libavcodec.hg
comparison qcelpdec.c @ 8240:d3d0d9cc0e50 libavcodec
Commit last ok'ed parts of QCELP decoder and enable it.
patch by Kenan Gillet, kenan.gillet gmail com
author | vitor |
---|---|
date | Tue, 02 Dec 2008 16:48:05 +0000 |
parents | 93ee77578391 |
children | 75ae6859ac73 |
comparison
equal
deleted
inserted
replaced
8239:dcfdb3352dde | 8240:d3d0d9cc0e50 |
---|---|
63 float rnd_fir_filter_mem[180]; | 63 float rnd_fir_filter_mem[180]; |
64 float formant_mem[170]; | 64 float formant_mem[170]; |
65 float last_codebook_gain; | 65 float last_codebook_gain; |
66 int prev_g1[2]; | 66 int prev_g1[2]; |
67 int prev_bitrate; | 67 int prev_bitrate; |
68 float prev_pitch_gain[4]; | 68 float pitch_gain[4]; |
69 uint8_t prev_pitch_lag[4]; | 69 uint8_t pitch_lag[4]; |
70 uint16_t first16bits; | 70 uint16_t first16bits; |
71 } QCELPContext; | 71 } QCELPContext; |
72 | 72 |
73 /** | 73 /** |
74 * Reconstructs LPC coefficients from the line spectral pair frequencies. | 74 * Reconstructs LPC coefficients from the line spectral pair frequencies. |
75 * | 75 * |
76 * TIA/EIA/IS-733 2.4.3.3.5 | 76 * TIA/EIA/IS-733 2.4.3.3.5 |
77 */ | 77 */ |
78 void qcelp_lspf2lpc(const float *lspf, float *lpc); | 78 void ff_qcelp_lspf2lpc(const float *lspf, float *lpc); |
79 | 79 |
80 static void weighted_vector_sumf(float *out, const float *in_a, | 80 static void weighted_vector_sumf(float *out, const float *in_a, |
81 const float *in_b, float weight_coeff_a, | 81 const float *in_b, float weight_coeff_a, |
82 float weight_coeff_b, int length) | 82 float weight_coeff_b, int length) |
83 { | 83 { |
493 memmove(memory, memory + 160, 143 * sizeof(float)); | 493 memmove(memory, memory + 160, 143 * sizeof(float)); |
494 return memory + 143; | 494 return memory + 143; |
495 } | 495 } |
496 | 496 |
497 /** | 497 /** |
498 * Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector. | |
499 * TIA/EIA/IS-733 2.4.5.2 | |
500 * | |
501 * @param q the context | |
502 * @param cdn_vector the scaled codebook vector | |
503 */ | |
504 static void apply_pitch_filters(QCELPContext *q, | |
505 float *cdn_vector) { | |
506 int i; | |
507 const float *v_synthesis_filtered, *v_pre_filtered; | |
508 | |
509 if (q->bitrate >= RATE_HALF || | |
510 (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) { | |
511 | |
512 if (q->bitrate >= RATE_HALF) { | |
513 | |
514 // Compute gain & lag for the whole frame. | |
515 for (i = 0; i < 4; i++) { | |
516 q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0; | |
517 | |
518 q->pitch_lag[i] = q->frame.plag[i] + 16; | |
519 } | |
520 } else { | |
521 float max_pitch_gain = q->erasure_count < 3 ? 0.9 - 0.3 * (q->erasure_count - 1) | |
522 : 0.0; | |
523 for (i = 0; i < 4; i++) | |
524 q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain); | |
525 | |
526 memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac)); | |
527 } | |
528 | |
529 // pitch synthesis filter | |
530 v_synthesis_filtered = do_pitchfilter(q->pitch_synthesis_filter_mem, cdn_vector, | |
531 q->pitch_gain, q->pitch_lag, q->frame.pfrac); | |
532 | |
533 // pitch prefilter update | |
534 for (i = 0; i < 4; i++) | |
535 q->pitch_gain[i] = 0.5 * FFMIN(q->pitch_gain[i], 1.0); | |
536 | |
537 v_pre_filtered = do_pitchfilter(q->pitch_pre_filter_mem, v_synthesis_filtered, | |
538 q->pitch_gain, q->pitch_lag, q->frame.pfrac); | |
539 | |
540 apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered); | |
541 } else { | |
542 memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17, 143 * sizeof(float)); | |
543 memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float)); | |
544 memset(q->pitch_gain, 0, sizeof(q->pitch_gain)); | |
545 memset(q->pitch_lag, 0, sizeof(q->pitch_lag)); | |
546 } | |
547 } | |
548 | |
549 /** | |
498 * Interpolates LSP frequencies and computes LPC coefficients | 550 * Interpolates LSP frequencies and computes LPC coefficients |
499 * for a given bitrate & pitch subframe. | 551 * for a given bitrate & pitch subframe. |
500 * | 552 * |
501 * TIA/EIA/IS-733 2.4.3.3.4 | 553 * TIA/EIA/IS-733 2.4.3.3.4 |
502 * | 554 * |
520 | 572 |
521 if(weight != 1.0) | 573 if(weight != 1.0) |
522 { | 574 { |
523 weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, | 575 weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, |
524 weight, 1.0 - weight, 10); | 576 weight, 1.0 - weight, 10); |
525 qcelp_lspf2lpc(interpolated_lspf, lpc); | 577 ff_qcelp_lspf2lpc(interpolated_lspf, lpc); |
526 }else if(q->bitrate >= RATE_QUARTER || (q->bitrate == I_F_Q && !subframe_num)) | 578 }else if(q->bitrate >= RATE_QUARTER || (q->bitrate == I_F_Q && !subframe_num)) |
527 qcelp_lspf2lpc(curr_lspf, lpc); | 579 ff_qcelp_lspf2lpc(curr_lspf, lpc); |
528 } | 580 } |
529 | 581 |
530 static int buf_size2bitrate(const int buf_size) | 582 static int buf_size2bitrate(const int buf_size) |
531 { | 583 { |
532 switch(buf_size) | 584 switch(buf_size) |