From 03d08ecc250ee095f46a77848bde28f162493276 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Fri, 13 May 2005 00:16:14 +0000 Subject: (1) Wait for the MAS to run out of buffered data on fade out. Fixes bug #778930/#1189756. (2) Fade in/out from/to zero. (3) Always fade in 30 steps, independent of the global volume. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6463 a1c6a512-1295-4272-9138-f99709370657 --- apps/wps.c | 27 ++++++++++++++++----------- firmware/export/mp3_playback.h | 1 + firmware/mp3_playback.c | 13 +++++++++++++ 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) static void fade(bool fade_in) { + unsigned fp_global_vol = global_settings.volume << 8; + unsigned fp_step = fp_global_vol / 30; + if (fade_in) { /* fade in */ - int current_volume = 20; - + unsigned fp_volume = 0; + /* zero out the sound */ - sound_set(SOUND_VOLUME, current_volume); + sound_set(SOUND_VOLUME, 0); sleep(HZ/10); /* let audio thread run */ audio_resume(); - while (current_volume < global_settings.volume) { - current_volume += 2; + while (fp_volume < fp_global_vol) { + fp_volume += fp_step; sleep(1); - sound_set(SOUND_VOLUME, current_volume); + sound_set(SOUND_VOLUME, fp_volume >> 8); } sound_set(SOUND_VOLUME, global_settings.volume); } else { /* fade out */ - int current_volume = global_settings.volume; + unsigned fp_volume = fp_global_vol; - while (current_volume > 20) { - current_volume -= 2; + while (fp_volume > fp_step) { + fp_volume -= fp_step; sleep(1); - sound_set(SOUND_VOLUME, current_volume); + sound_set(SOUND_VOLUME, fp_volume >> 8); } audio_pause(); - sleep(HZ/5); /* let audio thread run */ + /* let audio thread run and wait for the mas to run out of data */ + while (!mp3_pause_done()) + sleep(HZ/10); /* reset volume to what it was before the fade */ 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, void (*get_more)(unsigned char** start, int* size) /* callback fn */ ); void mp3_play_pause(bool play); +bool mp3_pause_done(void); void mp3_play_stop(void); long mp3_get_playtime(void); void 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) paused = true; cumulative_ticks += current_tick - playstart_tick; } +} + +bool mp3_pause_done(void) +{ + unsigned long frame_count; + + if (!paused) + return false; + + mas_readmem(MAS_BANK_D0, MAS_D0_MPEG_FRAME_COUNT, &frame_count, 1); + /* This works because the frame counter never wraps, + * i.e. zero always means lost sync. */ + return frame_count == 0; } void mp3_play_stop(void) -- cgit v1.2.3