www.pudn.com > aacenc.rar > winswitch.c


 
 
#include "tf_main.h" 
#include "winswitch.h" 
 
#define ntt_N_SUP_MAX       2 
 
int num_channel; 
 
 
int winSwitch(/* Input */ 
			double sig[],         /* input signal */ 
			/* Output */ 
			enum WINDOW_TYPE *w_type,     /* code index for block type */ 
			/* Control */ 
			int    InitFlag)/* initialization flag */ 
{ 
    /*--- Variables ---*/ 
    int s_attack; 
	int ratio; 
 
    /*--- A.Jin 1997.10.19 ---*/ 
	ratio = checkAttack(sig, &s_attack, InitFlag); 
 
    getWindowType( s_attack,  w_type, InitFlag ); 
	return ratio; 
} 
 
 
void getWindowType(int flag,      /* Input : trigger for short block length */ 
		 enum WINDOW_TYPE *w_type,   /* Output : code index for block type */ 
		 int InitFlag ) /* Control : initialization flag */ 
{ 
    static int	w_type_pre; 
    static int	flag_pre; 
 
    if ( InitFlag ){ 
		flag_pre = 0; 
		w_type_pre = ONLY_LONG_WINDOW; 
    } 
 
    if (InitFlag){ 
		if (flag)        *w_type = ONLY_SHORT_WINDOW; 
		else             *w_type = ONLY_LONG_WINDOW; 
    } 
    else{ 
		switch( w_type_pre ){ 
		case ONLY_LONG_WINDOW: 
			if ( flag )      *w_type = LONG_SHORT_WINDOW; 
			else             *w_type = ONLY_LONG_WINDOW; 
			break; 
		case LONG_SHORT_WINDOW: 
			*w_type = ONLY_SHORT_WINDOW; 
			break; 
		case SHORT_LONG_WINDOW: 
			if ( flag )      *w_type = LONG_SHORT_WINDOW; 
			else             *w_type = ONLY_LONG_WINDOW; 
			break; 
		case ONLY_SHORT_WINDOW: 
			if (flag || flag_pre) *w_type = ONLY_SHORT_WINDOW; 
			else                  *w_type = SHORT_LONG_WINDOW; 
		} 
    } 
    w_type_pre = *w_type; 
    flag_pre = flag; 
} 
 
 
#define ST_CHKATK    (BLOCK_LEN_LONG/2+BLOCK_LEN_SHORT/2) 
 
#define N_BLK_MAX	4096 
#define	N_SFT_MAX   256 
#define	N_LPC_MAX	2 
 
__inline void ZeroMem(int n, double xx[]) 
{ 
	int i = n; 
	while(i-- != 0) 
		*(xx++) = 0.0; 
} 
 
void LagWindow(/* Output */ 
                double wdw[],  /* lag window data */ 
                /* Input */ 
                int n,         /* dimension of wdw[.] */ 
                double h)      /* ratio of window half value band width to sampling frequency */ 
{ 
	int i; 
	double pi=3.14159265358979323846264338327959288419716939; 
	double a,b,w; 
	if(h<=0.0) for(i=0;i<=n;i++) wdw[i]=1.0; 
	else 
	{ 
		a=log(0.5)*0.5/log(cos(0.5*pi*h)); 
		a=(double)((int)a); 
		w=1.0; b=a; wdw[0]=1.0; 
		for(i=1;i<=n;i++) 
		{ 
			b+=1.0; w*=a/b; wdw[i]=w; a-=1.0; 
		} 
	} 
} 
 
void HammingWindow(/* Output */ 
                double wdw[],  /* Hamming window data */ 
                int n)         /* window length */ 
{ 
	int i; 
	double d,pi=3.14159265358979323846264338327950288419716939; 
	if(n>0) 
	{ 
		d=2.0*pi/n; 
		for(i=0;i0) { 
		sqsum = DotProd(n, sig, sig)+1.e-35; 
		dsqsum = 1./sqsum; 
		k=p; 
		do { 
			c = DotProd(n-k, sig, sig+k); 
			cor[k] = c*dsqsum; 
		}while(--k); 
	} 
	*_pow = (sqsum-1.e-35)/(double)n; 
} 
 
__inline void Corr2Ref(int p,          /* Input : LPC analysis order */ 
	    double cor[],   /* Input : correlation coefficients */ 
	    double alf[],   /* Output : linear predictive coefficients */ 
	    double ref[],   /* Output : reflection coefficients */ 
	    double *resid_) /* Output : normalized residual power */ 
{ 
	int i,j,k; 
	double resid,r,a; 
	if(p>0) { 
		ref[1]=cor[1]; 
		alf[1]= -ref[1]; 
		resid=(1.0-ref[1])*(1.0+ref[1]); 
		for(i=2;i<=p;i++) { 
			r=cor[i]; 
			for(j=1;j 8000) { 
		*flag = 1; 
	} else { 
		*flag = 0; 
	} 
	return (int)ratio+0.5; 
} 
 
 
void winSwitchInit(int max_ch) 
{ 
	num_channel = max_ch; 
}