Package wellen.analysis
Class PitchDetection
java.lang.Object
wellen.analysis.PitchDetection
detectes the pitch of a signal.
it uses the YIN algorithm described in the paper Alain de Cheveigné + Hideki Kawahara:YIN, a fundamental frequency estimator for speech and music.
Fair Use Disclaimer: this implementation was taken, with minor modifications, from a project called TarsosDSP by Joren Six released under the GPL-3.0 license. the project seems to be really well written. i therefore think it is fair to use the existing source code and modify it.
-
Constructor Summary
ConstructorDescriptionCreate a new pitch detector for a stream with the defined sample rate.PitchDetection
(float audioSampleRate, int bufferSize) Create a new pitch detector for a stream with the defined sample rate.PitchDetection
(float audioSampleRate, int bufferSize, double yinThreshold) Create a new pitch detector for a stream with the defined sample rate. -
Method Summary
Modifier and TypeMethodDescriptionfloat
float
boolean
float[]
process
(float[] audioBuffer) The main flow of the YIN algorithm.
-
Constructor Details
-
PitchDetection
public PitchDetection()Create a new pitch detector for a stream with the defined sample rate. Processes the audio in blocks of the defined size. -
PitchDetection
public PitchDetection(float audioSampleRate, int bufferSize) Create a new pitch detector for a stream with the defined sample rate. Processes the audio in blocks of the defined size.- Parameters:
audioSampleRate
- The sample rate of the audio stream. E.g. 44.1 kHz.bufferSize
- The size of a buffer. E.g. 1024.
-
PitchDetection
public PitchDetection(float audioSampleRate, int bufferSize, double yinThreshold) Create a new pitch detector for a stream with the defined sample rate. Processes the audio in blocks of the defined size.- Parameters:
audioSampleRate
- The sample rate of the audio stream. E.g. 44.1 kHz.bufferSize
- The size of a buffer. E.g. 1024.yinThreshold
- The parameter that defines which peaks are kept as possible pitch candidates. See the YIN paper for more details.
-
-
Method Details
-
process
public float[] process(float[] audioBuffer) The main flow of the YIN algorithm. Returns a pitch value in Hz or -1 if no pitch is detected.- Returns:
- a pitch value in Hz or -1 if no pitch is detected.
-
get_pitch
public float get_pitch() -
get_probability
public float get_probability() -
is_pitched
public boolean is_pitched()
-