Debian Codegraph @

artsynth/praat_Artsynth.cpp

raw
1 /* praat_Artsynth.cpp
2 *
3 * Copyright (C) 1992-2009,2011,2012,2014-2024,2026 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 3 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
19 #include "Art_Speaker.h"
20 #include "Artword_Speaker.h"
21 #include "Art_Speaker_to_VocalTract.h"
22 #include "Artword_Speaker_Sound.h"
23 #include "Artword_Speaker_to_Sound.h"
24 #include "Artword_to_Art.h"
25 #include "ArtwordEditor.h"
26 #include "VocalTract_to_Spectrum.h"
27
28 #include "praat_Matrix.h"
29
30 // MARK: - ART
31
32 FORM (NEW1_Art_create, U"Create a default Articulation", U"Articulatory synthesis") {
33 WORD (name, U"Name", U"articulation")
34 OK
35 DO
36 CREATE_ONE
37 autoArt result = Art_create ();
38 CREATE_ONE_END (name);
39 }
40
41 FORM (WINDOW_Art_viewAndEdit, U"View & Edit Articulation", nullptr) {
42 static double muscles [1 + (int) kArt_muscle::MAX];
43 for (kArt_muscle muscle = (kArt_muscle) 1; muscle <= kArt_muscle::MAX; ++ muscle)
44 UiForm_addReal (_dia_.get(), & muscles [(int) muscle], nullptr /* GUI-only */, kArt_muscle_getText (muscle), U"0.0");
45 OK
46 FIND_ONE (Art)
47 for (int i = 1; i <= (int) kArt_muscle::MAX; i ++)
48 SET_REAL (muscles [i], my art [i])
49 DO
50 FIND_ONE (Art)
51 if (theCurrentPraatApplication -> batch)
52 Melder_throw (U"Cannot edit an Art from batch.");
53 for (int i = 1; i <= (int) kArt_muscle::MAX; i ++)
54 my art [i] = muscles [i];
55 END_NO_NEW_DATA
56 }
57
58 // MARK: - ARTWORD
59
60 FORM (NEW1_Artword_create, U"Create an empty Artword", U"Create Artword...") {
61 WORD (name, U"Name", U"hallo")
62 POSITIVE (duration, U"Duration (seconds)", U"1.0")
63 OK
64 DO
65 CREATE_ONE
66 autoArtword result = Artword_create (duration);
67 CREATE_ONE_END (name)
68 }
69
70 FORM (GRAPHICS_Artword_draw, U"Draw one Artword tier", nullptr) {
71 OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
72 for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
73 OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
74 BOOLEAN (garnish, U"Garnish", true)
75 OK
76 DO
77 GRAPHICS_EACH (Artword)
78 Artword_draw (me, GRAPHICS, (kArt_muscle) muscle, garnish);
79 GRAPHICS_EACH_END
80 }
81
82 DIRECT (EDITOR_ONE_Artword_viewAndEdit) {
83 EDITOR_ONE (an,Artword)
84 autoArtwordEditor editor = ArtwordEditor_create (ID_AND_FULL_NAME, me);
85 EDITOR_ONE_END
86 }
87
88 FORM (REAL_Artword_getTarget, U"Get one Artword target", nullptr) {
89 REAL (time, U"Time (seconds)", U"0.0")
90 OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
91 for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
92 OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
93 OK
94 DO
95 QUERY_ONE_FOR_REAL (Artword)
96 double result = Artword_getTarget (me, (kArt_muscle) muscle, time);
97 QUERY_ONE_FOR_REAL_END (U"")
98 }
99
100 DIRECT (HELP_Artword_help) {
101 HELP (U"Artword")
102 }
103
104 FORM (MODIFY_EACH_Artword_setTarget, U"Set one Artword target", nullptr) {
105 REAL (time, U"Time (seconds)", U"0.0")
106 REAL (targetValue, U"Target value (0-1)", U"0.0")
107 OPTIONMENU (muscle, U"Muscle", (int) kArt_muscle::LUNGS)
108 for (int ienum = 1; ienum <= (int) kArt_muscle::MAX; ienum ++)
109 OPTION (kArt_muscle_getText ((kArt_muscle) ienum))
110 OK
111 DO
112 if (time < 0.0)
113 Melder_throw (U"The specified time should not be less than 0.");
114 MODIFY_EACH (Artword)
115 Artword_setTarget (me, (kArt_muscle) muscle, time, targetValue);
116 MODIFY_EACH_END
117 }
118
119 FORM (CONVERT_EACH_Artword_to_Art, U"From Artword to Art", nullptr) {
120 REAL (time, U"Time (seconds)", U"0.0")
121 OK
122 DO
123 CONVERT_EACH_TO_ONE (Artword)
124 autoArt result = Artword_to_Art (me, time);
125 CONVERT_EACH_TO_ONE_END (my name.get())
126 }
127
128 // MARK: - ART & SPEAKER
129
130 DIRECT (GRAPHICS_Art_Speaker_draw) {
131 GRAPHICS_ONE_AND_ONE (Art, Speaker)
132 Art_Speaker_draw (me, you, GRAPHICS);
133 GRAPHICS_ONE_AND_ONE_END
134 }
135
136 DIRECT (GRAPHICS_Art_Speaker_fillInnerContour) {
137 GRAPHICS_ONE_AND_ONE (Art, Speaker)
138 Art_Speaker_fillInnerContour (me, you, GRAPHICS);
139 GRAPHICS_ONE_AND_ONE_END
140 }
141
142 DIRECT (GRAPHICS_Art_Speaker_drawMesh) {
143 GRAPHICS_ONE_AND_ONE (Art, Speaker)
144 Art_Speaker_drawMesh (me, you, GRAPHICS);
145 GRAPHICS_ONE_AND_ONE_END
146 }
147
148 DIRECT (CONVERT_TWO_Art_Speaker_to_VocalTract) {
149 CONVERT_ONE_AND_ONE_TO_ONE (Art, Speaker)
150 autoVocalTract result = Art_Speaker_to_VocalTract (me, you);
151 CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get())
152 }
153
154 // MARK: - ARTWORD & SPEAKER
155
156 FORM (GRAPHICS_Artword_Speaker_draw, U"Draw Artword & Speaker", nullptr) {
157 NATURAL (numberOfSteps, U"Number of steps", U"5")
158 OK
159 DO
160 GRAPHICS_ONE_AND_ONE (Artword, Speaker)
161 Artword_Speaker_draw (me, you, GRAPHICS, numberOfSteps);
162 GRAPHICS_ONE_AND_ONE_END
163 }
164
165 FORM (NEW1_Artword_Speaker_to_Sound, U"Articulatory synthesizer", U"Artword & Speaker: To Sound...") {
166 POSITIVE (samplingFrequency, U"Sampling frequency (Hz)", U"22050.0")
167 NATURAL (oversamplingFactor, U"Oversampling factor", U"25")
168 INTEGER (width1, U"Width 1", U"0")
169 INTEGER (width2, U"Width 2", U"0")
170 INTEGER (width3, U"Width 3", U"0")
171 INTEGER (pressure1, U"Pressure 1", U"0")
172 INTEGER (pressure2, U"Pressure 2", U"0")
173 INTEGER (pressure3, U"Pressure 3", U"0")
174 INTEGER (velocity1, U"Velocity 1", U"0")
175 INTEGER (velocity2, U"Velocity 2", U"0")
176 INTEGER (velocity3, U"Velocity 3", U"0")
177 OK
178 DO
179 CONVERT_ONE_AND_ONE_TO_MULTIPLE (Artword, Speaker)
180 autoSound w1, w2, w3, p1, p2, p3, v1, v2, v3;
181 autoSound sound = Artword_Speaker_to_Sound (me, you,
182 samplingFrequency, oversamplingFactor,
183 & w1, width1, & w2, width2, & w3, width3,
184 & p1, pressure1, & p2, pressure2, & p3, pressure3,
185 & v1, velocity1, & v2, velocity2, & v3, velocity3);
186 praat_new (sound.move(), my name.get(), U"_", your name.get());
187 if (width1)
188 praat_new (w1.move(), U"width", width1);
189 if (width2)
190 praat_new (w2.move(), U"width", width2);
191 if (width3)
192 praat_new (w3.move(), U"width", width3);
193 if (pressure1)
194 praat_new (p1.move(), U"pressure", pressure1);
195 if (pressure2)
196 praat_new (p2.move(), U"pressure", pressure2);
197 if (pressure3)
198 praat_new (p3.move(), U"pressure", pressure3);
199 if (velocity1)
200 praat_new (v1.move(), U"velocity", velocity1);
201 if (velocity2)
202 praat_new (v2.move(), U"velocity", velocity2);
203 if (velocity3)
204 praat_new (v3.move(), U"velocity", velocity3);
205 CONVERT_ONE_AND_ONE_TO_MULTIPLE_END
206 }
207
208 DIRECT (MOVIE_Artword_Speaker_playMovie) {
209 MOVIE_ONE_AND_ONE (Artword, Speaker, U"Artword & Speaker movie", 300, 300)
210 Artword_Speaker_playMovie (me, you, graphics);
211 MOVIE_ONE_AND_ONE_END
212 }
213
214 // MARK: - ARTWORD & SPEAKER & SOUND
215
216 DIRECT (MOVIE_Artword_Speaker_Sound_playMovie) {
217 MOVIE_ONE_AND_ONE_AND_ONE (Artword, Speaker, Sound, U"Artword & Speaker & Sound movie", 300, 300)
218 Artword_Speaker_Sound_playMovie (me, you, him, graphics);
219 MOVIE_ONE_AND_ONE_AND_ONE_END
220 }
221
222 // MARK: - SPEAKER
223
224 FORM (NEW1_Speaker_create, U"Create a Speaker", U"Create Speaker...") {
225 WORD (name, U"Name", U"speaker")
226 OPTIONMENUSTR (kindOfSpeaker, U"Kind of speaker", 1)
227 OPTION (U"female")
228 OPTION (U"male")
229 OPTION (U"child")
230 OPTIONMENUSTR (numberOfTubesInGlottis, U"Number of tubes in glottis", 2)
231 OPTION (U"1")
232 OPTION (U"2")
233 OPTION (U"10")
234 OK
235 DO
236 CREATE_ONE
237 autoSpeaker result = Speaker_create (kindOfSpeaker, (int16) Melder_atoi (numberOfTubesInGlottis)); // conversion OK because the values are 1, 2, 10
238 CREATE_ONE_END (name)
239 }
240
241 DIRECT (HELP_Speaker_help) {
242 HELP (U"Speaker")
243 }
244
245 // MARK: - VOCALTRACT
246
247 FORM (NEW1_VocalTract_createFromPhone, U"Create Vocal Tract from phone", U"Create Vocal Tract from phone...") {
248 OPTIONMENUSTR (phone, U"Phone", 1)
249 OPTION (U"a")
250 OPTION (U"e")
251 OPTION (U"i")
252 OPTION (U"o")
253 OPTION (U"u")
254 OPTION (U"y1")
255 OPTION (U"y2")
256 OPTION (U"y3")
257 OPTION (U"jery")
258 OPTION (U"p")
259 OPTION (U"t")
260 OPTION (U"k")
261 OPTION (U"x")
262 OPTION (U"pa")
263 OPTION (U"ta")
264 OPTION (U"ka")
265 OPTION (U"pi")
266 OPTION (U"ti")
267 OPTION (U"ki")
268 OPTION (U"pu")
269 OPTION (U"tu")
270 OPTION (U"ku")
271 OK
272 DO
273 CREATE_ONE
274 autoVocalTract result = VocalTract_createFromPhone (phone);
275 CREATE_ONE_END (phone)
276 }
277
278 DIRECT (GRAPHICS_VocalTract_draw) {
279 GRAPHICS_EACH (VocalTract)
280 VocalTract_draw (me, GRAPHICS);
281 GRAPHICS_EACH_END
282 }
283
284 FORM (MODIFY_VocalTract_formula, U"VocalTract Formula", U"Matrix: Formula...") {
285 COMMENT (U"`x` is the distance form the glottis in metres, `col` is the section number, `self` is in m\u00B2")
286 COMMENT (U"x := x1; for col := 1 to ncol do { self [col] := `formula' ; x := x + dx }")
287 FORMULA (formula, U"Formula", U"0")
288 OK
289 DO
290 MODIFY_EACH_WEAK (VocalTract)
291 Matrix_formula (me, formula, interpreter, nullptr);
292 MODIFY_EACH_WEAK_END
293 }
294
295 DIRECT (HELP_VocalTract_help) {
296 HELP (U"VocalTract")
297 }
298
299 DIRECT (NEW_VocalTract_to_Matrix) {
300 CONVERT_EACH_TO_ONE (VocalTract)
301 autoMatrix result = VocalTract_to_Matrix (me);
302 CONVERT_EACH_TO_ONE_END (my name.get())
303 }
304
305 FORM (NEW_VocalTract_to_Spectrum, U"From Vocal Tract to Spectrum", nullptr) {
306 COMMENT (U"Compute transfer function")
307 NATURAL (numberOfFequencies, U"Number of frequencies", U"4097")
308 POSITIVE (maximumFrequency, U"Maximum frequency (Hz)", U"5000.0")
309 REAL (glottalDamping, U"Glottal damping", U"0.1")
310 BOOLEAN (radiationDamping, U"Radiation damping", true)
311 BOOLEAN (internalDamping, U"Internal damping", true)
312 OK
313 DO
314 CONVERT_EACH_TO_ONE (VocalTract)
315 autoSpectrum result = VocalTract_to_Spectrum (me, numberOfFequencies,
316 maximumFrequency, glottalDamping, radiationDamping, internalDamping);
317 CONVERT_EACH_TO_ONE_END (my name.get())
318 }
319
320 DIRECT (HELP_ArticulatorySynthesisTutorial) {
321 HELP (U"Articulatory synthesis")
322 }
323
324 void manual_Artsynth_init (ManPages me);
325
326 // MARK: - buttons
327
328 void praat_uvafon_Artsynth_init ();
329 void praat_uvafon_Artsynth_init () {
330 Thing_recognizeClassesByName (classArt, classArtword, classSpeaker);
331
332 praat_addMenuCommand (U"Objects", U"New", U"Articulatory synthesis",
333 nullptr, 0, nullptr);
334 praat_addMenuCommand (U"Objects", U"New", U"Articulatory synthesis tutorial",
335 nullptr, 1, HELP_ArticulatorySynthesisTutorial);
336 praat_addMenuCommand (U"Objects", U"New", U"-- new articulatory synthesis --",
337 nullptr, 1, nullptr);
338 praat_addMenuCommand (U"Objects", U"New", U"Create Articulation...",
339 nullptr, 1, NEW1_Art_create);
340 praat_addMenuCommand (U"Objects", U"New", U"Create Speaker...",
341 nullptr, 1, NEW1_Speaker_create);
342 praat_addMenuCommand (U"Objects", U"New", U"Create Artword...",
343 nullptr, 1, NEW1_Artword_create);
344 praat_addMenuCommand (U"Objects", U"New", U"-- new vocal tract --",
345 nullptr, 1, nullptr);
346 praat_addMenuCommand (U"Objects", U"New", U"Create Vocal Tract from phone...",
347 nullptr, 1, NEW1_VocalTract_createFromPhone);
348
349 praat_addAction1 (classArt, 1, U"View & Edit || Edit",
350 nullptr, GuiMenu_ATTRACTIVE, WINDOW_Art_viewAndEdit); // alternative GuiMenu_DEPRECATED_2011
351
352 praat_addAction1 (classArtword, 0, U"Artword help",
353 nullptr, 0, HELP_Artword_help);
354 praat_addAction1 (classArtword, 1, U"View & Edit || Edit",
355 nullptr, GuiMenu_ATTRACTIVE, EDITOR_ONE_Artword_viewAndEdit);
356 praat_addAction1 (classArtword, 0, U"Info",
357 nullptr, 0, nullptr);
358 praat_addAction1 (classArtword, 1, U"Get target...",
359 nullptr, 0, REAL_Artword_getTarget);
360 praat_addAction1 (classArtword, 0, U"Draw", nullptr, 0, nullptr);
361 praat_addAction1 (classArtword, 0, U"Draw...",
362 nullptr, 0, GRAPHICS_Artword_draw);
363 praat_addAction1 (classArtword, 0, U"Modify", nullptr, 0, nullptr);
364 praat_addAction1 (classArtword, 1, U"Set target...",
365 nullptr, 0, MODIFY_EACH_Artword_setTarget);
366 praat_addAction1 (classArtword, 0, U"Analyse",
367 nullptr, 0, nullptr);
368 praat_addAction1 (classArtword, 0, U"To Art (slice)...",
369 nullptr, 0, CONVERT_EACH_Artword_to_Art);
370
371 praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw",
372 nullptr, 0, nullptr);
373 praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw",
374 nullptr, 0, GRAPHICS_Art_Speaker_draw);
375 praat_addAction2 (classArt, 1, classSpeaker, 1, U"Fill inner contour",
376 nullptr, 0, GRAPHICS_Art_Speaker_fillInnerContour);
377 praat_addAction2 (classArt, 1, classSpeaker, 1, U"Draw mesh",
378 nullptr, 0, GRAPHICS_Art_Speaker_drawMesh);
379 praat_addAction2 (classArt, 1, classSpeaker, 1, U"Synthesize",
380 nullptr, 0, nullptr);
381 praat_addAction2 (classArt, 1, classSpeaker, 1, U"To VocalTract",
382 nullptr, 0, CONVERT_TWO_Art_Speaker_to_VocalTract);
383
384 praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Play movie || Movie",
385 nullptr, 0, MOVIE_Artword_Speaker_playMovie);
386 praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Draw", nullptr, 0, nullptr);
387 praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Draw...",
388 nullptr, 0, GRAPHICS_Artword_Speaker_draw);
389 praat_addAction2 (classArtword, 1, classSpeaker, 1, U"Synthesize", nullptr, 0, nullptr);
390 praat_addAction2 (classArtword, 1, classSpeaker, 1, U"To Sound...",
391 nullptr, 0, NEW1_Artword_Speaker_to_Sound);
392
393 praat_addAction3 (classArtword, 1, classSpeaker, 1, classSound, 1, U"Play movie || Movie",
394 nullptr, 0, MOVIE_Artword_Speaker_Sound_playMovie);
395
396 praat_addAction1 (classSpeaker, 0, U"Speaker help", nullptr, 0, HELP_Speaker_help);
397
398 praat_addAction1 (classVocalTract, 0, U"VocalTract help",
399 nullptr, 0, HELP_VocalTract_help);
400 praat_addAction1 (classVocalTract, 0, U"Draw", nullptr, 0, nullptr);
401 praat_addAction1 (classVocalTract, 0, U"Draw",
402 nullptr, 0, GRAPHICS_VocalTract_draw);
403 praat_addAction1 (classVocalTract, 0, U"Analyse", nullptr, 0, nullptr);
404 praat_addAction1 (classVocalTract, 0, U"To Spectrum...",
405 nullptr, 0, NEW_VocalTract_to_Spectrum);
406 praat_addAction1 (classVocalTract, 0, U"Modify", nullptr, 0, nullptr);
407 praat_addAction1 (classVocalTract, 0, U"Formula...",
408 nullptr, 0, MODIFY_VocalTract_formula);
409 praat_addAction1 (classVocalTract, 0, U"Hack", nullptr, 0, nullptr);
410 praat_addAction1 (classVocalTract, 0, U"To Matrix",
411 nullptr, 0, NEW_VocalTract_to_Matrix);
412
413 manual_Artsynth_init (theCurrentPraatApplication -> manPages);
414 }
415
416 /* End of file praat_Artsynth.cpp */