5 #include <unistd.h> /* F_OK ?? */
17 #include "Pitch_to_Sound.h"
21 gpointer
sound_init(void *args
)
23 Sound melderSoundFromMic
;
26 gsl_set_error_handler_off ();
27 Melder_setMaximumAsynchronicity (Melder_SYNCHRONOUS
);
29 melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 1.0);
30 forget(melderSoundFromMic
);
32 // Melder_flushError (NULL);
36 static void playInPraat(gchar
*path
) {
37 if (g_access(path
, F_OK
) == 0) {
38 structMelderFile file
;
39 Sound melderSoundFromFile
;
40 Melder_pathToFile(path
, & file
);
41 melderSoundFromFile
= Sound_readFromSoundFile (& file
);
42 if (! melderSoundFromFile
) {
43 g_warning(_("Praat cannot open the file!"));
45 Sound_play(melderSoundFromFile
, NULL
, NULL
);
46 forget(melderSoundFromFile
);
49 g_warning(_("The file %s just don't exist!"), path
);
52 // Melder_flushError (NULL);
56 static void playVoice() {
60 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
61 path
= voicepath(string
);
69 static void playHum() {
72 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
74 gchar
*upper
= g_malloc(4);
75 g_ascii_dtostr(upper
, 4, upperRegister
);
77 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".wav", NULL
);
79 path
= g_strjoin(NULL
, PITCHPATH
, G_DIR_SEPARATOR_S
, string
, "-", upper
, ".Pitch", NULL
);
86 if (g_access(path
, F_OK
) == 0) {
87 structMelderFile file
;
88 Pitch melderPitchFromFile
;
90 __declspec(dllimport
) Pitch_Table classPitch
;
92 Thing_recognizeClassesByName (classPitch
, NULL
);
93 Melder_pathToFile(path
, & file
);
94 melderPitchFromFile
= Data_readFromTextFile (& file
);
95 if (melderPitchFromFile
!= NULL
) {
96 Pitch_hum(melderPitchFromFile
, 0, 0);
97 forget(melderPitchFromFile
);
99 g_debug("PITCH IS NULL!");
105 Melder_flushError (NULL
);
110 static void playBefore() {
111 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemBeforeVoice");
112 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemBeforeHum");
114 /* Check play Example */
115 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
121 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
126 gpointer
example(void *args
) {
127 GtkWidget
*gimiVoice
= glade_xml_get_widget(xml
, "checkmenuitemExampleVoice");
128 GtkWidget
*gimiHum
= glade_xml_get_widget(xml
, "checkmenuitemExampleHum");
130 g_idle_add(setButtonsFalse
, NULL
);
132 /* Check play Example */
133 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiVoice
))) {
139 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gimiHum
))) {
143 g_idle_add(setButtonsTrue
, NULL
);
147 gpointer
play(void *args
) {
149 gchar
*path
= g_build_filename(SCRIPTPATH
, "lastExample.wav", NULL
);
152 g_idle_add(setButtonsTrue
, NULL
);
158 gpointer
record(void *args
) {
161 gtk_tree_model_get(GTK_TREE_MODEL(liststore
), &mainIter
, COL_TEXT
, &string
, -1);
162 // g_debug("%s %d welcome!\n\n\n", __func__, rand());
163 g_idle_add(setButtonsFalse
, NULL
);
165 if (g_access(RECORDPATH
, F_OK
) == 0) {
166 Sound melderSoundFromMic
= Sound_recordFixedTime (1, 1.0, 0.5, 44100, 5.0);
168 if (! melderSoundFromMic
) {
169 g_warning(_("No sound from praat!"));
171 GString
*filename
= g_string_sized_new(128);
172 GString
*cmd
= g_string_sized_new(128);
174 structMelderFile file
;
176 g_string_printf(filename
, "%s.wav", string
);
178 path
= g_build_filename(RECORDPATH
, filename
->str
, NULL
);
179 g_string_free(filename
, TRUE
);
181 Vector_scale(melderSoundFromMic
, 0.99);
182 Melder_pathToFile(path
, &file
);
183 Sound_writeToAudioFile16 (melderSoundFromMic
, &file
, Melder_WAV
);
184 forget(melderSoundFromMic
);
187 g_string_printf(cmd
, "%s SGC_ToneProt.praat ..%s%s %s %0.f 3 none 0", PRAATBIN
, G_DIR_SEPARATOR_S
, path
, string
, upperRegister
);
190 // g_debug("EXECUTES! ");
192 // g_debug("DONE!\n");
194 g_string_free(cmd
, TRUE
);
197 g_warning(_("Missing recording directory %s."), RECORDPATH
);
201 // Melder_flushError (NULL);
202 g_idle_add(setButtonsTrue
, NULL
);
203 // g_debug("%s bye!\n", __func__);