be.hogent.tarsos.dsp.pitch
Class McLeodPitchMethod

java.lang.Object
  extended by be.hogent.tarsos.dsp.pitch.McLeodPitchMethod
All Implemented Interfaces:
PitchDetector

public final class McLeodPitchMethod
extends java.lang.Object
implements PitchDetector

Implementation of The McLeod Pitch Method (MPM). It is described in the article A Smarter Way to Find Pitch. According to the article:

A fast, accurate and robust method for finding the continuous pitch in monophonic musical sounds. [It uses] a special normalized version of the Squared Difference Function (SDF) coupled with a peak picking algorithm.

MPM runs in real time with a standard 44.1 kHz sampling rate. It operates without using low-pass filtering so it can work on sound with high harmonic frequencies such as a violin and it can display pitch changes of one cent reliably. MPM works well without any post processing to correct the pitch.

For the moment this implementation uses the inefficient way of calculating the pitch. It uses O(Ww) with W the window size in samples and w the desired number of ACF coefficients. The implementation can be optimized to O((W+w)log(W+w)) by using an FFT to calculate the ACF. But I am still afraid of the dark magic of the FFT and clinging to the familiar, friendly, laggard time domain.

Author:
Phillip McLeod, Joren Six

Field Summary
static int DEFAULT_BUFFER_SIZE
          The expected size of an audio buffer (in samples).
static int DEFAULT_OVERLAP
          Overlap defines how much two audio buffers following each other should overlap (in samples).
 
Constructor Summary
McLeodPitchMethod(float audioSampleRate)
          Initializes the normalized square difference value array and stores the sample rate.
McLeodPitchMethod(float audioSampleRate, int audioBufferSize)
          Create a new pitch detector.
McLeodPitchMethod(float audioSampleRate, int audioBufferSize, double cutoffMPM)
          Create a new pitch detector.
 
Method Summary
 PitchDetectionResult getPitch(float[] audioBuffer)
          Analyzes a buffer with audio information and estimates a pitch in Hz.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The expected size of an audio buffer (in samples).

See Also:
Constant Field Values

DEFAULT_OVERLAP

public static final int DEFAULT_OVERLAP
Overlap defines how much two audio buffers following each other should overlap (in samples). 75% overlap is advised in the MPM article.

See Also:
Constant Field Values
Constructor Detail

McLeodPitchMethod

public McLeodPitchMethod(float audioSampleRate)
Initializes the normalized square difference value array and stores the sample rate.

Parameters:
audioSampleRate - The sample rate of the audio to check.

McLeodPitchMethod

public McLeodPitchMethod(float audioSampleRate,
                         int audioBufferSize)
Create a new pitch detector.

Parameters:
audioSampleRate - The sample rate of the audio.
audioBufferSize - The size of one audio buffer 1024 samples is common.

McLeodPitchMethod

public McLeodPitchMethod(float audioSampleRate,
                         int audioBufferSize,
                         double cutoffMPM)
Create a new pitch detector.

Parameters:
audioSampleRate - The sample rate of the audio.
audioBufferSize - The size of one audio buffer 1024 samples is common.
cutoffMPM - The cutoff (similar to the YIN threshold). In the Tartini paper 0.93 is used.
Method Detail

getPitch

public PitchDetectionResult getPitch(float[] audioBuffer)
Description copied from interface: PitchDetector
Analyzes a buffer with audio information and estimates a pitch in Hz. Currently this interface only allows one pitch per buffer.

Specified by:
getPitch in interface PitchDetector
Parameters:
audioBuffer - The buffer with audio information. The information in the buffer is not modified so it can be (re)used for e.g. FFT analysis.
Returns:
An estimation of the pitch in Hz or -1 if no pitch is detected or present in the buffer.