-
Notifications
You must be signed in to change notification settings - Fork 0
/
scientific.go
61 lines (51 loc) · 1.81 KB
/
scientific.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
package equal
import (
"math"
"github.com/heucuva/go-qwertysynth/internal/standards/scale"
"github.com/heucuva/go-qwertysynth/internal/standards/tuning"
)
const (
Scientific_C4Frequency = 256.0
Scientific_CSharp4Frequency = Scientific_C4Frequency * twelfthRoot2
Scientific_D4Frequency = Scientific_CSharp4Frequency * twelfthRoot2
Scientific_DSharp4Frequency = Scientific_D4Frequency * twelfthRoot2
Scientific_E4Frequency = Scientific_DSharp4Frequency * twelfthRoot2
Scientific_F4Frequency = Scientific_E4Frequency * twelfthRoot2
Scientific_FSharp4Frequency = Scientific_F4Frequency * twelfthRoot2
Scientific_G4Frequency = Scientific_FSharp4Frequency * twelfthRoot2
Scientific_GSharp4Frequency = Scientific_G4Frequency * twelfthRoot2
Scientific_A4Frequency = Scientific_GSharp4Frequency * twelfthRoot2
Scientific_ASharp4Frequency = Scientific_A4Frequency * twelfthRoot2
Scientific_B4Frequency = Scientific_ASharp4Frequency * twelfthRoot2
)
type scientific struct{}
var Scientific tuning.Tuning = &scientific{}
var scientific_scale = [TwelveKeysPerOctave]float64{
Scientific_C4Frequency,
Scientific_CSharp4Frequency,
Scientific_D4Frequency,
Scientific_DSharp4Frequency,
Scientific_E4Frequency,
Scientific_F4Frequency,
Scientific_FSharp4Frequency,
Scientific_G4Frequency,
Scientific_GSharp4Frequency,
Scientific_A4Frequency,
Scientific_ASharp4Frequency,
Scientific_B4Frequency,
}
func (scientific) ToFrequency(ko tuning.KeyOctave) float64 {
k, o := ko.Split(Scientific)
freq := scientific_scale[k.Index()]
freq *= math.Pow(2.0, float64(o)-4.0)
return freq
}
func (scientific) Key(index int) scale.Key {
return TwelveKey(index)
}
func (scientific) BaseKey() (scale.Key, scale.Octave) {
return TwelveKeyA, 4
}
func (scientific) KeysPerOctave() int {
return TwelveKeysPerOctave
}