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/), choosing the rate | IO: none -> 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    pub precision_bits: i32,
14    pub prune_db: f64,
15}
16
17pub const PSYCHOACOUSTIC_V1: Profile = Profile {
18    name: "psychoacoustic-v1",
19    level_db: 0.5,
20    floor_db: -20.0,
21    floor_db_above_5k: -25.0,
22    ceiling_hz: 20_000.0,
23    band_db: 1.0,
24    flop_budget: 10_000_000_000,
25    precision_bits: 24,
26    prune_db: -120.0,
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 half_lsb(&self) -> f64 {
35        2f64.powi(-self.precision_bits)
36    }
37
38    pub fn prune_level(&self) -> f64 {
39        10f64.powf(self.prune_db / 20.0)
40    }
41
42    pub fn floor(&self, hz: f64) -> f64 {
43        if hz > 5_000.0 {
44            self.floor_db_above_5k
45        } else {
46            self.floor_db
47        }
48    }
49}