mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-20 23:04:18 +02:00
alsa updates
The first while loop in the callback doesn't need to be a loop. If the audio fails, we can just print an error and return.
This commit is contained in:
parent
46bf3d99d5
commit
9b7dcebb6d
1 changed files with 3 additions and 9 deletions
12
alsa.c
12
alsa.c
|
|
@ -58,24 +58,19 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events)
|
|||
int samples_written = 0;
|
||||
int avail;
|
||||
int to_write;
|
||||
int rc;
|
||||
snd_pcm_state_t state;
|
||||
int user_data_new;
|
||||
|
||||
lock_audio_mutex();
|
||||
user_data_new = *(int *) events->user_data;
|
||||
if (stop_requested) {
|
||||
rc = snd_pcm_drop(handle);
|
||||
while(rc < 0) {
|
||||
if(snd_pcm_drop(handle) < 0) {
|
||||
fprintf(stderr, "Negative return from snd_pcm_drop!\n");
|
||||
/* Try to reset stream. */
|
||||
snd_pcm_prepare(handle);
|
||||
rc = snd_pcm_drop(handle);
|
||||
return 1;
|
||||
}
|
||||
stop_requested = 0;
|
||||
discarding_packets = 1;
|
||||
}
|
||||
|
||||
unlock_audio_mutex();
|
||||
|
||||
/*
|
||||
|
|
@ -86,7 +81,6 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events)
|
|||
* 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. */
|
||||
|
|
@ -100,7 +94,7 @@ static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events)
|
|||
if (state != SND_PCM_STATE_RUNNING)
|
||||
snd_pcm_prepare(handle);
|
||||
|
||||
while (numsamples > 0) {
|
||||
while (numsamples > 0 && ! stop_requested) {
|
||||
avail = snd_pcm_avail_update(handle);
|
||||
if (avail == 0)
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue