Sigmund/sigmund.c
/*************** gather peak lists into sinusoidal tracks *************/
gather peak lists into sinusoidal tracks
gather peak lists into sinusoidal tracks
void sigmund_peaktrack(int ninpeak, t_peak *inpeakv, 
		       int noutpeak, t_peak *outpeakv, int loud)
{
  int incnt, outcnt;
  for (outcnt = 0; outcnt < noutpeak; outcnt++)
    outpeakv[outcnt].p_tmp = -1;
  for (incnt = 0; incnt < ninpeak; incnt++)
    {
      t_float besterror = 1e20;
      int bestcnt = -1;
      inpeakv[incnt].p_tmp = -1;
      for (outcnt = 0; outcnt < noutpeak; outcnt++)
	{
	  t_float thiserror =
	    inpeakv[incnt].p_freq - outpeakv[outcnt].p_freq;
	  if (thiserror < 0)
	    thiserror = -thiserror;
	  if (thiserror < besterror)
	    {
	      besterror = thiserror;
	      bestcnt = outcnt;
	    }
	}
      if (outpeakv[bestcnt].p_tmp < 0)
	{
	  outpeakv[bestcnt] = inpeakv[incnt];
	  inpeakv[incnt].p_tmp = 0;
	  outpeakv[bestcnt].p_tmp = 0;
	}
    }
  for (incnt = 0; incnt < ninpeak; incnt++)
    if (inpeakv[incnt].p_tmp < 0)
      {
	for (outcnt = 0; outcnt < noutpeak; outcnt++)
	  if (outpeakv[outcnt].p_tmp < 0)
	    {
	      outpeakv[outcnt] = inpeakv[incnt];
	      inpeakv[incnt].p_tmp = 0;
	      outpeakv[outcnt].p_tmp = 1;
	      break;
	    }
      }
  for (outcnt = 0; outcnt < noutpeak; outcnt++)
    if (outpeakv[outcnt].p_tmp == -1)
      outpeakv[outcnt].p_amp = 0;
}
void sigmund_peaktrack ( int ninpeak , t_peak * inpeakv , int noutpeak , t_peak * outpeakv , int loud ) { int incnt , outcnt ; for ( outcnt = 0 ; outcnt < noutpeak ; outcnt ++ ) outpeakv [ outcnt ] . p_tmp = -1 ; for ( incnt = 0 ; incnt < ninpeak ; incnt ++ ) { t_float besterror = 1e20 ; int bestcnt = -1 ; inpeakv [ incnt ] . p_tmp = -1 ; for ( outcnt = 0 ; outcnt < noutpeak ; outcnt ++ ) { t_float thiserror = inpeakv [ incnt ] . p_freq - outpeakv [ outcnt ] . p_freq ; if ( thiserror < 0 ) thiserror = - thiserror ; if ( thiserror < besterror ) { besterror = thiserror ; bestcnt = outcnt ; } } if ( outpeakv [ bestcnt ] . p_tmp < 0 ) { outpeakv [ bestcnt ] = inpeakv [ incnt ] ; inpeakv [ incnt ] . p_tmp = 0 ; outpeakv [ bestcnt ] . p_tmp = 0 ; } } for ( incnt = 0 ; incnt < ninpeak ; incnt ++ ) if ( inpeakv [ incnt ] . p_tmp < 0 ) { for ( outcnt = 0 ; outcnt < noutpeak ; outcnt ++ ) if ( outpeakv [ outcnt ] . p_tmp < 0 ) { outpeakv [ outcnt ] = inpeakv [ incnt ] ; inpeakv [ incnt ] . p_tmp = 0 ; outpeakv [ outcnt ] . p_tmp = 1 ; break ; } } for ( outcnt = 0 ; outcnt < noutpeak ; outcnt ++ ) if ( outpeakv [ outcnt ] . p_tmp == -1 ) outpeakv [ outcnt ] . p_amp = 0 ; }
gather peak lists into sinusoidal tracks
gather peak lists into sinusoidal tracks
/* first pass. Match each "in" peak with the closest previous
     "out" peak, but no two to the same one. */ /* second pass.  Unmatched "in" peaks assigned to free "out"
     peaks */