www.pudn.com > lpc.zip > vparms_i.c


/**********************************************************************
*
*	VPARMS Version 50
*
**********************************************************************
*
*  Calculate voicing parameters:
*
* Inputs:
*  VWIN   - Voicing window limits
*  INBUF  - Input speech buffer
*  LPBUF  - Low pass filtered speech
*  BUFLIM - Array bounds for INBUF and LPBUF
*  HALF   - Half frame (1 or 2)
*  DITHER - Zero crossing threshold
*  MINTAU - Lag corresponding to minimum AMDF value (pitch estimate)
* Outputs:
*  ZC     - Zero crossing rate
*  LBE    - Low band energy (sum of magnitudes - SM)
*  FBE    - Full band energy (SM)
*  QS     - Ratio of 6 dB/oct preemphasized energy to full band energy
*  RC1    - First reflection coefficient
*  AR_B   - Product of the causal forward and reverse pitch
*           prediction gains
*  AR_F   - Product of the noncausal forward and reverse pitch
*           prediction gains
* Internal:
*  OLDSGN - Previous sign of dithered signal
*  VLEN   - Length of voicing window
*  START  - Lower address of current half of voicing window
*  STOP   - Upper address of current half of voicing window
*  E_0    - Energy of LPF speech (sum of squares - SS)
*  E_B    - Energy of LPF speech backward one pitch period (SS)
*  E_F    - Energy of LPF speech forward one pitch period (SS)
*  R_B    - Autocovariance of LPF speech backward one pitch period
*  R_F    - Autocovariance of LPF speech forward one pitch period
*  LP_RMS - Energy of LPF speech (sum of magnitudes - SM)
*  AP_RMS - Energy of all-pass speech (SM)
*  E_PRE  - Energy of 6dB preemphasized speech (SM)
*  E0AP   - Energy of all-pass speech (SS)
*/

#include "ourstuff.h"
#include "lpcdefs.h"
#include 

/********sw*******/
extern float min1, min2, min3;
extern float max1, max2, max3;
/*****************/

vparms_i(vwin, inbuf, lpbuf, half, dither, mintau, zc, lbe, fbe, qs, rc1,
	 ar_b, ar_f )
int_type *vwin;
int_type *inbuf;
int_type half, *zc, *lbe, *fbe, mintau;
int_type *dither, *qs, *rc1, *ar_b;
int_type *ar_f;
int_type *lpbuf;
{
int_type i, vlen, start, stop;
int_type oldsgn, e_0, e_b, r_b, lp_rms, ap_rms, e_pre, e0ap;
int_type e_f, r_f;
int_type sign;
int_type *ptr1, *ptr2;
int_type sw;

                        /******** VWIN(1) => vwin[0][2] ********
                         ******** VWIN(2) => vwin[1][2] ********/

/*   Calculate zero crossings (ZC) and several energy and correlation
*   measures on low band and full band speech.  Each measure is taken
*   over either the first or the second half of the voicing window,
*   depending on the variable HALF.	*/

lp_rms = 0;
ap_rms = 0;
e_pre = 0;
e0ap = 0;
*rc1 = 0;
e_0 = 0;
e_b = 0;
e_f = 0;
r_f = 0;
r_b = 0;
*zc = 0;

vlen = *(vwin+AF+2) - *(vwin+2) + 1;
start = *(vwin+2) + (half-1)*(vlen>>1) + 1;
stop = start + (vlen>>1) - 1;
oldsgn = ( ((*(inbuf+start-1))>>2) - *dither < 0 )?-1:1;
ptr1 = lpbuf+start;
ptr2 = inbuf+start;
/*
printf(">> %d %d %d %d %f %f\n",
       vlen,start,stop,oldsgn,*ptr1/4096.,*ptr2/4096.);
fflush(stdout);
*/       
for(i=start; i<= stop; i++)	{
        lp_rms += (*ptr1>0)?(*ptr1 >> 3):-(*ptr1 >> 3);
	/*
	if(lp_rms>max1)
	  max1=lp_rms;
	if(lp_rms0)?(*ptr2 >> 3):-(*ptr2 >> 3);
	/*
	if(ap_rms>max2)
	  max2=ap_rms;
	if(ap_rms0)?((*ptr2-*(ptr2-1)) >> 3) :
	  -((*ptr2-*(ptr2-1)) >> 3);
	/*
	if(e_pre>max3)
	  max3=e_pre;
	if(e_pre> 14);
	/*
	if(e0ap>max1)
	  max1=e0ap;
	if(e0ap> 14);
	/*
	if(*rc1>max2)
	  max2=*rc1;
	if(*rc1> 14);
	/*
	if(e_0>max3)
	  max3=e_0;
	if(e_0> 14);
	/*
	if(e_b>max1)
	  max1=e_b;
	if(e_b> 14);
	/*
	if(e_f>max2)
	  max2=e_f;
	if(e_f> 14);
	/*
	if(r_f>max3)
	  max3=r_f;
	if(r_f> 14);
	/*
	if(r_b>max1)
	  max1=r_b;
	if(r_bmax2)
	  max2=*ptr1;
	if(*ptr1max3)
	  max3=*ptr2;
	if(*ptr21)?(*rc1 << 14)/e0ap:*rc1;

/*   Ratio of the energy of the first difference signal (6 dB/oct preemphasis)
 *   to the energy of the full band signal	*/

*qs = (ap_rms>1)?(e_pre << 13)/ap_rms:ap_rms;

/*   aR_b is the product of the forward and reverse prediction gains,
 *   looking backward in time (the causal case).	*/

/***** *ar_b = (r_b / mmax(e_b,1.)) * (r_b / mmax(e_0,1.)); *****/
sw = (mmax(e_b,1) * mmax(e_0,1) >> 14);
*ar_b = (sw>1)?(r_b * r_b) / sw : (r_b * r_b >> 14);

/* aR_f is the same as aR_b, but looking forward in time (non causal case). */

*ar_f = ((((r_f << 14) / mmax(e_f,1)) *
	  ((r_f << 14) / mmax(e_0,1))) >> 14);

/*   Normalize ZC, LBE, and FBE to old fixed window length of 180.
 *   (The fraction 90/VLEN has a range of .58 to 1)		*/

/*****
*zc = *zc*2 * (90./vlen) );
*lbe = mmin( nint( lp_rms*0.25 * (90./vlen) ), 32767 );
*fbe = mmin( nint( ap_rms*0.25 * (90./vlen) ), 32767 );
*****/

*zc = ( (*zc<<1) * (11557/vlen) + 64 ) >> 7;
*lbe = mmin( ((lp_rms * (11557/vlen)) + 64) >> 6, 32767 );
*fbe = mmin( ((ap_rms * (11557/vlen)) + 64) >> 6, 32767 );
/*
printf("(i) %f %f %f %f %d %d %d\n",
       *rc1, *qs, *ar_b, *ar_f, *zc, *lbe, *fbe);
       */
}