123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #include "cl_ltp.h"
- const char cl_ltp_id[] = "@(#)$Id $" cl_ltp_h;
-
- #include <stdlib.h>
- #include <stdio.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "count.h"
- #include "oper_32b.h"
- #include "cnst.h"
- #include "convolve.h"
- #include "g_pitch.h"
- #include "pred_lt.h"
- #include "pitch_fr.h"
- #include "enc_lag3.h"
- #include "enc_lag6.h"
- #include "q_gain_p.h"
- #include "ton_stab.h"
- int cl_ltp_init (clLtpState **state)
- {
- clLtpState* s;
-
- if (state == (clLtpState **) NULL){
- wfprintf(stderr, "cl_ltp_init: invalid parameter\n");
- return -1;
- }
- *state = NULL;
-
-
- if ((s= (clLtpState *) wmalloc(sizeof(clLtpState))) == NULL){
- wfprintf(stderr, "cl_ltp_init: can not malloc state structure\n");
- return -1;
- }
-
-
- if (Pitch_fr_init(&s->pitchSt)) {
- cl_ltp_exit(&s);
- return -1;
- }
-
- cl_ltp_reset(s);
-
- *state = s;
-
- return 0;
- }
-
- int cl_ltp_reset (clLtpState *state)
- {
- if (state == (clLtpState *) NULL){
- wfprintf(stderr, "cl_ltp_reset: invalid parameter\n");
- return -1;
- }
-
-
- Pitch_fr_reset (state->pitchSt);
-
- return 0;
- }
- void cl_ltp_exit (clLtpState **state)
- {
- if (state == NULL || *state == NULL)
- return;
-
- Pitch_fr_exit(&(*state)->pitchSt);
-
-
- wfree(*state);
- *state = NULL;
-
- return;
- }
- int cl_ltp (
- clLtpState *clSt,
- tonStabState *tonSt,
- enum Mode mode,
- Word16 frameOffset,
- Word16 T_op[],
- Word16 *h1,
- Word16 *exc,
- Word16 res2[],
- Word16 xn[],
- Word16 lsp_flag,
- Word16 xn2[],
- Word16 y1[],
- Word16 *T0,
- Word16 *T0_frac,
- Word16 *gain_pit,
- Word16 g_coeff[],
- Word16 **anap,
- Word16 *gp_limit
- )
- {
- Word16 i;
- Word16 index;
- Word32 L_temp;
- Word16 resu3;
- Word16 gpc_flag;
-
-
- *T0 = Pitch_fr(clSt->pitchSt,
- mode, T_op, exc, xn, h1,
- L_SUBFR, frameOffset,
- T0_frac, &resu3, &index); move16 ();
-
- *(*anap)++ = index; move16 ();
-
-
-
- Pred_lt_3or6(exc, *T0, *T0_frac, L_SUBFR, resu3);
-
- Convolve(exc, h1, y1, L_SUBFR);
-
-
- *gain_pit = G_pitch(mode, xn, y1, g_coeff, L_SUBFR); move16 ();
-
-
- gpc_flag = 0; move16 ();
- *gp_limit = MAX_16; move16 ();
- test (); test ();
- if ((lsp_flag != 0) &&
- (sub_ex(*gain_pit, GP_CLIP) > 0))
- {
- gpc_flag = check_gp_clipping(tonSt, *gain_pit); move16 ();
- }
-
-
- test (); test ();
- if ((sub_ex (mode, MR475) == 0) || (sub_ex (mode, MR515) == 0)) {
- test ();
- if ( sub_ex (*gain_pit, 13926) > 0) {
- *gain_pit = 13926; move16 ();
- }
- test ();
- if (gpc_flag != 0) {
- *gp_limit = GP_CLIP; move16 ();
- }
- }
- else
- {
- test ();
- if (gpc_flag != 0)
- {
- *gp_limit = GP_CLIP; move16 ();
- *gain_pit = GP_CLIP; move16 ();
- }
-
- if (test (), sub_ex(mode, MR122)==0)
- {
- *(*anap)++ = q_gain_pitch(MR122, *gp_limit, gain_pit,
- NULL, NULL);
- move16 ();
- }
- }
-
- for (i = 0; i < L_SUBFR; i++) {
- L_temp = L_mult_ex(y1[i], *gain_pit);
- L_temp = L_shl_ex(L_temp, 1);
- xn2[i] = sub_ex(xn[i], extract_h_ex(L_temp)); move16 ();
-
- L_temp = L_mult_ex(exc[i], *gain_pit);
- L_temp = L_shl_ex(L_temp, 1);
- res2[i] = sub_ex(res2[i], extract_h_ex(L_temp)); move16 ();
- }
-
- return 0;
- }
|