summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/pcm_playback.h1
-rw-r--r--firmware/pcm_playback.c11
2 files changed, 9 insertions, 3 deletions
diff --git a/firmware/export/pcm_playback.h b/firmware/export/pcm_playback.h
index 960641531a..c78936a3f2 100644
--- a/firmware/export/pcm_playback.h
+++ b/firmware/export/pcm_playback.h
@@ -43,6 +43,7 @@ void pcm_play_set_watermark(int numbytes, void (*callback)(int bytes_left));
43void pcm_set_boost_mode(bool state); 43void pcm_set_boost_mode(bool state);
44bool pcm_is_lowdata(void); 44bool pcm_is_lowdata(void);
45bool pcm_crossfade_start(void); 45bool pcm_crossfade_start(void);
46void audiobuffer_add_event(void (*event_handler)(void));
46unsigned int audiobuffer_get_latency(void); 47unsigned int audiobuffer_get_latency(void);
47bool audiobuffer_insert(char *buf, size_t length); 48bool audiobuffer_insert(char *buf, size_t length);
48bool pcm_is_crossfade_enabled(void); 49bool pcm_is_crossfade_enabled(void);
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c
index b18238cd3e..45e91ac3be 100644
--- a/firmware/pcm_playback.c
+++ b/firmware/pcm_playback.c
@@ -62,6 +62,8 @@ static int crossfade_pos;
62static int crossfade_amount; 62static int crossfade_amount;
63static int crossfade_rem; 63static int crossfade_rem;
64 64
65static void (*pcm_event_handler)(void);
66
65static unsigned char *next_start; 67static unsigned char *next_start;
66static long next_size; 68static long next_size;
67 69
@@ -202,6 +204,8 @@ static void pcm_play_callback(unsigned char** start, long* size)
202 { 204 {
203 /* No more buffers */ 205 /* No more buffers */
204 *size = 0; 206 *size = 0;
207 if (pcm_event_handler)
208 pcm_event_handler();
205 } 209 }
206#if 1 210#if 1
207 if(pcmbuf_unplayed_bytes <= pcmbuf_watermark) 211 if(pcmbuf_unplayed_bytes <= pcmbuf_watermark)
@@ -363,8 +367,7 @@ void pcm_set_boost_mode(bool state)
363 367
364void audiobuffer_add_event(void (*event_handler)(void)) 368void audiobuffer_add_event(void (*event_handler)(void))
365{ 369{
366 while (!pcm_play_add_chunk(NULL, 0, event_handler)) 370 pcm_event_handler = event_handler;
367 yield();
368} 371}
369 372
370unsigned int audiobuffer_get_latency(void) 373unsigned int audiobuffer_get_latency(void)
@@ -474,10 +477,11 @@ bool audiobuffer_insert(char *buf, size_t length)
474 copy_n += audiobuffer_fillpos; 477 copy_n += audiobuffer_fillpos;
475 478
476 while (!pcm_play_add_chunk(&audiobuffer[audiobuffer_pos], 479 while (!pcm_play_add_chunk(&audiobuffer[audiobuffer_pos],
477 copy_n, NULL)) { 480 copy_n, pcm_event_handler)) {
478 pcm_boost(false); 481 pcm_boost(false);
479 yield(); 482 yield();
480 } 483 }
484 pcm_event_handler = NULL;
481 485
482 audiobuffer_pos += copy_n; 486 audiobuffer_pos += copy_n;
483 audiobuffer_fillpos = 0; 487 audiobuffer_fillpos = 0;
@@ -502,6 +506,7 @@ void pcm_play_init(void)
502 pcmbuf_write_index = 0; 506 pcmbuf_write_index = 0;
503 pcmbuf_unplayed_bytes = 0; 507 pcmbuf_unplayed_bytes = 0;
504 crossfade_enabled = false; 508 crossfade_enabled = false;
509 pcm_event_handler = NULL;
505 pcm_play_set_watermark(PCM_WATERMARK, pcm_watermark_callback); 510 pcm_play_set_watermark(PCM_WATERMARK, pcm_watermark_callback);
506} 511}
507 512