1#[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 pub flop_budget: u128,
13 pub precision_bits: i32,
14}
15
16pub const PSYCHOACOUSTIC_V1: Profile = Profile {
17 name: "psychoacoustic-v1",
18 level_db: 0.5,
19 floor_db: -20.0,
20 floor_db_above_5k: -25.0,
21 ceiling_hz: 20_000.0,
22 band_db: 1.0,
23 flop_budget: 10_000_000_000,
24 precision_bits: 24,
25};
26
27impl Profile {
28 pub fn ceiling(&self, rate: u32) -> f64 {
29 self.ceiling_hz.min(f64::from(rate) / 2.0)
30 }
31
32 pub fn half_lsb(&self) -> f64 {
33 2f64.powi(-self.precision_bits)
34 }
35
36 pub fn floor(&self, hz: f64) -> f64 {
37 if hz > 5_000.0 {
38 self.floor_db_above_5k
39 } else {
40 self.floor_db
41 }
42 }
43}