Skip to main content

sva_samples/
profile.rs

1// Concern: the named tolerance set every label cites, and the ceiling and floor it puts on a rate | Non-concern: what a collapse does with either (collapse/) | IO: (name) -> Profile
2
3#[derive(Clone, Copy, Debug, PartialEq)]
4pub struct Profile {
5    pub name: &'static str,
6    pub level_db: f64,
7    pub floor_db: f64,
8    pub floor_db_above_5k: f64,
9    pub ceiling_hz: f64,
10    pub band_db: f64,
11    /// The operation count a render pays without the caller saying so.
12    pub flop_budget: u128,
13}
14
15pub const PSYCHOACOUSTIC_V1: Profile = Profile {
16    name: "psychoacoustic-v1",
17    level_db: 0.5,
18    floor_db: -20.0,
19    floor_db_above_5k: -25.0,
20    ceiling_hz: 20_000.0,
21    band_db: 1.0,
22    flop_budget: 10_000_000_000,
23};
24
25pub fn named(name: &str) -> Option<Profile> {
26    (name == PSYCHOACOUSTIC_V1.name).then_some(PSYCHOACOUSTIC_V1)
27}
28
29impl Profile {
30    pub fn ceiling(&self, rate: u32) -> f64 {
31        self.ceiling_hz.min(f64::from(rate) / 2.0)
32    }
33
34    pub fn floor(&self, hz: f64) -> f64 {
35        if hz > 5_000.0 {
36            self.floor_db_above_5k
37        } else {
38            self.floor_db
39        }
40    }
41}