| 1 |
# pitch.praat |
| 2 |
# Paul Boersma 2020-01-02 |
| 3 |
# Tests "Sound: To Pitch..." |
| 4 |
|
| 5 |
writeInfoLine: "Pitch test" |
| 6 |
stopwatch |
| 7 |
|
| 8 |
method$ = "cc" |
| 9 |
|
| 10 |
for freq from 76.1 to 106 |
| 11 |
@sineTest: freq, 0.1 |
| 12 |
endfor |
| 13 |
for freq from 106.1 to 226 |
| 14 |
@sineTest: freq, 0.01 |
| 15 |
endfor |
| 16 |
for i from 2 to 20 |
| 17 |
@sineTest: i * 100 + 77, 0.02 |
| 18 |
endfor |
| 19 |
for i from 21 to 29 |
| 20 |
@sineTest: i * 100 + 77, 0.1 |
| 21 |
endfor |
| 22 |
for i from 30 to 35 |
| 23 |
@sineTest: i * 100 + 77, 1.0 |
| 24 |
endfor |
| 25 |
for i from 36 to 60 |
| 26 |
@sineTest: i * 100 + 77, 5.0 |
| 27 |
endfor |
| 28 |
for i from 61 to 107 |
| 29 |
@sineTest: i * 100 + 77, 10.0 |
| 30 |
endfor |
| 31 |
for i from 1080 to 1095 |
| 32 |
@sineTest: i * 10 - 0.1, 10.0 |
| 33 |
endfor |
| 34 |
|
| 35 |
for freq from 76.1 to 136 |
| 36 |
@pulseTest: freq, 0.1 |
| 37 |
endfor |
| 38 |
for freq from 136.1 to 226 |
| 39 |
@pulseTest: freq, 0.2 |
| 40 |
endfor |
| 41 |
for i from 2 to 13 |
| 42 |
@pulseTest: i * 100 + 77, 1 |
| 43 |
endfor |
| 44 |
for i from 14 to 20 |
| 45 |
@pulseTest: i * 100 + 77, 2 |
| 46 |
endfor |
| 47 |
for i from 210 to 219 |
| 48 |
@pulseTest: i * 10 + 77, 10 |
| 49 |
endfor |
| 50 |
for i from 22 to 30 |
| 51 |
@pulseTest: i * 100 + 77, 2 |
| 52 |
endfor |
| 53 |
for i from 31 to 53 |
| 54 |
@pulseTest: i * 100 + 77, 5 |
| 55 |
endfor |
| 56 |
@pulseTest: 219, 1 |
| 57 |
@pulseTest: 220, 1 |
| 58 |
|
| 59 |
method$ = "ac" |
| 60 |
|
| 61 |
for freq from 75.1 to 106 |
| 62 |
@sineTest: freq, 0.1 |
| 63 |
endfor |
| 64 |
for freq from 106.1 to 226 |
| 65 |
@sineTest: freq, 0.01 |
| 66 |
endfor |
| 67 |
for i from 2 to 105 |
| 68 |
@sineTest: i * 100 + 77, 0.02 |
| 69 |
endfor |
| 70 |
for i from 106 to 107 |
| 71 |
@sineTest: i * 100 + 77, 0.1 |
| 72 |
endfor |
| 73 |
for i from 1080 to 1095 |
| 74 |
@sineTest: i * 10 - 0.1, 0.3 |
| 75 |
endfor |
| 76 |
|
| 77 |
for freq from 75.1 to 226 |
| 78 |
@pulseTest: freq, 0.03 |
| 79 |
endfor |
| 80 |
for i from 2 to 20 |
| 81 |
@pulseTest: i * 100 + 77, 1 |
| 82 |
endfor |
| 83 |
for i from 210 to 219 |
| 84 |
@pulseTest: i * 10 + 77, 4 |
| 85 |
endfor |
| 86 |
for i from 22 to 53 |
| 87 |
@pulseTest: i * 100 + 77, 1 |
| 88 |
endfor |
| 89 |
@pulseTest: 219, 1 |
| 90 |
@pulseTest: 220, 1 |
| 91 |
# Tests above 5512.5 Hz are superfluous, |
| 92 |
# since pulses are no different from sine waves then. |
| 93 |
|
| 94 |
appendInfoLine: "Pitch test finished OK ", stopwatch |
| 95 |
|
| 96 |
procedure sineTest: pitch, precision |
| 97 |
sound = Create Sound: "sound", 0, 1, 22050, ~ sin (2 * pi * pitch * x) |
| 98 |
@analyse: precision |
| 99 |
removeObject: sound |
| 100 |
endproc |
| 101 |
|
| 102 |
procedure pulseTest: pitch, precision |
| 103 |
pitchTier = Create PitchTier: "sound", 0, 1 |
| 104 |
Add point: 0.5, pitch |
| 105 |
sound = To Sound (pulse train): 22050, 1, 1e-9, 2000, "no" |
| 106 |
@analyse: precision |
| 107 |
removeObject: pitchTier, sound |
| 108 |
endproc |
| 109 |
|
| 110 |
procedure analyse: precision |
| 111 |
timeStep = 0.09457464735 |
| 112 |
;timeStep = 0.001 |
| 113 |
;To Pitch... timeStep 75 11025 |
| 114 |
my.Pitch = noprogress To Pitch ('method$'): timeStep, 75, 15, "no", 0.03, 0.45, 0.03, 0.35, 0.14, 11025 |
| 115 |
minPitch = Get minimum... 0 0 Hertz None |
| 116 |
maxPitch = Get maximum... 0 0 Hertz None |
| 117 |
diff1 = minPitch - pitch |
| 118 |
diff2 = maxPitch - pitch |
| 119 |
absDiff = max (abs (diff1), abs (diff2)) |
| 120 |
relDiff = absDiff / pitch |
| 121 |
printline 'pitch' 'diff1:6' 'diff2:6' 'relDiff:3%' |
| 122 |
;assert absDiff < precision ; 'pitch' 'minPitch' 'maxPitch' |
| 123 |
removeObject: my.Pitch |
| 124 |
endproc |