From bcd64cb263745e3994484156713a601db1b59990 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 27 Jun 2009 17:49:57 -0500 Subject: [PATCH] created a start_audio function This moves audio control to the specific files, espeak_sound.c and alsa.c, which are tied to the sound systems. --- alsa.c | 31 +++++++++++++++++++------------ espeak_sound.c | 7 +------ espeakup.h | 3 +-- synth.c | 4 +--- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/alsa.c b/alsa.c index b83dc64..976769e 100644 --- a/alsa.c +++ b/alsa.c @@ -37,13 +37,23 @@ static snd_pcm_hw_params_t *params; snd_pcm_status_t *status; static int dir = 0; -int sound_error(int err, const char *msg) +static void lock_audio_mutex(void) +{ + pthread_mutex_lock(&audio_mutex); +} + +static void unlock_audio_mutex(void) +{ + pthread_mutex_unlock(&audio_mutex); +} + +static int sound_error(int err, const char *msg) { fprintf(stderr, "%s: %s\n", msg, snd_strerror(err)); return err; } -int minimum(int x, int y) +static int minimum(int x, int y) { if (x <= y) return x; @@ -68,7 +78,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); return 1; } - stop_requested = 0; discarding_packets = 1; } unlock_audio_mutex(); @@ -188,12 +197,10 @@ void stop_audio(void) unlock_audio_mutex(); } -void lock_audio_mutex(void) -{ - pthread_mutex_lock(&audio_mutex); -} - -void unlock_audio_mutex(void) -{ - pthread_mutex_unlock(&audio_mutex); -} + void start_audio(int *user_data) + { + lock_audio_mutex(); + *user_data = (*user_data + 1) % 100; + stop_requested = 0; + unlock_audio_mutex(); + } diff --git a/espeak_sound.c b/espeak_sound.c index 6cba147..ec3f286 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -15,12 +15,7 @@ void stop_audio(void) return; } -void lock_audio_mutex(void) -{ - return; -} - -void unlock_audio_mutex(void) +void start_audio(int *user_data) { return; } diff --git a/espeakup.h b/espeakup.h index 9650bb6..91e9cbb 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,8 +78,7 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void lock_audio_mutex(void); -extern void unlock_audio_mutex(void); +extern void start_audio(int *user_data); extern volatile int should_run; extern volatile int runner_must_stop; extern int self_pipe_fds[2]; diff --git a/synth.c b/synth.c index 77e5a5c..28aa15c 100644 --- a/synth.c +++ b/synth.c @@ -130,9 +130,7 @@ static espeak_ERROR stop_speech(void) stop_audio(); rc = espeak_Cancel(); - lock_audio_mutex(); - user_data = (user_data + 1) % 100; - unlock_audio_mutex(); + start_audio(&user_data); return rc; }