-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
76 lines (59 loc) · 1.63 KB
/
configuration.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
package muse
import (
"container/list"
"github.com/almerlucke/muse/utils/timing"
)
var configList *list.List
func configurationInit() {
configList = list.New()
configList.PushFront(&Configuration{
SampleRate: DefaultSamplerate,
BufferSize: DefaultBufferSize,
})
}
type Configuration struct {
SampleRate float64
BufferSize int
}
func (cfg *Configuration) MilliToSamps(milli float64) int64 {
return timing.MilliToSamps(milli, cfg.SampleRate)
}
func (cfg *Configuration) MilliToSampsf(milli float64) float64 {
return timing.MilliToSampsf(milli, cfg.SampleRate)
}
func (cfg *Configuration) SecToSamps(sec float64) int64 {
return timing.SecToSamps(sec, cfg.SampleRate)
}
func (cfg *Configuration) SecToSampsf(sec float64) float64 {
return timing.SecToSampsf(sec, cfg.SampleRate)
}
func (cfg *Configuration) SampsToSec(samps int64) float64 {
return float64(samps) / cfg.SampleRate
}
func (cfg *Configuration) SampsToMilli(samps int64) float64 {
return (float64(samps) / cfg.SampleRate) * 1000.0
}
func (cfg *Configuration) ControlRate() float64 {
return cfg.SampleRate / float64(cfg.BufferSize)
}
func PushConfiguration(config *Configuration) {
configList.PushFront(config)
}
func PopConfiguration() *Configuration {
front := configList.Front()
config := front.Value.(*Configuration)
configList.Remove(front)
return config
}
func CurrentConfiguration() *Configuration {
return configList.Front().Value.(*Configuration)
}
func SampleRate() float64 {
return CurrentConfiguration().SampleRate
}
func ControlRate() float64 {
return CurrentConfiguration().ControlRate()
}
func BufferSize() int {
return CurrentConfiguration().BufferSize
}