sonic_lite.c
static int findPitchPeriod(short *samples, int preferNewPeriod) {
  int minPeriod = SONIC_MIN_PERIOD;
  int maxPeriod = SONIC_MAX_PERIOD;
  int minDiff, maxDiff, retPeriod;
  int period;

  if (SONIC_SKIP == 1) {
    period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff, &maxDiff);
  } else {
    downSampleInput(samples);
    period = findPitchPeriodInRange(sonicStream.downSampleBuffer, minPeriod / SONIC_SKIP,
                                    maxPeriod / SONIC_SKIP, &minDiff, &maxDiff);
    period *= SONIC_SKIP;
    minPeriod = period - (SONIC_SKIP << 2);
    maxPeriod = period + (SONIC_SKIP << 2);
    if (minPeriod < SONIC_MIN_PERIOD) {
      minPeriod = SONIC_MIN_PERIOD;
    }
    if (maxPeriod > SONIC_MAX_PERIOD) {
      maxPeriod = SONIC_MAX_PERIOD;
    }
    period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff, &maxDiff);
  }
  if (prevPeriodBetter(minDiff, maxDiff, preferNewPeriod)) {
    retPeriod = sonicStream.prevPeriod;
  } else {
    retPeriod = period;
  }
  sonicStream.prevMinDiff = minDiff;
  sonicStream.prevPeriod = period;
  return retPeriod;
}
/* Find the pitch period.  This is a critical step, and we may have to try
   multiple ways to get a good answer.  This version uses Average Magnitude
   Difference Function (AMDF).  To improve speed, we down sample by an integer
   factor get in the 11KHz range, and then do it again with a narrower
   frequency range without down sampling */
Find the pitch period.  This is a critical step, and we may have to try
multiple ways to get a good answer.  This version uses Average Magnitude
Difference Function (AMDF).  To improve speed, we down sample by an integer
factor get in the 11KHz range, and then do it again with a narrower
frequency range without down sampling
Find the pitch period . This is a critical step and we may have to try multiple ways to get a good answer . This version uses Average Magnitude Difference Function ( AMDF ) . To improve speed we down sample by an integer factor get in the 11KHz range and then do it again with a narrower frequency range without down sampling
static int findPitchPeriod(short *samples, int preferNewPeriod) {
  int minPeriod = SONIC_MIN_PERIOD;
  int maxPeriod = SONIC_MAX_PERIOD;
  int minDiff, maxDiff, retPeriod;
  int period;
  if (SONIC_SKIP == 1) {
    period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff, &maxDiff);
  } else {
    downSampleInput(samples);
    period = findPitchPeriodInRange(sonicStream.downSampleBuffer, minPeriod / SONIC_SKIP,
                                    maxPeriod / SONIC_SKIP, &minDiff, &maxDiff);
    period *= SONIC_SKIP;
    minPeriod = period - (SONIC_SKIP << 2);
    maxPeriod = period + (SONIC_SKIP << 2);
    if (minPeriod < SONIC_MIN_PERIOD) {
      minPeriod = SONIC_MIN_PERIOD;
    }
    if (maxPeriod > SONIC_MAX_PERIOD) {
      maxPeriod = SONIC_MAX_PERIOD;
    }
    period = findPitchPeriodInRange(samples, minPeriod, maxPeriod, &minDiff, &maxDiff);
  }
  if (prevPeriodBetter(minDiff, maxDiff, preferNewPeriod)) {
    retPeriod = sonicStream.prevPeriod;
  } else {
    retPeriod = period;
  }
  sonicStream.prevMinDiff = minDiff;
  sonicStream.prevPeriod = period;
  return retPeriod;
}
static int findPitchPeriod ( short * samples , int preferNewPeriod ) { int minPeriod = SONIC_MIN_PERIOD ; int maxPeriod = SONIC_MAX_PERIOD ; int minDiff , maxDiff , retPeriod ; int period ; if ( SONIC_SKIP == 1 ) { period = findPitchPeriodInRange ( samples , minPeriod , maxPeriod , & minDiff , & maxDiff ) ; } else { downSampleInput ( samples ) ; period = findPitchPeriodInRange ( sonicStream . downSampleBuffer , minPeriod / SONIC_SKIP , maxPeriod / SONIC_SKIP , & minDiff , & maxDiff ) ; period *= SONIC_SKIP ; minPeriod = period - ( SONIC_SKIP << 2 ) ; maxPeriod = period + ( SONIC_SKIP << 2 ) ; if ( minPeriod < SONIC_MIN_PERIOD ) { minPeriod = SONIC_MIN_PERIOD ; } if ( maxPeriod > SONIC_MAX_PERIOD ) { maxPeriod = SONIC_MAX_PERIOD ; } period = findPitchPeriodInRange ( samples , minPeriod , maxPeriod , & minDiff , & maxDiff ) ; } if ( prevPeriodBetter ( minDiff , maxDiff , preferNewPeriod ) ) { retPeriod = sonicStream . prevPeriod ; } else { retPeriod = period ; } sonicStream . prevMinDiff = minDiff ; sonicStream . prevPeriod = period ; return retPeriod ; }
Find the pitch period.
Find the pitch period .