A utility class for estimating the pitch (fundamental period) of a given audio signal segment.
More...
#include <pitch_detector.h>
|
| PitchDetector () |
| Constructs a PitchDetector with no loaded signal.
|
|
void | setSize (int size) |
| Sets the internal size of the signal used for pitch detection.
|
|
void | loadSignal (const float *signal, int size) |
| Loads a signal into the PitchDetector for analysis.
|
|
float | getPeriodError (float period) |
| Computes the error metric for a given period length.
|
|
float | findYinPeriod (int max_period) |
| Searches for a period using a YIN-like algorithm, up to a specified maximum period.
|
|
float | matchPeriod (int max_period) |
| High-level method to find the best matching period using the YIN approach.
|
|
const float * | data () const |
| Returns a pointer to the internal signal data buffer.
|
|
|
static constexpr int | kNumPoints = 2520 |
| A fixed number of points used in the period error computation.
|
|
|
int | size_ |
| Number of samples in the loaded signal.
|
|
std::unique_ptr< float[]> | signal_data_ |
| Buffer holding the loaded signal samples.
|
|
A utility class for estimating the pitch (fundamental period) of a given audio signal segment.
The PitchDetector class loads a segment of audio samples and attempts to determine its fundamental period using a variation of the YIN pitch detection algorithm. By estimating the period length that minimizes differences between segments of the waveform, it can guide other components (like wavetable extraction) to align frames to a fundamental cycle.
◆ PitchDetector()
PitchDetector::PitchDetector |
( |
| ) |
|
◆ data()
const float * PitchDetector::data |
( |
| ) |
const |
|
inline |
Returns a pointer to the internal signal data buffer.
- Returns
- A const pointer to the loaded signal samples.
◆ findYinPeriod()
float PitchDetector::findYinPeriod |
( |
int | max_period | ) |
|
Searches for a period using a YIN-like algorithm, up to a specified maximum period.
Evaluates candidate periods and selects the one with minimal error.
- Parameters
-
max_period | The maximum period length to consider, in samples. |
- Returns
- The detected period length in samples.
◆ getPeriodError()
float PitchDetector::getPeriodError |
( |
float | period | ) |
|
Computes the error metric for a given period length.
A lower error typically indicates a more likely fundamental period. This function uses differences between successive segments of the waveform to compute the error.
- Parameters
-
period | The candidate period length in samples. |
- Returns
- An error metric for how well this period fits the waveform.
◆ loadSignal()
void PitchDetector::loadSignal |
( |
const float * | signal, |
|
|
int | size ) |
Loads a signal into the PitchDetector for analysis.
Copies the given signal into the detector's buffer.
- Parameters
-
signal | Pointer to the signal samples. |
size | Number of samples in the signal. |
◆ matchPeriod()
float PitchDetector::matchPeriod |
( |
int | max_period | ) |
|
High-level method to find the best matching period using the YIN approach.
- Parameters
-
max_period | The maximum period length to consider. |
- Returns
- The best matching period in samples.
◆ setSize()
void PitchDetector::setSize |
( |
int | size | ) |
|
|
inline |
Sets the internal size of the signal used for pitch detection.
- Parameters
-
size | Number of samples in the loaded signal. |
◆ kNumPoints
int PitchDetector::kNumPoints = 2520 |
|
staticconstexpr |
A fixed number of points used in the period error computation.
This number controls how many sample comparisons are made to estimate the signal's period.
◆ signal_data_
std::unique_ptr<float[]> PitchDetector::signal_data_ |
|
protected |
Buffer holding the loaded signal samples.
◆ size_
Number of samples in the loaded signal.
The documentation for this class was generated from the following files: