summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playback.c')
-rw-r--r--apps/playback.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/apps/playback.c b/apps/playback.c
index e81b32dbf9..c98455ccb0 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -88,8 +88,6 @@
88 88
89#define PLAYBACK_VOICE 89#define PLAYBACK_VOICE
90 90
91/* default point to start buffer refill */
92#define AUDIO_DEFAULT_WATERMARK (1024*512)
93/* amount of guess-space to allow for codecs that must hunt and peck 91/* amount of guess-space to allow for codecs that must hunt and peck
94 * for their correct seeek target, 32k seems a good size */ 92 * for their correct seeek target, 32k seems a good size */
95#define AUDIO_REBUFFER_GUESS_SIZE (1024*32) 93#define AUDIO_REBUFFER_GUESS_SIZE (1024*32)
@@ -162,20 +160,12 @@ enum filling_state {
162 STATE_FINISHED, /* all remaining tracks are fully buffered */ 160 STATE_FINISHED, /* all remaining tracks are fully buffered */
163}; 161};
164 162
165#if MEM > 1
166#define MAX_TRACK 128 163#define MAX_TRACK 128
167#else
168#define MAX_TRACK 32
169#endif
170 164
171#define MAX_TRACK_MASK (MAX_TRACK-1) 165#define MAX_TRACK_MASK (MAX_TRACK-1)
172 166
173/* As defined in plugins/lib/xxx2wav.h */ 167/* As defined in plugins/lib/xxx2wav.h */
174#if MEM > 1
175#define GUARD_BUFSIZE (32*1024) 168#define GUARD_BUFSIZE (32*1024)
176#else
177#define GUARD_BUFSIZE (8*1024)
178#endif
179 169
180/* As defined in plugin.lds */ 170/* As defined in plugin.lds */
181#if defined(CPU_PP) 171#if defined(CPU_PP)
@@ -277,11 +267,13 @@ static bool track_load_started = false;
277 */ 267 */
278static bool codec_requested_stop = false; 268static bool codec_requested_stop = false;
279 269
270#ifdef HAVE_DISK_STORAGE
280static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */ 271static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) */
272#endif
281 273
282/* Multiple threads */ 274/* Multiple threads */
283/* Set the watermark to trigger buffer fill (A/C) FIXME */ 275/* Set the watermark to trigger buffer fill (A/C) */
284static void set_filebuf_watermark(int seconds, size_t max); 276static void set_filebuf_watermark(void);
285 277
286/* Audio thread */ 278/* Audio thread */
287static struct event_queue audio_queue SHAREDBSS_ATTR; 279static struct event_queue audio_queue SHAREDBSS_ATTR;
@@ -797,7 +789,7 @@ void audio_set_buffer_margin(int setting)
797 static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; 789 static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600};
798 buffer_margin = lookup[setting]; 790 buffer_margin = lookup[setting];
799 logf("buffer margin: %ld", (long)buffer_margin); 791 logf("buffer margin: %ld", (long)buffer_margin);
800 set_filebuf_watermark(buffer_margin, 0); 792 set_filebuf_watermark();
801} 793}
802#endif 794#endif
803 795
@@ -843,16 +835,35 @@ void audio_set_crossfade(int enable)
843 835
844/* --- Routines called from multiple threads --- */ 836/* --- Routines called from multiple threads --- */
845 837
846static void set_filebuf_watermark(int seconds, size_t max) 838static void set_filebuf_watermark(void)
847{ 839{
848 size_t bytes;
849
850 if (!filebuf) 840 if (!filebuf)
851 return; /* Audio buffers not yet set up */ 841 return; /* Audio buffers not yet set up */
852 842
853 bytes = seconds?MAX(curtrack_id3.bitrate * seconds * (1000/8), max):max; 843#ifdef HAVE_FLASH_STORAGE
854 bytes = MIN(bytes, filebuflen / 2); 844 int seconds = 1;
845#else
846 int seconds;
847 int spinup = ata_spinup_time();
848 if (spinup)
849 seconds = (spinup / HZ) + 1;
850 else
851 seconds = 3;
852#endif
853
854 /* bitrate of last track in buffer dictates watermark */
855 struct mp3entry* id3 = NULL;
856 if (tracks[track_widx].taginfo_ready)
857 id3 = bufgetid3(tracks[track_widx].id3_hid);
858 else
859 id3 = bufgetid3(tracks[track_widx-1].id3_hid);
860 if (!id3) {
861 logf("fwmark: No id3 for last track (r%d/w%d), aborting!", track_ridx, track_widx);
862 return;
863 }
864 size_t bytes = id3->bitrate * (1000/8) * seconds;
855 buf_set_watermark(bytes); 865 buf_set_watermark(bytes);
866 logf("fwmark: %d", bytes);
856} 867}
857 868
858const char *get_codec_filename(int cod_spec) 869const char *get_codec_filename(int cod_spec)
@@ -1106,10 +1117,6 @@ static bool codec_seek_buffer_callback(size_t newpos)
1106static void codec_configure_callback(int setting, intptr_t value) 1117static void codec_configure_callback(int setting, intptr_t value)
1107{ 1118{
1108 switch (setting) { 1119 switch (setting) {
1109 case CODEC_SET_FILEBUF_WATERMARK:
1110 set_filebuf_watermark(buffer_margin, value);
1111 break;
1112
1113 default: 1120 default:
1114 if (!dsp_configure(ci.dsp, setting, value)) 1121 if (!dsp_configure(ci.dsp, setting, value))
1115 { logf("Illegal key:%d", setting); } 1122 { logf("Illegal key:%d", setting); }
@@ -1709,7 +1716,7 @@ static bool audio_load_track(size_t offset, bool start_play)
1709 /* Set default values */ 1716 /* Set default values */
1710 if (start_play) 1717 if (start_play)
1711 { 1718 {
1712 buf_set_watermark(AUDIO_DEFAULT_WATERMARK); 1719 buf_set_watermark(filebuflen/2);
1713 dsp_configure(ci.dsp, DSP_RESET, 0); 1720 dsp_configure(ci.dsp, DSP_RESET, 0);
1714 track_changed = true; 1721 track_changed = true;
1715 playlist_update_resume_info(audio_current_track()); 1722 playlist_update_resume_info(audio_current_track());
@@ -2223,10 +2230,6 @@ static void audio_play_start(size_t offset)
2223 /* Officially playing */ 2230 /* Officially playing */
2224 queue_reply(&audio_queue, 1); 2231 queue_reply(&audio_queue, 1);
2225 2232
2226#ifdef HAVE_DISK_STORAGE
2227 set_filebuf_watermark(buffer_margin, 0);
2228#endif
2229
2230 audio_fill_file_buffer(true, offset); 2233 audio_fill_file_buffer(true, offset);
2231 2234
2232 add_event(BUFFER_EVENT_BUFFER_LOW, false, buffering_low_buffer_callback); 2235 add_event(BUFFER_EVENT_BUFFER_LOW, false, buffering_low_buffer_callback);
@@ -2358,11 +2361,13 @@ static void audio_reset_buffer(void)
2358 2361
2359 /* Subtract whatever the pcm buffer says it used plus the guard buffer */ 2362 /* Subtract whatever the pcm buffer says it used plus the guard buffer */
2360 const size_t pcmbuf_size = pcmbuf_init(filebuf + filebuflen) +GUARD_BUFSIZE; 2363 const size_t pcmbuf_size = pcmbuf_init(filebuf + filebuflen) +GUARD_BUFSIZE;
2364
2361#ifdef DEBUG 2365#ifdef DEBUG
2362 if(pcmbuf_size > filebuflen) 2366 if(pcmbuf_size > filebuflen)
2363 panicf("Not enough memory for pcmbuf_init() : %d > %d", 2367 panicf("Not enough memory for pcmbuf_init() : %d > %d",
2364 (int)pcmbuf_size, (int)filebuflen); 2368 (int)pcmbuf_size, (int)filebuflen);
2365#endif 2369#endif
2370
2366 filebuflen -= pcmbuf_size; 2371 filebuflen -= pcmbuf_size;
2367 2372
2368 /* Make sure filebuflen is a longword multiple after adjustment - filebuf 2373 /* Make sure filebuflen is a longword multiple after adjustment - filebuf
@@ -2414,6 +2419,7 @@ static void audio_thread(void)
2414 case Q_AUDIO_FILL_BUFFER: 2419 case Q_AUDIO_FILL_BUFFER:
2415 LOGFQUEUE("audio < Q_AUDIO_FILL_BUFFER %d", (int)ev.data); 2420 LOGFQUEUE("audio < Q_AUDIO_FILL_BUFFER %d", (int)ev.data);
2416 audio_fill_file_buffer((bool)ev.data, 0); 2421 audio_fill_file_buffer((bool)ev.data, 0);
2422 set_filebuf_watermark();
2417 break; 2423 break;
2418 2424
2419 case Q_AUDIO_FINISH_LOAD: 2425 case Q_AUDIO_FINISH_LOAD: