123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
-
- #include "gain_q.h"
- const char gain_q_id[] = "@(#)$Id $" gain_q_h;
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "count.h"
- #include "qua_gain.h"
- #include "cnst.h"
- #include "mode.h"
- #include "g_code.h"
- #include "q_gain_c.h"
- #include "gc_pred.h"
- #include "calc_en.h"
- #include "qgain795.h"
- #include "qgain475.h"
- #include "set_zero.h"
- int gainQuant_init (gainQuantState **state)
- {
- gainQuantState* s;
-
- if (state == (gainQuantState **) NULL){
- wfprintf(stderr, "gainQuant_init: invalid parameter\n");
- return -1;
- }
- *state = NULL;
-
-
- if ((s= (gainQuantState *) wmalloc(sizeof(gainQuantState))) == NULL){
- wfprintf(stderr, "gainQuant_init: can not malloc state structure\n");
- return -1;
- }
-
- s->gain_idx_ptr = NULL;
-
- s->gc_predSt = NULL;
- s->gc_predUnqSt = NULL;
- s->adaptSt = NULL;
-
- if ( gc_pred_init(&s->gc_predSt)
- || gc_pred_init(&s->gc_predUnqSt)
- || gain_adapt_init(&s->adaptSt)) {
- gainQuant_exit(&s);
- return -1;
- }
-
- gainQuant_reset(s);
- *state = s;
-
- return 0;
- }
- int gainQuant_reset (gainQuantState *state)
- {
-
- if (state == (gainQuantState *) NULL){
- wfprintf(stderr, "gainQuant_reset: invalid parameter\n");
- return -1;
- }
-
- state->sf0_exp_gcode0 = 0;
- state->sf0_frac_gcode0 = 0;
- state->sf0_exp_target_en = 0;
- state->sf0_frac_target_en = 0;
-
- Set_zero (state->sf0_exp_coeff, 5);
- Set_zero (state->sf0_frac_coeff, 5);
- state->gain_idx_ptr = NULL;
-
- gc_pred_reset(state->gc_predSt);
- gc_pred_reset(state->gc_predUnqSt);
- gain_adapt_reset(state->adaptSt);
-
- return 0;
- }
-
- void gainQuant_exit (gainQuantState **state)
- {
- if (state == NULL || *state == NULL)
- return;
-
- gc_pred_exit(&(*state)->gc_predSt);
- gc_pred_exit(&(*state)->gc_predUnqSt);
- gain_adapt_exit(&(*state)->adaptSt);
-
- wfree(*state);
- *state = NULL;
-
- return;
- }
-
- int gainQuant(
- gainQuantState *st,
- enum Mode mode,
- Word16 res[],
- Word16 exc[],
- Word16 code[],
-
- Word16 xn[],
- Word16 xn2[],
- Word16 y1[],
- Word16 Y2[],
- Word16 g_coeff[],
-
- Word16 even_subframe,
- Word16 gp_limit,
- Word16 *sf0_gain_pit,
- Word16 *sf0_gain_cod,
- Word16 *gain_pit,
- Word16 *gain_cod,
-
-
- Word16 **anap
- )
- {
- Word16 exp_gcode0;
- Word16 frac_gcode0;
- Word16 qua_ener_MR122;
- Word16 qua_ener;
- Word16 frac_coeff[5];
- Word16 exp_coeff[5];
- Word16 exp_en, frac_en;
- Word16 cod_gain_exp, cod_gain_frac;
-
- test ();
- if (sub_ex (mode, MR475) == 0)
- {
- test ();
- if (even_subframe != 0)
- {
-
- st->gain_idx_ptr = (*anap)++;
- gc_pred_copy(st->gc_predSt, st->gc_predUnqSt);
-
-
-
- gc_pred(st->gc_predUnqSt, mode, code,
- &st->sf0_exp_gcode0, &st->sf0_frac_gcode0,
- &exp_en, &frac_en);
-
-
- calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff,
- st->sf0_frac_coeff, st->sf0_exp_coeff,
- &cod_gain_frac, &cod_gain_exp);
-
- *gain_cod = shl_ex (cod_gain_frac, add_ex (cod_gain_exp, 1));
- move16 ();
- calc_target_energy(xn,
- &st->sf0_exp_target_en, &st->sf0_frac_target_en);
-
- MR475_update_unq_pred(st->gc_predUnqSt,
- st->sf0_exp_gcode0, st->sf0_frac_gcode0,
- cod_gain_exp, cod_gain_frac);
-
-
- }
- else
- {
-
-
- gc_pred(st->gc_predUnqSt, mode, code,
- &exp_gcode0, &frac_gcode0,
- &exp_en, &frac_en);
-
-
- calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff,
- frac_coeff, exp_coeff,
- &cod_gain_frac, &cod_gain_exp);
- calc_target_energy(xn, &exp_en, &frac_en);
-
- *st->gain_idx_ptr = MR475_gain_quant(
- st->gc_predSt,
- st->sf0_exp_gcode0, st->sf0_frac_gcode0,
- st->sf0_exp_coeff, st->sf0_frac_coeff,
- st->sf0_exp_target_en, st->sf0_frac_target_en,
- code,
- exp_gcode0, frac_gcode0,
- exp_coeff, frac_coeff,
- exp_en, frac_en,
- gp_limit,
- sf0_gain_pit, sf0_gain_cod,
- gain_pit, gain_cod);
- }
- }
- else
- {
-
- gc_pred(st->gc_predSt, mode, code, &exp_gcode0, &frac_gcode0,
- &exp_en, &frac_en);
-
- test ();
- if (sub_ex(mode, MR122) == 0)
- {
- *gain_cod = G_code_ex (xn2, Y2); move16 ();
- *(*anap)++ = q_gain_code (mode, exp_gcode0, frac_gcode0,
- gain_cod, &qua_ener_MR122, &qua_ener);
- move16 ();
- }
- else
- {
-
- calc_filt_energies(mode, xn, xn2, y1, Y2, g_coeff,
- frac_coeff, exp_coeff,
- &cod_gain_frac, &cod_gain_exp);
-
- test ();
- if (sub_ex (mode, MR795) == 0)
- {
- MR795_gain_quant(st->adaptSt, res, exc, code,
- frac_coeff, exp_coeff,
- exp_en, frac_en,
- exp_gcode0, frac_gcode0, L_SUBFR,
- cod_gain_frac, cod_gain_exp,
- gp_limit, gain_pit, gain_cod,
- &qua_ener_MR122, &qua_ener,
- anap);
- }
- else
- {
- *(*anap)++ = Qua_gain(mode,
- exp_gcode0, frac_gcode0,
- frac_coeff, exp_coeff, gp_limit,
- gain_pit, gain_cod,
- &qua_ener_MR122, &qua_ener);
- move16 ();
- }
- }
-
-
- gc_pred_update(st->gc_predSt, qua_ener_MR122, qua_ener);
- }
-
- return 0;
- }
|