Vital
Loading...
Searching...
No Matches
pitch_detector.h
Go to the documentation of this file.
1/*
2Summary:
3The PitchDetector class attempts to find the fundamental period of a loaded signal using a method inspired by the YIN algorithm. By computing an error metric that measures how well the waveform repeats at different periods, it identifies a period length that best represents the fundamental frequency. This helps ensure that wavetables and other audio processing steps align wave cycles with their fundamental pitch.
4 */
5
6#pragma once
7
8#include "JuceHeader.h"
9
19public:
25 static constexpr int kNumPoints = 2520;
26
31
37 void setSize(int size) { size_ = size; }
38
47 void loadSignal(const float* signal, int size);
48
58 float getPeriodError(float period);
59
68 float findYinPeriod(int max_period);
69
76 float matchPeriod(int max_period);
77
83 const float* data() const { return signal_data_.get(); }
84
85protected:
86 int size_;
87 std::unique_ptr<float[]> signal_data_;
88
89 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PitchDetector)
90};
A utility class for estimating the pitch (fundamental period) of a given audio signal segment.
Definition pitch_detector.h:18
float findYinPeriod(int max_period)
Searches for a period using a YIN-like algorithm, up to a specified maximum period.
Definition pitch_detector.cpp:65
float matchPeriod(int max_period)
High-level method to find the best matching period using the YIN approach.
Definition pitch_detector.cpp:95
int size_
Number of samples in the loaded signal.
Definition pitch_detector.h:86
void setSize(int size)
Sets the internal size of the signal used for pitch detection.
Definition pitch_detector.h:37
void loadSignal(const float *signal, int size)
Loads a signal into the PitchDetector for analysis.
Definition pitch_detector.cpp:17
static constexpr int kNumPoints
A fixed number of points used in the period error computation.
Definition pitch_detector.h:25
std::unique_ptr< float[]> signal_data_
Buffer holding the loaded signal samples.
Definition pitch_detector.h:87
float getPeriodError(float period)
Computes the error metric for a given period length.
Definition pitch_detector.cpp:24
PitchDetector()
Constructs a PitchDetector with no loaded signal.
Definition pitch_detector.cpp:12
const float * data() const
Returns a pointer to the internal signal data buffer.
Definition pitch_detector.h:83