diff options
Diffstat (limited to 'apps/voice_thread.c')
-rw-r--r-- | apps/voice_thread.c | 33 |
1 files changed, 18 insertions, 15 deletions
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 | ||