praat_Artsynth.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /* praat_Artsynth.cpp
  2. *
  3. * Copyright (C) 1992-2009,2011,2012,2014-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "Art_Speaker.h"
  19. #include "Artword_Speaker.h"
  20. #include "Art_Speaker_to_VocalTract.h"
  21. #include "Artword_Speaker_Sound.h"
  22. #include "Artword_Speaker_to_Sound.h"
  23. #include "Artword_to_Art.h"
  24. #include "ArtwordEditor.h"
  25. #include "VocalTract_to_Spectrum.h"
  26. #include "praat_Matrix.h"
  27. // MARK: - ART
  28. FORM (NEW1_Art_create, U"Create a default Articulation", U"Articulatory synthesis") {
  29. WORD (name, U"Name", U"articulation")
  30. OK
  31. DO
  32. CREATE_ONE
  33. autoArt result = Art_create ();
  34. CREATE_ONE_END (name);
  35. }
  36. FORM (WINDOW_Art_viewAndEdit, U"View & Edit Articulation", nullptr) {
  37. static double muscles [1 + (int) kArt_muscle::MAX];
  38. for (kArt_muscle muscle = (kArt_muscle) 1; muscle <= kArt_muscle::MAX; ++ muscle)
  39. UiForm_addReal (_dia_.get(), & muscles [(int) muscle], nullptr /* GUI-only */, kArt_muscle_getText (muscle), U"0.0");
  40. OK
  41. FIND_ONE (Art)
  42. for (int i = 1; i <= (int) kArt_muscle::MAX; i ++)
  43. SET_REAL (muscles [i], my art [i])
  44. DO
  45. FIND_ONE (Art)
  46. if (theCurrentPraatApplication -> batch)
  47. Melder_throw (U"Cannot edit an Art from batch.");
  48. for (int i = 1; i <= (int) kArt_muscle::MAX; i ++)
  49. my art [i] = muscles [i];
  50. END
  51. }
  52. // MARK: - ARTWORD
  53. FORM (NEW1_Artword_create, U"Create an empty Artword", U"Create Artword...") {
  54. WORD (name, U"Name", U"hallo")
  55. POSITIVE (duration, U"Duration (seconds)", U"1.0")
  56. OK
  57. DO
  58. CREATE_ONE
  59. autoArtword result = Artword_create (duration);
  60. CREATE_ONE_END (name)
  61. }
  62. FORM (GRAPHICS_Artword_draw, U"Draw one Artword tier", nullptr) {
  63. OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
  64. for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
  65. OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
  66. BOOLEAN (garnish, U"Garnish", true)
  67. OK
  68. DO
  69. GRAPHICS_EACH (Artword)
  70. Artword_draw (me, GRAPHICS, (kArt_muscle) muscle, garnish);
  71. GRAPHICS_EACH_END
  72. }
  73. DIRECT (WINDOW_Artword_viewAndEdit) {
  74. if (theCurrentPraatApplication -> batch) Melder_throw (U"Cannot view or edit an Artword from batch.");
  75. FIND_ONE_WITH_IOBJECT (Artword)
  76. autoArtwordEditor editor = ArtwordEditor_create (ID_AND_FULL_NAME, me);
  77. praat_installEditor (editor.get(), IOBJECT);
  78. editor.releaseToUser();
  79. END
  80. }
  81. FORM (REAL_Artword_getTarget, U"Get one Artword target", nullptr) {
  82. REAL (time, U"Time (seconds)", U"0.0")
  83. OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
  84. for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
  85. OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
  86. OK
  87. DO
  88. NUMBER_ONE (Artword)
  89. double result = Artword_getTarget (me, (kArt_muscle) muscle, time);
  90. NUMBER_ONE_END (U"")
  91. }
  92. DIRECT (HELP_Artword_help) {
  93. HELP (U"Artword")
  94. }
  95. FORM (MODIFY_Artword_setTarget, U"Set one Artword target", nullptr) {
  96. REAL (time, U"Time (seconds)", U"0.0")
  97. REAL (targetValue, U"Target value (0-1)", U"0.0")
  98. OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
  99. for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
  100. OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
  101. OK
  102. DO
  103. if (time < 0.0) Melder_throw (U"The specified time should not be less than 0.");
  104. MODIFY_EACH (Artword)
  105. Artword_setTarget (me, (kArt_muscle) muscle, time, targetValue);
  106. MODIFY_EACH_END
  107. }
  108. FORM (NEW_Artword_to_Art, U"From Artword to Art", nullptr) {
  109. REAL (time, U"Time (seconds)", U"0.0")
  110. OK
  111. DO
  112. CONVERT_EACH (Artword)
  113. autoArt result = Artword_to_Art (me, time);
  114. CONVERT_EACH_END (my name.get())
  115. }
  116. // MARK: - ART & SPEAKER
  117. DIRECT (GRAPHICS_Art_Speaker_draw) {
  118. GRAPHICS_TWO (Art, Speaker)
  119. Art_Speaker_draw (me, you, GRAPHICS);
  120. GRAPHICS_TWO_END
  121. }
  122. DIRECT (GRAPHICS_Art_Speaker_fillInnerContour) {
  123. GRAPHICS_TWO (Art, Speaker)
  124. Art_Speaker_fillInnerContour (me, you, GRAPHICS);
  125. GRAPHICS_TWO_END
  126. }
  127. DIRECT (GRAPHICS_Art_Speaker_drawMesh) {
  128. GRAPHICS_TWO (Art, Speaker)
  129. Art_Speaker_drawMesh (me, you, GRAPHICS);
  130. GRAPHICS_TWO_END
  131. }
  132. DIRECT (NEW1_Art_Speaker_to_VocalTract) {
  133. CONVERT_TWO (Art, Speaker)
  134. autoVocalTract result = Art_Speaker_to_VocalTract (me, you);
  135. CONVERT_TWO_END (my name.get(), U"_", your name.get())
  136. }
  137. // MARK: - ARTWORD & SPEAKER
  138. FORM (GRAPHICS_Artword_Speaker_draw, U"Draw Artword & Speaker", nullptr) {
  139. NATURAL (numberOfSteps, U"Number of steps", U"5")
  140. OK
  141. DO
  142. GRAPHICS_TWO (Artword, Speaker)
  143. Artword_Speaker_draw (me, you, GRAPHICS, numberOfSteps);
  144. GRAPHICS_TWO_END
  145. }
  146. FORM (NEW1_Artword_Speaker_to_Sound, U"Articulatory synthesizer", U"Artword & Speaker: To Sound...") {
  147. POSITIVE (samplingFrequency, U"Sampling frequency (Hz)", U"22050.0")
  148. NATURAL (oversamplingFactor, U"Oversampling factor", U"25")
  149. INTEGER (width1, U"Width 1", U"0")
  150. INTEGER (width2, U"Width 2", U"0")
  151. INTEGER (width3, U"Width 3", U"0")
  152. INTEGER (pressure1, U"Pressure 1", U"0")
  153. INTEGER (pressure2, U"Pressure 2", U"0")
  154. INTEGER (pressure3, U"Pressure 3", U"0")
  155. INTEGER (velocity1, U"Velocity 1", U"0")
  156. INTEGER (velocity2, U"Velocity 2", U"0")
  157. INTEGER (velocity3, U"Velocity 3", U"0")
  158. OK
  159. DO
  160. FIND_TWO (Artword, Speaker)
  161. autoSound w1, w2, w3, p1, p2, p3, v1, v2, v3;
  162. autoSound result = Artword_Speaker_to_Sound (me, you,
  163. samplingFrequency, oversamplingFactor,
  164. & w1, width1, & w2, width2, & w3, width3,
  165. & p1, pressure1, & p2, pressure2, & p3, pressure3,
  166. & v1, velocity1, & v2, velocity2, & v3, velocity3);
  167. praat_new (result.move(), my name.get(), U"_", your name.get());
  168. if (width1) praat_new (w1.move(), U"width", width1);
  169. if (width2) praat_new (w2.move(), U"width", width2);
  170. if (width3) praat_new (w3.move(), U"width", width3);
  171. if (pressure1) praat_new (p1.move(), U"pressure", pressure1);
  172. if (pressure2) praat_new (p2.move(), U"pressure", pressure2);
  173. if (pressure3) praat_new (p3.move(), U"pressure", pressure3);
  174. if (velocity1) praat_new (v1.move(), U"velocity", velocity1);
  175. if (velocity2) praat_new (v2.move(), U"velocity", velocity2);
  176. if (velocity3) praat_new (v3.move(), U"velocity", velocity3);
  177. END
  178. }
  179. DIRECT (MOVIE_Artword_Speaker_movie) {
  180. MOVIE_TWO (Artword, Speaker, U"Artword & Speaker movie", 300, 300)
  181. Artword_Speaker_movie (me, you, graphics);
  182. MOVIE_TWO_END
  183. }
  184. // MARK: - ARTWORD & SPEAKER & SOUND
  185. DIRECT (MOVIE_Artword_Speaker_Sound_movie) {
  186. MOVIE_THREE (Artword, Speaker, Sound, U"Artword & Speaker & Sound movie", 300, 300)
  187. Artword_Speaker_Sound_movie (me, you, him, graphics);
  188. MOVIE_THREE_END
  189. }
  190. // MARK: - SPEAKER
  191. FORM (NEW1_Speaker_create, U"Create a Speaker", U"Create Speaker...") {
  192. WORD (name, U"Name", U"speaker")
  193. OPTIONMENUSTR (kindOfSpeaker, U"Kind of speaker", 1)
  194. OPTION (U"Female")
  195. OPTION (U"Male")
  196. OPTION (U"Child")
  197. OPTIONMENUSTR (numberOfTubesInGlottis, U"Number of tubes in glottis", 2)
  198. OPTION (U"1")
  199. OPTION (U"2")
  200. OPTION (U"10")
  201. OK
  202. DO
  203. CREATE_ONE
  204. autoSpeaker result = Speaker_create (kindOfSpeaker, (int16) Melder_atoi (numberOfTubesInGlottis)); // conversion OK because the values are 1, 2, 10
  205. CREATE_ONE_END (name)
  206. }
  207. DIRECT (HELP_Speaker_help) {
  208. HELP (U"Speaker")
  209. }
  210. // MARK: - VOCALTRACT
  211. FORM (NEW1_VocalTract_createFromPhone, U"Create Vocal Tract from phone", U"Create Vocal Tract from phone...") {
  212. OPTIONMENUSTR (phone, U"Phone", 1)
  213. OPTION (U"a")
  214. OPTION (U"e")
  215. OPTION (U"i")
  216. OPTION (U"o")
  217. OPTION (U"u")
  218. OPTION (U"y1")
  219. OPTION (U"y2")
  220. OPTION (U"y3")
  221. OPTION (U"jery")
  222. OPTION (U"p")
  223. OPTION (U"t")
  224. OPTION (U"k")
  225. OPTION (U"x")
  226. OPTION (U"pa")
  227. OPTION (U"ta")
  228. OPTION (U"ka")
  229. OPTION (U"pi")
  230. OPTION (U"ti")
  231. OPTION (U"ki")
  232. OPTION (U"pu")
  233. OPTION (U"tu")
  234. OPTION (U"ku")
  235. OK
  236. DO
  237. CREATE_ONE
  238. autoVocalTract result = VocalTract_createFromPhone (phone);
  239. CREATE_ONE_END (phone)
  240. }
  241. DIRECT (GRAPHICS_VocalTract_draw) {
  242. GRAPHICS_EACH (VocalTract)
  243. VocalTract_draw (me, GRAPHICS);
  244. GRAPHICS_EACH_END
  245. }
  246. FORM (MODIFY_VocalTract_formula, U"VocalTract Formula", U"Matrix: Formula...") {
  247. LABEL (U"`x` is the distance form the glottis in metres, `col` is the section number, `self` is in m\u00B2")
  248. LABEL (U"x := x1; for col := 1 to ncol do { self [col] := `formula' ; x := x + dx }")
  249. TEXTFIELD (formula, U"Formula:", U"0")
  250. OK
  251. DO
  252. MODIFY_EACH_WEAK (VocalTract)
  253. Matrix_formula (me, formula, interpreter, nullptr);
  254. MODIFY_EACH_WEAK_END
  255. }
  256. DIRECT (HELP_VocalTract_help) {
  257. HELP (U"VocalTract")
  258. }
  259. DIRECT (NEW_VocalTract_to_Matrix) {
  260. CONVERT_EACH (VocalTract)
  261. autoMatrix result = VocalTract_to_Matrix (me);
  262. CONVERT_EACH_END (my name.get())
  263. }
  264. FORM (NEW_VocalTract_to_Spectrum, U"From Vocal Tract to Spectrum", nullptr) {
  265. LABEL (U"Compute transfer function")
  266. NATURAL (numberOfFequencies, U"Number of frequencies", U"4097")
  267. POSITIVE (maximumFrequency, U"Maximum frequency (Hz)", U"5000.0")
  268. REAL (glottalDamping, U"Glottal damping", U"0.1")
  269. BOOLEAN (radiationDamping, U"Radiation damping", true)
  270. BOOLEAN (internalDamping, U"Internal damping", true)
  271. OK
  272. DO
  273. CONVERT_EACH (VocalTract)
  274. autoSpectrum result = VocalTract_to_Spectrum (me, numberOfFequencies,
  275. maximumFrequency, glottalDamping, radiationDamping, internalDamping);
  276. CONVERT_EACH_END (my name.get())
  277. }
  278. DIRECT (HELP_ArticulatorySynthesisTutorial) {
  279. HELP (U"Articulatory synthesis")
  280. }
  281. void manual_Artsynth_init (ManPages me);
  282. // MARK: - buttons
  283. void praat_uvafon_Artsynth_init ();
  284. void praat_uvafon_Artsynth_init () {
  285. Thing_recognizeClassesByName (classArt, classArtword, classSpeaker, nullptr);
  286. praat_addMenuCommand (U"Objects", U"New", U"Articulatory synthesis", nullptr, 0, nullptr);
  287. praat_addMenuCommand (U"Objects", U"New", U"Articulatory synthesis tutorial", nullptr, praat_DEPTH_1, HELP_ArticulatorySynthesisTutorial);
  288. praat_addMenuCommand (U"Objects", U"New", U"-- new articulatory synthesis -- ", nullptr, 1, nullptr);
  289. praat_addMenuCommand (U"Objects", U"New", U"Create Articulation...", nullptr, 1, NEW1_Art_create);
  290. praat_addMenuCommand (U"Objects", U"New", U"Create Speaker...", nullptr, 1, NEW1_Speaker_create);
  291. praat_addMenuCommand (U"Objects", U"New", U"Create Artword...", nullptr, 1, NEW1_Artword_create);
  292. praat_addMenuCommand (U"Objects", U"New", U"-- new vocal tract --", nullptr, 1, nullptr);
  293. praat_addMenuCommand (U"Objects", U"New", U"Create Vocal Tract from phone...", nullptr, 1, NEW1_VocalTract_createFromPhone);
  294. praat_addAction1 (classArt, 1, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_Art_viewAndEdit);
  295. praat_addAction1 (classArt, 1, U"Edit", U"*View & Edit", praat_DEPRECATED_2011, WINDOW_Art_viewAndEdit);
  296. praat_addAction1 (classArtword, 0, U"Artword help", nullptr, 0, HELP_Artword_help);
  297. praat_addAction1 (classArtword, 1, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_Artword_viewAndEdit);
  298. praat_addAction1 (classArtword, 1, U"Edit", U"*View & Edit", praat_DEPRECATED_2011, WINDOW_Artword_viewAndEdit);
  299. praat_addAction1 (classArtword, 0, U"Info", nullptr, 0, nullptr);
  300. praat_addAction1 (classArtword, 1, U"Get target...", nullptr, 0, REAL_Artword_getTarget);
  301. praat_addAction1 (classArtword, 0, U"Draw", nullptr, 0, nullptr);
  302. praat_addAction1 (classArtword, 0, U"Draw...", nullptr, 0, GRAPHICS_Artword_draw);
  303. praat_addAction1 (classArtword, 0, U"Modify", nullptr, 0, nullptr);
  304. praat_addAction1 (classArtword, 1, U"Set target...", nullptr, 0, MODIFY_Artword_setTarget);
  305. praat_addAction1 (classArtword, 0, U"Analyse", nullptr, 0, nullptr);
  306. praat_addAction1 (classArtword, 0, U"To Art (slice)...", nullptr, 0, NEW_Artword_to_Art);
  307. praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw", nullptr, 0, nullptr);
  308. praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw", nullptr, 0, GRAPHICS_Art_Speaker_draw);
  309. praat_addAction2 (classArt, 1, classSpeaker, 1, U"Fill inner contour", nullptr, 0, GRAPHICS_Art_Speaker_fillInnerContour);
  310. praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw mesh", nullptr, 0, GRAPHICS_Art_Speaker_drawMesh);
  311. praat_addAction2 (classArt, 1, classSpeaker, 1, U"Synthesize", nullptr, 0, nullptr);
  312. praat_addAction2 (classArt, 1, classSpeaker, 1, U"To VocalTract", nullptr, 0, NEW1_Art_Speaker_to_VocalTract);
  313. praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Movie", nullptr, 0, MOVIE_Artword_Speaker_movie);
  314. praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Draw", nullptr, 0, nullptr);
  315. praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Draw...", nullptr, 0, GRAPHICS_Artword_Speaker_draw);
  316. praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Synthesize", nullptr, 0, nullptr);
  317. praat_addAction2 (classArtword, 1, classSpeaker, 1, U"To Sound...", nullptr, 0, NEW1_Artword_Speaker_to_Sound);
  318. praat_addAction3 (classArtword, 1, classSpeaker, 1, classSound, 1, U"Movie", nullptr, 0, MOVIE_Artword_Speaker_Sound_movie);
  319. praat_addAction1 (classSpeaker, 0, U"Speaker help", nullptr, 0, HELP_Speaker_help);
  320. praat_addAction1 (classVocalTract, 0, U"VocalTract help", nullptr, 0, HELP_VocalTract_help);
  321. praat_addAction1 (classVocalTract, 0, U"Draw", nullptr, 0, nullptr);
  322. praat_addAction1 (classVocalTract, 0, U"Draw", nullptr, 0, GRAPHICS_VocalTract_draw);
  323. praat_addAction1 (classVocalTract, 0, U"Analyse", nullptr, 0, nullptr);
  324. praat_addAction1 (classVocalTract, 0, U"To Spectrum...", nullptr, 0, NEW_VocalTract_to_Spectrum);
  325. praat_addAction1 (classVocalTract, 0, U"Modify", nullptr, 0, nullptr);
  326. praat_addAction1 (classVocalTract, 0, U"Formula...", nullptr, 0, MODIFY_VocalTract_formula);
  327. praat_addAction1 (classVocalTract, 0, U"Hack", nullptr, 0, nullptr);
  328. praat_addAction1 (classVocalTract, 0, U"To Matrix", nullptr, 0, NEW_VocalTract_to_Matrix);
  329. manual_Artsynth_init (theCurrentPraatApplication -> manPages);
  330. }
  331. /* End of file praat_Artsynth.cpp */