Skip to main content

sva_samples/measure/
mod.rs

1// Concern: groups the readings taken off samples, and declares the three things one can consume | Non-concern: which reading consumes which (sva-engine's query.rs) | IO: none
2
3pub mod alias;
4pub mod bands;
5pub mod crest;
6pub mod envelope;
7pub mod formants;
8pub mod harmony;
9pub mod ledger;
10pub mod loudness;
11pub mod modulation;
12pub mod onsets;
13pub mod partials;
14pub mod peaks;
15pub mod periodicity;
16pub mod pitch;
17pub mod self_similarity;
18pub mod sliding;
19pub mod spectrum;
20pub mod stereo;
21pub(crate) mod stiff;
22
23pub(crate) fn held(planes: &[&[f64]]) -> usize {
24    let len = planes
25        .first()
26        .expect("a reading reads at least one channel")
27        .len();
28    assert!(
29        planes.iter().all(|p| p.len() == len),
30        "a reading's channels are one length"
31    );
32    len
33}
34
35/// Every channel in power, as `envelope` reads it: summed, then divided by the count.
36pub(crate) fn averaged(per_channel: Vec<Vec<f64>>) -> Vec<f64> {
37    let count = per_channel.len() as f64;
38    let mut each = per_channel.into_iter();
39    let mut out = each.next().unwrap_or_default();
40    for more in each {
41        for (sum, x) in out.iter_mut().zip(more) {
42            *sum += x;
43        }
44    }
45    out.iter_mut().for_each(|sum| *sum /= count);
46    out
47}
48
49#[derive(Clone, Copy, Debug, PartialEq, Eq)]
50pub enum Consumes {
51    ClosedForm,
52    Buffer,
53    Frames,
54}