pub fn waveform_points(
samples: &[f32],
bounds: Rect,
max_points: usize,
) -> Vec<Point>Expand description
Map audio samples to a polyline inside bounds.
- Samples are amplitudes nominally in [-1, 1]; larger magnitudes are clamped, NaN and infinities count as 0.
- x runs from
bounds.x(first point) tobounds.x + bounds.width(last point);y = centre - sample * (height / 2), so +1 is the top edge, -1 the bottom edge and 0 the centre line. - More samples than
max_pointsare reduced by buckets, keeping the largest-magnitude sample per bucket. The result never has more thanmax(max_points, 2)points. - No samples (silence) gives the centre line: two points, left-centre and right-centre. A lone sample gives a flat line at its level.
- Every point is finite and lies inside
bounds(edges inclusive), for any input. Negative width/height count as 0, non-finite components as 0, and components beyond +-1e15 are clamped to it so that no sum overflows; the “inside” promise is then to those sanitized bounds, which equalboundswhenever it is finite, not negative and within +-1e15.