-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynth.go
More file actions
70 lines (54 loc) · 1.27 KB
/
synth.go
File metadata and controls
70 lines (54 loc) · 1.27 KB
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
63
64
65
66
67
68
69
70
package synth
const SAMPLERATE = 44100
const dt = 1 / float32(SAMPLERATE)
func chk(err error) {
if err != nil {
panic(err)
}
}
type Synth struct {
*portaudio.Stream
ModuleGraph
buffers map[*Module]Buffer
}
type Buffer [][]byte
func NewSynth(sampleRate float64) *Synth {
s := &Synth{}
s.Stream, err := portaudio.OpenDefaultStream(0, 2, sampleRate, 0, s.Process)
chk(err)
return s
}
func (s *Synth) Process(out [][]byte) {
// set up buffers if they don't already exist
}
type E interface{}
type ModuleGraph struct {
output *Module
connections map[*Module]Set
}
func NewModuleGraph(vs []*Module, edgs map[int]map[int]bool, out_module *Module) *ModuleGraph {
g := &ModuleGraph{ouput: out_module}
g.connections = map[*Module]Set
for i1 := range edgs {
g.connections[vs[i1]] = Set{}
for i2 := range edgs[i1] {
g.connections[vs[i1]].Add(vs[i2])
}
}
}
type Set map[E]E
func (s *Set) Add(elt E) {
is s==nil {
s = Set{}
}
s[elt] = nil
}
func (s *Set) Delete(elt E) /*bool*/ {
// _, ok := s[elt]
delete(s, elt)
// return ok
}
func (s *Set) Has(elt E) bool {
_, ok := s[elt]
return ok
}