diff options
-rw-r--r-- | apps/appevents.h | 2 | ||||
-rw-r--r-- | apps/playback.c | 7 | ||||
-rw-r--r-- | apps/voice_thread.c | 33 |
3 files changed, 27 insertions, 15 deletions
diff --git a/apps/appevents.h b/apps/appevents.h index a11e423a90..506f00329b 100644 --- a/apps/appevents.h +++ b/apps/appevents.h | |||
@@ -45,6 +45,8 @@ enum { | |||
45 | PLAYBACK_EVENT_TRACK_SKIP, | 45 | PLAYBACK_EVENT_TRACK_SKIP, |
46 | /* Next track medadata was just loaded */ | 46 | /* Next track medadata was just loaded */ |
47 | PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, | 47 | PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, |
48 | /* Voice is playing: data = &(bool){true|false} */ | ||
49 | PLAYBACK_EVENT_VOICE_PLAYING, | ||
48 | }; | 50 | }; |
49 | 51 | ||
50 | /** Buffering events **/ | 52 | /** Buffering events **/ |
diff --git a/apps/playback.c b/apps/playback.c index 870cb08d17..9cc29ea2d8 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -344,6 +344,12 @@ void audio_pcmbuf_sync_position(void); | |||
344 | 344 | ||
345 | /**************************************/ | 345 | /**************************************/ |
346 | 346 | ||
347 | /** --- voice event --- **/ | ||
348 | void playback_voice_event(void *data) | ||
349 | { | ||
350 | pcmbuf_soft_mode(*(bool *)data); | ||
351 | } | ||
352 | |||
347 | /** --- audio_queue helpers --- **/ | 353 | /** --- audio_queue helpers --- **/ |
348 | static void audio_queue_post(long id, intptr_t data) | 354 | static void audio_queue_post(long id, intptr_t data) |
349 | { | 355 | { |
@@ -3760,6 +3766,7 @@ void playback_init(void) | |||
3760 | mutex_init(&id3_mutex); | 3766 | mutex_init(&id3_mutex); |
3761 | track_list_init(); | 3767 | track_list_init(); |
3762 | buffering_init(); | 3768 | buffering_init(); |
3769 | add_event(PLAYBACK_EVENT_VOICE_PLAYING, false, playback_voice_event); | ||
3763 | #ifdef HAVE_CROSSFADE | 3770 | #ifdef HAVE_CROSSFADE |
3764 | /* Set crossfade setting for next buffer init which should be about... */ | 3771 | /* Set crossfade setting for next buffer init which should be about... */ |
3765 | pcmbuf_request_crossfade_enable(global_settings.crossfade); | 3772 | pcmbuf_request_crossfade_enable(global_settings.crossfade); |
diff --git a/apps/voice_thread.c b/apps/voice_thread.c index e8c7fcce55..1fb8c15d1a 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c | |||
@@ -22,12 +22,10 @@ | |||
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "core_alloc.h" | 23 | #include "core_alloc.h" |
24 | #include "thread.h" | 24 | #include "thread.h" |
25 | #include "appevents.h" | ||
25 | #include "voice_thread.h" | 26 | #include "voice_thread.h" |
26 | #include "talk.h" | 27 | #include "talk.h" |
27 | #include "dsp_core.h" | 28 | #include "dsp_core.h" |
28 | #include "audio.h" | ||
29 | #include "playback.h" | ||
30 | #include "pcmbuf.h" | ||
31 | #include "pcm.h" | 29 | #include "pcm.h" |
32 | #include "pcm_mixer.h" | 30 | #include "pcm_mixer.h" |
33 | #include "codecs/libspeex/speex/speex.h" | 31 | #include "codecs/libspeex/speex/speex.h" |
@@ -84,6 +82,7 @@ static const char voice_thread_name[] = "voice"; | |||
84 | static struct event_queue voice_queue SHAREDBSS_ATTR; | 82 | static struct event_queue voice_queue SHAREDBSS_ATTR; |
85 | static struct queue_sender_list voice_queue_sender_list SHAREDBSS_ATTR; | 83 | static struct queue_sender_list voice_queue_sender_list SHAREDBSS_ATTR; |
86 | static int quiet_counter SHAREDDATA_ATTR = 0; | 84 | static int quiet_counter SHAREDDATA_ATTR = 0; |
85 | static bool voice_playing = false; | ||
87 | 86 | ||
88 | #define VOICE_PCM_FRAME_COUNT ((NATIVE_FREQUENCY*VOICE_FRAME_COUNT + \ | 87 | #define VOICE_PCM_FRAME_COUNT ((NATIVE_FREQUENCY*VOICE_FRAME_COUNT + \ |
89 | VOICE_SAMPLE_RATE) / VOICE_SAMPLE_RATE) | 88 | VOICE_SAMPLE_RATE) / VOICE_SAMPLE_RATE) |
@@ -301,7 +300,7 @@ void mp3_play_pause(bool play) | |||
301 | /* Tell if voice is still in a playing state */ | 300 | /* Tell if voice is still in a playing state */ |
302 | bool mp3_is_playing(void) | 301 | bool mp3_is_playing(void) |
303 | { | 302 | { |
304 | return quiet_counter != 0; | 303 | return voice_playing; |
305 | } | 304 | } |
306 | 305 | ||
307 | /* This function is meant to be used by the buffer request functions to | 306 | /* This function is meant to be used by the buffer request functions to |
@@ -319,7 +318,7 @@ void voice_wait(void) | |||
319 | * new clip by the time we wait. This should be resolvable if conditions | 318 | * new clip by the time we wait. This should be resolvable if conditions |
320 | * ever require knowing the very clip you requested has finished. */ | 319 | * ever require knowing the very clip you requested has finished. */ |
321 | 320 | ||
322 | while (quiet_counter != 0) | 321 | while (voice_playing) |
323 | sleep(1); | 322 | sleep(1); |
324 | } | 323 | } |
325 | 324 | ||
@@ -341,10 +340,8 @@ static void voice_data_init(struct voice_thread_data *td) | |||
341 | /* Voice thread message processing */ | 340 | /* Voice thread message processing */ |
342 | static enum voice_state voice_message(struct voice_thread_data *td) | 341 | static enum voice_state voice_message(struct voice_thread_data *td) |
343 | { | 342 | { |
344 | if (quiet_counter > 0) | 343 | queue_wait_w_tmo(&voice_queue, &td->ev, |
345 | queue_wait_w_tmo(&voice_queue, &td->ev, HZ/10); | 344 | quiet_counter > 0 ? HZ/10 : TIMEOUT_BLOCK); |
346 | else | ||
347 | queue_wait(&voice_queue, &td->ev); | ||
348 | 345 | ||
349 | switch (td->ev.id) | 346 | switch (td->ev.id) |
350 | { | 347 | { |
@@ -361,6 +358,14 @@ static enum voice_state voice_message(struct voice_thread_data *td) | |||
361 | voice_stop_playback(); | 358 | voice_stop_playback(); |
362 | } | 359 | } |
363 | 360 | ||
361 | if (quiet_counter <= 0) | ||
362 | { | ||
363 | /* Make audio play more softly and set delay to return to normal | ||
364 | playback level */ | ||
365 | voice_playing = true; | ||
366 | send_event(PLAYBACK_EVENT_VOICE_PLAYING, &voice_playing); | ||
367 | } | ||
368 | |||
364 | quiet_counter = QUIET_COUNT; | 369 | quiet_counter = QUIET_COUNT; |
365 | 370 | ||
366 | /* Copy the clip info */ | 371 | /* Copy the clip info */ |
@@ -369,10 +374,6 @@ static enum voice_state voice_message(struct voice_thread_data *td) | |||
369 | /* We need nothing more from the sending thread - let it run */ | 374 | /* We need nothing more from the sending thread - let it run */ |
370 | queue_reply(&voice_queue, 1); | 375 | queue_reply(&voice_queue, 1); |
371 | 376 | ||
372 | /* Make audio play more softly and set delay to return to normal | ||
373 | playback level */ | ||
374 | pcmbuf_soft_mode(true); | ||
375 | |||
376 | /* Clean-start the decoder */ | 377 | /* Clean-start the decoder */ |
377 | td->st = speex_decoder_init(&speex_wb_mode); | 378 | td->st = speex_decoder_init(&speex_wb_mode); |
378 | 379 | ||
@@ -394,8 +395,10 @@ static enum voice_state voice_message(struct voice_thread_data *td) | |||
394 | if (quiet_counter-- != QUIET_COUNT) | 395 | if (quiet_counter-- != QUIET_COUNT) |
395 | { | 396 | { |
396 | if (quiet_counter <= 0) | 397 | if (quiet_counter <= 0) |
397 | pcmbuf_soft_mode(false); | 398 | { |
398 | 399 | voice_playing = false; | |
400 | send_event(PLAYBACK_EVENT_VOICE_PLAYING, &voice_playing); | ||
401 | } | ||
399 | break; | 402 | break; |
400 | } | 403 | } |
401 | 404 | ||