Skip to main content

sva_samples/
label.rs

1// Concern: states how exact one sampled value is and what it cost | Non-concern: deciding that (collapse.rs), printing it | IO: none
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum Source {
5    Exact,
6    Measured,
7}
8
9/// A line the grid could not hold, levelled against amplitude 1.0.
10#[derive(Clone, Copy, Debug, PartialEq)]
11pub struct Dropped {
12    pub hz: f64,
13    pub db: f64,
14}
15
16macro_rules! rules {
17    ($($variant:ident => $text:literal,)+) => {
18        #[derive(Clone, Copy, Debug, PartialEq, Eq)]
19        pub enum Rule {
20            $($variant,)+
21        }
22
23        impl Rule {
24            /// The row of FORMAT 9.1 that ran, as the label prints it.
25            pub fn as_str(self) -> &'static str {
26                match self {
27                    $(Rule::$variant => $text,)+
28                }
29            }
30
31            pub fn named(text: &str) -> Option<Rule> {
32                match text {
33                    $($text => Some(Rule::$variant),)+
34                    _ => None,
35                }
36            }
37        }
38    };
39}
40
41rules! {
42    LineSpectrumExact => "line spectrum, no crop",
43    LineSpectrumSummed => "line spectrum, summed directly",
44    LineSpectrumMixed => "line spectrum, placed and summed",
45    BandLimited => "band-limited projection",
46    CroppedPair => "cropped pair, tail truncated",
47    PointSampled => "point sampling",
48    InverseSpectrum => "inverse spectrum",
49    Istft => "inverse short-time transform",
50    Reading => "reading",
51    Added => "sum, addend by addend",
52}
53
54#[derive(Clone, Debug, PartialEq)]
55pub enum Detail {
56    Lines {
57        rule: Rule,
58        /// Lines the transform placed; the rest were summed directly.
59        placed: usize,
60        summed: usize,
61        dropped: Vec<Dropped>,
62        dropped_more: usize,
63        terms: Option<usize>,
64        tail_db: Option<f64>,
65    },
66    Continuous {
67        rule: Rule,
68    },
69    Cropped {
70        rule: Rule,
71        tail_db: Option<f64>,
72    },
73    Point {
74        rule: Rule,
75        alias_db: Option<f64>,
76        tail_db: Option<f64>,
77    },
78    Spectrum {
79        rule: Rule,
80        wrap_db: f64,
81    },
82    Roundtrip {
83        rule: Rule,
84        edited: bool,
85    },
86    /// A reading off a buffer that exists; no collapse ran under it.
87    Reading {
88        rule: Rule,
89    },
90    /// A sum whose addends named different rows; the planes added.
91    Added {
92        parts: Vec<Detail>,
93    },
94}
95
96#[derive(Clone, Copy, Debug, PartialEq, Eq)]
97pub struct Cost {
98    pub flops: u128,
99    pub budget: u128,
100}
101
102/// The level a render prunes at, and the sample each node it cut is zero from.
103#[derive(Clone, Debug, PartialEq)]
104pub struct Pruned {
105    pub db: f64,
106    pub cuts: Vec<(String, i64)>,
107}
108
109#[derive(Clone, Debug, PartialEq)]
110pub struct Label {
111    pub source: Source,
112    pub profile: &'static str,
113    pub rate: u32,
114    pub detail: Detail,
115    pub cost: Option<Cost>,
116    /// The most seconds a read was moved to land on a whole sample.
117    pub moved: Option<f64>,
118    pub pruned: Option<Pruned>,
119}
120
121impl Label {
122    pub fn measured(profile: &'static str, rate: u32) -> Label {
123        Label {
124            source: Source::Measured,
125            profile,
126            rate,
127            detail: Detail::Reading {
128                rule: Rule::Reading,
129            },
130            cost: None,
131            moved: None,
132            pruned: None,
133        }
134    }
135
136    pub fn new(source: Source, profile: &'static str, rate: u32, detail: Detail) -> Label {
137        Label {
138            source,
139            profile,
140            rate,
141            detail,
142            cost: None,
143            moved: None,
144            pruned: None,
145        }
146    }
147
148    pub fn costing(self, flops: u128, budget: u128) -> Label {
149        Label {
150            cost: Some(Cost { flops, budget }),
151            ..self
152        }
153    }
154
155    pub fn rule(&self) -> Rule {
156        self.detail.rule()
157    }
158}
159
160impl Detail {
161    pub fn rule(&self) -> Rule {
162        match *self {
163            Detail::Lines { rule, .. }
164            | Detail::Continuous { rule }
165            | Detail::Cropped { rule, .. }
166            | Detail::Point { rule, .. }
167            | Detail::Spectrum { rule, .. }
168            | Detail::Roundtrip { rule, .. }
169            | Detail::Reading { rule } => rule,
170            Detail::Added { .. } => Rule::Added,
171        }
172    }
173}