-
Notifications
You must be signed in to change notification settings - Fork 0
/
gate_mix.go
53 lines (45 loc) · 941 Bytes
/
gate_mix.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
package module
import (
"strconv"
"buddin.us/eolian/dsp"
"github.com/mitchellh/mapstructure"
)
func init() {
Register("GateMix", func(c Config) (Patcher, error) {
var config struct{ Size int }
if err := mapstructure.Decode(c, &config); err != nil {
return nil, err
}
if config.Size == 0 {
config.Size = 4
}
return newGateMix(config.Size)
})
}
type gateMix struct {
IO
sources []*In
}
func newGateMix(size int) (*gateMix, error) {
m := &gateMix{
sources: make([]*In, size),
}
for i := range m.sources {
m.sources[i] = NewInBuffer(strconv.Itoa(i), dsp.Float64(0))
}
return m, m.Expose("GateMix", m.sources, []*Out{{Name: "output", Provider: dsp.Provide(m)}})
}
func (m *gateMix) Process(out dsp.Frame) {
for _, s := range m.sources {
s.ProcessFrame()
}
for i := range out {
out[i] = -1
for _, s := range m.sources {
if v := s.LastFrame()[i]; v > 0 {
out[i] = 1
break
}
}
}
}