mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-20 14:54:17 +02:00
more sound updates
removed the user_data processing code and put the call to snd_pcm_drop in stop_audio.
This commit is contained in:
parent
ceaae3640a
commit
04d10d88ec
4 changed files with 9 additions and 32 deletions
32
alsa.c
32
alsa.c
|
|
@ -63,42 +63,19 @@ static int minimum(int x, int y)
|
|||
|
||||
static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events)
|
||||
{
|
||||
static int discarding_packets = 0;
|
||||
static int user_data_old = 0;
|
||||
int samples_written = 0;
|
||||
int avail;
|
||||
int to_write;
|
||||
snd_pcm_state_t state;
|
||||
int user_data_new;
|
||||
int rc = 0;
|
||||
|
||||
lock_audio_mutex();
|
||||
user_data_new = *(int *) events->user_data;
|
||||
if (stop_requested) {
|
||||
if(snd_pcm_drop(handle) < 0) {
|
||||
fprintf(stderr, "Negative return from snd_pcm_drop!\n");
|
||||
return 1;
|
||||
}
|
||||
discarding_packets = 1;
|
||||
unlock_audio_mutex();
|
||||
return 1;
|
||||
}
|
||||
unlock_audio_mutex();
|
||||
|
||||
/*
|
||||
* If discarding_packets is true, then do the following.
|
||||
* Compare user_data_old and user_data_new. If they are equal,
|
||||
* then espeak is still sending stale data through the callback.
|
||||
* Keep on discarding it, and return 1.
|
||||
* If they are different, a new stream has started. We can stop
|
||||
* discarding. Just process the new data.
|
||||
*/
|
||||
if (discarding_packets) {
|
||||
if (user_data_new == user_data_old)
|
||||
return 1; /* Discard stale data. */
|
||||
else
|
||||
discarding_packets = 0;
|
||||
}
|
||||
|
||||
user_data_old = user_data_new;
|
||||
snd_pcm_status(handle, status);
|
||||
state = snd_pcm_status_get_state(status);
|
||||
if (state != SND_PCM_STATE_RUNNING)
|
||||
|
|
@ -199,13 +176,14 @@ void stop_audio(void)
|
|||
{
|
||||
lock_audio_mutex();
|
||||
stop_requested = 1;
|
||||
if(snd_pcm_drop(handle) < 0)
|
||||
fprintf(stderr, "Negative return from snd_pcm_drop!\n");
|
||||
unlock_audio_mutex();
|
||||
}
|
||||
|
||||
void start_audio(int *user_data)
|
||||
void start_audio(void)
|
||||
{
|
||||
lock_audio_mutex();
|
||||
*user_data = (*user_data + 1) % 100;
|
||||
stop_requested = 0;
|
||||
unlock_audio_mutex();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ void stop_audio(void)
|
|||
return;
|
||||
}
|
||||
|
||||
void start_audio(int *user_data)
|
||||
void start_audio(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +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 start_audio(int *user_data);
|
||||
extern void start_audio(void);
|
||||
extern volatile int should_run;
|
||||
extern volatile int runner_must_stop;
|
||||
extern int self_pipe_fds[2];
|
||||
|
|
|
|||
5
synth.c
5
synth.c
|
|
@ -38,7 +38,6 @@ const int rateMultiplier = 34;
|
|||
const int rateOffset = 84;
|
||||
const int volumeMultiplier = 22;
|
||||
|
||||
static int user_data = 0;
|
||||
volatile int runner_must_stop = 0;
|
||||
|
||||
static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj)
|
||||
|
|
@ -130,7 +129,7 @@ static espeak_ERROR stop_speech(void)
|
|||
espeak_ERROR rc;
|
||||
|
||||
rc = espeak_Cancel();
|
||||
start_audio(&user_data);
|
||||
start_audio();
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +138,7 @@ static espeak_ERROR speak_text(struct synth_t * s)
|
|||
espeak_ERROR rc;
|
||||
|
||||
rc = espeak_Synth(s->buf, s->len + 1, 0, POS_CHARACTER, 0, 0, NULL,
|
||||
&user_data);
|
||||
NULL);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue