Index: apps/pcmbuf.c =================================================================== --- apps/pcmbuf.c (revision 19566) +++ apps/pcmbuf.c (working copy) @@ -421,20 +421,14 @@ static size_t pcmbuf_get_next_required_pcmbuf_size(void) { -#if MEM > 1 size_t seconds = 1; if (crossfade_enabled_pending) seconds += global_settings.crossfade_fade_out_delay + global_settings.crossfade_fade_out_duration; - /* Buffer has to be at least 2s long. */ - seconds += 2; logf("pcmbuf len: %ld", seconds); - return seconds * (NATIVE_FREQUENCY*4); -#else - return NATIVE_FREQUENCY*2; -#endif + return seconds * (NATIVE_FREQUENCY*4); /* 2 channels + 2 bytes/sample */ } static char *pcmbuf_calc_audiobuffer_ptr(size_t bufsize) Index: apps/dsp.h =================================================================== --- apps/dsp.h (revision 19566) +++ apps/dsp.h (working copy) @@ -42,8 +42,7 @@ enum { - CODEC_SET_FILEBUF_WATERMARK = 1, - DSP_MYDSP, + DSP_MYDSP = 1, DSP_SET_FREQUENCY, DSP_SWITCH_FREQUENCY, DSP_SET_SAMPLE_DEPTH, Index: apps/playback.c =================================================================== --- apps/playback.c (revision 19566) +++ apps/playback.c (working copy) @@ -84,14 +84,12 @@ #define PLAYBACK_VOICE -/* default point to start buffer refill */ -#define AUDIO_DEFAULT_WATERMARK (1024*512) /* amount of guess-space to allow for codecs that must hunt and peck * for their correct seeek target, 32k seems a good size */ #define AUDIO_REBUFFER_GUESS_SIZE (1024*32) /* Define LOGF_ENABLE to enable logf output in this file */ -/*#define LOGF_ENABLE*/ +#define LOGF_ENABLE #include "logf.h" /* macros to enable logf for queues @@ -271,11 +269,13 @@ */ static bool codec_requested_stop = false; +#ifdef HAVE_DISK_STORAGE static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ +#endif /* Multiple threads */ -/* Set the watermark to trigger buffer fill (A/C) FIXME */ -static void set_filebuf_watermark(int seconds, size_t max); +/* Set the watermark to trigger buffer fill (A/C) */ +static void set_filebuf_watermark(void); /* Audio thread */ static struct event_queue audio_queue SHAREDBSS_ATTR; @@ -788,7 +788,7 @@ static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; buffer_margin = lookup[setting]; logf("buffer margin: %ld", (long)buffer_margin); - set_filebuf_watermark(buffer_margin, 0); + set_filebuf_watermark(); } #endif @@ -834,16 +834,35 @@ /* --- Routines called from multiple threads --- */ -static void set_filebuf_watermark(int seconds, size_t max) +static void set_filebuf_watermark(void) { - size_t bytes; - if (!filebuf) return; /* Audio buffers not yet set up */ - bytes = seconds?MAX(curtrack_id3.bitrate * seconds * (1000/8), max):max; - bytes = MIN(bytes, filebuflen / 2); +#ifdef HAVE_FLASH_STORAGE + int seconds = 1; +#else + int seconds; + int spinup = ata_spinup_time(); + if (spinup) + seconds = (spinup / HZ) + 1.5; + else + seconds = 3; +#endif + + /* bitrate of last track in buffer dictates watermark */ + struct mp3entry* id3 = NULL; + if (tracks[track_widx].taginfo_ready) + id3 = bufgetid3(tracks[track_widx].id3_hid); + else + id3 = bufgetid3(tracks[track_widx-1].id3_hid); + if (!id3) { + logf("fwmark: No id3 for last track (r%d/w%d), aborting!", track_ridx, track_widx); + return; + } + size_t bytes = id3->bitrate * (1000/8) * seconds; buf_set_watermark(bytes); + logf("fwmark: %d", bytes); } const char *get_codec_filename(int cod_spec) @@ -1097,10 +1116,6 @@ static void codec_configure_callback(int setting, intptr_t value) { switch (setting) { - case CODEC_SET_FILEBUF_WATERMARK: - set_filebuf_watermark(buffer_margin, value); - break; - default: if (!dsp_configure(ci.dsp, setting, value)) { logf("Illegal key:%d", setting); } @@ -1215,7 +1230,7 @@ return false; default: - LOGFQUEUE("codec |< default"); + LOGFQUEUE("codec |< default (result: %lx)", result); ci.stop_codec = true; codec_requested_stop = true; return false; @@ -1308,7 +1323,7 @@ #endif /* AUDIO_HAVE_RECORDING */ default: - LOGFQUEUE("codec < default"); + LOGFQUEUE("codec < default (event: %lx)", ev.id); } if (audio_codec_loaded) @@ -1491,6 +1506,8 @@ /* Update track info after successful a codec track change */ static void audio_update_trackinfo(void) { + logf("audio_update_trackinfo()"); + /* Load the curent track's metadata into curtrack_id3 */ if (CUR_TI->id3_hid >= 0) copy_mp3entry(&curtrack_id3, bufgetid3(CUR_TI->id3_hid)); @@ -1616,6 +1633,8 @@ const char *trackname; int fd = -1; + logf("audio_load_track(%d,%s)",offset,start_play?"true":"false"); + if (track_load_started) { /* There is already a track load in progress, so track_widx hasn't been incremented yet. Loading another track would overwrite the one that @@ -1677,7 +1696,7 @@ /* Set default values */ if (start_play) { - buf_set_watermark(AUDIO_DEFAULT_WATERMARK); + buf_set_watermark(filebuflen/2); dsp_configure(ci.dsp, DSP_RESET, 0); track_changed = true; playlist_update_resume_info(audio_current_track()); @@ -1690,6 +1709,8 @@ if (tracks[track_widx].id3_hid < 0) { + struct buffering_debug d; + buffering_get_debugdata(&d); /* Buffer is full. */ get_metadata(&lasttrack_id3, fd, trackname); last_peek_offset--; @@ -1946,6 +1967,8 @@ int i, idx; bool forward; + logf("audio_check_new_track()"); + /* Now it's good time to send track finish events. */ send_event(PLAYBACK_EVENT_TRACK_FINISH, &curtrack_id3); if (dir_skip) @@ -2191,10 +2214,6 @@ /* Officially playing */ queue_reply(&audio_queue, 1); -#ifdef HAVE_DISK_STORAGE - set_filebuf_watermark(buffer_margin, 0); -#endif - audio_fill_file_buffer(true, offset); add_event(BUFFER_EVENT_BUFFER_LOW, false, buffering_low_buffer_callback); @@ -2382,6 +2401,7 @@ case Q_AUDIO_FILL_BUFFER: LOGFQUEUE("audio < Q_AUDIO_FILL_BUFFER %d", (int)ev.data); audio_fill_file_buffer((bool)ev.data, 0); + set_filebuf_watermark(); break; case Q_AUDIO_FINISH_LOAD: @@ -2490,7 +2510,7 @@ break; default: - LOGFQUEUE("audio < default"); + LOGFQUEUE("audio < default (event: %lx)", ev.id); break; } /* end switch */ } /* end while */ Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 19566) +++ apps/buffering.c (working copy) @@ -63,7 +63,7 @@ #endif /* Define LOGF_ENABLE to enable logf output in this file */ -/*#define LOGF_ENABLE*/ +#define LOGF_ENABLE #include "logf.h" /* macros to enable logf for queues @@ -91,8 +91,6 @@ #define BUFFERING_DEFAULT_WATERMARK (1024*512) /* amount of data to read in one read() call */ #define BUFFERING_DEFAULT_FILECHUNK (1024*32) -/* point at which the file buffer will fight for CPU time */ -#define BUFFERING_CRITICAL_LEVEL (1024*128) #define BUF_HANDLE_MASK 0x7FFFFFFF @@ -555,7 +553,7 @@ static inline bool buffer_is_low(void) { update_data_counters(); - return data_counters.useful < BUFFERING_CRITICAL_LEVEL; + return data_counters.useful < (conf_watermark / 2); } /* Buffer data for the given handle. @@ -1313,8 +1311,7 @@ void buf_set_watermark(size_t bytes) { - LOGFQUEUE("buffering > Q_SET_WATERMARK %ld", (long)bytes); - queue_post(&buffering_queue, Q_SET_WATERMARK, bytes); + conf_watermark = bytes; } static void shrink_buffer_inner(struct memory_handle *h) @@ -1389,12 +1386,6 @@ case Q_SET_WATERMARK: LOGFQUEUE("buffering < Q_SET_WATERMARK"); conf_watermark = (size_t)ev.data; - if (conf_watermark < BUFFERING_DEFAULT_FILECHUNK) - { - logf("wmarkconfigure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_SAMPLE_DEPTH, FLAC_OUTPUT_DEPTH-1); next_track: Index: apps/codecs/ape.c =================================================================== --- apps/codecs/ape.c (revision 19566) +++ apps/codecs/ape.c (working copy) @@ -147,8 +147,6 @@ size_t resume_offset; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_SAMPLE_DEPTH, APE_OUTPUT_DEPTH-1); next_track: Index: apps/codecs/aiff.c =================================================================== --- apps/codecs/aiff.c (revision 19566) +++ apps/codecs/aiff.c (working copy) @@ -66,7 +66,6 @@ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, 28); - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); next_track: if (codec_init()) { Index: apps/codecs/aac.c =================================================================== --- apps/codecs/aac.c (revision 19566) +++ apps/codecs/aac.c (working copy) @@ -55,8 +55,6 @@ unsigned char c = 0; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, 29); Index: apps/codecs/spc.c =================================================================== --- apps/codecs/spc.c (revision 19566) +++ apps/codecs/spc.c (working copy) @@ -559,8 +559,6 @@ /* Read the entire file */ DEBUGF("SPC: request initial buffer\n"); - ci->configure(CODEC_SET_FILEBUF_WATERMARK, ci->filesize); - ci->seek_buffer(0); size_t buffersize; uint8_t* buffer = ci->request_buffer(&buffersize, ci->filesize); Index: apps/codecs/alac.c =================================================================== --- apps/codecs/alac.c (revision 19566) +++ apps/codecs/alac.c (working copy) @@ -44,8 +44,6 @@ int retval; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1); Index: apps/codecs/mod.c =================================================================== --- apps/codecs/mod.c (revision 19566) +++ apps/codecs/mod.c (working copy) @@ -1229,9 +1229,6 @@ int bytesdone; - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - - next_track: if (codec_init()) { return CODEC_ERROR; Index: apps/codecs/sid.c =================================================================== --- apps/codecs/sid.c (revision 19566) +++ apps/codecs/sid.c (working copy) @@ -1215,9 +1215,6 @@ int nSamplesPerCall = 882; /* This is PAL SID single speed (44100/50Hz) */ int nSamplesToRender = 0; - /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - next_track: if (codec_init()) { return CODEC_ERROR; Index: apps/codecs/shorten.c =================================================================== --- apps/codecs/shorten.c (revision 19566) +++ apps/codecs/shorten.c (working copy) @@ -47,8 +47,6 @@ size_t bytesleft; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, SHN_OUTPUT_DEPTH-1); Index: apps/codecs/asap.c =================================================================== --- apps/codecs/asap.c (revision 19566) +++ apps/codecs/asap.c (working copy) @@ -38,9 +38,6 @@ char* module; int bytesPerSample =2; - /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - next_track: if (codec_init()) { DEBUGF("codec init failed\n"); Index: apps/codecs/wma.c =================================================================== --- apps/codecs/wma.c (revision 19566) +++ apps/codecs/wma.c (working copy) @@ -468,8 +468,6 @@ int errcount = 0; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_SAMPLE_DEPTH, 29); next_track: Index: apps/codecs/wavpack.c =================================================================== --- apps/codecs/wavpack.c (revision 19566) +++ apps/codecs/wavpack.c (working copy) @@ -44,8 +44,6 @@ int retval; /* Generic codec initialisation */ - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); - ci->configure(DSP_SET_SAMPLE_DEPTH, 28); next_track: Index: apps/codecs/wav.c =================================================================== --- apps/codecs/wav.c (revision 19566) +++ apps/codecs/wav.c (working copy) @@ -228,7 +228,6 @@ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, 28); - ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); next_track: if (codec_init()) {