public static int pitch_fr3(          /* output: integer part of pitch period        */
	 float exc[],int excs,           /* input : excitation buffer                   */
	 float xn[],int xns,            /* input : target vector                       */
	 float h[], int hs,            /* input : impulse response of filters.        */
	 int l_subfr,           /* input : Length of frame to compute pitch    */
	 int t0_min,            /* input : minimum value in the searched range */
	 int t0_max,            /* input : maximum value in the searched range */
	 int i_subfr,           /* input : indicator for first subframe        */
	 IntegerPointer pit_frac          /* output: chosen fraction                     */
	)
	{
	  int    i, frac;
	  int    lag, t_min, t_max;
	  float  max;
	  float  corr_int;
	  float  corr_v[] = new float[10+2*LD8KConstants.L_INTER4];  /* size: 2*L_INTER4+t0_max-t0_min+1 */
	  int  corr;

	  /* Find interval to compute normalized correlation */

	  t_min = t0_min - LD8KConstants.L_INTER4;
	  t_max = t0_max + LD8KConstants.L_INTER4;

	  corr = -t_min;    /* corr[t_min:t_max] */

	  /* Compute normalized correlation between target and filtered excitation */

	  norm_corr(exc, excs, xn, xns, h, hs, l_subfr, t_min, t_max, corr_v, corr);

	  /* find integer pitch */

	  max = corr_v[corr+t0_min];
	  lag  = t0_min;

	  for(i= t0_min+1; i<=t0_max; i++)
	  {
	    if( corr_v[corr+i] >= max)
	    {
	      max = corr_v[corr+i];
	      lag = i;
	    }
	  }

	  /* If first subframe and lag > 84 do not search fractionnal pitch */

	  if( (i_subfr == 0) && (lag > 84) )
	  {
	    pit_frac.value = 0;
	    return(lag);
	  }

	  /* test the fractions around lag and choose the one which maximizes
	     the interpolated normalized correlation */

	  max  = interpol_3(corr_v, corr+lag, -2);
	  frac = -2;

	  for (i = -1; i <= 2; i++)
	  {
	    corr_int = interpol_3(corr_v, corr+lag, i);
	    if(corr_int > max)
	    {
	      max = corr_int;
	      frac = i;
	    }
	  }

	  /* limit the fraction value in the interval [-1,0,1] */

	  if (frac == -2)
	  {
	    frac = 1;
	    lag -= 1;
	  }
	  if (frac == 2)
	  {
	    frac = -1;
	    lag += 1;
	  }

	  pit_frac.value = frac;

	  return lag;
	}
public static int pitch_fr3 ( float exc [ ] , int excs , float xn [ ] , int xns , float h [ ] , int hs , int l_subfr , int t0_min , int t0_max , int i_subfr , IntegerPointer pit_frac ) { int i , frac ; int lag , t_min , t_max ; float max ; float corr_int ; float corr_v [ ] = new float [ 10 + 2 * LD8KConstants . L_INTER4 ] ; int corr ; t_min = t0_min - LD8KConstants . L_INTER4 ; t_max = t0_max + LD8KConstants . L_INTER4 ; corr = - t_min ; norm_corr ( exc , excs , xn , xns , h , hs , l_subfr , t_min , t_max , corr_v , corr ) ; max = corr_v [ corr + t0_min ] ; lag = t0_min ; for ( i = t0_min + 1 ; i <= t0_max ; i ++ ) { if ( corr_v [ corr + i ] >= max ) { max = corr_v [ corr + i ] ; lag = i ; } } if ( ( i_subfr == 0 ) && ( lag > 84 ) ) { pit_frac . value = 0 ; return ( lag ) ; } max = interpol_3 ( corr_v , corr + lag , - 2 ) ; frac = - 2 ; for ( i = - 1 ; i <= 2 ; i ++ ) { corr_int = interpol_3 ( corr_v , corr + lag , i ) ; if ( corr_int > max ) { max = corr_int ; frac = i ; } } if ( frac == - 2 ) { frac = 1 ; lag -= 1 ; } if ( frac == 2 ) { frac = - 1 ; lag += 1 ; } pit_frac . value = frac ; return lag ; }
/*----------------------------------------------------------------------------
pitch_fr3 - find the pitch period  with 1/3 subsample resolution
----------------------------------------------------------------------------