#include "pitch.h"

float 
getpch(sigf,tphi,tpsi,tgamph,tgamps,freq,n)
float tphi[50][5][18],tpsi[50][6][18],tgamph[50][5],tgamps[50][5];
float *sigf, *freq;
int n;
{
	int i, j,tenj;
	float s[35],g[18],h[18];
	float fm,xx,qsum,search();

        for (j=0 ;j < JMAX ; ++j)
	{
		tenj = 10 * (j+1) - 1 ;
		s[j]=sigf[tenj];
	}
	for (i=0 ; i<MM ; ++i)
	{
		g[i] = .5 * ( s[MM+i-1] - s[MM-i-1] );
		h[i] = .5 * ( s[MM+i-1] + s[MM-i-1] );
	}
	qsum = 0.;
	for (i=0 ; i<MM ; ++i)
		qsum += (g[i]*g[i]) + (h[i]*h[i]);
	xx=search(&fm,qsum,tphi,tpsi,tgamph,tgamps,g,h,freq,n);
	return(xx);
}
