cl_ltp.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 310 行
C
310 行
/******************************************************************************** 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 "cl_ltp.h"const char cl_ltp_id[] = "@(#)$Id $" cl_ltp_h; /******************************************************************************* INCLUDE FILES******************************************************************************/#include <uclib.h>#include <uclib.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"//add for jzmedia accerative instruction sets#ifdef JZ4740_MXU_OPT#include "jzmedia.h"#endifstatic int Pitch_frT = 0, Pred_lt_3or6T = 0, ConvolveT = 0, G_pitchT = 0,check_gp_clippingT = 0, q_gain_pitchT = 0; /******************************************************************************* LOCAL VARIABLES AND TABLES******************************************************************************//******************************************************************************* PUBLIC PROGRAM CODE******************************************************************************//*************************************************************************** Function: cl_ltp_init* Purpose: Allocates state memory and initializes state memory****************************************************************************/int cl_ltp_init (clLtpState **state){ clLtpState* s; if (state == (clLtpState **) NULL){ fprintf(stderr, "cl_ltp_init: invalid parameter\n"); return -1; } *state = NULL; /* allocate memory */ if ((s= (clLtpState *) malloc(sizeof(clLtpState))) == NULL){ fprintf(stderr, "cl_ltp_init: can not malloc state structure\n"); return -1; } /* init the sub state */ if (Pitch_fr_init(&s->pitchSt)) { cl_ltp_exit(&s); return -1; } cl_ltp_reset(s); *state = s; return 0;} /*************************************************************************** Function: cl_ltp_reset* Purpose: Initializes state memory to zero****************************************************************************/int cl_ltp_reset (clLtpState *state){ if (state == (clLtpState *) NULL){ fprintf(stderr, "cl_ltp_reset: invalid parameter\n"); return -1; } /* Reset pitch search states */ Pitch_fr_reset (state->pitchSt); return 0;}/*************************************************************************** Function: cl_ltp_exit* Purpose: The memory used for state memory is freed****************************************************************************/void cl_ltp_exit (clLtpState **state){ if (state == NULL || *state == NULL) return; /* dealloc members */ Pitch_fr_exit(&(*state)->pitchSt); /* deallocate memory */ free(*state); *state = NULL; printf(" Pitch_frT = %d, Pred_lt_3or6T = %d\n",Pitch_frT , Pred_lt_3or6T ); printf(" ConvolveT = %d, G_pitchT = %d\n" ,ConvolveT , G_pitchT ); printf(" check_gp_clippingT = %d, q_gain_pitchT = %d\n",check_gp_clippingT , q_gain_pitchT ); return;}/*************************************************************************** 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; Word32 readyT, endT; #ifdef JZ4740_MXU_OPT Word16 *ptr_y1, *ptr_res2, *ptr_xn, *ptr_xn2, *ptr_exc; unsigned int ref_rs;#endif /*----------------------------------------------------------------------* * Closed-loop fractional pitch search * *----------------------------------------------------------------------*/ readyT = GetTimer2(); *T0 = Pitch_fr(clSt->pitchSt, mode, T_op, exc, xn, h1, L_SUBFR, frameOffset, T0_frac, &resu3, &index); //move16 (); endT = GetTimer2(); Pitch_frT += (endT - readyT); *(*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. * *-----------------------------------------------------------------*/ readyT = GetTimer2(); Pred_lt_3or6(exc, *T0, *T0_frac, L_SUBFR, resu3); endT = GetTimer2(); Pred_lt_3or6T += (endT - readyT); readyT = GetTimer2(); Convolve(exc, h1, y1, L_SUBFR); endT = GetTimer2(); ConvolveT += (endT - readyT); readyT = GetTimer2(); /* gain_pit is Q14 for all modes */ *gain_pit = G_pitch(mode, xn, y1, g_coeff, L_SUBFR); //move16 (); endT = GetTimer2(); G_pitchT += (endT - readyT); /* check if the pitch gain should be limit due to resonance in LPC filter */ gpc_flag = 0; //move16 (); *gp_limit = MAX_16; //move16 (); readyT = GetTimer2(); //test (); test (); if ((lsp_flag != 0) && (sub(*gain_pit, GP_CLIP) > 0)) { gpc_flag = check_gp_clipping(tonSt, *gain_pit); //move16 (); } endT = GetTimer2(); check_gp_clippingT += (endT - readyT); /* 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 (); readyT = GetTimer2(); 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 (); } } endT = GetTimer2(); q_gain_pitchT += (endT - readyT);//add for jzmedia accerative instruction sets#ifdef JZ4740_MXU_OPT ptr_y1 = y1 - 2; ptr_xn = xn - 2; ptr_xn2 = xn2 - 2; ptr_exc = ((unsigned int)(exc-2) & 0xfffffffc); ref_rs = 4 - ((unsigned int)exc & 3); ptr_res2 = res2 -2 ; S32I2M(xr1, *gain_pit); S32LDI(xr14, ptr_exc, 0x04); for (i = 0; i < L_SUBFR / 2; i++) { S32LDI(xr2, ptr_y1, 0x04); // load y1[i] and y1[i+1] D16MUL_LW(xr4, xr1, xr2,xr5); // y1[i] and y1[i+1] multiply *gain_pit D32SLL(xr6, xr4, xr5, xr7, 2); //y1 and exc of i and i + 1 are shift 2 S32SFL(xr2,xr6, xr7,xr3,ptn3); S32LDI(xr3, ptr_xn, 0x04); //load xn[i] and xn[i+1] Q16ADD_SS_WW(xr4, xr3, xr2, xr0);//y1[i] and y1[i+1] subtruct xn[i] and xn[i+1] S32SDI(xr4, ptr_xn2, 0x04); S32LDI(xr4, ptr_exc, 0x04); // load exc[i] and exc[i+1] S32ALN(xr3, xr4, xr14, ref_rs); // align exc[i] Q16ADD_SS_WW(xr14, xr4, xr0,xr0); // save last exc[i] D16MUL_LW(xr4, xr1, xr3,xr5); // exc[i] and exc[i+1] multiply *gain_pit D32SLL(xr6, xr4, xr5, xr7, 2); //y1 and exc of i and i + 1 are shift 2 S32SFL(xr4,xr6, xr7,xr5,ptn3); S32LDI(xr8, ptr_res2, 0x04); // load res2[i] and res2[i+1] Q16ADD_SS_WW(xr2, xr8, xr4, xr3);//res2[i] and res2[i+1] subtruct exc[i]and exc[i+1] S32STD(xr2, ptr_res2, 0x00); }#else /* 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 (); } #endif return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?