Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

Commit 7959f71

Browse files
authored
Merge pull request #4 from heucuva/volstringer
Add volume stringer
2 parents 65ff401 + 654f16c commit 7959f71

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/gotracker/gomixing
22

3-
go 1.18
3+
go 1.21

volume/volume.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package volume
22

33
import (
4+
"fmt"
45
"math"
56
)
67

@@ -94,3 +95,13 @@ func (v Volume) WithOverflowProtection() float64 {
9495
// overflow, positive
9596
return 1.0
9697
}
98+
99+
func (v Volume) String() string {
100+
var db float64
101+
if v > 0 {
102+
db = math.Log10(float64(v)) * 20.0
103+
} else {
104+
db = math.Inf(-1)
105+
}
106+
return fmt.Sprintf("%0.2f (%0.2fdB)", v, db)
107+
}

0 commit comments

Comments
 (0)