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

Commit 91cc9c1

Browse files
author
Jason Crawford
committed
Adding reversal of panning position to stereo pan
1 parent e7e21c9 commit 91cc9c1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

panning/position.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ func MakeStereoPosition(value float32, leftValue float32, rightValue float32) Po
3030
Distance: 1.0,
3131
}
3232
}
33+
34+
// FromStereoPosition inverts a stereo panning position into a linear interpolation value between `leftValue` and `RightValue`
35+
func FromStereoPosition(pos Position, leftValue float32, rightValue float32) float32 {
36+
if leftValue == rightValue {
37+
panic("leftValue and rightValue should be distinct")
38+
}
39+
prad := pos.Angle
40+
t := float64(prad*2.0) / math.Pi
41+
d := float64(rightValue - leftValue)
42+
value := d - (t * d)
43+
44+
return float32(value)
45+
}

0 commit comments

Comments
 (0)