/** * The main flow of the YIN algorithm. Returns a pitch value in Hz or -1 if * no pitch is detected. * * @return a pitch value in Hz or -1 if no pitch is detected. */ public PitchDetectionResult getPitch(float[] audioBuffer) { int tauEstimate; float pitchInHertz; // step 2 difference(audioBuffer); // step 3 cumulativeMeanNormalizedDifference(); // step 4 tauEstimate = absoluteThreshold(); // step 5 if (tauEstimate != -1) { float betterTau = parabolicInterpolation(tauEstimate); // 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; } result.setPitch(pitchInHertz); return(result); }