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

Commit 0c3fa83

Browse files
author
Jason Crawford
committed
Fixing panning so it's on the correct channels
1 parent c3fdb1c commit 0c3fa83

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

mixing/mixbuffer.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@ type MixBuffer []ChannelMixBuffer
3030
func (m *MixBuffer) C() (chan<- SampleMixIn, func()) {
3131
ch := make(chan SampleMixIn, 32)
3232
go func() {
33-
outerLoop:
34-
for {
35-
select {
36-
case d, ok := <-ch:
37-
if !ok {
38-
break outerLoop
39-
}
40-
m.MixInSample(d)
41-
}
33+
for d := range ch {
34+
m.MixInSample(d)
4235
}
4336
}()
4437
return ch, func() {
@@ -86,7 +79,7 @@ func (m *MixBuffer) ToRenderData(samples int, bitsPerSample int, mixerVolume vol
8679
for _, buf := range *m {
8780
v := buf[i] * mixerVolume
8881
val := v.ToSample(bitsPerSample)
89-
binary.Write(writer, binary.LittleEndian, val)
82+
_ = binary.Write(writer, binary.LittleEndian, val) // lint
9083
}
9184
}
9285
return writer.Bytes()
@@ -138,7 +131,7 @@ func (m *MixBuffer) ToRenderDataWithBufs(outBuffers [][]byte, samples int, bitsP
138131
pos += 4
139132
default:
140133
writer := &bytes.Buffer{}
141-
binary.Write(writer, binary.LittleEndian, val)
134+
_ = binary.Write(writer, binary.LittleEndian, val) // lint
142135
pos += copy(out[pos:], writer.Bytes())
143136
}
144137
}

mixing/panmixer.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ type panMixerStereo struct {
4343

4444
func (p panMixerStereo) GetMixingMatrix(pan panning.Position) volume.Matrix {
4545
pangle := float64(pan.Angle)
46-
d := volume.Volume(pan.Distance)
47-
l := d * volume.Volume(math.Cos(pangle))
48-
r := d * volume.Volume(math.Sin(pangle))
46+
s, c := math.Sincos(pangle)
47+
var d volume.Volume
48+
if pan.Distance > 0 {
49+
d = 1 / volume.Volume(pan.Distance*pan.Distance)
50+
}
51+
l := d * volume.Volume(s)
52+
r := d * volume.Volume(c)
4953
return volume.Matrix{l, r}
5054
}
5155

@@ -59,11 +63,16 @@ type panMixerQuad struct {
5963

6064
func (p panMixerQuad) GetMixingMatrix(pan panning.Position) volume.Matrix {
6165
pangle := float64(pan.Angle)
62-
d := volume.Volume(pan.Distance)
63-
lf := d * volume.Volume(math.Cos(pangle))
64-
rf := d * volume.Volume(math.Sin(pangle))
65-
lr := d * volume.Volume(math.Sin(pangle+math.Pi/2.0))
66-
rr := d * volume.Volume(math.Cos(pangle-math.Pi/2.0))
66+
sf, cf := math.Sincos(pangle)
67+
sr, cr := math.Sin(pangle+math.Pi/2.0), math.Cos(pangle-math.Pi/2.0)
68+
var d volume.Volume
69+
if pan.Distance > 0 {
70+
d = 1 / volume.Volume(pan.Distance*pan.Distance)
71+
}
72+
lf := d * volume.Volume(sf)
73+
rf := d * volume.Volume(cf)
74+
lr := d * volume.Volume(cr)
75+
rr := d * volume.Volume(sr)
6776
return volume.Matrix{lf, rf, lr, rr}
6877
}
6978

0 commit comments

Comments
 (0)