📄 encodeld.dsp
字号:
/***********************************************************************
* Functions Coder_ld8a and Init_Coder_ld8a *
* Init_Coder_ld8a(void); *
* ->Initialization of variables for the coder section. *
* Coder_ld8a(Word16 ana[]); *
* ->Main coder function. *
* Input: *
* 80 Enc_speech data should have beee copy to vector Enc_newspeech[]*
* This vector is global and is declared in this function. *
* Ouputs: *
* ana[] ->analysis parameters. *
* $$01/10/2000 checked Cod_ld8a module data variables and function *
* $$01/16/2001 modified and printed,Author: Jason.wang (zhigang wang) *
* $$01/16/2001 Email: wzg119@yeah.net, BP: 86+02195950-161452 *
* $$01/16/2001 This modlue is not optimized! should be test on Emulator*
************************************************************************/
.MODULE/SEG=App_PM Encodeld;
/***********************************************************************/
#include "ld8a.inc"
#include "vad.inc"
#include "dtx.inc"
#include "Tab_ld8a.inc"
/************************************************************************/
/* $$01/10/2000 static memory and pointer */
/************************************************************************/
.VAR/DM/RAM/SEG=App_DMmem Enc_excit,Enc_oldspeech[L_TOTAL]; /* Speech vector */
.VAR/DM/RAM/SEG=App_DMmem Enc_wsp,Enc_pwindow,Enc_newspeech;/* Global variable */
.VAR/DM/RAM/SEG=App_DMmem Enc_oldwsp[L_FRAME+PIT_MAX]; /* Weighted Enc_speech vector */
.VAR/DM/RAM/SEG=App_DMmem Enc_oldexc[L_FRAME+PIT_MAX+L_INTERPOL]; /* Excitation vector*/
.VAR/DM/RAM/SEG=App_DMmem Enc_lspold[M],Enc_lspold_q[M]; /* Lsp (Line spectral pairs) */
.VAR/DM/RAM/SEG=App_DMmem Enc_memw0[M],Enc_memw[M],Enc_memzero[M];/* Filter's memory */
.VAR/DM/RAM/SEG=App_DMmem Enc_pastVad,Enc_ppastVad; /* DTX variables */
.VAR/DM/RAM/SEG=App_DMmem Enc_sharp,Enc_seed,Enc_speech; /* DTX variables */
/************************************************************************/
.GLOBAL Enc_xn,Enc_xn2,Enc_h1,Enc_y2,Enc_lsfqmem,Enc_seed;
.GLOBAL Enc_newspeech,Enc_lspnew_q,Enc_lspold_q,Enc_excit;
.GLOBAL Enc_code,Enc_T0,Enc_subfr,Enc_expR0,Enc_Aqt,Enc_lsfnew;
.GLOBAL Enc_gcoeff_cs,Enc_exp_gcoeff_cs,tameflag,analy,Enc_pwindow;
.GLOBAL Enc_T0min,Enc_T0max,Enc_pastVad,Enc_ppastVad;
.EXTERNAL Vad_Enable,VadEncode;
.EXTERNAL Residu;
.EXTERNAL Az_lsp;
.EXTERNAL G_pitch;
.EXTERNAL Qua_lsp;
.EXTERNAL test_err;
.EXTERNAL Cod_cng;
.EXTERNAL Lsp_lsf;
.EXTERNAL Int_qlpc;
.EXTERNAL vad_init;
.EXTERNAL Autocorr;
.EXTERNAL Corr_xy2;
.EXTERNAL Qua_gain;
.EXTERNAL Enc_lag3;
.EXTERNAL Syn_filt;
.EXTERNAL Vadcheck;
.EXTERNAL Levinson;
.EXTERNAL Weight_Az;
.EXTERNAL Update_cng;
.EXTERNAL Lag_window;
.EXTERNAL Parity_Pitch;
.EXTERNAL Init_exc_err;
.EXTERNAL ACELP_Code_A;
.EXTERNAL Get_freq_prev;
.EXTERNAL Pitch_ol_fast;
.EXTERNAL update_exc_err;
.EXTERNAL Pitch_fr3_fast;
.EXTERNAL Lsp_encw_reset;
.EXTERNAL Init_lsfq_noise;
.EXTERNAL Update_freq_prev;
/***********************************************************************
* Function Init_Coder_ld8a *
* Init_Coder_ld8a(void); *
* ->Initialization of variables for the coder section. *
* - initialize pointers to Enc_speech buffer *
* - initialize static pointers *
* - set static vectors to zero *
* Initialize pointers to Enc_speech vector. *
*----------------------------------------------------------------------*
* *
* |--------------------|-------------|-------------|------------| *
* previous Enc_speech sf1 sf2 L_NEXT *
* *
* <---------------- Total Enc_speech vector (L_TOTAL) ----------->*
* <---------------- LPC analysis window (L_WINDOW) -----------> *
* | <-- present frame (L_FRAME) --> *
* Enc_oldspeech | <--new Enc_speech(L_FRAME)-->*
* Enc_pwindow | | *
* Enc_speech | *
* Enc_newspeech *
*----------------------------------------------------------------------*
* $$01/10/2000 used only in encoder *
* $$01/11/2000 move table from dm area to pm area *
* Calling Parameters *
* Return Values *
* Altered Registers: AR,SI,I4,I1,I2,M1,M4 *
* Computation Time : 18 cycles *
************************************************************************/
.ENTRY Init_Coder_ld8a;
Init_Coder_ld8a:
AR=^Enc_oldspeech+L_TOTAL-L_FRAME;
DM(Enc_newspeech)=AR; /* New Enc_speech */
AR=^Enc_oldspeech+L_TOTAL-L_FRAME-L_NEXT;
DM(Enc_speech)=AR; /* Present frame */
AR=^Enc_oldspeech+L_TOTAL-L_WINDOW;
DM(Enc_pwindow)=AR; /* For LPC window */
/*-------Initialize static pointers--------*/
AR=^Enc_oldwsp+PIT_MAX;
DM(Enc_wsp)=AR;
AR=^Enc_oldexc+PIT_MAX+L_INTERPOL;
DM(Enc_excit)=AR;
/*------Static vectors to zero------------*/
// CNTR=L_TOTAL;
I1=^Enc_oldspeech;
CNTR=L_TOTAL;
DO zero_speech UNTIL CE;
zero_speech: DM(I1,M1)=0;
I1=^Enc_oldexc;
CNTR=PIT_MAX+L_INTERPOL;
DO zero_oldexc UNTIL CE;
zero_oldexc: DM(I1,M1)=0;
I1=^Enc_oldwsp;
CNTR=PIT_MAX;
DO zero_wsp UNTIL CE;
zero_wsp: DM(I1,M1)=0;
I1=^Enc_lspold;
DM(I1,M1)=30000;
DM(I1,M1)=26000;
DM(I1,M1)=21000;
DM(I1,M1)=15000;
DM(I1,M1)=8000;
DM(I1,M1)=0;
DM(I1,M1)=-8000;
DM(I1,M1)=-15000;
DM(I1,M1)=-21000;
DM(I1,M1)=-26000;
/*------Initialize Enc_lspold_q[]--------------*/
// CNTR=M;
I0=^Enc_memw;
I1=^Enc_memw0;
I2=^Enc_memzero;
I4=^Enc_lspold;
I5=^Enc_lspold_q;
CNTR=M;
DO back_lspold UNTIL CE;
DM(I0,M1)=0;
DM(I1,M1)=0;
DM(I2,M1)=0;
AR=PASS 1,SI=DM(I4,M4);
back_lspold: DM(I5,M4)=SI;
/*------Initialize VAD/DTX parameters-------*/
DM(Enc_pastVad)=AR;
DM(Enc_ppastVad)=AR;
SI=SHARPMIN;
DM(Enc_sharp)=SI;
SI=INIT_SEED;
DM(Enc_seed)=SI;
CALL Lsp_encw_reset;
CALL Init_exc_err;
CALL vad_init;
CALL Init_lsfq_noise;
RTS;
/*************************************************************************
* Functions Coder_ld8a *
* Coder_ld8a(Word16 ana[]); *
* ->Main coder function. *
* $$01/10/2000 used only in encoder *
* Calling Parameters *
* 80 Enc_speech data should have beee copy to vector Enc_newspeech *
* This vector is global and is declared in this function. *
* frame : frame counter *
* Vad_Enable: VAD enable flag *
* Return Values *
* ana : Analysis parameters *
* Altered Registers: MR,SR,SE,AR,I0,AY0,MY0 *
* Computation Time : 18 cycles *
**************************************************************************/
.ENTRY Coder_ld8a;
.VAR/DM/RAM/SEG=App_DMbuf Enc_Aqt[MP1*2]; /* A(z) quantized for the 2 subframes */
.VAR/DM/RAM/SEG=App_DMbuf Enc_Apt[MP1*2]; /* A(z/gamma) for the 2 subframes */
.VAR/DM/RAM/SEG=App_DMbuf Enc_h1[L_SUBFR]; /* Impulse response h1[] */
.VAR/DM/RAM/SEG=App_DMbuf Enc_xn[L_SUBFR]; /* Target vector for pitch search */
.VAR/DM/RAM/SEG=App_DMbuf Enc_xn2[L_SUBFR]; /* Target vector for codebook search */
.VAR/DM/RAM/SEG=App_DMbuf Enc_rc[M]; /* Reflection coefficients. */
.VAR/DM/RAM/SEG=App_DMbuf Enc_y1[L_SUBFR]; /* Filtered adaptive excitation */
.VAR/DM/RAM/SEG=App_DMbuf Enc_y2[L_SUBFR]; /* Filtered fixed codebook excitation */
.VAR/DM/RAM/SEG=App_DMbuf Enc_gcoeff[4]; /* Correlations between xn & y1 */
.VAR/DM/RAM/SEG=App_DMbuf Enc_gcoeff_cs[5];
.VAR/DM/RAM/SEG=App_DMbuf Enc_exp_gcoeff_cs[5]; /* Correlations between xn, y1, & y2*/
.VAR/DM/RAM/SEG=App_DMbuf Enc_rl[NP+1], Enc_rh[NP+1],Ap1[MP1];/* Autocorrelations low and hi */
.VAR/DM/RAM/SEG=App_DMbuf Enc_lspnew[M],Enc_lspnew_q[M]; /* LSPs at 2th subframe */
.VAR/DM/RAM/SEG=App_DMbuf Enc_rhnbe[MP1],Enc_lsfnew[M];
.VAR/DM/RAM/SEG=App_DMbuf Enc_code[L_SUBFR]; /* Fixed codebook excitation */
.VAR/DM/RAM/SEG=App_DMbuf Enc_lsfqmem[MA_NP*M];
.VAR/DM/RAM/SEG=App_DMbuf Enc_expR0,Enc_T0,Enc_T0frac;
.VAR/DM/RAM/SEG=App_DMbuf Enc_T0min,Enc_T0max,Enc_subfr;
.VAR/DM/RAM/SEG=App_DMbuf Enc_gainpitch,Enc_gaincode;
.VAR/DM/RAM/SEG=App_DMbuf Enc_Ap,Enc_Aq,analy,tameflag;
Coder_ld8a: DM(analy)=I6;
/*------------------------------------------------------------------------*
* - Perform LPC analysis: *
* * autocorrelation + lag windowing *
* * Levinson-durbin algorithm to find a[] *
* * convert a[] to lsp[] *
* * quantize and Enc_code the LSPs *
* * find the interpolated LSPs and convert to a[] for the 2 *
* subframes (both quantized and unquantized) *
*------------------------------------------------------------------------*/
AY0=NP;
I2=^Enc_rl;
I3=^Enc_rh;
I1=DM(Enc_pwindow);
CALL Autocorr;
// CNTR=MP1;
I1=^Enc_rh;
I0=^Enc_rhnbe;
DM(Enc_expR0)=AR;
CNTR=MP1;
DO copy_rhnbe UNTIL CE;
AR=DM(I1,M1);
copy_rhnbe: DM(I0,M1)=AR;
I1=^Enc_rl+1;
I2=^Enc_rh+1;
CNTR=NP;
CALL Lag_window;
I1=^Enc_rc;
I0=^Enc_Apt;
I2=^Enc_rl;
I3=^Enc_rh;
CALL Levinson;
I1=^Enc_Apt+1;
I2=^Enc_Apt+M;
I3=^Enc_lspold;
I0=^Enc_lspnew;
CALL Az_lsp;
I1=^Enc_lspnew+M-1;
I0=^Enc_lsfnew+M-1;
CNTR=M;
CALL Lsp_lsf;
I0=^Enc_rh;
I1=^Enc_rl;
SI=DM(Enc_rc+1);
CALL Vadcheck;
I2=^Enc_rhnbe;
AX0=DM(Enc_expR0);
AY0=DM(VadEncode);
CALL Update_cng;
/* ---------------------- */
/* Case of Inactive frame */
/* ---------------------- */
AR=DM(VadEncode);
AR=PASS AR;
IF NE JUMP active_frame;
AR=DM(Vad_Enable);
AR=AR-1;
IF NE JUMP active_frame;
I1=^Enc_lsfqmem;
CALL Get_freq_prev;
CALL Cod_cng;
I0=^Enc_lsfqmem;
CALL Update_freq_prev;
AR=DM(Enc_pastVad);
DM(Enc_ppastVad)=AR;
AR=DM(VadEncode);
DM(Enc_pastVad)=AR;
/*--------Update Enc_wsp, Enc_memw and Enc_memw0------------*/
AR=^Enc_Aqt;
DM(Enc_Aq)=AR;
AR=PASS 0;
Residu_loop: DM(Enc_subfr)=AR;
I2=DM(Enc_Aq);
I1=DM(Enc_speech);
M3=DM(Enc_subfr);
MODIFY(I1,M3);
I0=^Enc_xn;
CNTR=L_SUBFR;
CALL Residu;
CNTR=M-1;
MY1=GAMMA1;
I0=^Enc_Apt;
I1=DM(Enc_Aq);
CALL Weight_Az;
/*---------Compute Enc_wsp and Enc_memw-------------------*/
// CNTR=M;
MY0=22938;
I1=^Enc_Apt;
I0=^Enc_Apt+MP1;
DM(Enc_Ap)=I0;
MX0=DM(I1,M1);
DM(I0,M1)=4096;
CNTR=M;
DO calc_Ap UNTIL CE;
MR=MX0 * MY0(SS),AY0=DM(I1,M0);
AR=AY0-MR1,MX0=DM(I1,M1);
calc_Ap: DM(I0,M1)=AR;
AY0=1;
I1=DM(Enc_Ap);
I2=^Enc_xn;
I0=DM(Enc_wsp);
M3=DM(Enc_subfr);
MODIFY(I0,M3);
I3=^Enc_memw;
SI=L_SUBFR;
CALL Syn_filt;
/*-----Compute Enc_memw0--------*/
I1=DM(Enc_excit);
M3=DM(Enc_subfr);
MODIFY(I1,M3);
I2=^Enc_xn;
CNTR=L_SUBFR;
DO calc_xn UNTIL CE;
AY0=DM(I1,M1);
AX0=DM(I2,M0);
AR=AX0-AY0;
calc_xn: DM(I2,M1)=AR;
AY0=1;
I1=^Enc_Apt;
I2=^Enc_xn;
I0=^Enc_xn;
I3=^Enc_memw0;
SI=L_SUBFR;
CALL Syn_filt;
AY0=MP1;
AX0=DM(Enc_Aq);
AR=AX0+AY0;
DM(Enc_Aq)=AR;
AR=DM(Enc_subfr);
AY0=L_SUBFR;
AR=AR+AY0;
AY0=L_FRAME;
NONE=AR-AY0;
IF LT JUMP Residu_loop;
AY0=SHARPMIN;
DM(Enc_sharp)=AY0;
JUMP update_mem;
/* -------------------- */
/* Case of Active frame */
/* -------------------- */
active_frame: I6=DM(analy);
DM(I6,M4)=1;
DM(analy)=I6;
AR=INIT_SEED;
DM(Enc_seed)=AR;
AR=DM(Enc_pastVad);
DM(Enc_ppastVad)=AR;
AR=DM(VadEncode);
DM(Enc_pastVad)=AR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -