From 9c0f1a9e395a4a680e7b2532ebdb468cbeccaca5 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Fri, 18 Nov 2005 20:21:13 +0000 Subject: [PATCH] More stable playback with reduced stuttering when skipping tracks. Removed CODEC_SET_FILEBUF_LIMIT setting; now playback.c determines how to buffer the files. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7970 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/a52.c | 1 - apps/codecs/aac.c | 1 - apps/codecs/alac.c | 1 - apps/codecs/flac.c | 1 - apps/codecs/mpa.c | 1 - apps/codecs/mpc.c | 1 - apps/codecs/shorten.c | 1 - apps/codecs/vorbis.c | 1 - apps/codecs/wav.c | 1 - apps/codecs/wavpack.c | 1 - apps/dsp.h | 1 - apps/playback.c | 37 ++++++++++++++++++++++--------------- 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c index 050bfff25d..ee80f66892 100644 --- a/apps/codecs/a52.c +++ b/apps/codecs/a52.c @@ -140,7 +140,6 @@ enum codec_status codec_start(struct codec_api *api) ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)30); ci->configure(DSP_SET_CLIP_MAX, (long *)((1 << 30) - 1)); ci->configure(DSP_SET_CLIP_MIN, (long *)-(1 << 30)); - ci->configure(CODEC_SET_FILEBUF_LIMIT, (long *)(1024*1024*2)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128)); next_track: diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index f6a6de53da..c62fb2d007 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -60,7 +60,6 @@ enum codec_status codec_start(struct codec_api* api) rb->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c index 1ecaab6b85..deb1e289a7 100644 --- a/apps/codecs/alac.c +++ b/apps/codecs/alac.c @@ -57,7 +57,6 @@ enum codec_status codec_start(struct codec_api* api) rb->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index b94152dec5..7639b9a352 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c @@ -233,7 +233,6 @@ enum codec_status codec_start(struct codec_api* api) ci->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index c6342df262..0f575924d0 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -95,7 +95,6 @@ enum codec_status codec_start(struct codec_api *api) ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(MAD_F_FRACBITS)); ci->configure(DSP_SET_CLIP_MIN, (int *)-MAD_F_ONE); ci->configure(DSP_SET_CLIP_MAX, (int *)(MAD_F_ONE - 1)); - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*2)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16)); ci->memset(&stream, 0, sizeof(struct mad_stream)); diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 0f113c7bdc..db2501525e 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c @@ -96,7 +96,6 @@ enum codec_status codec_start(struct codec_api *api) /* disable these until we can figure out what's going on. ci->configure(DSP_SET_CLIP_MAX, (long *)MPC_FIXED_POINT_SCALE); ci->configure(DSP_SET_CLIP_MIN, (long *)-MPC_FIXED_POINT_SCALE);*/ - ci->configure(CODEC_SET_FILEBUF_LIMIT, (long *)(1024*1024*2)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); /* Create a decoder instance */ diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index 50d72997ce..26b5e09d6c 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c @@ -56,7 +56,6 @@ enum codec_status codec_start(struct codec_api* api) ci->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index 1fbe131e10..69eba24bb8 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -135,7 +135,6 @@ enum codec_status codec_start(struct codec_api *api) /* Note: These are sane defaults for these values. Perhaps * they should be set differently based on quality setting */ - rb->configure(CODEC_SET_FILEBUF_LIMIT, (long *)(1024*1024*2)); /* The chunk size below is magic. If set any lower, resume * doesn't work properly (ov_raw_seek() does the wrong thing). diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index 6bf7bcd408..85e24124ab 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c @@ -237,7 +237,6 @@ enum codec_status codec_start(struct codec_api* api) ci->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256)); diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c index 93f5002538..21c194773b 100644 --- a/apps/codecs/wavpack.c +++ b/apps/codecs/wavpack.c @@ -58,7 +58,6 @@ enum codec_status codec_start(struct codec_api* api) ci->memcpy(iramstart, iramcopy, iramend-iramstart); #endif - ci->configure(CODEC_SET_FILEBUF_LIMIT, (int *)(1024*1024*10)); ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512)); ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); diff --git a/apps/dsp.h b/apps/dsp.h index 19ba6db980..f250d89708 100644 --- a/apps/dsp.h +++ b/apps/dsp.h @@ -31,7 +31,6 @@ enum { CODEC_SET_FILEBUF_WATERMARK = 1, CODEC_SET_FILEBUF_CHUNKSIZE, - CODEC_SET_FILEBUF_LIMIT, CODEC_DSP_ENABLE, DSP_SET_FREQUENCY, DSP_SWITCH_FREQUENCY, diff --git a/apps/playback.c b/apps/playback.c index 6a944c9dc8..2418eba367 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -81,6 +81,7 @@ static volatile bool paused; #define CODEC_AAC "/.rockbox/codecs/aac.codec" #define CODEC_SHN "/.rockbox/codecs/shorten.codec" +#define AUDIO_DEFAULT_FIRST_LIMIT (1024*1024*10) #define AUDIO_FILL_CYCLE (1024*256) #define AUDIO_DEFAULT_WATERMARK (1024*512) #define AUDIO_DEFAULT_FILECHUNK (1024*32) @@ -717,10 +718,6 @@ void codec_configure_callback(int setting, void *value) conf_filechunk = (unsigned int)value; break; - case CODEC_SET_FILEBUF_LIMIT: - conf_bufferlimit = (unsigned int)value; - break; - case CODEC_DSP_ENABLE: if ((bool)value) ci.pcmbuf_insert = codec_pcmbuf_insert_callback; @@ -1009,9 +1006,11 @@ bool read_next_metadata(void) fd = open(trackname, O_RDONLY); if (fd < 0) return false; - - /* Start buffer refilling also because we need to spin-up the disk. */ - filling = true; + + /** Start buffer refilling also because we need to spin-up the disk. + * In fact, it might be better not to start filling here, because if user + * is manipulating the playlist a lot, we will just lose battery. */ + // filling = true; tracks[next_track].id3.codectype = probe_file_format(trackname); status = get_metadata(&tracks[next_track],fd,trackname,v1first); tracks[next_track].id3.codectype = 0; @@ -1081,7 +1080,7 @@ bool audio_load_track(int offset, bool start_play, int peek_offset) if (start_play) { int last_codec = current_codec; current_codec = CODEC_IDX_AUDIO; - conf_bufferlimit = 0; + conf_bufferlimit = AUDIO_DEFAULT_FIRST_LIMIT; conf_watermark = AUDIO_DEFAULT_WATERMARK; conf_filechunk = AUDIO_DEFAULT_FILECHUNK; dsp_configure(DSP_RESET, 0); @@ -1329,13 +1328,13 @@ void initialize_buffer_fill(void) { int cur_idx, i; - - fill_bytesleft = filebuflen - filebufused; - cur_ti->start_pos = ci.curpos; - + /* Initialize only once; do not truncate the tracks. */ if (filling) return ; + fill_bytesleft = filebuflen - filebufused; + cur_ti->start_pos = ci.curpos; + pcmbuf_set_boost_mode(true); filling = true; @@ -1392,8 +1391,14 @@ void audio_check_buffer(void) /* Load new files to fill the entire buffer. */ if (audio_load_track(0, false, last_peek_offset + 1)) { - - } else if (tracks[track_widx].filerem == 0 || fill_bytesleft == 0) { + if (conf_bufferlimit) + fill_bytesleft = 0; + } + else if (tracks[track_widx].filerem == 0) + fill_bytesleft = 0; + + if (fill_bytesleft <= 0) + { /* Read next unbuffered track's metadata as necessary. */ read_next_metadata(); @@ -1659,7 +1664,7 @@ void audio_thread(void) bool play_pending = false; while (1) { - if (!play_pending) + if (!play_pending && queue_empty(&audio_queue)) { yield_codecs(); audio_check_buffer(); @@ -1683,12 +1688,14 @@ void audio_thread(void) * fast to prevent UI lag. */ track_count = 0; last_peek_offset = 0; + track_changed = true; if (current_tick - last_tick < HZ/2) { play_pending = true; break ; } play_pending = false; + last_tick = current_tick; /* Do not start crossfading if audio is paused. */ if (paused)