Skip to main content

smooth_frequencies

Function smooth_frequencies 

Source
pub fn smooth_frequencies(
    frequencies: &[FloatType],
    smooth_levels: usize,
) -> Result<Vec<i64>>
Expand description

Each frequency averaged with its neighbours, smooth_levels at a time, and rounded to a whole number: music21’s smoothFrequencies. As in music21, each average takes in those already made before it, and the first and last few frequencies are the truncated average of the first and last smooth_levels.

use music21_rs::audiosearch::smooth_frequencies;

let smoothed = smooth_frequencies(&[100.0, 100.0, 400.0, 100.0, 100.0], 3)?;
// Each average takes in the ones made before it.
assert_eq!(smoothed, [200, 233, 244, 200, 200]);

§Errors

No levels, or more levels than frequencies.