KlattGrid_test.praat 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. # KlattGrid_test.praat
  2. # djmw 20081208, 20090420, 20140113
  3. printline =========== KlattGrid test start
  4. call test_get_add_remove_extract_replace_old_interface
  5. call test_get_add_remove_replace
  6. printline =========== KlattGrid test end
  7. procedure test_get_add_remove_replace
  8. numberOfOralFormants = 6
  9. numberOfNasalFormants = 1
  10. numberOfTrachealFormants = 1
  11. numberOfFricationFormants = 5
  12. numberOfNasalAntiFormants = 1
  13. numberOfTrachealAntiFormants = 1
  14. numberOfDeltaFormants = 1
  15. tmin = 0
  16. tmax = 1
  17. kg = Create KlattGrid... kg tmin tmax numberOfOralFormants numberOfNasalFormants numberOfNasalAntiFormants
  18. ... numberOfFricationFormants numberOfTrachealFormants numberOfTrachealAntiFormants numberOfDeltaFormants
  19. printline =========== KlattGrid test_get_add_remove_extract_replace start
  20. for .itime to 20
  21. call setget_1 "pitch" 130
  22. call setget_1 "voicing amplitude" 90
  23. call setget_1 "flutter" 0.5
  24. call setget_1 "power1" 2
  25. call setget_1 "power2" 3
  26. call setget_1 "open phase" 0.5
  27. call setget_1 "collision phase" 0.035
  28. call setget_1 "double pulsing" 0.4
  29. call setget_1 "spectral tilt" 20
  30. call setget_1 "aspiration amplitude" 90
  31. call setget_1 "breathiness amplitude" 90
  32. call setget_1 "frication bypass" 20
  33. call setget_1 "frication amplitude" 50
  34. call setget_formants Oral
  35. call setget_formants Nasal
  36. call setget_formants Tracheal
  37. call setget_formants Delta
  38. call setget_formants Frication
  39. call setget_antiformants Nasal
  40. call setget_antiformants Tracheal
  41. endfor
  42. call test_deltaFormants
  43. removeObject (kg)
  44. printline =========== KlattGrid test_get_add_remove_extract_replace succesful
  45. endproc
  46. procedure test_get_add_remove_extract_replace_old_interface
  47. numberOfOralFormants = 6
  48. numberOfNormalFormants = numberOfOralFormants
  49. numberOfNasalFormants = 1
  50. numberOfTrachealFormants = 1
  51. numberOfFricationFormants = 5
  52. numberOfNasalAntiFormants = 1
  53. numberOfTrachealAntiFormants = 1
  54. numberOfDeltaFormants = 1
  55. tmin = 0
  56. tmax = 1
  57. printline =========== KlattGrid test_get_add_remove_extract_replace_old_interface start
  58. kg = Create KlattGrid... kg tmin tmax numberOfOralFormants numberOfNasalFormants numberOfNasalAntiFormants
  59. ... numberOfFricationFormants numberOfTrachealFormants numberOfTrachealAntiFormants numberOfDeltaFormants
  60. for .itime to 20
  61. call setget_1 "pitch" 130
  62. call setget_1 "voicing amplitude" 90
  63. call setget_1 "flutter" 0.5
  64. call setget_1 "power1" 2
  65. call setget_1 "power2" 3
  66. call setget_1 "open phase" 0.5
  67. call setget_1 "collision phase" 0.035
  68. call setget_1 "double pulsing" 0.4
  69. call setget_1 "spectral tilt" 20
  70. call setget_1 "aspiration amplitude" 90
  71. call setget_1 "breathiness amplitude" 90
  72. call setget_1 "frication bypass" 20
  73. call setget_1 "frication amplitude" 50
  74. call setget_formants_old Normal
  75. call setget_formants_old Nasal
  76. call setget_formants_old Tracheal
  77. call setget_formants_old Frication
  78. call setget_antiformants_old Nasal
  79. call setget_antiformants_old Tracheal
  80. call setget_deltaformants
  81. endfor
  82. call test_deltaFormants_old
  83. removeObject (kg)
  84. printline =========== KlattGrid test_get_add_remove_extract_replace_old_interface succesful
  85. endproc
  86. procedure setget_1 .var$ .value
  87. selectObject (kg)
  88. .time = randomUniform (tmin,tmax)
  89. Add '.var$' point... .time .value
  90. .val = Get '.var$' at time... .time
  91. .vt = Extract '.var$' tier
  92. selectObject (kg)
  93. Remove '.var$' points between... tmin tmax
  94. .val1 = Get '.var$' at time... .time
  95. assert .val1 = undefined; Add '.var$' at time... '.time' '.value'
  96. plusObject (.vt)
  97. Replace '.var$' tier
  98. selectObject (kg)
  99. .val1 = Get '.var$' at time... .time
  100. assert .val1 =.val; Add '.var$' at time... '.time' '.value'
  101. removeObject (.vt)
  102. endproc
  103. procedure setget_2p .var$ .ifor .time .value
  104. selectObject (kg)
  105. Add delta '.var$' point... .ifor .time .value
  106. .val = Get delta '.var$' at time... .ifor .time
  107. assert .val = .value; Add delta '.var$' point... .ifor .time .value
  108. .fg = Extract delta formant grid
  109. selectObject (kg)
  110. Remove delta '.var$' points between... .ifor tmin tmax
  111. .val1 = Get delta '.var$' at time... .ifor .time
  112. assert .val1 = undefined; Get delta '.var$' at time... .ifor .time
  113. plusObject (.fg)
  114. Replace delta formant grid
  115. selectObject (kg)
  116. .val1 = Get delta '.var$' at time... .ifor .time
  117. assert .val1 =.val; Get delta '.var$' at time... .ifor .time
  118. removeObject (.fg)
  119. endproc
  120. procedure setget_3_old .var$ .choice$ .ifor .time .value
  121. selectObject (kg)
  122. Add '.var$' point... "'.choice$'" .ifor .time .value
  123. .val = Get '.var$' at time... "'.choice$'" .ifor .time
  124. assert .val = .value; Add '.var$' point... "'.choice$'" .ifor .time .value
  125. .fg = Extract formant grid... '.choice$'
  126. selectObject (kg)
  127. Remove '.var$' points between... "'.choice$'" .ifor tmin tmax
  128. .val1 = Get '.var$' at time... "'.choice$'" .ifor .time
  129. assert .val1 = undefined; Get '.var$' at time... "'.choice$'" .ifor .time
  130. plusObject (.fg)
  131. Replace formant grid... '.choice$'
  132. selectObject (kg)
  133. .val1 = Get '.var$' at time... "'.choice$'" .ifor .time
  134. assert .val1 =.val; Get '.var$' at time... "'.choice$'" .ifor .time
  135. removeObject (.fg)
  136. endproc
  137. procedure setget_3a_old .var$ .choice$ .ifor .time .value
  138. selectObject (kg)
  139. Add '.var$' point... "'.choice$'" .ifor .time .value
  140. .val = Get '.var$' at time... "'.choice$'" .ifor .time
  141. assert .val = .value; Add '.var$' point... "'.choice$'" .ifor .time .value
  142. .tier = Extract amplitude tier... "'.choice$'" .ifor
  143. selectObject (kg)
  144. Remove '.var$' points between... "'.choice$'" .ifor tmin tmax
  145. .val1 = Get '.var$' at time... "'.choice$'" .ifor .time
  146. assert .val1 = undefined; Get '.var$' at time... "'.choice$'" .ifor .time
  147. plusObject (.tier)
  148. Replace amplitude tier... "'.choice$'" .ifor
  149. selectObject (kg)
  150. .val1 = Get '.var$' at time... "'.choice$'" .ifor .time
  151. assert .val1 =.val; Get '.var$' at time... "'.choice$'" .ifor .time
  152. removeObject (.tier)
  153. endproc
  154. procedure setget_formants_old .type$
  155. for .i to numberOf'.type$'Formants
  156. .time = randomUniform (tmin, tmax)
  157. .f = (2*.i-1) * randomUniform (450, 550)
  158. .b = .f /10
  159. .a = randomUniform (70, 90)
  160. call setget_3_old "formant" "'.type$' formant" .i .time .f
  161. call setget_3_old "bandwidth" "'.type$' formant" .i .time .b
  162. call setget_3a_old "amplitude" "'.type$' formant" .i .time .a
  163. endfor
  164. selectObject (kg)
  165. Formula (frequencies)... "'.type$' formant" self + 100
  166. Formula (bandwidths)... "'.type$' formant" self * 2
  167. endproc
  168. procedure setget_3 .type$ .formant$ .var$ .ifor .time .value
  169. selectObject (kg)
  170. what$ = "'.type$' '.formant$' '.var$'"
  171. Remove 'what$' points... .ifor tmin tmax
  172. Add 'what$' point... .ifor .time .value
  173. .val = Get 'what$' at time... .ifor .time
  174. assert .val = .value; '.val' '.value' (Get 'what$' at time... '.ifor' '.time')
  175. .fg = Extract '.type$' '.formant$' grid
  176. selectObject (kg)
  177. Remove 'what$' points... .ifor tmin tmax
  178. .val1 = Get 'what$' at time... .ifor .time
  179. assert .val1 = undefined; '.val1' (Get 'what$' at time... '.ifor' '.time')
  180. plusObject (.fg)
  181. Replace '.type$' '.formant$' grid
  182. selectObject (kg)
  183. .val1 = Get 'what$' at time... .ifor .time
  184. if .var$ = "amplitude"
  185. .val = undefined
  186. endif
  187. assert .val1 =.val; '.val1' '.val' (Get 'what$' at time... '.ifor' '.time')
  188. removeObject (.fg)
  189. endproc
  190. procedure setget_formants .tYPE$
  191. .type$ = replace_regex$ (.tYPE$, "(^.)","\L\1", 1)
  192. for .i to numberOf'.tYPE$'Formants
  193. .time = randomUniform (tmin, tmax)
  194. .f = (2*.i-1) * randomUniform (450, 550)
  195. .b = .f /10
  196. .a = randomUniform (70, 90)
  197. call setget_3 '.type$' "formant" "frequency" .i .time .f
  198. call setget_3 '.type$' "formant" "bandwidth" .i .time .b
  199. if .tYPE$ <> "Delta"
  200. call setget_3 '.type$' "formant" "amplitude" .i .time .a
  201. endif
  202. endfor
  203. selectObject (kg)
  204. Formula ('.type$' formant frequencies)... self + 100
  205. Formula ('.type$' formant bandwidths)... self * 2
  206. endproc
  207. procedure setget_antiformants .tYPE$
  208. .type$ = replace_regex$ (.tYPE$, "(^.)","\L\1", 1)
  209. for .i to numberOf'.tYPE$'AntiFormants
  210. .time = randomUniform (tmin, tmax)
  211. .f = (2*.i-1) * randomUniform (450, 550)
  212. .b = .f /10
  213. call setget_3 '.type$' "antiformant" "frequency" .i .time .f
  214. call setget_3 '.type$' "antiformant" "bandwidth" .i .time .b
  215. endfor
  216. selectObject (kg)
  217. Formula ('.type$' antiformant frequencies)... self + 100
  218. Formula ('.type$' antiformant bandwidths)... self * 2
  219. endproc
  220. procedure setget_deltaformants
  221. for .i to numberOfDeltaFormants
  222. .time = randomUniform (tmin, tmax)
  223. .f = randomUniform (50, 60)
  224. .b = .f /10
  225. call setget_2p "formant" .i .time .f
  226. call setget_2p "bandwidth" .i .time .b
  227. endfor
  228. endproc
  229. procedure setget_antiformants_old .type$
  230. for .i to numberOf'.type$'AntiFormants
  231. .time = randomUniform (tmin, tmax)
  232. .f = (2*.i-1) * randomUniform (450, 550)
  233. .b = .f /10
  234. call setget_3_old "formant" "'.type$' antiformant" .i .time .f
  235. call setget_3_old "bandwidth" "'.type$' antiformant" .i .time .b
  236. endfor
  237. endproc
  238. procedure test_deltaFormants_old
  239. .kg = Create KlattGrid... kg 0 1 6 1 1 6 1 1 1
  240. Add pitch point... 0.5 100
  241. Add voicing amplitude point... 0.5 90
  242. Add bandwidth point... "Normal formant" 1 0.5 50
  243. Add delta formant point... 1 0.5 500
  244. Remove formant points between... "Normal formant" 1 0 2
  245. Add formant point... "Normal formant" 1 0 400
  246. Add formant point... "Normal formant" 1 1 600
  247. Add formant point... "Normal formant" 1 0.003553 400
  248. Add formant point... "Normal formant" 1 0.002 300
  249. Add formant point... "Normal formant" 1 0.0112 430
  250. .sound = To Sound
  251. selectObject (.kg)
  252. .fg = Extract formant grid (open phases)... 0.1
  253. removeObject (.sound, .kg, .fg)
  254. endproc
  255. procedure test_deltaFormants
  256. .kg = Create KlattGrid... kg 0 1 6 1 1 6 1 1 1
  257. Add pitch point... 0.5 100
  258. Add voicing amplitude point... 0.5 90
  259. Add oral formant bandwidth point... 1 0.5 50
  260. Add delta formant frequency point... 1 0.5 500
  261. Remove oral formant frequency points... 1 0 2
  262. Add oral formant frequency point... 1 0 400
  263. Add oral formant frequency point... 1 1 600
  264. Add oral formant frequency point... 1 0.003553 400
  265. Add oral formant frequency point... 1 0.002 300
  266. Add oral formant frequency point... 1 0.0112 430
  267. .sound = To Sound
  268. selectObject (.kg)
  269. .fg = Extract oral formant grid (open phases)... 0.1
  270. removeObject (.sound, .fg, .kg)
  271. endproc