-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.go
77 lines (65 loc) · 1.81 KB
/
config.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
package catnip
import (
"errors"
"fmt"
"github.com/noriah/catnip/dsp"
"github.com/noriah/catnip/dsp/window"
"github.com/noriah/catnip/processor"
)
type Config struct {
// The name of the backend from the input package
Backend string
// The name of the device to pull data from
Device string
// The rate that samples are read
SampleRate float64
// The number of samples per batch
SampleSize int
// The number of channels to read data from
ChannelCount int
// The number of times per second to process data
ProcessRate int
// Merge multiple channels into a single stream
Combine bool
// testing. leave false
// Use threaded processor
UseThreaded bool
// Function to call when setting up the pipeline
SetupFunc SetupFunc
// Function to call when starting the pipeline
StartFunc StartFunc
// Function to call when cleaning up the pipeline
CleanupFunc CleanupFunc
// Where to send the data from the audio analysis
Output processor.Output
// Method to run on data before running fft
Windower window.Function
// Analyzer to run analysis on data
Analyzer dsp.Analyzer
// Smoother to run smoothing on output from Analyzer
Smoother dsp.Smoother
}
func NewZeroConfig() Config {
return Config{
SampleRate: 44100,
SampleSize: 1024,
ChannelCount: 1,
}
}
func (cfg *Config) Validate() error {
if cfg.SampleRate < float64(cfg.SampleSize) {
return errors.New("sample rate lower than sample size")
}
if cfg.SampleSize < 4 {
return errors.New("sample size too small (4+ required)")
}
switch {
case cfg.ChannelCount > MaxChannelCount:
return fmt.Errorf("too many channels (%d max)", MaxChannelCount)
case cfg.ChannelCount < 1:
return errors.New("too few channels (1 min)")
case cfg.SampleSize > MaxSampleSize:
return fmt.Errorf("sample size too large (%d max)", MaxSampleSize)
}
return nil
}