summaryrefslogtreecommitdiff
path: root/apps/pcmbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r--apps/pcmbuf.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index 095b5209eb..c8ed91e21a 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -48,8 +48,12 @@ static inline int32_t clip_sample_16(int32_t sample)
48 return sample; 48 return sample;
49} 49}
50 50
51#if MEMORYSIZE > 2
51/* Keep watermark high for iPods at least (2s) */ 52/* Keep watermark high for iPods at least (2s) */
52#define PCMBUF_WATERMARK (NATIVE_FREQUENCY * 4 * 2) 53#define PCMBUF_WATERMARK (NATIVE_FREQUENCY * 4 * 2)
54#else
55#define PCMBUF_WATERMARK (NATIVE_FREQUENCY * 1) /* 0.25 seconds */
56#endif
53 57
54/* Structure we can use to queue pcm chunks in memory to be played 58/* Structure we can use to queue pcm chunks in memory to be played
55 * by the driver code. */ 59 * by the driver code. */
@@ -125,7 +129,7 @@ extern unsigned int codec_thread_id;
125 (pcmbuf_unplayed_bytes < NATIVE_FREQUENCY * quarter_secs) 129 (pcmbuf_unplayed_bytes < NATIVE_FREQUENCY * quarter_secs)
126 130
127static bool prepare_insert(size_t length); 131static bool prepare_insert(size_t length);
128static void pcmbuf_under_watermark(void); 132static void pcmbuf_under_watermark(bool under);
129static bool pcmbuf_flush_fillpos(void); 133static bool pcmbuf_flush_fillpos(void);
130 134
131#define CALL_IF_EXISTS(function, args...) if (function) function(args) 135#define CALL_IF_EXISTS(function, args...) if (function) function(args)
@@ -194,7 +198,7 @@ static void pcmbuf_set_watermark_bytes(void)
194 pcmbuf_watermark = (crossfade_enabled && pcmbuf_size) ? 198 pcmbuf_watermark = (crossfade_enabled && pcmbuf_size) ?
195 /* If crossfading, try to keep the buffer full other than 1 second */ 199 /* If crossfading, try to keep the buffer full other than 1 second */
196 (pcmbuf_size - (NATIVE_FREQUENCY * 4 * 1)) : 200 (pcmbuf_size - (NATIVE_FREQUENCY * 4 * 1)) :
197 /* Otherwise, just keep it above 2 second */ 201 /* Otherwise, just use the default */
198 PCMBUF_WATERMARK; 202 PCMBUF_WATERMARK;
199} 203}
200 204
@@ -271,7 +275,7 @@ static void boost_codec_thread(bool boost)
271} 275}
272#endif /* HAVE_PRIORITY_SCHEDULING */ 276#endif /* HAVE_PRIORITY_SCHEDULING */
273 277
274static void pcmbuf_under_watermark(void) 278static void pcmbuf_under_watermark(bool under)
275{ 279{
276 /* Only codec thread initiates boost - voice boosts the cpu when playing 280 /* Only codec thread initiates boost - voice boosts the cpu when playing
277 a clip */ 281 a clip */
@@ -279,13 +283,21 @@ static void pcmbuf_under_watermark(void)
279 if (thread_get_current() == codec_thread_id) 283 if (thread_get_current() == codec_thread_id)
280#endif /* SIMULATOR */ 284#endif /* SIMULATOR */
281 { 285 {
286 if (under)
287 {
282#ifdef HAVE_PRIORITY_SCHEDULING 288#ifdef HAVE_PRIORITY_SCHEDULING
283 /* If buffer is critically low, override UI priority, else 289 /* If buffer is critically low, override UI priority, else
284 set back to the original priority. */ 290 set back to the original priority. */
285 boost_codec_thread(LOW_DATA(2) && pcm_is_playing()); 291 boost_codec_thread(LOW_DATA(2) && pcm_is_playing());
286#endif 292#endif
287 /* Fill audio buffer by boosting cpu */ 293 /* Fill audio buffer by boosting cpu */
288 trigger_cpu_boost(); 294 trigger_cpu_boost();
295 }
296 else
297 {
298 boost_codec_thread(false);
299 cancel_cpu_boost();
300 }
289 } 301 }
290 302
291 /* Disable crossfade if < .5s of audio */ 303 /* Disable crossfade if < .5s of audio */
@@ -318,8 +330,13 @@ bool pcmbuf_is_lowdata(void)
318 crossfade_init || crossfade_active) 330 crossfade_init || crossfade_active)
319 return false; 331 return false;
320 332
333#if MEMORYSIZE > 2
321 /* 1 seconds of buffer is low data */ 334 /* 1 seconds of buffer is low data */
322 return LOW_DATA(4); 335 return LOW_DATA(4);
336#else
337 /* under watermark is low data */
338 return (pcmbuf_unplayed_bytes < pcmbuf_watermark);
339#endif
323} 340}
324 341
325/* Amount of bytes left in the buffer. */ 342/* Amount of bytes left in the buffer. */
@@ -421,20 +438,18 @@ static void pcmbuf_init_pcmbuffers(void)
421 438
422static size_t pcmbuf_get_next_required_pcmbuf_size(void) 439static size_t pcmbuf_get_next_required_pcmbuf_size(void)
423{ 440{
424#if MEM > 1
425 size_t seconds = 1; 441 size_t seconds = 1;
426 442
427 if (crossfade_enabled_pending) 443 if (crossfade_enabled_pending)
428 seconds += global_settings.crossfade_fade_out_delay 444 seconds += global_settings.crossfade_fade_out_delay
429 + global_settings.crossfade_fade_out_duration; 445 + global_settings.crossfade_fade_out_duration;
430 446
447#if MEMORYSIZE > 2
431 /* Buffer has to be at least 2s long. */ 448 /* Buffer has to be at least 2s long. */
432 seconds += 2; 449 seconds += 2;
433 logf("pcmbuf len: %ld", seconds);
434 return seconds * (NATIVE_FREQUENCY*4);
435#else
436 return NATIVE_FREQUENCY*2;
437#endif 450#endif
451 logf("pcmbuf len: %ld", seconds);
452 return seconds * (NATIVE_FREQUENCY*4); /* 2 channels + 2 bytes/sample */
438} 453}
439 454
440static char *pcmbuf_calc_audiobuffer_ptr(size_t bufsize) 455static char *pcmbuf_calc_audiobuffer_ptr(size_t bufsize)
@@ -817,8 +832,7 @@ static bool prepare_insert(size_t length)
817 if (low_latency_mode) 832 if (low_latency_mode)
818 { 833 {
819 /* 1/4s latency. */ 834 /* 1/4s latency. */
820 if (pcmbuf_unplayed_bytes > NATIVE_FREQUENCY * 4 / 2 835 if (!LOW_DATA(1) && pcm_is_playing())
821 && pcm_is_playing())
822 return false; 836 return false;
823 } 837 }
824 838
@@ -830,11 +844,11 @@ static bool prepare_insert(size_t length)
830 { 844 {
831 trigger_cpu_boost(); 845 trigger_cpu_boost();
832 846
833 /* Pre-buffer 1s. */ 847 /* Pre-buffer up to watermark */
834#if MEM <= 1 848#if MEMORYSIZE > 2
835 if (!LOW_DATA(1))
836#else
837 if (!LOW_DATA(4)) 849 if (!LOW_DATA(4))
850#else
851 if (pcmbuf_unplayed_bytes > pcmbuf_watermark)
838#endif 852#endif
839 { 853 {
840 logf("pcm starting"); 854 logf("pcm starting");
@@ -842,8 +856,8 @@ static bool prepare_insert(size_t length)
842 pcmbuf_play_start(); 856 pcmbuf_play_start();
843 } 857 }
844 } 858 }
845 else if (pcmbuf_unplayed_bytes <= pcmbuf_watermark) 859 else
846 pcmbuf_under_watermark(); 860 pcmbuf_under_watermark(pcmbuf_unplayed_bytes <= pcmbuf_watermark);
847 861
848 return true; 862 return true;
849} 863}
@@ -1119,11 +1133,8 @@ void pcmbuf_write_voice_complete(int count)
1119 1133
1120void pcmbuf_crossfade_enable(bool on_off) 1134void pcmbuf_crossfade_enable(bool on_off)
1121{ 1135{
1122#if MEM > 1
1123 /* Next setting to be used, not applied now */ 1136 /* Next setting to be used, not applied now */
1124 crossfade_enabled_pending = on_off; 1137 crossfade_enabled_pending = on_off;
1125#endif
1126 (void)on_off;
1127} 1138}
1128 1139
1129void pcmbuf_crossfade_enable_finished(void) 1140void pcmbuf_crossfade_enable_finished(void)