From c5fce64f259bce473cd3c9371d7b095639a87fe5 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 24 Jun 2009 20:44:42 -0500 Subject: [PATCH] removed open_softsynth and close_softsynth The thread can now handle the softsynth device, so main doesn't need to call these functions. --- espeakup.c | 12 ++++++------ espeakup.h | 2 -- softsynth.c | 28 +++++++++------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/espeakup.c b/espeakup.c index db86232..7c8c257 100644 --- a/espeakup.c +++ b/espeakup.c @@ -97,12 +97,6 @@ int main(int argc, char **argv) return 1; } - /* open the softsynth. */ - if (!open_softsynth()) { - perror("Unable to open the softsynth device"); - return 3; - } - /* * If we are not in debug mode, become a daemon and store the pid. */ @@ -135,5 +129,11 @@ int main(int argc, char **argv) return 4; } + /* Spawn our softsynth thread. */ + err = pthread_create(&softsynth_thread_id, NULL, &softsynth_thread, &s); + if (err != 0) { + return 4; + } + return 0; } diff --git a/espeakup.h b/espeakup.h index b00dd69..fd22467 100644 --- a/espeakup.h +++ b/espeakup.h @@ -74,8 +74,6 @@ extern espeak_ERROR set_volume(struct synth_t *s, int vol, enum adjust_t adj); extern espeak_ERROR stop_speech(void); extern espeak_ERROR speak_text(struct synth_t *s); -extern int open_softsynth(void); -extern void close_softsynth(void); extern void *softsynth_thread(void *arg); extern void stop_runner(void); extern void *queue_runner(void *arg); diff --git a/softsynth.c b/softsynth.c index 6d6a13d..06d9cc6 100644 --- a/softsynth.c +++ b/softsynth.c @@ -33,25 +33,6 @@ const size_t maxBufferSize = 1025; /* synth flush character */ const int synthFlushChar = 0x18; -static int softFD = 0; - -int open_softsynth(void) -{ - int rc; - - softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); - if (softFD < 0) - rc = 0; - else - rc = 1; - return rc; -} - -void close_softsynth(void) -{ - close(softFD); -} - static int process_command(struct synth_t *s, char *buf, int start) { char *cp; @@ -150,6 +131,13 @@ void *softsynth_thread(void *arg) char buf[maxBufferSize]; char *cp; + /* open the softsynth. */ + softFD = open("/dev/softsynth", O_RDWR | O_NONBLOCK); + if (softFD < 0) { + perror("Unable to open the softsynth device"); + should_run = 0; + } + while (should_run) { FD_ZERO(&set); FD_SET(softFD, &set); @@ -180,5 +168,7 @@ void *softsynth_thread(void *arg) } process_buffer(s, buf, length); } + if (softFD) + close(softFD); return NULL; }