// Peak meter display: maps a linear sample peak to the bar position and // lets the bar fall back smoothly instead of flickering. ///| /// How much of the full bar a falling meter drops per update (~25 updates /// per second, so silence empties a full bar in about a second). pub const METER_DECAY : Double = 0.04 ///| /// Bar position 0..1 for a linear peak. Uses the same cubic curve as the /// volume sliders, so a full-scale signal at 50% volume shows at half the bar /// and quiet sounds are still visible. pub fn meter_level(linear_peak : Double) -> Double { if linear_peak <= 0.0 { 0.0 } else if linear_peak >= 1.0 { 1.0 } else { @math.cbrt(linear_peak) } } ///| /// Next bar position: jump up at once, fall by at most METER_DECAY. pub fn meter_step(shown : Double, level : Double) -> Double { if level >= shown { level } else { let fallen = shown - METER_DECAY if fallen > level { fallen } else { level } } }