-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodular.go
58 lines (49 loc) · 1.44 KB
/
modular.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
package modular
// Config provides synth configuration and options.
type Config struct {
// SampleRate configures how many samples are played per second.
//
// Defaults to 44.1k.
SampleRate int
// BufferSize configures the size of module buffers.
//
// Defaults to 44.1k.
BufferSize int
// DriverBufferSize configures the size of driver buffers.
//
// Defaults to 44.1k.
//
// Note that drivers require a larger buffer to be performant,
// but sound might not begin playing until the buffer is full.
DriverBufferSize int
// SampleSize configures the sample size in number of samples.
// The default is 512 (about 12ms at the standard sample rate).
SampleSize int
// Phase configures the phase shift value for supported modules.
Phase float32
}
// New returns a new modular config with default values.
func New() *Config {
return &Config{
SampleRate: 44100,
BufferSize: 44100,
DriverBufferSize: 44100,
SampleSize: 512, // ~12ms
}
}
// Processor is an interface for block processors.
type Processor interface {
// Process processes the audio block in place.
//
// The processor must not retain b.
Process(b []float32)
}
// Module is an interface for configurable block processors.
type Module interface {
Processor
// SetConfig updates the module configuration to cfg.
//
// Modules should expect UpdateConfig once for initialization and allow
// arbitrarily many times after.
SetConfig(cfg *Config) error
}