code: public static int lag_max(     /* output: lag found */
  	  float signal[], int signals,       /* input : Signal to compute the open loop pitch
  	                                   signal[-142:-1] should be known.       */
  	  int l_frame,          /* input : Length of frame to compute pitch       */
  	  int lagmax,           /* input : maximum lag                            */
  	  int lagmin,           /* input : minimum lag                            */
  	  FloatPointer cor_max        /* input : normalized correlation of selected lag */
  	)
  	{
  	    int    i, j;
  	    int  p=0, p1;
  	    float  max, t0;
  	    int    p_max=0;
  
  	    max = LD8KConstants.FLT_MIN_G729;
  
  	    for (i = lagmax; i >= lagmin; i--) {
  	        p  = 0;//signal;
  	        p1 = -i;//&signal[-i];
  	        t0 = (float)0.0;
  
  	        for (j=0; j<l_frame; j++) {
  	            t0 += signal[signals + p++] * signal[signals + p1++];
  	        }
  
  	        if (t0 >= max) {
  	            max    = t0;
  	            p_max = i;
  	        }
  	    }
  
  	    /* compute energy */
  
  	    t0 = (float)0.01;                  /* to avoid division by zero */
  	    p = -p_max;
  	    for(i=0; i<l_frame; i++, p++) {
  	        t0 += signal[signals + p] * signal[signals + p];
  	    }
  	    t0 = inv_sqrt(t0);          /* 1/sqrt(energy)    */
  
  	    cor_max.value = max * t0;        /* max/sqrt(energy)  */
  
  	    return(p_max);
  	}
docs: /*----------------------------------------------------------------------------
  lag_max - Find the lag that has maximum correlation
  ----------------------------------------------------------------------------