-
Notifications
You must be signed in to change notification settings - Fork 7
/
f0.jl
67 lines (54 loc) · 1.95 KB
/
f0.jl
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
function test_swipe()
srand(98765)
dummy_input = rand(1024)
println("-- test_swipe")
for otype in [0, 1, 2]
for fs in [16000]
for hopsize in [40, 80, 160, 320]
f0 = swipe(dummy_input, fs, hopsize, otype=otype)
@test all(isfinite(f0))
otype == 0 && @test all(f0 .>= 0)
end
end
end
fs = 16000
# invalid otype
@test_throws ArgumentError swipe(dummy_input, fs, 80, otype=-1)
@test_throws ArgumentError swipe(dummy_input, fs, 80, otype=-3)
# invalid min/max
@test_throws ArgumentError swipe(dummy_input, fs, 80, min=60.0, max=60.0)
swipe(dummy_input, 16000, 80, min=60.0, max=7999.0)
@test_throws ArgumentError swipe(dummy_input, fs, 80, min=60.0, max=8000.0)
end
function test_rapt()
srand(98765)
dummy_input = rand(Float32, 1024)
println("-- test_rapt")
for otype in [0, 1, 2]
for fs in [16000]
for hopsize in [40, 80, 160, 320]
println(" where otype = $otype, fs = $fs and hopsize = $hopsize")
f0 = rapt(dummy_input, fs, hopsize, otype=otype)
@test all(isfinite(f0))
otype == 0 && @test all(f0 .>= 0)
end
end
end
fs = 16000
# invalid otype
@test_throws ArgumentError rapt(dummy_input, fs, 80, otype=-1)
@test_throws ArgumentError rapt(dummy_input, fs, 80, otype=-3)
# invalid min/max
@test_throws ArgumentError rapt(dummy_input, fs, 80, min=60.0, max=60.0)
@test_throws ArgumentError rapt(dummy_input, fs, 80, min=60.0, max=8000.0)
# valid frame period (corner case)
# TODO: should be 1599 instead of 1600
rapt(rand(Float32, 10000), fs, 1599)
# invalid frame_period
@test_throws ArgumentError rapt(dummy_input, fs, 1601)
# invalid input length (too small)
@test_throws Exception rapt(dummy_input[:100], fs, 80)
end
println("test f0 estimation")
test_swipe()
test_rapt()