src/thread.c
changeset 0 06dd3b8d90ad
equal deleted inserted replaced
-1:000000000000 0:06dd3b8d90ad
       
     1 /**
       
     2  *  $Id: thread.c 53 2008-01-10 00:19:41Z mbroeker $
       
     3  * $URL: http://localhost/svn/c/VirtualReader/trunk/src/thread.c $
       
     4  */
       
     5 
       
     6 #include <thread.h>
       
     7 
       
     8 int p_thread_restart (pthread_t p_thread, void *func, ThreadData * data)
       
     9 {
       
    10     // stops a thread, waits for it to exit and then restarts it using
       
    11     // the current data structure
       
    12     int ret;
       
    13 
       
    14     pthread_cancel (p_thread);
       
    15     if (pthread_join (p_thread, NULL))
       
    16         printf ("RESTART: Cannot find a suitable thread :)\n");
       
    17 
       
    18     ret = pthread_create (&p_thread, NULL, (void *)func, data);
       
    19 
       
    20     /*
       
    21      * TODO: Error Handling
       
    22      */
       
    23     return ret;
       
    24 }
       
    25 
       
    26 void readtext (ThreadData * data)
       
    27 {
       
    28     // read the current sentence using the audio player
       
    29     // TODO - test for existence (completeness?) of file before read
       
    30     char fname[80];
       
    31 
       
    32     pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
       
    33     pthread_cleanup_push (audioplayer_stop, NULL);
       
    34 
       
    35     for (; data->satz < data->items; data->satz++) {
       
    36         sprintf (fname, "audio/%s-%i.wav", data->fname, data->satz);
       
    37         if ((audioplayer (fname, TIMEOUT)) != -1)
       
    38             audioplayer_stop ();
       
    39         else
       
    40             pthread_exit (NULL);
       
    41     }
       
    42 
       
    43     pthread_exit (NULL);
       
    44     pthread_cleanup_pop (1);
       
    45 }
       
    46 
       
    47 void writewav (ThreadData * data)
       
    48 {
       
    49     // write wav file for each sentence between data->satz adn
       
    50     // data->items
       
    51     char fname[80];
       
    52     int i;
       
    53 
       
    54     for (i = data->satz; i < data->items; i++) {
       
    55         sprintf (fname, "audio/%s-%i.wav", data->fname, i);
       
    56         interface_write_to_wav (fname, data->sentences[i], data->ttsh, data->ttsopt);
       
    57     }
       
    58 
       
    59     pthread_exit (NULL);
       
    60 }