-
Notifications
You must be signed in to change notification settings - Fork 13
/
wrapped.go
46 lines (40 loc) · 1 KB
/
wrapped.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
package derived
import (
"github.com/bspaans/bleep/audio"
"github.com/bspaans/bleep/generators"
)
type WrappedGenerator struct {
GetSamplesFunc func(cfg *audio.AudioConfig, n int) []float64
SetPitchFunc func(float64)
SetPitchbendFunc func(float64)
SetGainFunc func(float64)
}
func NewWrappedGenerator(g generators.Generator) *WrappedGenerator {
return &WrappedGenerator{
GetSamplesFunc: g.GetSamples,
SetPitchFunc: g.SetPitch,
SetPitchbendFunc: g.SetPitchbend,
SetGainFunc: g.SetGain,
}
}
func (b *WrappedGenerator) GetSamples(cfg *audio.AudioConfig, n int) []float64 {
if b.GetSamplesFunc != nil {
return b.GetSamplesFunc(cfg, n)
}
return make([]float64, n)
}
func (b *WrappedGenerator) SetPitch(f float64) {
if b.SetPitchFunc != nil {
b.SetPitchFunc(f)
}
}
func (b *WrappedGenerator) SetPitchbend(f float64) {
if b.SetPitchbendFunc != nil {
b.SetPitchbendFunc(f)
}
}
func (b *WrappedGenerator) SetGain(f float64) {
if b.SetGainFunc != nil {
b.SetGainFunc(f)
}
}