⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postfilt.dsp

📁 基于ADSP的G.729语音编解码程序
💻 DSP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
* $$01/10/2000 checked post filter 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  *
* Performs adaptive postfiltering on the synthesis speech                *
* This file contains all functions related to the post filter.           *
**************************************************************************/
.MODULE/SEG=App_PM        Postfilter;

/*************************************************************************/
#include       "ld8a.inc"

/*************************************************************************/
/* inverse filtered synthesis (with A(z/GAMMA2_PST))                     */
/* $$01/10/2000 static memory and pointer                                */
/*************************************************************************/
.VAR/DM/RAM/SEG=App_DMmem    res2_buf[PIT_MAX+L_SUBFR];
.VAR/DM/RAM/SEG=App_DMmem    scal_res2_buf[PIT_MAX+L_SUBFR];
.VAR/DM/RAM/SEG=App_DMmem    res2,scal_res2;

/*************************************************************************/
/* memory of filter 1/A(z/GAMMA1_PST)                                    */
/* $$01/10/2000 static memory and pointer                                */
/*************************************************************************/
.VAR/DM/RAM/SEG=App_DMmem    mem_syn_pst[M];
.VAR/DM/RAM/SEG=App_DMmem    past_gain,mem_pre;

/*************************************************************************/
.EXTERNAL      SynthDecode,VadDecode;
.EXTERNAL      Syn_filt,div_s;
.EXTERNAL      Inv_sqrt,Residu;
.EXTERNAL      Weight_Az;

/**************************************************************************
* The postfiltering process is described as follows:                      *
*  - inverse filtering of synth[] through A(z/GAMMA2_PST) to get res2[]   *
*  - use res2[] to compute pitch parameters                               *
*  - perform pitch postfiltering                                          *
*  - tilt compensation filtering; 1 - MU*k*z^-1                           *
*  - synthesis filtering through 1/A(z/GAMMA1_PST)                        *
*  - adaptive gain control                                                *
* $$01/10/2000 only used in decoder                                       *
* $$01/11/2000 modify pointer and varaibles to adapt table change         *
* Calling Parameters												      *	
*         I2       : interpolated LPC parameters in all subframes		  *
*         I1       : decoded pitch lags in all subframes				  *
*         VadDecode: voice active detect flag  							  *
* Return Values														      *
*         Synth    : synthesis speech (postfiltered is output)			  *
* Altered Registers: AR,I0,I1,M1                                          *	
* Computation Time : 18 cycles										      *	
***************************************************************************/
.ENTRY         Post_Filter;

/*-------------------------------------------------------------------------*
* Declaration of parameters                                                *
* $$01/10/2000 only used in decoder,local buffers and variables            *
*--------------------------------------------------------------------------*/
.VAR/DM/RAM/SEG=App_DMbuf    res2_pst[L_SUBFR];      /* res2[] after pitch postfiltering */
.VAR/DM/RAM/SEG=App_DMbuf    syn_pst[L_FRAME],h[L_H];/* post filtered synthesis speech   */
.VAR/DM/RAM/SEG=App_DMbuf    Ap3[MP1], Ap4[MP1];     /* bandwidth expanded LP parameters */
.VAR/DM/RAM/SEG=App_DMtmp    t0_min,t0_max,Subfr_no; /* index for beginning of subframe  */
.VAR/DM/RAM/SEG=App_DMtmp    Az_back,T2_back;        /* pointer to Az_4:                 */

Post_Filter:   AR=PASS 0;
filter_subfr:  DM(Az_back)=I2;
			   DM(Subfr_no)=AR;
	 {---------Find pitch range t0_min - t0_max---------}
	           AX0=DM(I1,M1);
			   DM(T2_back)=I1;
			   M3=AR;
			   AY0=6;
			   AR=AX0-3;
			   DM(t0_min)=AR;
			   AR=AR+AY0;
			   DM(t0_max)=AR;
			   AY1=PIT_MAX;
			   AF=AR-AY1,AX0=AY1;
			   IF LE JUMP no_modmax;
			   AR=AX0-AY0;
			   DM(t0_min)=AR;
			   DM(t0_max)=AY1;
no_modmax:     //CNTR=M-1;
	 {---------Find weighted filter coefficients Ap3[] and ap[4]------}
			   I0=^Ap3;
			   I1=DM(Az_back);
			   MY1=GAMMA2_PST;
			   CNTR=M-1;
	           CALL Weight_Az;
//			   CNTR=M-1;
			   I0=^Ap4;
	           I1=DM(Az_back);
			   MY1=GAMMA1_PST;
			   CNTR=M-1;
			   CALL Weight_Az;
	 {---------filtering of synthesis speech by A(z/GAMMA2_PST) to find res2[]--}
			   I2=^Ap3;	   
			   I0=DM(res2); 
               I1=DM(SynthDecode);
			   M3=DM(Subfr_no);
//			   CNTR=L_SUBFR;          
			   MODIFY(I1,M3);
			   CNTR=L_SUBFR;          
			   CALL Residu;
	 {---------scaling of "res2[]" to avoid energy overflow------}
			   SE=-2;
			   I4=DM(res2);
			   AR=DM(I4,M4);
//	           CNTR=L_SUBFR;
               I5=DM(scal_res2);
	           CNTR=L_SUBFR;
			   DO shr_scal UNTIL CE;			   
			   SR=ASHIFT AR (LO),AR=DM(I4,M4);
shr_scal:      DM(I5,M4)=SR0;
	 {---------pitch postfiltering--------------}
	           AY0=DM(VadDecode);
			   NONE=AY0-1;
			   IF NE JUMP no_pit_filter;
			   I1=DM(res2);
			   I2=DM(scal_res2);
     		   SI=L_SUBFR;
			   I0=^res2_pst;
			   CALL pit_pst_filt;
			   JUMP tilt_comp;
no_pit_filter: I4=DM(res2);
//               CNTR=L_SUBFR;
			   I5=^res2_pst;
               CNTR=L_SUBFR;
			   DO copy_respst UNTIL CE;
			   AR=DM(I4,M4);
copy_respst:   DM(I5,M4)=AR;
	 {---------tilt compensation filter------------}
	 {---------impulse response of A(z/GAMMA2_PST)/A(z/GAMMA1_PST)----}
tilt_comp:     I3=^h;
			   I4=^Ap3;
               CNTR=M+1;
			   DO copy_imp UNTIL CE;
			   AX0=DM(I4,M4);
copy_imp:      DM(I3,M1)=AX0;
			   I4=^h+M+1;
			   CNTR=L_H-M-1;
			   DO zero_imp UNTIL CE;
zero_imp:      DM(I4,M4)=0;
               AY0=0;
			   I2=^h;
			   I0=^h;
			   SI=L_H;
               I1=^Ap4;
			   I3=^h+M+1;
               CALL Syn_filt;
	 {---------1st correlation of h[]--------------------}
               I4=^h;
//			   CNTR=L_H-1;
			   AR=DM(I4,M4);
			   MR=AR * AR(SS);
			   CNTR=L_H-1;
			   DO mac_imp UNTIL CE;
			   AR=DM(I4,M4); 
mac_imp:       IF NOT MV MR=MR+AR*AR(SS);
               IF MV SAT MR;
			   I4=^h;
			   I5=^h+1;
//			   CNTR=L_H-2;
			   MX0=DM(I4,M4);
			   MY0=DM(I5,M4);
			   MR=MX0 * MY0(SS),AX0=MR1;
			   CNTR=L_H-2;
			   DO mac_hhh UNTIL CE;
			   MX0=DM(I4,M4);
			   MY0=DM(I5,M4);
mac_hhh:       IF NOT MV MR=MR+MX0*MY0(SS);
               IF MV SAT MR;
               MX0=0;
			   AR=PASS MR1,SR0=AX0;
			   IF LE JUMP do_preemp;
			   MY0=MU;
			   SR=ASHIFT SR0 BY 0(LO);
			   MR=MR1 * MY0(SS); 
			   MR0=MR1;
			   MR1=MR2;			   
			   CALL div_s;
			   MX0=AR;
do_preemp:     I0=^res2_pst;
			   AY0=L_SUBFR-1;
               CALL preemphasis;
      {--------filtering through  1/A(z/GAMMA1_PST)----------}
			   AY0=1;
               I1=^Ap4;
			   SI=L_SUBFR;
			   I0=^syn_pst;
			   I2=^res2_pst;
			   M3=DM(Subfr_no);
			   I3=^mem_syn_pst;
			   MODIFY(I0,M3);
	           CALL Syn_filt;
	  {--------scale output to input-------------------------}
			   I1=DM(SynthDecode);
			   M3=DM(Subfr_no);
		 	   SI=L_SUBFR;
			   I2=^syn_pst;
			   MODIFY(I1,M3);
			   MODIFY(I2,M3);
	           CALL agc;
	  {--------update res2[] buffer;  shift by L_SUBFR-------}
//	           CNTR=PIT_MAX;
			   M5=-PIT_MAX;
			   M6=L_SUBFR-PIT_MAX;
			   I4=DM(res2);
			   I5=DM(res2);
			   MODIFY(I4,M5);
			   MODIFY(I5,M6);
	           CNTR=PIT_MAX;
			   DO back_res2 UNTIL CE;
			   AR=DM(I5,M4);
back_res2:     DM(I4,M4)=AR;
				nop;
			   I4=DM(scal_res2);
//               CNTR=PIT_MAX;
			   I5=DM(scal_res2);
			   MODIFY(I4,M5);
			   MODIFY(I5,M6);
               CNTR=PIT_MAX;
			   DO back_scal UNTIL CE;
			   AR=DM(I5,M4);
back_scal:     DM(I4,M4)=AR;
			   M3=MP1;
			   I1=DM(T2_back);
               I2=DM(Az_back);
			   MODIFY(I2,M3);
			   AX0=DM(Subfr_no);
			   AY0=L_SUBFR;
			   AR=AX0+AY0;
               AY0=L_FRAME;
			   NONE=AR-AY0;
			   IF LT JUMP filter_subfr;
		{----- update SynthDecode[] buffer------------}
			   M3=-M;
//			   CNTR=M;
			   I0=DM(SynthDecode);
			   I1=DM(SynthDecode);
			   MODIFY(I1,M3);
			   M3=L_FRAME-M;
			   MODIFY(I0,M3);
			   CNTR=M;
			   DO copy_synth UNTIL CE;
			   AR=DM(I0,M1);
copy_synth:	   DM(I1,M1)=AR;
	  {--------overwrite synthesis speech by postfiltered synthesis speech-----}
			   I0=DM(SynthDecode);
			   I1=^syn_pst;
			   CNTR=L_FRAME;
			   DO copy_synpst UNTIL CE;
			   AR=DM(I1,M1);
copy_synpst:   DM(I0,M1)=AR;
	           RTS;
/**************************************************************************
* procedure pitch_pst_filt                                                *
* Find the pitch period  around the transmitted pitch and perform         *
* harmonic postfiltering.                                                 *
* Filtering through   (1 + g z^-T) / (1+g) ;   g = min(pit_gain*gammap, 1)*
* $$01/10/2000 only used in decoder                                       *
* Calling Parameters												      *	
*         I1   : input signal                                             *
*         I2   : input signal (scaled, divided by 4)                      *
*         SI   : size of filtering                                        *
* Return Values														      *
*         I0   : harmonically postfiltered signal                         *
* Altered Registers: AR,I0,I1,M1                                          *	
* Computation Time : 18 cycles										      *	
***************************************************************************/
.ENTRY         pit_pst_filt;
.VAR/DM/RAM/SEG=App_DMtmp    cormax_lo,cormax_hi,T0_index;

pit_pst_filt:  I4=I2;
			   AX0=DM(t0_min);
			   AR=-AX0;
			   M5=AR;
			   MODIFY(I4,M5); 
			   AY0=DM(t0_max);
/*------------------------------------------------------------------*
 * Compute the correlations for all delays                          *
 * and select the delay which maximizes the correlation             *
 *------------------------------------------------------------------*/
			   AR=AY0-AX0;
			   AR=AR+1;
//			   CNTR=AR;
               AY1=H#8000;
			   AY0=H#0000;
			   AF=PASS AX0;
               DM(T0_index)=AX0;
			   CNTR=AR;
			   Do find_cormax UNTIL CE;
			   I3=I2;
			   I5=I4;
//               CNTR=SI;
			   MR=0,MX0=DM(I4,M7);
               CNTR=SI;
			   Do mac_corrmax UNTIL CE;
			   MX0=DM(I3,M1);
			   MY0=DM(I5,M4);
mac_corrmax:   IF NOT MV MR=MR+MX0*MY0(SS);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -