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


/************************************************************
*
*	DIFMAG Version 49
*
*************************************************************
*
*  Compute Average Magnitude Difference Function
*
* Inputs:
*  SPEECH - Low pass filtered speech
*  LPITA  - Length of speech buffer
*  TAU    - Table of lags
*  LTAU   - Number of lag values to compute
*  MAXLAG - Maximum possible lag value
* Outputs:
*  AMDF   - Average Magnitude Difference for each lag in TAU
*  MINPTR - Index of minimum AMDF value
*  MAXPTR - Index of maximum AMDF value
*/

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


difmag_i( speech, tau, ltau, maxlag, amdf, minptr, maxptr )
int_type maxlag, *minptr, *maxptr, ltau;
int_type tau[];
int_type speech[], amdf[];
{
int_type i, j, n1, n2;
int_type sum, temp;

*minptr = 1;
*maxptr = 1;
for(i=1;i<=ltau;i++)	{
	n1 = ((maxlag-tau[i])>>1) +1;
	n2 = n1 + MAXWIN - 1;
	/*	printf("n1: %d n2: %d i:%d\n",n1, n2,i);
	printf("maxlag: %d tau: %d\n",maxlag, tau[i]);*/
	sum = 0;
	for(j=n1;j<=n2;j+=4)	{
	  temp = (speech[j] - speech[j+tau[i]])>>1;
	  sum += (temp > 0 )?(temp):(-temp);
	}
	sum = (sum >= 16383)?(32767):(sum<<1);
	amdf[i] = sum;
	if( amdf[i] < amdf[*minptr]) {
	  *minptr = i;
	}
	if( amdf[i] > amdf[*maxptr]) {
	  *maxptr = i;
	}
}

}