summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/pcm_playback.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c
index 12f6e08bd0..b024d7c69c 100644
--- a/firmware/pcm_playback.c
+++ b/firmware/pcm_playback.c
@@ -44,7 +44,7 @@
44/* Must be a power of 2 */ 44/* Must be a power of 2 */
45#define NUM_PCM_BUFFERS (PCMBUF_SIZE / CHUNK_SIZE) 45#define NUM_PCM_BUFFERS (PCMBUF_SIZE / CHUNK_SIZE)
46#define NUM_PCM_BUFFERS_MASK (NUM_PCM_BUFFERS - 1) 46#define NUM_PCM_BUFFERS_MASK (NUM_PCM_BUFFERS - 1)
47#define PCM_WATERMARK 0x10000 47#define PCM_WATERMARK (CHUNK_SIZE * 3)
48 48
49static bool pcm_playing; 49static bool pcm_playing;
50static bool pcm_paused; 50static bool pcm_paused;
@@ -103,7 +103,7 @@ void pcm_boost(bool state)
103{ 103{
104 static bool boost_state = false; 104 static bool boost_state = false;
105 105
106 if (crossfade_active) 106 if (crossfade_active || boost_mode)
107 return ; 107 return ;
108 108
109 if (state != boost_state) { 109 if (state != boost_state) {
@@ -348,9 +348,9 @@ void pcm_watermark_callback(int bytes_left)
348 348
349void pcm_set_boost_mode(bool state) 349void pcm_set_boost_mode(bool state)
350{ 350{
351 boost_mode = state;
352 if (state) 351 if (state)
353 pcm_boost(true); 352 pcm_boost(true);
353 boost_mode = state;
354} 354}
355 355
356void audiobuffer_add_event(void (*event_handler)(void)) 356void audiobuffer_add_event(void (*event_handler)(void))
@@ -377,7 +377,7 @@ bool pcm_is_lowdata(void)
377 if (!pcm_is_playing()) 377 if (!pcm_is_playing())
378 return false; 378 return false;
379 379
380 if (PCMBUF_SIZE - audiobuffer_free <= PCM_WATERMARK) 380 if (pcmbuf_unplayed_bytes < PCM_WATERMARK)
381 return true; 381 return true;
382 382
383 return false; 383 return false;
@@ -421,8 +421,7 @@ bool audiobuffer_insert(char *buf, size_t length)
421 size_t copy_n = 0; 421 size_t copy_n = 0;
422 422
423 if (audiobuffer_free < length + CHUNK_SIZE && !crossfade_active) { 423 if (audiobuffer_free < length + CHUNK_SIZE && !crossfade_active) {
424 if (!boost_mode) 424 pcm_boost(false);
425 pcm_boost(false);
426 return false; 425 return false;
427 } 426 }
428 427
@@ -448,7 +447,7 @@ bool audiobuffer_insert(char *buf, size_t length)
448 } else { 447 } else {
449 copy_n = MIN(length, PCMBUF_SIZE - audiobuffer_pos - 448 copy_n = MIN(length, PCMBUF_SIZE - audiobuffer_pos -
450 audiobuffer_fillpos); 449 audiobuffer_fillpos);
451 copy_n = MIN(CHUNK_SIZE, copy_n); 450 copy_n = MIN(CHUNK_SIZE - audiobuffer_fillpos, copy_n);
452 451
453 memcpy(&audiobuffer[audiobuffer_pos+audiobuffer_fillpos], 452 memcpy(&audiobuffer[audiobuffer_pos+audiobuffer_fillpos],
454 buf, copy_n); 453 buf, copy_n);
@@ -467,8 +466,7 @@ bool audiobuffer_insert(char *buf, size_t length)
467 466
468 while (!pcm_play_add_chunk(&audiobuffer[audiobuffer_pos], 467 while (!pcm_play_add_chunk(&audiobuffer[audiobuffer_pos],
469 copy_n, NULL)) { 468 copy_n, NULL)) {
470 if (!boost_mode) 469 pcm_boost(false);
471 pcm_boost(false);
472 yield(); 470 yield();
473 } 471 }
474 472