123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- #include "qgain795.h"
- const char qgain795_id[] = "@(#)$Id $" qgain795_h;
- #include <stdio.h>
- #include <stdlib.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "oper_32b.h"
- #include "count.h"
- #include "cnst.h"
- #include "log2.h"
- #include "pow2.h"
- #include "sqrt_l.h"
- #include "g_adapt.h"
- #include "calc_en.h"
- #include "q_gain_p.h"
- #include "mac_32.h"
- #include "gains.tab"
- static void
- MR795_gain_code_quant3(
- Word16 exp_gcode0,
- Word16 gcode0,
- Word16 g_pitch_cand[],
- Word16 g_pitch_cind[],
- Word16 frac_coeff[],
- Word16 exp_coeff[],
-
- Word16 *gain_pit,
- Word16 *gain_pit_ind,
- Word16 *gain_cod,
- Word16 *gain_cod_ind,
- Word16 *qua_ener_MR122,
-
- Word16 *qua_ener
-
- )
- {
- const Word16 *p;
- Word16 i, j, cod_ind, pit_ind;
- Word16 e_max, exp_code;
- Word16 g_pitch, g2_pitch, g_code, g2_code_h, g2_code_l;
- Word16 g_pit_cod_h, g_pit_cod_l;
- Word16 coeff[5], coeff_lo[5];
- Word16 exp_max[5];
- Word32 L_tmp, L_tmp0, dist_min;
-
-
- exp_code = sub_ex(exp_gcode0, 10);
-
- exp_max[0] = sub_ex(exp_coeff[0], 13); move16 ();
- exp_max[1] = sub_ex(exp_coeff[1], 14); move16 ();
- exp_max[2] = add_ex(exp_coeff[2], add_ex(15, shl_ex(exp_code, 1))); move16 ();
- exp_max[3] = add_ex(exp_coeff[3], exp_code); move16 ();
- exp_max[4] = add_ex(exp_coeff[4], add_ex(exp_code,1)); move16 ();
-
- e_max = exp_max[0]; move16 ();
- for (i = 1; i < 5; i++)
- {
- move16(); test();
- if (sub_ex(exp_max[i], e_max) > 0)
- {
- e_max = exp_max[i]; move16 ();
- }
- }
- e_max = add_ex(e_max, 1);
- for (i = 0; i < 5; i++) {
- j = sub_ex(e_max, exp_max[i]);
- L_tmp = L_deposit_h_ex(frac_coeff[i]);
- L_tmp = L_shr_ex(L_tmp, j);
- L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
- }
-
-
- dist_min = MAX_32; move16 ();
- cod_ind = 0; move16 ();
- pit_ind = 0; move16 ();
-
- for (j = 0; j < 3; j++)
- {
-
- g_pitch = g_pitch_cand[j]; move16 ();
- g2_pitch = mult_ex(g_pitch, g_pitch);
- L_tmp0 = Mpy_32_16( coeff[0], coeff_lo[0], g2_pitch);
- L_tmp0 = Mac_32_16(L_tmp0, coeff[1], coeff_lo[1], g_pitch);
- p = &qua_gain_code[0];
- for (i = 0; i < NB_QUA_CODE; i++)
- {
- g_code = *p++; move16 ();
- p++;
- p++;
- g_code = mult_ex(g_code, gcode0);
- L_tmp = L_mult_ex (g_code, g_code);
- L_Extract (L_tmp, &g2_code_h, &g2_code_l);
- L_tmp = L_mult_ex(g_code, g_pitch);
- L_Extract (L_tmp, &g_pit_cod_h, &g_pit_cod_l);
- L_tmp = Mac_32 (L_tmp0, coeff[2], coeff_lo[2],
- g2_code_h, g2_code_l);
- L_tmp = Mac_32_16(L_tmp, coeff[3], coeff_lo[3],
- g_code);
- L_tmp = Mac_32 (L_tmp, coeff[4], coeff_lo[4],
- g_pit_cod_h, g_pit_cod_l);
-
- test ();
- if (L_sub_ex(L_tmp, dist_min) < (Word32) 0)
- {
- dist_min = L_tmp; move32 ();
- cod_ind = i; move16 ();
- pit_ind = j; move16 ();
- }
- }
- }
-
-
- p = &qua_gain_code[add_ex (add_ex (cod_ind, cod_ind), cod_ind)]; move16 ();
- g_code = *p++; move16();
- *qua_ener_MR122 = *p++; move16();
- *qua_ener = *p; move16();
-
- L_tmp = L_mult_ex(g_code, gcode0);
- L_tmp = L_shr_ex(L_tmp, sub_ex(9, exp_gcode0));
- *gain_cod = extract_h_ex(L_tmp);
- *gain_cod_ind = cod_ind; move16 ();
- *gain_pit = g_pitch_cand[pit_ind]; move16 ();
- *gain_pit_ind = g_pitch_cind[pit_ind]; move16 ();
- }
- static Word16
- MR795_gain_code_quant_mod(
- Word16 gain_pit,
- Word16 exp_gcode0,
- Word16 gcode0,
- Word16 frac_en[],
- Word16 exp_en[],
- Word16 alpha,
- Word16 gain_cod_unq,
-
- Word16 *gain_cod,
- Word16 *qua_ener_MR122,
-
- Word16 *qua_ener
-
- )
- {
- const Word16 *p;
- Word16 i, index, tmp;
- Word16 one_alpha;
- Word16 exp, e_max;
- Word16 g2_pitch, g_code;
- Word16 g2_code_h, g2_code_l;
- Word16 d2_code_h, d2_code_l;
- Word16 coeff[5], coeff_lo[5], exp_coeff[5];
- Word32 L_tmp, L_t0, L_t1, dist_min;
- Word16 gain_code;
-
-
- gain_code = shl_ex (*gain_cod, sub_ex (10, exp_gcode0));
- g2_pitch = mult_ex (gain_pit, gain_pit);
-
- one_alpha = add_ex (sub_ex (32767, alpha), 1);
-
- tmp = extract_h_ex (L_shl_ex (L_mult_ex (alpha, frac_en[1]), 1));
-
- L_t1 = L_mult_ex (tmp, g2_pitch); move16 ();
- exp_coeff[1] = sub_ex (exp_en[1], 15); move16 ();
- tmp = extract_h_ex (L_shl_ex (L_mult_ex (alpha, frac_en[2]), 1));
- coeff[2] = mult_ex (tmp, gain_pit); move16 ();
- exp = sub_ex (exp_gcode0, 10);
- exp_coeff[2] = add_ex (exp_en[2], exp); move16 ();
-
- coeff[3] = extract_h_ex (L_shl_ex (L_mult_ex (alpha, frac_en[3]), 1));
- exp = sub_ex (shl_ex (exp_gcode0, 1), 7);
- exp_coeff[3] = add_ex (exp_en[3], exp); move16 ();
- coeff[4] = mult_ex (one_alpha, frac_en[3]); move16 ();
- exp_coeff[4] = add_ex (exp_coeff[3], 1); move16 ();
- L_tmp = L_mult_ex (alpha, frac_en[0]);
-
-
- L_t0 = sqrt_l_exp (L_tmp, &exp);
- move32 ();
- exp = add_ex (exp, 47);
- exp_coeff[0] = sub_ex (exp_en[0], exp); move16 ();
-
-
- e_max = add_ex (exp_coeff[0], 31);
- for (i = 1; i <= 4; i++)
- {
- test ();
- if (sub_ex (exp_coeff[i], e_max) > 0)
- {
- e_max = exp_coeff[i]; move16 ();
- }
- }
-
- tmp = sub_ex (e_max, exp_coeff[1]);
- L_t1 = L_shr_ex(L_t1, tmp);
-
- for (i = 2; i <= 4; i++)
- {
- tmp = sub_ex (e_max, exp_coeff[i]);
- L_tmp = L_deposit_h_ex(coeff[i]);
- L_tmp = L_shr_ex(L_tmp, tmp);
- L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
- }
-
- exp = sub_ex (e_max, 31);
- tmp = sub_ex (exp, exp_coeff[0]);
- L_t0 = L_shr_ex (L_t0, shr_ex (tmp, 1));
-
- test (); logic16 ();
- if ((tmp & 0x1) != 0)
- {
- L_Extract(L_t0, &coeff[0], &coeff_lo[0]);
- L_t0 = Mpy_32_16(coeff[0], coeff_lo[0],
- 23170);
- }
-
- dist_min = MAX_32; move32 ();
- index = 0; move16 ();
- p = &qua_gain_code[0]; move16 ();
- for (i = 0; i < NB_QUA_CODE; i++)
- {
- g_code = *p++; move16 ();
- p++;
- p++;
- g_code = mult_ex (g_code, gcode0);
-
- test ();
- if (sub_ex (g_code, gain_code) >= 0)
- break;
- L_tmp = L_mult_ex (g_code, g_code);
- L_Extract (L_tmp, &g2_code_h, &g2_code_l);
- tmp = sub_ex (g_code, gain_cod_unq);
- L_tmp = L_mult_ex (tmp, tmp);
- L_Extract (L_tmp, &d2_code_h, &d2_code_l);
-
- L_tmp = Mac_32_16 (L_t1, coeff[2], coeff_lo[2], g_code);
- L_tmp = Mac_32(L_tmp, coeff[3], coeff_lo[3], g2_code_h, g2_code_l);
- L_tmp = sqrt_l_exp (L_tmp, &exp);
- L_tmp = L_shr_ex (L_tmp, shr_ex (exp, 1));
-
- tmp = round_ex (L_sub_ex (L_tmp, L_t0));
- L_tmp = L_mult_ex (tmp, tmp);
-
- L_tmp = Mac_32(L_tmp, coeff[4], coeff_lo[4], d2_code_h, d2_code_l);
-
- test ();
- if (L_sub_ex (L_tmp, dist_min) < (Word32) 0)
- {
- dist_min = L_tmp; move16 ();
- index = i; move16 ();
- }
- }
-
-
- p = &qua_gain_code[add_ex (add_ex (index, index), index)]; move16 ();
- g_code = *p++; move16();
- *qua_ener_MR122 = *p++; move16();
- *qua_ener = *p; move16();
-
- L_tmp = L_mult_ex(g_code, gcode0);
- L_tmp = L_shr_ex(L_tmp, sub_ex(9, exp_gcode0));
- *gain_cod = extract_h_ex(L_tmp);
- return index;
- }
- void
- MR795_gain_quant(
- GainAdaptState *adapt_st,
- Word16 res[],
- Word16 exc[],
- Word16 code[],
- Word16 frac_coeff[],
- Word16 exp_coeff[],
-
- Word16 exp_code_en,
- Word16 frac_code_en,
- Word16 exp_gcode0,
- Word16 frac_gcode0,
- Word16 L_subfr,
- Word16 cod_gain_frac,
- Word16 cod_gain_exp,
- Word16 gp_limit,
- Word16 *gain_pit,
- Word16 *gain_cod,
- Word16 *qua_ener_MR122,
-
- Word16 *qua_ener,
-
- Word16 **anap
-
- )
- {
- Word16 frac_en[4];
- Word16 exp_en[4];
- Word16 ltpg, alpha, gcode0;
- Word16 g_pitch_cand[3];
- Word16 g_pitch_cind[3];
- Word16 gain_pit_index;
- Word16 gain_cod_index;
- Word16 exp;
- Word16 gain_cod_unq;
-
- gain_pit_index = q_gain_pitch (MR795, gp_limit, gain_pit,
- g_pitch_cand, g_pitch_cind);
- move16 ();
-
- gcode0 = extract_l_ex(Pow2(14, frac_gcode0));
-
- MR795_gain_code_quant3(
- exp_gcode0, gcode0, g_pitch_cand, g_pitch_cind,
- frac_coeff, exp_coeff,
- gain_pit, &gain_pit_index, gain_cod, &gain_cod_index,
- qua_ener_MR122, qua_ener);
-
- calc_unfilt_energies(res, exc, code, *gain_pit, L_subfr,
- frac_en, exp_en, <pg);
-
- gain_adapt(adapt_st, ltpg, *gain_cod, &alpha);
-
- test (); move16 (); test ();
- if (frac_en[0] != 0 && alpha > 0)
- {
-
-
- frac_en[3] = frac_code_en; move16 ();
- exp_en[3] = exp_code_en; move16 ();
-
-
- exp = add_ex (sub_ex (cod_gain_exp, exp_gcode0), 10);
- gain_cod_unq = shl_ex (cod_gain_frac, exp);
-
-
- gain_cod_index = MR795_gain_code_quant_mod(
- *gain_pit, exp_gcode0, gcode0,
- frac_en, exp_en, alpha, gain_cod_unq,
- gain_cod, qua_ener_MR122, qua_ener); move16 ();
- }
- *(*anap)++ = gain_pit_index; move16 ();
- *(*anap)++ = gain_cod_index; move16 ();
- }
|