summaryrefslogtreecommitdiff
path: root/firmware/pcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/pcm.c')
-rw-r--r--firmware/pcm.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/firmware/pcm.c b/firmware/pcm.c
index c2ebc67687..b0a91fb64e 100644
--- a/firmware/pcm.c
+++ b/firmware/pcm.c
@@ -43,6 +43,7 @@
43 * Semi-private - 43 * Semi-private -
44 * pcm_play_get_more_callback 44 * pcm_play_get_more_callback
45 * pcm_play_dma_init 45 * pcm_play_dma_init
46 * pcm_play_dma_postinit
46 * pcm_play_dma_start 47 * pcm_play_dma_start
47 * pcm_play_dma_stop 48 * pcm_play_dma_stop
48 * pcm_play_dma_pause 49 * pcm_play_dma_pause
@@ -79,6 +80,9 @@
79 * 80 *
80 */ 81 */
81 82
83/* 'true' when all stages of pcm initialization have completed */
84static bool pcm_is_ready = false;
85
82/* the registered callback function to ask for more mp3 data */ 86/* the registered callback function to ask for more mp3 data */
83static pcm_play_callback_type pcm_callback_for_more SHAREDBSS_ATTR = NULL; 87static pcm_play_callback_type pcm_callback_for_more SHAREDBSS_ATTR = NULL;
84void (* pcm_play_dma_started)(void) SHAREDBSS_ATTR = NULL; 88void (* pcm_play_dma_started)(void) SHAREDBSS_ATTR = NULL;
@@ -105,6 +109,12 @@ static void pcm_play_stopped(void)
105 pcm_playing = false; 109 pcm_playing = false;
106} 110}
107 111
112static void pcm_wait_for_init(void)
113{
114 while (!pcm_is_ready)
115 sleep(0);
116}
117
108/** 118/**
109 * Perform peak calculation on a buffer of packed 16-bit samples. 119 * Perform peak calculation on a buffer of packed 16-bit samples.
110 * 120 *
@@ -230,6 +240,23 @@ void pcm_init(void)
230 pcm_play_dma_init(); 240 pcm_play_dma_init();
231} 241}
232 242
243/* Finish delayed init */
244void pcm_postinit(void)
245{
246 logf("pcm_postinit");
247
248 logf(" pcm_play_dma_postinit");
249
250 pcm_play_dma_postinit();
251
252 pcm_is_ready = true;
253}
254
255bool pcm_is_initialized(void)
256{
257 return pcm_is_ready;
258}
259
233/* Common code to pcm_play_data and pcm_play_pause */ 260/* Common code to pcm_play_data and pcm_play_pause */
234static void pcm_play_data_start(unsigned char *start, size_t size) 261static void pcm_play_data_start(unsigned char *start, size_t size)
235{ 262{
@@ -402,6 +429,8 @@ void pcm_apply_settings(void)
402{ 429{
403 logf("pcm_apply_settings"); 430 logf("pcm_apply_settings");
404 431
432 pcm_wait_for_init();
433
405 if (pcm_sampr != pcm_curr_sampr) 434 if (pcm_sampr != pcm_curr_sampr)
406 { 435 {
407 logf(" pcm_dma_apply_settings"); 436 logf(" pcm_dma_apply_settings");
@@ -487,6 +516,8 @@ void pcm_init_recording(void)
487{ 516{
488 logf("pcm_init_recording"); 517 logf("pcm_init_recording");
489 518
519 pcm_wait_for_init();
520
490 /* Stop the beasty before attempting recording */ 521 /* Stop the beasty before attempting recording */
491 mixer_reset(); 522 mixer_reset();
492 523