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

Commit 1d8cab3

Browse files
author
Jason Crawford
committed
Fix for stereo position calculations
1 parent 0c3fa83 commit 1d8cab3

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

panning/position.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func MakeStereoPosition(value float32, leftValue float32, rightValue float32) Po
2121
panic("leftValue and rightValue should be distinct")
2222
}
2323
d := float64(rightValue - leftValue)
24-
t := (d - float64(value)) / d
24+
t := float64(value-leftValue) / d
2525
// we're using a 2d rotation matrix to calcuate the left and right channels, so we really want the half angle
26-
prad := t * math.Pi / 2.0
26+
prad := (1 - t) * math.Pi / 2.0
2727

2828
return Position{
2929
Angle: float32(prad),
@@ -37,9 +37,6 @@ func FromStereoPosition(pos Position, leftValue float32, rightValue float32) flo
3737
panic("leftValue and rightValue should be distinct")
3838
}
3939
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)
40+
t := 1 - (float64(prad*2.0) / math.Pi)
41+
return leftValue + float32(t)*(rightValue-leftValue)
4542
}

0 commit comments

Comments
 (0)