summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/wps.c27
-rw-r--r--firmware/export/mp3_playback.h1
-rw-r--r--firmware/mp3_playback.c13
3 files changed, 30 insertions, 11 deletions
diff --git a/apps/wps.c b/apps/wps.c
index e281131836..097c908ca8 100644
--- a/apps/wps.c
+++ b/apps/wps.c
@@ -384,34 +384,39 @@ static bool update(void)
384 384
385static void fade(bool fade_in) 385static void fade(bool fade_in)
386{ 386{
387 unsigned fp_global_vol = global_settings.volume << 8;
388 unsigned fp_step = fp_global_vol / 30;
389
387 if (fade_in) { 390 if (fade_in) {
388 /* fade in */ 391 /* fade in */
389 int current_volume = 20; 392 unsigned fp_volume = 0;
390 393
391 /* zero out the sound */ 394 /* zero out the sound */
392 sound_set(SOUND_VOLUME, current_volume); 395 sound_set(SOUND_VOLUME, 0);
393 396
394 sleep(HZ/10); /* let audio thread run */ 397 sleep(HZ/10); /* let audio thread run */
395 audio_resume(); 398 audio_resume();
396 399
397 while (current_volume < global_settings.volume) { 400 while (fp_volume < fp_global_vol) {
398 current_volume += 2; 401 fp_volume += fp_step;
399 sleep(1); 402 sleep(1);
400 sound_set(SOUND_VOLUME, current_volume); 403 sound_set(SOUND_VOLUME, fp_volume >> 8);
401 } 404 }
402 sound_set(SOUND_VOLUME, global_settings.volume); 405 sound_set(SOUND_VOLUME, global_settings.volume);
403 } 406 }
404 else { 407 else {
405 /* fade out */ 408 /* fade out */
406 int current_volume = global_settings.volume; 409 unsigned fp_volume = fp_global_vol;
407 410
408 while (current_volume > 20) { 411 while (fp_volume > fp_step) {
409 current_volume -= 2; 412 fp_volume -= fp_step;
410 sleep(1); 413 sleep(1);
411 sound_set(SOUND_VOLUME, current_volume); 414 sound_set(SOUND_VOLUME, fp_volume >> 8);
412 } 415 }
413 audio_pause(); 416 audio_pause();
414 sleep(HZ/5); /* let audio thread run */ 417 /* let audio thread run and wait for the mas to run out of data */
418 while (!mp3_pause_done())
419 sleep(HZ/10);
415 420
416 /* reset volume to what it was before the fade */ 421 /* reset volume to what it was before the fade */
417 sound_set(SOUND_VOLUME, global_settings.volume); 422 sound_set(SOUND_VOLUME, global_settings.volume);
diff --git a/firmware/export/mp3_playback.h b/firmware/export/mp3_playback.h
index 4da1ffce6d..3611c1c9c1 100644
--- a/firmware/export/mp3_playback.h
+++ b/firmware/export/mp3_playback.h
@@ -42,6 +42,7 @@ void mp3_play_data(const unsigned char* start, int size,
42 void (*get_more)(unsigned char** start, int* size) /* callback fn */ 42 void (*get_more)(unsigned char** start, int* size) /* callback fn */
43); 43);
44void mp3_play_pause(bool play); 44void mp3_play_pause(bool play);
45bool mp3_pause_done(void);
45void mp3_play_stop(void); 46void mp3_play_stop(void);
46long mp3_get_playtime(void); 47long mp3_get_playtime(void);
47void mp3_reset_playtime(void); 48void mp3_reset_playtime(void);
diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c
index 67a5ff739b..a8d2d698eb 100644
--- a/firmware/mp3_playback.c
+++ b/firmware/mp3_playback.c
@@ -542,6 +542,19 @@ void mp3_play_pause(bool play)
542 paused = true; 542 paused = true;
543 cumulative_ticks += current_tick - playstart_tick; 543 cumulative_ticks += current_tick - playstart_tick;
544 } 544 }
545}
546
547bool mp3_pause_done(void)
548{
549 unsigned long frame_count;
550
551 if (!paused)
552 return false;
553
554 mas_readmem(MAS_BANK_D0, MAS_D0_MPEG_FRAME_COUNT, &frame_count, 1);
555 /* This works because the frame counter never wraps,
556 * i.e. zero always means lost sync. */
557 return frame_count == 0;
545} 558}
546 559
547void mp3_play_stop(void) 560void mp3_play_stop(void)