123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- #include "calc_en.h"
- const char calc_en_id[] = "@(#)$Id $" calc_en_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"
- void
- calc_unfilt_energies(
- Word16 res[],
- Word16 exc[],
- Word16 code[],
- Word16 gain_pit,
- Word16 L_subfr,
- Word16 frac_en[],
- Word16 exp_en[],
- Word16 *ltpg
- )
- {
- Word32 s, L_temp;
- Word16 i, exp, tmp;
- Word16 ltp_res_en, pred_gain;
- Word16 ltpg_exp, ltpg_frac;
-
- s = L_mac_ex((Word32) 0, res[0], res[0]);
- for (i = 1; i < L_subfr; i++)
- s = L_mac_ex(s, res[i], res[i]);
-
- test();
- if (L_sub_ex (s, 400L) < 0)
- {
- frac_en[0] = 0; move16 ();
- exp_en[0] = -15; move16 ();
- }
- else
- {
- exp = norm_l_ex(s);
- frac_en[0] = extract_h_ex(L_shl_ex(s, exp)); move16 ();
- exp_en[0] = sub_ex(15, exp); move16 ();
- }
-
-
- s = L_mac_ex((Word32) 0, exc[0], exc[0]);
- for (i = 1; i < L_subfr; i++)
- s = L_mac_ex(s, exc[i], exc[i]);
- exp = norm_l_ex(s);
- frac_en[1] = extract_h_ex(L_shl_ex(s, exp)); move16 ();
- exp_en[1] = sub_ex(15, exp); move16 ();
-
- s = L_mac_ex((Word32) 0, exc[0], code[0]);
- for (i = 1; i < L_subfr; i++)
- s = L_mac_ex(s, exc[i], code[i]);
- exp = norm_l_ex(s);
- frac_en[2] = extract_h_ex(L_shl_ex(s, exp)); move16 ();
- exp_en[2] = sub_ex(16-14, exp); move16 ();
-
- s = 0L; move32 ();
- for (i = 0; i < L_subfr; i++)
- {
- L_temp = L_mult_ex(exc[i], gain_pit);
- L_temp = L_shl_ex(L_temp, 1);
- tmp = sub_ex(res[i], round_ex(L_temp));
- s = L_mac_ex (s, tmp, tmp);
- }
- exp = norm_l_ex(s);
- ltp_res_en = extract_h_ex (L_shl_ex (s, exp));
- exp = sub_ex (15, exp);
- frac_en[3] = ltp_res_en; move16 ();
- exp_en[3] = exp; move16 ();
-
-
- test (); test ();
- if (ltp_res_en > 0 && frac_en[0] != 0)
- {
-
- pred_gain = div_s (shr_ex (frac_en[0], 1), ltp_res_en);
- exp = sub_ex (exp, exp_en[0]);
-
- L_temp = L_deposit_h_ex (pred_gain);
-
- L_temp = L_shr_ex (L_temp, add_ex (exp, 3));
-
- Log2(L_temp, <pg_exp, <pg_frac);
-
- L_temp = L_Comp (sub_ex (ltpg_exp, 27), ltpg_frac);
- *ltpg = round_ex (L_shl_ex (L_temp, 13));
- }
- else
- {
- *ltpg = 0; move16 ();
- }
- }
- void
- calc_filt_energies(
- enum Mode mode,
- Word16 xn[],
- Word16 xn2[],
- Word16 y1[],
- Word16 Y2[],
- Word16 g_coeff[],
-
- Word16 frac_coeff[],
- Word16 exp_coeff[],
- Word16 *cod_gain_frac,
- Word16 *cod_gain_exp
- )
- {
- Word32 s, ener_init;
- Word16 i, exp, frac;
- Word16 y2[L_SUBFR];
- if (test(), sub_ex(mode, MR795) == 0 || sub_ex(mode, MR475) == 0)
- {
- ener_init = 0L; move32 ();
- }
- else
- {
- ener_init = 1L; move32 ();
- }
-
- for (i = 0; i < L_SUBFR; i++) {
- y2[i] = shr_ex(Y2[i], 3); move16 ();
- }
- frac_coeff[0] = g_coeff[0]; move16 ();
- exp_coeff[0] = g_coeff[1]; move16 ();
- frac_coeff[1] = negate_ex(g_coeff[2]); move16 ();
- exp_coeff[1] = add_ex(g_coeff[3], 1); move16 ();
-
- s = L_mac_ex(ener_init, y2[0], y2[0]);
- for (i = 1; i < L_SUBFR; i++)
- s = L_mac_ex(s, y2[i], y2[i]);
- exp = norm_l_ex(s);
- frac_coeff[2] = extract_h_ex(L_shl_ex(s, exp)); move16 ();
- exp_coeff[2] = sub_ex(15 - 18, exp); move16();
-
- s = L_mac_ex(ener_init, xn[0], y2[0]);
- for (i = 1; i < L_SUBFR; i++)
- s = L_mac_ex(s, xn[i], y2[i]);
- exp = norm_l_ex(s);
- frac_coeff[3] = negate_ex(extract_h_ex(L_shl_ex(s, exp))); move16 ();
- exp_coeff[3] = sub_ex(15 - 9 + 1, exp); move16 ();
-
- s = L_mac_ex(ener_init, y1[0], y2[0]);
- for (i = 1; i < L_SUBFR; i++)
- s = L_mac_ex(s, y1[i], y2[i]);
- exp = norm_l_ex(s);
- frac_coeff[4] = extract_h_ex(L_shl_ex(s, exp)); move16 ();
- exp_coeff[4] = sub_ex(15 - 9 + 1, exp); move16();
- if (test(), test (), sub_ex(mode, MR475) == 0 || sub_ex(mode, MR795) == 0)
- {
-
- s = L_mac_ex(ener_init, xn2[0], y2[0]);
- for (i = 1; i < L_SUBFR; i++)
- s = L_mac_ex(s, xn2[i], y2[i]);
-
- exp = norm_l_ex(s);
- frac = extract_h_ex(L_shl_ex(s, exp));
- exp = sub_ex(15 - 9, exp);
-
- if (test (), frac <= 0)
- {
- *cod_gain_frac = 0; move16 ();
- *cod_gain_exp = 0; move16 ();
- }
- else
- {
-
-
- *cod_gain_frac = div_s (shr_ex (frac,1), frac_coeff[2]); move16 ();
- *cod_gain_exp = sub_ex (sub_ex (exp, exp_coeff[2]), 14); move16 ();
- }
- }
- }
- void
- calc_target_energy(
- Word16 xn[],
- Word16 *en_exp,
- Word16 *en_frac
- )
- {
- Word32 s;
- Word16 i, exp;
-
- s = L_mac_ex(0L, xn[0], xn[0]);
- for (i = 1; i < L_SUBFR; i++)
- s = L_mac_ex(s, xn[i], xn[i]);
-
- exp = norm_l_ex(s);
- *en_frac = extract_h_ex(L_shl_ex(s, exp));
- *en_exp = sub_ex(16, exp); move16();
- }
|