-
Notifications
You must be signed in to change notification settings - Fork 2
/
agraph.go
92 lines (75 loc) · 1.76 KB
/
agraph.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package agraph
import (
"github.com/clandry94/agraph/filter"
)
type Graph struct {
Meta MetaData
graphDef *GraphDef
graph *graph
}
func (g *Graph) Compile() error {
meta := filter.MetaData{
SampleRate: g.Meta.SampleRate,
NumChannels: g.Meta.NumChannels,
}
var prevFilter filter.Node
for i, filterDef := range g.graphDef.filters {
opts := filter.Options{
VolumeMultiplier: filterDef.fields["VolumeMultiplier"].(float32),
Delay: filterDef.fields["Delay"].(int),
Decay: filterDef.fields["Decay"].(float32),
MovingAverageLength: filterDef.fields["MovingAverageLength"].(int),
Angle: filterDef.fields["Angle"].(float64),
}
filt, err := filter.NewNode(filterDef.filter,
meta,
"name not implemented",
opts,
)
if err != nil {
return err
}
if i == 0 {
g.graph.sink = filt.Source()
prevFilter = filt
continue
} else if i == len(g.graphDef.filters) {
g.graph.sink = filt.Sink()
} else if i != 0 && i != len(g.graphDef.filters) {
filt.SetSource(prevFilter.Sink())
}
prevFilter = filt
}
return nil
}
type graph struct {
source chan []uint16
sink chan []uint16
}
type Fields map[string]interface{}
// Meta is a type which has information about a file
type MetaData struct {
SampleRate uint32
NumChannels uint16
}
type GraphDef struct {
filters []*FilterDef
}
type FilterDef struct {
filter filter.Type
fields Fields
}
func NewFilter(filter filter.Type, fields Fields) *FilterDef {
return &FilterDef{
filter: filter,
fields: fields,
}
}
// New returns a new *Graph if file exists, otherwise returns an error
func NewGraph(graphDef *GraphDef, meta MetaData) (*Graph, error) {
return &Graph{
Meta: meta,
graphDef: graphDef,
graph: nil,
}, nil
}