-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombinators.go
More file actions
31 lines (28 loc) · 798 Bytes
/
combinators.go
File metadata and controls
31 lines (28 loc) · 798 Bytes
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
package gotes
// CombineWaves returns a simple aggregated waveform of all the given waves.
func CombineWaves(fns ...WaveFn) WaveFn {
if len(fns) == 0 {
return ZeroWave()
}
return func(t float64) float64 {
total := 0.0
for _, fn := range fns {
total += fn(t)
}
return total
}
}
// IntegrateWave creates a wave function that will take the initial time, pass
// it to the given time function, and pass that result to the wave function.
func IntegrateWave(tFn TimeFn, wFn WaveFn) WaveFn {
return func(t float64) float64 {
return wFn(tFn(t))
}
}
// AmplifyWave will amplify the given wave function at each time point by the
// value yielded by the amplify function.
func AmplifyWave(aFn AmpFn, wFn WaveFn) WaveFn {
return func(t float64) float64 {
return wFn(t) * aFn(t)
}
}