Skip to main content

select_melody_contour

Function select_melody_contour 

Source
pub fn select_melody_contour(
    mean_salience: &[f32],
    pitch_variance: &[f32],
    n: usize,
    salience_weight: f32,
) -> Result<usize, AudioError>
Expand description

Choose the predominant-melody contour among n candidates.

Each candidate i is summarised by mean_salience[i] (higher = stronger) and pitch_variance[i] in squared bins (higher = more erratic pitch). The selection score normalises both across the candidate set and combines them:

score(i) = salience_weight * (salience[i] / max_salience)
         + (1 - salience_weight) * (1 - variance[i] / max_variance)

so a candidate is preferred when it is loud and smooth. The index of the highest score is returned (ties resolve to the lowest index).

  • salience_weight: relative importance of salience vs. smoothness, in [0, 1]. 1.0 selects purely on salience; 0.0 purely on smoothness.

ยงErrors

  • AudioError::InvalidParameter if n == 0, either slice is shorter than n, salience_weight is not a finite value in [0, 1], or any summarised value is non-finite / negative.