getPitch method

  1. @override
Future<PitchDetectorResult> getPitch(
  1. List<double> audioBuffer
)
override

Implementation

@override
Future<PitchDetectorResult> getPitch(final List<double> audioBuffer) {
  final double pitchInHertz;

  // step 2
  _difference(audioBuffer);

  // step 3
  _cumulativeMeanNormalizedDifference();

  // step 4
  final pitched = _absoluteThreshold();

  // step 5
  if (pitched.tau != -1) {
    final double betterTau = _parabolicInterpolation(pitched.tau);

    // step 6
    // TODO Implement optimization for the AUBIO_YIN algorithm.
    // 0.77% => 0.5% error rate,
    // using the data of the YIN paper
    // bestLocalEstimate()

    // conversion to Hz
    pitchInHertz = _sampleRate / betterTau;
  } else {
    // no pitch found
    pitchInHertz = -1;
  }

  return Future.value(PitchDetectorResult(
    pitch: pitchInHertz,
    probability: pitched.probability,
    pitched: pitched.pitched,
  ));
}