pub fn detect_peaks(
x: &[f32],
threshold: f32,
min_distance: usize,
out_pos: &mut [f32],
out_mag: &mut [f32],
) -> Result<usize, AudioError>Expand description
Detect local-maximum peaks in x.
A sample x[i] (interior index 1..len-1) is a candidate peak when it is
strictly greater than its left neighbour, greater-or-equal to its right
neighbour, and at least threshold. When two accepted peaks are closer than
min_distance samples, the one with the smaller magnitude is discarded
(greedy, cascading — the tallest survivor within any min_distance window
is kept). Accepted peaks are written in ascending index order:
out_pos[k] receives the parabolically-interpolated sub-sample position and
out_mag[k] the peak sample magnitude.
Returns the number of peaks written.
Zero-heap: the output arrays double as the working stack; no allocation.
§Errors
AudioError::InvalidParameterifthresholdis not finite.AudioError::OutputBufferTooSmallif more peaks are found than the output arrays can hold (min(out_pos.len(), out_mag.len())).