From eab434c416a89a9de30bcca255334eeac97eb433 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Fri, 22 Jul 2005 06:32:55 +0000 Subject: [PATCH] More accurate playback position calculation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7218 a1c6a512-1295-4272-9138-f99709370657 --- apps/pcmbuf.c | 4 ++-- apps/playback.c | 5 +---- firmware/export/pcm_playback.h | 1 + firmware/pcm_playback.c | 7 ++++++- uisimulator/common/stubs.c | 5 +++++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index cf6911b606..a8769e3829 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -202,8 +202,8 @@ unsigned int pcmbuf_get_latency(void) { int latency; - /* This has to be done better. */ - latency = (pcmbuf_size - audiobuffer_free - CHUNK_SIZE)/4 / (44100/1000); + latency = (pcmbuf_unplayed_bytes + pcm_get_bytes_waiting()) + / 4 / (44100/1000); if (latency < 0) latency = 0; diff --git a/apps/playback.c b/apps/playback.c index aadb1e289e..7aaff01e54 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -265,10 +265,7 @@ void codec_set_offset_callback(unsigned int value) if (ci.stop_codec) return ; - /* The 1000 here is a hack. pcmbuf_get_latency() should - * be more accurate - */ - latency = (pcmbuf_get_latency() + 1000) * cur_ti->id3.bitrate / 8; + latency = pcmbuf_get_latency() * cur_ti->id3.bitrate / 8; if (value < latency) { cur_ti->id3.offset = 0; diff --git a/firmware/export/pcm_playback.h b/firmware/export/pcm_playback.h index 6222574ed8..3972e45768 100644 --- a/firmware/export/pcm_playback.h +++ b/firmware/export/pcm_playback.h @@ -26,6 +26,7 @@ void pcm_set_frequency(unsigned int frequency); void pcm_play_data(void (*get_more)(unsigned char** start, long* size)); void pcm_calculate_peaks(int *left, int *right); +long pcm_get_bytes_waiting(void); void pcm_play_stop(void); void pcm_play_pause(bool play); diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c index 3a68db4d0c..bafbd8c761 100644 --- a/firmware/pcm_playback.c +++ b/firmware/pcm_playback.c @@ -164,7 +164,7 @@ static long calculate_channel_peak_average(int channel, unsigned short *addr, void pcm_calculate_peaks(int *left, int *right) { unsigned short *addr = (unsigned short *)SAR0; - long size = MIN(512, BCR0 / 2); + long size = MIN(512, (BCR0 & 0xffffff) / 2); if (left != NULL) *left = calculate_channel_peak_average(0, addr, size); @@ -222,6 +222,11 @@ void pcm_play_data(void (*get_more)(unsigned char** start, long* size)) uda1380_mute(false); } +long pcm_get_bytes_waiting(void) +{ + return next_size + (BCR0 & 0xffffff); +} + void pcm_play_stop(void) { if (pcm_playing) { diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index 4ad89e4681..b887fbda83 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -66,6 +66,11 @@ void pcm_play_data(void (*get_more)(unsigned char** start, long* size)) playing = true; } +long pcm_get_bytes_waiting(long) +{ + return 0; +} + #if CONFIG_HWCODEC != MASNONE void audio_set_buffer_margin(int seconds) {