|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Single-frequency magnitude detector using the Goertzel algorithm. More...
#include <Goertzel.h>
Public Member Functions | |
| void | prepare (double sampleRate, double targetFreqHz, int blockSize) noexcept |
| Prepares the detector for a specific frequency. | |
| void | processBlock (const T *data, int numSamples) noexcept |
| Processes a block of audio samples, updating the internal state. | |
| bool | pushSample (T sample) noexcept |
| Feeds a single sample into the running Goertzel computation. | |
| void | forceCompute () noexcept |
| Manually forces the computation of the result before N samples are reached. | |
| bool | checkNewResultAvailable () noexcept |
| Checks if a new result has been computed. | |
| T | getMagnitude () const noexcept |
| Returns the magnitude at the target frequency (linear scale). | |
| T | getPower () const noexcept |
| Returns the power at the target frequency. | |
| T | getMagnitudeDb () const noexcept |
| Returns the magnitude in decibels. | |
| T | getPhase () const noexcept |
| Returns the phase angle at the target frequency. | |
| double | getTargetFrequency () const noexcept |
| Returns the currently configured target frequency. | |
| double | getSampleRate () const noexcept |
| Returns the configured sample rate in Hz. | |
| int | getBlockSize () const noexcept |
| Returns the configured analysis block size in samples. | |
| void | reset () noexcept |
| Resets the internal IIR state and counters to zero. | |
Single-frequency magnitude detector using the Goertzel algorithm.
Designed for continuous streaming or block-based real-time analysis. State is unified: you can mix processBlock and pushSample safely. Before prepare() the detector is inert and reports zero magnitude.
| T | Sample type (float or double). Requires dspark::FloatType concept. |
Definition at line 46 of file Goertzel.h.
|
inlinenoexcept |
Checks if a new result has been computed.
Calling this will return true only once after an analysis block completes, resetting the flag internally.
Definition at line 186 of file Goertzel.h.
|
inlinenoexcept |
Manually forces the computation of the result before N samples are reached.
Definition at line 168 of file Goertzel.h.
|
inlinenoexcept |
Returns the configured analysis block size in samples.
Definition at line 248 of file Goertzel.h.
|
inlinenoexcept |
Returns the magnitude at the target frequency (linear scale).
Definition at line 200 of file Goertzel.h.
|
inlinenoexcept |
Returns the magnitude in decibels.
Definition at line 219 of file Goertzel.h.
|
inlinenoexcept |
Returns the phase angle at the target frequency.
The phase is referenced to the analysis block boundary: it is reproducible between blocks when the target frequency is an exact multiple of sampleRate/blockSize (bin-exact tones).
Definition at line 233 of file Goertzel.h.
|
inlinenoexcept |
Returns the power at the target frequency.
Definition at line 209 of file Goertzel.h.
|
inlinenoexcept |
Returns the configured sample rate in Hz.
Definition at line 245 of file Goertzel.h.
|
inlinenoexcept |
Returns the currently configured target frequency.
Definition at line 242 of file Goertzel.h.
|
inlinenoexcept |
Prepares the detector for a specific frequency.
Release-safe: a non-finite or non-positive sample rate, a non-finite target frequency or a non-positive block size are ignored (no-op keeping the previous configuration); the target frequency is clamped to [0, sampleRate/2].
| sampleRate | Sample rate in Hz. Must be > 0. |
| targetFreqHz | The frequency to detect, in [0, sampleRate/2]. |
| blockSize | Number of samples per analysis window. Must be > 0. With float precision, very long windows (hundreds of thousands of samples) accumulate rounding error in the resonator; prefer double for extreme block sizes. At exact DC and Nyquist the recursion sits on a double pole and its state grows O(N^2), so float precision degrades much sooner there: use double (or a short window) when measuring those two edge frequencies. |
Definition at line 68 of file Goertzel.h.
|
inlinenoexcept |
Processes a block of audio samples, updating the internal state.
This method accumulates samples. To know if a full analysis block has been completed, check checkNewResultAvailable() after processing.
| data | Pointer to the audio samples. |
| numSamples | Number of samples in the buffer. |
Definition at line 110 of file Goertzel.h.
|
inlinenoexcept |
Feeds a single sample into the running Goertzel computation.
| sample | Input audio sample. |
Definition at line 145 of file Goertzel.h.
|
inlinenoexcept |
Resets the internal IIR state and counters to zero.
Retains configured sample rate, frequency, and block size.
Definition at line 255 of file Goertzel.h.