-
Notifications
You must be signed in to change notification settings - Fork 2
/
channel.go
62 lines (51 loc) · 995 Bytes
/
channel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package audio
func (a *Audio) takeSample() {
if !a.control.on || a.l == nil || a.r == nil {
return
}
var wave1, wave2, wave3, wave4 float32
// channel 1
wave1 = a.ch1.takeSample()
// channel 2
wave2 = a.ch2.takeSample()
// channel 3
wave3 = a.ch3.takeSample()
// channel 4
wave4 = a.ch4.takeSample()
// Hardcode master volume for now
masterVolume := float32(0.6)
// Mix left channel
left := float32(0)
if a.control.ch1Left {
left += wave1
}
if a.control.ch2Left {
left += wave2
}
if a.control.ch3Left {
left += wave3
}
if a.control.ch4Left {
left += wave4
}
left /= 4
left *= float32(a.control.volumeLeft) / 8 * masterVolume
a.l <- left
// Mix right channel
right := float32(0)
if a.control.ch1Right {
right += wave1
}
if a.control.ch2Right {
right += wave2
}
if a.control.ch3Right {
right += wave3
}
if a.control.ch4Right {
right += wave4
}
right /= 4
right *= float32(a.control.volumeRight) / 8 * masterVolume
a.r <- right
}