-
Notifications
You must be signed in to change notification settings - Fork 1
/
t_test.go
66 lines (54 loc) · 1.14 KB
/
t_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 Scott Cotton. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.
package hilbert
import (
"fmt"
"math"
"testing"
snd "zikichombo.org/sound"
"zikichombo.org/sound/freq"
)
type sgen struct {
rps float64
ph float64
sr freq.T
}
func (s *sgen) Channels() int {
return 1
}
func (s *sgen) Close() error {
return nil
}
func newSinGen(fa, fs freq.T) snd.Source {
return &sgen{sr: fs, ph: 0.0, rps: fs.RadsPer(fa)}
}
func (s *sgen) Receive(dst []float64) (int, error) {
ph, rps := s.ph, s.rps
for i := range dst {
dst[i] = math.Sin(ph)
ph += rps
}
s.ph = ph
return len(dst), nil
}
func (s *sgen) SampleRate() freq.T {
return s.sr
}
func TestT(t *testing.T) {
testTSin(20*freq.Hertz, t)
}
func testTSin(fa freq.T, t *testing.T) {
src := newSinGen(fa, 44100*freq.Hertz)
var err error
N := 2048
Q := 8
hlb := New(snd.Discard, src, N, Q)
for n := 0; n < 100 && err == nil; n++ {
err = hlb.Process()
org, rot := hlb.Org(), hlb.Rotated()
fmt.Printf("block:\n")
for i := 0; i < N; i++ {
fmt.Printf("%d in %f out %f\n", i, org[i], rot[i])
}
}
}