-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathosc_test.go
51 lines (46 loc) · 911 Bytes
/
osc_test.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
package audio
import (
"math"
"math/cmplx"
"testing"
)
func TestSineOsc_expwdt_approx(t *testing.T) {
const sampleRate = 96000
var osc SineOsc
Init(&osc, Params{sampleRate})
for freq, err := range map[float64]float64{
32: 0.00,
64: 0.00,
128: 0.00,
256: 0.00,
512: 0.00,
1024: 0.00,
2048: 0.00,
4096: 0.01,
8192: 0.02,
16384: 0.09,
} {
_, θ := cmplx.Polar(osc.expwdt_approx(freq))
actualFreq := θ / 2 / math.Pi * sampleRate
actualErr := freq/actualFreq - 1
if math.Abs(err-actualErr) > .01 {
t.Errorf("freq=%5.f:, expected %.2f, got %.2f", freq, err, actualErr)
}
}
}
func BenchmarkSineOsc(b *testing.B) {
o := new(SineOsc)
Init(o, Params{96000})
for i := 0; i < b.N; i++ {
o.Freq(1234)
o.Sing()
}
}
func BenchmarkSawOsc(b *testing.B) {
o := new(SawOsc)
Init(o, Params{96000})
for i := 0; i < b.N; i++ {
o.Freq(1234)
o.Sing()
}
}