mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
43 lines
841 B
Go
43 lines
841 B
Go
package xair
|
|
|
|
import "math"
|
|
|
|
func mustDbInto(db float64) float64 {
|
|
switch {
|
|
case db >= 10:
|
|
return 1
|
|
case db >= -10:
|
|
return float64((db + 30) / 40)
|
|
case db >= -30:
|
|
return float64((db + 50) / 80)
|
|
case db >= -60:
|
|
return float64((db + 70) / 160)
|
|
case db >= -90:
|
|
return float64((db + 90) / 480)
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func mustDbFrom(level float64) float64 {
|
|
switch {
|
|
case level >= 1:
|
|
return 10
|
|
case level >= 0.5:
|
|
return toFixed(float64(level*40)-30, 1)
|
|
case level >= 0.25:
|
|
return toFixed(float64(level*80)-50, 1)
|
|
case level >= 0.0625:
|
|
return toFixed(float64(level*160)-70, 1)
|
|
case level >= 0:
|
|
return toFixed(float64(level*480)-90, 1)
|
|
default:
|
|
return -90
|
|
}
|
|
}
|
|
|
|
func toFixed(num float64, precision int) float64 {
|
|
output := math.Pow(10, float64(precision))
|
|
return float64(math.Round(num*output)) / output
|
|
}
|