pub const FLOOR_DB: f32 = -40.0;
pub const YELLOW_FROM_DB: f32 = -18.0;
pub const RED_FROM_DB: f32 = -6.0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Zone {
Green,
Yellow,
Red,
}
pub fn fraction(db: f32) -> f32 {
((db - FLOOR_DB) / -FLOOR_DB).clamp(0.0, 1.0)
}
pub fn level_at(fraction: f32) -> f32 {
FLOOR_DB * (1.0 - fraction)
}
pub fn zone(db: f32) -> Zone {
if db >= RED_FROM_DB {
Zone::Red
} else if db >= YELLOW_FROM_DB {
Zone::Yellow
} else {
Zone::Green
}
}
pub fn clipping(db: f32) -> bool {
db >= -0.1
}