summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2005-07-22 06:32:55 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2005-07-22 06:32:55 +0000
commiteab434c416a89a9de30bcca255334eeac97eb433 (patch)
treefd13b0eff472cd800d8d7b21babd70725d608de3
parentd3cbf8730579002093f003499104a861112d4dc5 (diff)
downloadrockbox-eab434c416a89a9de30bcca255334eeac97eb433.tar.gz
rockbox-eab434c416a89a9de30bcca255334eeac97eb433.zip
More accurate playback position calculation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7218 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/pcmbuf.c4
-rw-r--r--apps/playback.c5
-rw-r--r--firmware/export/pcm_playback.h1
-rw-r--r--firmware/pcm_playback.c7
-rw-r--r--uisimulator/common/stubs.c5
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)
202{ 202{
203 int latency; 203 int latency;
204 204
205 /* This has to be done better. */ 205 latency = (pcmbuf_unplayed_bytes + pcm_get_bytes_waiting())
206 latency = (pcmbuf_size - audiobuffer_free - CHUNK_SIZE)/4 / (44100/1000); 206 / 4 / (44100/1000);
207 if (latency < 0) 207 if (latency < 0)
208 latency = 0; 208 latency = 0;
209 209
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)
265 if (ci.stop_codec) 265 if (ci.stop_codec)
266 return ; 266 return ;
267 267
268 /* The 1000 here is a hack. pcmbuf_get_latency() should 268 latency = pcmbuf_get_latency() * cur_ti->id3.bitrate / 8;
269 * be more accurate
270 */
271 latency = (pcmbuf_get_latency() + 1000) * cur_ti->id3.bitrate / 8;
272 269
273 if (value < latency) { 270 if (value < latency) {
274 cur_ti->id3.offset = 0; 271 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);
26void pcm_play_data(void (*get_more)(unsigned char** start, long* size)); 26void pcm_play_data(void (*get_more)(unsigned char** start, long* size));
27 27
28void pcm_calculate_peaks(int *left, int *right); 28void pcm_calculate_peaks(int *left, int *right);
29long pcm_get_bytes_waiting(void);
29 30
30void pcm_play_stop(void); 31void pcm_play_stop(void);
31void pcm_play_pause(bool play); 32void 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,
164void pcm_calculate_peaks(int *left, int *right) 164void pcm_calculate_peaks(int *left, int *right)
165{ 165{
166 unsigned short *addr = (unsigned short *)SAR0; 166 unsigned short *addr = (unsigned short *)SAR0;
167 long size = MIN(512, BCR0 / 2); 167 long size = MIN(512, (BCR0 & 0xffffff) / 2);
168 168
169 if (left != NULL) 169 if (left != NULL)
170 *left = calculate_channel_peak_average(0, addr, size); 170 *left = calculate_channel_peak_average(0, addr, size);
@@ -222,6 +222,11 @@ void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
222 uda1380_mute(false); 222 uda1380_mute(false);
223} 223}
224 224
225long pcm_get_bytes_waiting(void)
226{
227 return next_size + (BCR0 & 0xffffff);
228}
229
225void pcm_play_stop(void) 230void pcm_play_stop(void)
226{ 231{
227 if (pcm_playing) { 232 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))
66 playing = true; 66 playing = true;
67} 67}
68 68
69long pcm_get_bytes_waiting(long)
70{
71 return 0;
72}
73
69#if CONFIG_HWCODEC != MASNONE 74#if CONFIG_HWCODEC != MASNONE
70void audio_set_buffer_margin(int seconds) 75void audio_set_buffer_margin(int seconds)
71{ 76{