# HG changeset patch # User Mychaela Falconia # Date 1715038379 0 # Node ID 85e9768d497f7f00f9b4ec62d4b8908ab20c2c26 # Parent 8fff74ca83e824c86f8f29190866b6f255c422cb libtwamr: integrate cl_ltp.c diff -r 8fff74ca83e8 -r 85e9768d497f libtwamr/Makefile --- a/libtwamr/Makefile Mon May 06 23:23:40 2024 +0000 +++ b/libtwamr/Makefile Mon May 06 23:32:59 2024 +0000 @@ -2,20 +2,20 @@ CFLAGS= -O2 OBJS= a_refl.o agc.o autocorr.o az_lsp.o b_cn_cod.o basicop2.o bgnscd.o \ bitno.o bits2prm.o c1035pf.o c2_11pf.o c2_9pf.o c3_14pf.o c4_17pf.o \ - c8_31pf.o c_g_aver.o calc_cor.o calc_en.o cbsearch.o convolve.o cor_h.o\ - d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o d8_31pf.o d_gain_c.o \ - d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o dec_gain.o dec_lag3.o \ - dec_lag6.o dhf_check.o dhf_tables.o e_homing.o ec_gains.o enc_lag3.o \ - enc_lag6.o ex_ctrl.o g_adapt.o g_code.o g_pitch.o gain_q.o gains_tab.o \ - gc_pred.o gmed_n.o graytab.o hp_max.o int_lpc.o int_lsf.o inter_36.o \ - inv_sqrt.o lag_wind.o levinson.o log2.o lpc.o lsfwt.o lsp.o lsp_avg.o \ - lsp_az.o lsp_lsf.o lsp_tab.o mac_32.o oper_32b.o ph_disp.o pitch_fr.o \ - post_pro.o pow2.o pre_big.o pre_proc.o pred_lt.o preemph.o prm2bits.o \ - prmno.o pstfilt.o q_gain_c.o q_gain_p.o q_plsf.o q_plsf3_tab.o \ - q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o qgain795.o qua_gain.o \ - qua_gain_tab.o reorder.o residu.o s10_8pf.o set_sign.o sid_sync.o \ - spreproc.o spstproc.o sqrt_l.o syn_filt.o tls_flags.o ton_stab.o \ - weight_a.o window.o + c8_31pf.o c_g_aver.o calc_cor.o calc_en.o cbsearch.o cl_ltp.o \ + convolve.o cor_h.o d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o \ + d8_31pf.o d_gain_c.o d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o \ + dec_gain.o dec_lag3.o dec_lag6.o dhf_check.o dhf_tables.o e_homing.o \ + ec_gains.o enc_lag3.o enc_lag6.o ex_ctrl.o g_adapt.o g_code.o g_pitch.o\ + gain_q.o gains_tab.o gc_pred.o gmed_n.o graytab.o hp_max.o int_lpc.o \ + int_lsf.o inter_36.o inv_sqrt.o lag_wind.o levinson.o log2.o lpc.o \ + lsfwt.o lsp.o lsp_avg.o lsp_az.o lsp_lsf.o lsp_tab.o mac_32.o \ + oper_32b.o ph_disp.o pitch_fr.o post_pro.o pow2.o pre_big.o pre_proc.o \ + pred_lt.o preemph.o prm2bits.o prmno.o pstfilt.o q_gain_c.o q_gain_p.o \ + q_plsf.o q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o \ + qgain795.o qua_gain.o qua_gain_tab.o reorder.o residu.o s10_8pf.o \ + set_sign.o sid_sync.o spreproc.o spstproc.o sqrt_l.o syn_filt.o \ + tls_flags.o ton_stab.o weight_a.o window.o HDRS= namespace.h LIB= libtwamr.a diff -r 8fff74ca83e8 -r 85e9768d497f libtwamr/cl_ltp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/cl_ltp.c Mon May 06 23:32:59 2024 +0000 @@ -0,0 +1,182 @@ +/* +***************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +***************************************************************************** +* +* File : cl_ltp.c +* +***************************************************************************** +*/ + +/* +***************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +***************************************************************************** +*/ +#include "namespace.h" +#include "cl_ltp.h" + +/* +***************************************************************************** +* INCLUDE FILES +***************************************************************************** +*/ +#include +#include "typedef.h" +#include "basic_op.h" +#include "no_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" + +/* +***************************************************************************** +* LOCAL VARIABLES AND TABLES +***************************************************************************** +*/ + +/* +***************************************************************************** +* PUBLIC PROGRAM CODE +***************************************************************************** +*/ + +/************************************************************************* +* +* Function: cl_ltp_reset +* Purpose: Initializes state memory to zero +* +************************************************************************** +*/ +void cl_ltp_reset (clLtpState *state) +{ + /* Reset pitch search states */ + Pitch_fr_reset (&state->pitchSt); +} + +/************************************************************************* +* +* Function: cl_ltp +* Purpose: closed-loop fractional pitch search +* +************************************************************************** +*/ +int cl_ltp ( + clLtpState *clSt, /* i/o : State struct */ + tonStabState *tonSt, /* i/o : State struct */ + enum Mode mode, /* i : coder mode */ + Word16 frameOffset, /* i : Offset to subframe */ + Word16 T_op[], /* i : Open loop pitch lags */ + Word16 *h1, /* i : Impulse response vector Q12 */ + Word16 *exc, /* i/o : Excitation vector Q0 */ + Word16 res2[], /* i/o : Long term prediction residual Q0 */ + Word16 xn[], /* i : Target vector for pitch search Q0 */ + Word16 lsp_flag, /* i : LSP resonance flag */ + Word16 xn2[], /* o : Target vector for codebook search Q0 */ + Word16 y1[], /* o : Filtered adaptive excitation Q0 */ + Word16 *T0, /* o : Pitch delay (integer part) */ + Word16 *T0_frac, /* o : Pitch delay (fractional part) */ + Word16 *gain_pit, /* o : Pitch gain Q14 */ + Word16 g_coeff[], /* o : Correlations between xn, y1, & y2 */ + Word16 **anap, /* o : Analysis parameters */ + Word16 *gp_limit /* o : pitch gain limit */ +) +{ + Word16 i; + Word16 index; + Word32 L_temp; /* temporarily variable */ + Word16 resu3; /* flag for upsample resolution */ + Word16 gpc_flag; + + /*----------------------------------------------------------------------* + * Closed-loop fractional pitch search * + *----------------------------------------------------------------------*/ + *T0 = Pitch_fr(&clSt->pitchSt, + mode, T_op, exc, xn, h1, + L_SUBFR, frameOffset, + T0_frac, &resu3, &index); move16 (); + + *(*anap)++ = index; move16 (); + + /*-----------------------------------------------------------------* + * - find unity gain pitch excitation (adapitve codebook entry) * + * with fractional interpolation. * + * - find filtered pitch exc. y1[]=exc[] convolve with h1[]) * + * - compute pitch gain and limit between 0 and 1.2 * + * - update target vector for codebook search * + * - find LTP residual. * + *-----------------------------------------------------------------*/ + + Pred_lt_3or6(exc, *T0, *T0_frac, L_SUBFR, resu3); + + Convolve(exc, h1, y1, L_SUBFR); + + /* gain_pit is Q14 for all modes */ + *gain_pit = G_pitch(mode, xn, y1, g_coeff, L_SUBFR); move16 (); + + + /* check if the pitch gain should be limit due to resonance in LPC filter */ + gpc_flag = 0; move16 (); + *gp_limit = MAX_16; move16 (); + test (); test (); + if ((lsp_flag != 0) && + (sub(*gain_pit, GP_CLIP) > 0)) + { + gpc_flag = check_gp_clipping(tonSt, *gain_pit); move16 (); + } + + /* special for the MR475, MR515 mode; limit the gain to 0.85 to */ + /* cope with bit errors in the decoder in a better way. */ + test (); test (); + if ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0)) { + test (); + if ( sub (*gain_pit, 13926) > 0) { + *gain_pit = 13926; /* 0.85 in Q14 */ 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 (); + } + /* For MR122, gain_pit is quantized here and not in gainQuant */ + if (test (), sub(mode, MR122)==0) + { + *(*anap)++ = q_gain_pitch(MR122, *gp_limit, gain_pit, + NULL, NULL); + move16 (); + } + } + + /* update target vector und evaluate LTP residual */ + for (i = 0; i < L_SUBFR; i++) { + L_temp = L_mult(y1[i], *gain_pit); + L_temp = L_shl(L_temp, 1); + xn2[i] = sub(xn[i], extract_h(L_temp)); move16 (); + + L_temp = L_mult(exc[i], *gain_pit); + L_temp = L_shl(L_temp, 1); + res2[i] = sub(res2[i], extract_h(L_temp)); move16 (); + } + + return 0; +} diff -r 8fff74ca83e8 -r 85e9768d497f libtwamr/cl_ltp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/cl_ltp.h Mon May 06 23:32:59 2024 +0000 @@ -0,0 +1,77 @@ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +******************************************************************************** +* +* File : cl_ltp.h +* Purpose : Closed-loop fractional pitch search +* +******************************************************************************** +*/ +#ifndef cl_ltp_h +#define cl_ltp_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "tw_amr.h" +#include "typedef.h" +#include "pitch_fr.h" +#include "ton_stab.h" + +/* +******************************************************************************** +* LOCAL VARIABLES AND TABLES +******************************************************************************** +*/ + +/* +******************************************************************************** +* DEFINITION OF DATA TYPES +******************************************************************************** +*/ + +/* state variable */ +typedef struct { + Pitch_frState pitchSt; +} clLtpState; + +/* +******************************************************************************** +* DECLARATION OF PROTOTYPES +******************************************************************************** +*/ + +void cl_ltp_reset (clLtpState *st); +/* reset of pre processing state (i.e. set state memory to zero) + returns 0 on success + */ + +int cl_ltp( + clLtpState *clSt, /* i/o : State struct */ + tonStabState *tonSt, /* i/o : State struct */ + enum Mode mode, /* i : coder mode */ + Word16 frameOffset, /* i : Offset to subframe */ + Word16 T_op[], /* i : Open loop pitch lags */ + Word16 *h1, /* i : Impulse response vector Q12 */ + Word16 *exc, /* i/o : Excitation vector Q0 */ + Word16 res2[], /* i/o : Long term prediction residual Q0 */ + Word16 xn[], /* i : Target vector for pitch search Q0 */ + Word16 lsp_flag, /* i : LSP resonance flag */ + Word16 xn2[], /* o : Target vector for codebook search Q0 */ + Word16 y1[], /* o : Filtered adaptive excitation Q0 */ + Word16 *T0, /* o : Pitch delay (integer part) */ + Word16 *T0_frac, /* o : Pitch delay (fractional part) */ + Word16 *gain_pit, /* o : Pitch gain Q14 */ + Word16 g_coeff[], /* o : Correlations between xn, y1, & y2 */ + Word16 **anap, /* o : Analysis parameters */ + Word16 *gp_limit /* o : pitch gain limit */ +); + +#endif diff -r 8fff74ca83e8 -r 85e9768d497f libtwamr/namespace.list --- a/libtwamr/namespace.list Mon May 06 23:23:40 2024 +0000 +++ b/libtwamr/namespace.list Mon May 06 23:32:59 2024 +0000 @@ -38,7 +38,7 @@ sqrt_l_exp set_sign set_sign12k2 cor_h cor_h_x cor_h_x2 comp_corr -cbsearch +cbsearch cl_ltp cl_ltp_reset d_gain_code d_gain_pitch gain_adapt gain_adapt_reset gainQuant gainQuant_reset