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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
PitchDetectionResult |
getPitch(float[] audioBuffer)
Analyzes a buffer with audio information and estimates a pitch in Hz.
|
public static final int DEFAULT_BUFFER_SIZE
public static final int DEFAULT_OVERLAP
public McLeodPitchMethod(float audioSampleRate)
audioSampleRate
- The sample rate of the audio to check.public McLeodPitchMethod(float audioSampleRate, int audioBufferSize)
audioSampleRate
- The sample rate of the audio.audioBufferSize
- The size of one audio buffer 1024 samples is common.public McLeodPitchMethod(float audioSampleRate, int audioBufferSize, double cutoffMPM)
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.public PitchDetectionResult getPitch(float[] audioBuffer)
PitchDetector
getPitch
in interface PitchDetector
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.