mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-24 08:34:18 +02:00
moved the audio_mutex code to alsa
This is not needed for native sound support, so it has been moved into the alsa specific code.
This commit is contained in:
parent
e49acbb59a
commit
8f3e8f1967
5 changed files with 24 additions and 30 deletions
31
alsa.c
31
alsa.c
|
|
@ -30,22 +30,13 @@
|
|||
#include "espeakup.h"
|
||||
|
||||
static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static volatile int stopped = 0;
|
||||
|
||||
static snd_pcm_t *handle;
|
||||
static snd_pcm_hw_params_t *params;
|
||||
snd_pcm_status_t *status;
|
||||
static int dir = 0;
|
||||
|
||||
void lock_audio_mutex(void)
|
||||
{
|
||||
pthread_mutex_lock(&audio_mutex);
|
||||
}
|
||||
|
||||
void unlock_audio_mutex(void)
|
||||
{
|
||||
pthread_mutex_unlock(&audio_mutex);
|
||||
}
|
||||
|
||||
int sound_error(int err, const char *msg)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", msg, snd_strerror(err));
|
||||
|
|
@ -68,14 +59,14 @@ static int alsa_play_callback(short *audio, int numsamples,
|
|||
int to_write;
|
||||
snd_pcm_state_t state;
|
||||
|
||||
lock_audio_mutex();
|
||||
pthread_mutex_lock(&audio_mutex);
|
||||
if (stopped) {
|
||||
snd_pcm_drop(handle);
|
||||
stopped = 0;
|
||||
unlock_audio_mutex();
|
||||
pthread_mutex_unlock(&audio_mutex);
|
||||
return 1;
|
||||
}
|
||||
unlock_audio_mutex();
|
||||
pthread_mutex_unlock(&audio_mutex);
|
||||
|
||||
snd_pcm_status(handle, status);
|
||||
state = snd_pcm_status_get_state(status);
|
||||
|
|
@ -165,3 +156,17 @@ int init_audio(unsigned int rate)
|
|||
espeak_SetSynthCallback(alsa_play_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stop_audio(void)
|
||||
{
|
||||
pthread_mutex_lock(&audio_mutex);
|
||||
stopped = 1;
|
||||
pthread_mutex_unlock(&audio_mutex);
|
||||
}
|
||||
|
||||
void allow_audio(void)
|
||||
{
|
||||
pthread_mutex_lock(&audio_mutex);
|
||||
stopped = 0;
|
||||
pthread_mutex_unlock(&audio_mutex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,12 @@ int init_audio(unsigned int rate)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* lock_audio_mutex and unlock_audio_mutex are no-ops if we use native
|
||||
* sound support. The stopped variable is never read; no need to protect it.
|
||||
*/
|
||||
|
||||
void lock_audio_mutex(void)
|
||||
void stop_audio(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void unlock_audio_mutex(void)
|
||||
void allow_audio(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ const char *pidPath = "/var/run/espeakup.pid";
|
|||
int debug = 0;
|
||||
|
||||
int self_pipe_fds[2];
|
||||
volatile int stopped = 0;
|
||||
volatile int should_run = 1;
|
||||
espeak_AUDIO_OUTPUT audio_mode;
|
||||
|
||||
|
|
|
|||
|
|
@ -77,10 +77,9 @@ extern void close_softsynth(void);
|
|||
extern void *softsynth_thread(void *arg);
|
||||
extern void select_audio_mode(void);
|
||||
extern int init_audio(unsigned int rate);
|
||||
extern void lock_audio_mutex(void);
|
||||
extern void unlock_audio_mutex(void);
|
||||
extern void stop_audio(void);
|
||||
extern void allow_audio(void);
|
||||
extern volatile int should_run;
|
||||
extern volatile int stopped;
|
||||
extern volatile int runner_must_stop;
|
||||
extern int self_pipe_fds[2];
|
||||
#define PIPE_READ_FD (self_pipe_fds[0])
|
||||
|
|
|
|||
8
synth.c
8
synth.c
|
|
@ -125,9 +125,7 @@ static espeak_ERROR set_volume(struct synth_t * s, int vol, enum adjust_t adj)
|
|||
|
||||
static espeak_ERROR stop_speech(void)
|
||||
{
|
||||
lock_audio_mutex();
|
||||
stopped = 1;
|
||||
unlock_audio_mutex();
|
||||
stop_audio();
|
||||
return (espeak_Cancel());
|
||||
}
|
||||
|
||||
|
|
@ -135,9 +133,7 @@ static espeak_ERROR speak_text(struct synth_t * s)
|
|||
{
|
||||
espeak_ERROR rc;
|
||||
|
||||
lock_audio_mutex();
|
||||
stopped = 0;
|
||||
unlock_audio_mutex();
|
||||
allow_audio();
|
||||
rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL,
|
||||
NULL);
|
||||
return rc;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue