mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-09 02:13:35 +00:00
initial commit
add internal/xair module
This commit is contained in:
42
internal/xair/util.go
Normal file
42
internal/xair/util.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user