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.
This commit is contained in:
William Hubbs 2009-06-27 17:49:57 -05:00
commit bcd64cb263
4 changed files with 22 additions and 23 deletions

31
alsa.c
View file

@ -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();
}

View file

@ -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;
}

View file

@ -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];

View file

@ -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;
}