-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_mixer.go
More file actions
51 lines (41 loc) · 994 Bytes
/
module_mixer.go
File metadata and controls
51 lines (41 loc) · 994 Bytes
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
package synth
import "fmt"
type Vol struct {
Fact float32
}
func (m *Vol) Process(out [][]float32) {
for i := range out[0] {
out[0][i] *= m.Fact
out[1][i] *= m.Fact
}
}
type Mixer struct {
inputs []Module
faders []float32
buffer [][]float32
}
func NewMixer() *Mixer {
return &Mixer{buffer: make([][]float32, 2)}
}
func (m *Mixer) AddInput(s Module, faderval float32) {
m.inputs = append(m.inputs, s)
m.faders = append(m.faders, faderval)
}
func (m *Mixer) Process(out [][]float32) {
if len(out[0]) > len(m.buffer[0]) {
m.buffer[0] = append(m.buffer[0], out[0][len(m.buffer[0]):]...)
m.buffer[1] = append(m.buffer[1], out[1][len(m.buffer[1]):]...)
}
for x := range out[0] {
out[0][x] = 0
out[1][x] = 0
}
for i, in := range m.inputs {
in.Process(m.buffer)
for x := range out[0] {
out[0][x] += m.buffer[0][x] * m.faders[i]
out[1][x] += m.buffer[1][x] * m.faders[i]
}
}
fmt.Println(out[0][100])
}