diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/pcm_playback.h | 6 | ||||
-rw-r--r-- | firmware/pcm_playback.c | 35 |
2 files changed, 23 insertions, 18 deletions
diff --git a/firmware/export/pcm_playback.h b/firmware/export/pcm_playback.h index 3fe60670b3..07e33e96bf 100644 --- a/firmware/export/pcm_playback.h +++ b/firmware/export/pcm_playback.h | |||
@@ -48,9 +48,9 @@ bool pcm_is_lowdata(void); | |||
48 | bool pcm_crossfade_init(void); | 48 | bool pcm_crossfade_init(void); |
49 | void audiobuffer_add_event(void (*event_handler)(void)); | 49 | void audiobuffer_add_event(void (*event_handler)(void)); |
50 | unsigned int audiobuffer_get_latency(void); | 50 | unsigned int audiobuffer_get_latency(void); |
51 | bool pcm_insert_buffer(char *buf, size_t length); | 51 | bool pcm_insert_buffer(char *buf, long length); |
52 | void pcm_flush_buffer(size_t length); | 52 | void pcm_flush_buffer(long length); |
53 | void* pcm_request_buffer(size_t length, size_t *realsize); | 53 | void* pcm_request_buffer(long length, long *realsize); |
54 | bool pcm_is_crossfade_enabled(void); | 54 | bool pcm_is_crossfade_enabled(void); |
55 | void pcm_crossfade_enable(bool on_off); | 55 | void pcm_crossfade_enable(bool on_off); |
56 | 56 | ||
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c index 89e72c76a0..b0bdfbbb32 100644 --- a/firmware/pcm_playback.c +++ b/firmware/pcm_playback.c | |||
@@ -55,9 +55,9 @@ static bool pcm_paused; | |||
55 | static int pcm_freq = 0x6; /* 44.1 is default */ | 55 | static int pcm_freq = 0x6; /* 44.1 is default */ |
56 | 56 | ||
57 | static char *audiobuffer; | 57 | static char *audiobuffer; |
58 | static size_t audiobuffer_pos; | 58 | static long audiobuffer_pos; |
59 | size_t audiobuffer_free; | 59 | long audiobuffer_free; |
60 | static size_t audiobuffer_fillpos; | 60 | static long audiobuffer_fillpos; |
61 | static bool boost_mode; | 61 | static bool boost_mode; |
62 | 62 | ||
63 | static bool crossfade_enabled; | 63 | static bool crossfade_enabled; |
@@ -457,7 +457,7 @@ int crossfade(short *buf, const short *buf2, int length) | |||
457 | return size; | 457 | return size; |
458 | } | 458 | } |
459 | 459 | ||
460 | inline static bool prepare_insert(size_t length) | 460 | inline static bool prepare_insert(long length) |
461 | { | 461 | { |
462 | crossfade_start(); | 462 | crossfade_start(); |
463 | if (audiobuffer_free < length + audiobuffer_fillpos | 463 | if (audiobuffer_free < length + audiobuffer_fillpos |
@@ -476,7 +476,7 @@ inline static bool prepare_insert(size_t length) | |||
476 | return true; | 476 | return true; |
477 | } | 477 | } |
478 | 478 | ||
479 | void* pcm_request_buffer(size_t length, size_t *realsize) | 479 | void* pcm_request_buffer(long length, long *realsize) |
480 | { | 480 | { |
481 | void *ptr = NULL; | 481 | void *ptr = NULL; |
482 | 482 | ||
@@ -487,13 +487,15 @@ void* pcm_request_buffer(size_t length, size_t *realsize) | |||
487 | 487 | ||
488 | if (crossfade_active) { | 488 | if (crossfade_active) { |
489 | *realsize = MIN(length, PCMBUF_GUARD); | 489 | *realsize = MIN(length, PCMBUF_GUARD); |
490 | //logf("cfb:%d/%d", *realsize, length); | ||
490 | ptr = &guardbuf[0]; | 491 | ptr = &guardbuf[0]; |
491 | } else { | 492 | } else { |
492 | *realsize = MIN(length, PCMBUF_SIZE - audiobuffer_pos | 493 | *realsize = MIN(length, PCMBUF_SIZE - audiobuffer_pos |
493 | - audiobuffer_fillpos); | 494 | - audiobuffer_fillpos); |
494 | if (*realsize < length) { | 495 | if (*realsize < length) { |
496 | //logf("gbr1:%d/%d", *realsize, length); | ||
495 | *realsize += MIN((long)(length - *realsize), PCMBUF_GUARD); | 497 | *realsize += MIN((long)(length - *realsize), PCMBUF_GUARD); |
496 | //logf("gbr:%d/%d", *realsize, length); | 498 | //logf("gbr2:%d/%d", *realsize, length); |
497 | } | 499 | } |
498 | ptr = &audiobuffer[audiobuffer_pos + audiobuffer_fillpos]; | 500 | ptr = &audiobuffer[audiobuffer_pos + audiobuffer_fillpos]; |
499 | } | 501 | } |
@@ -501,16 +503,18 @@ void* pcm_request_buffer(size_t length, size_t *realsize) | |||
501 | return ptr; | 503 | return ptr; |
502 | } | 504 | } |
503 | 505 | ||
504 | void pcm_flush_buffer(size_t length) | 506 | void pcm_flush_buffer(long length) |
505 | { | 507 | { |
506 | int copy_n; | 508 | int copy_n; |
507 | char *buf; | 509 | char *buf; |
508 | 510 | ||
509 | if (crossfade_active) { | 511 | if (crossfade_active) { |
512 | //logf("cfbf"); | ||
510 | buf = &guardbuf[0]; | 513 | buf = &guardbuf[0]; |
511 | length = MIN(length, PCMBUF_GUARD); | 514 | length = MIN(length, PCMBUF_GUARD); |
512 | while (length > 0 && crossfade_active) { | 515 | while (length > 0 && crossfade_active) { |
513 | copy_n = MIN(length, PCMBUF_SIZE - (unsigned int)crossfade_pos); | 516 | //logf("cfl:%d", length); |
517 | copy_n = MIN(length, PCMBUF_SIZE - crossfade_pos); | ||
514 | copy_n = 2 * crossfade((short *)&audiobuffer[crossfade_pos], | 518 | copy_n = 2 * crossfade((short *)&audiobuffer[crossfade_pos], |
515 | (const short *)buf, copy_n/2); | 519 | (const short *)buf, copy_n/2); |
516 | buf += copy_n; | 520 | buf += copy_n; |
@@ -521,7 +525,8 @@ void pcm_flush_buffer(size_t length) | |||
521 | } | 525 | } |
522 | 526 | ||
523 | while (length > 0) { | 527 | while (length > 0) { |
524 | copy_n = MIN(length, PCMBUF_SIZE - (unsigned)audiobuffer_pos); | 528 | //logf("cfl2:%d", length); |
529 | copy_n = MIN(length, PCMBUF_SIZE - audiobuffer_pos); | ||
525 | memcpy(&audiobuffer[audiobuffer_pos], buf, copy_n); | 530 | memcpy(&audiobuffer[audiobuffer_pos], buf, copy_n); |
526 | audiobuffer_fillpos = copy_n; | 531 | audiobuffer_fillpos = copy_n; |
527 | buf += copy_n; | 532 | buf += copy_n; |
@@ -538,12 +543,12 @@ void pcm_flush_buffer(size_t length) | |||
538 | - audiobuffer_pos - audiobuffer_fillpos > 0) | 543 | - audiobuffer_pos - audiobuffer_fillpos > 0) |
539 | return ; | 544 | return ; |
540 | 545 | ||
541 | copy_n = MIN((long)(audiobuffer_fillpos - (PCMBUF_SIZE | 546 | copy_n = audiobuffer_fillpos - (PCMBUF_SIZE - audiobuffer_pos); |
542 | - audiobuffer_pos)), PCMBUF_GUARD); | ||
543 | if (copy_n > 0) { | 547 | if (copy_n > 0) { |
544 | //logf("guard buf used:%d", copy_n); | 548 | //logf("gbu:%d/%d/%d", copy_n, audiobuffer_fillpos, audiobuffer_pos); |
545 | audiobuffer_fillpos -= copy_n; | 549 | audiobuffer_fillpos -= copy_n; |
546 | pcm_flush_fillpos(); | 550 | pcm_flush_fillpos(); |
551 | copy_n = MIN(copy_n, PCMBUF_GUARD); | ||
547 | memcpy(&audiobuffer[0], &guardbuf[0], copy_n); | 552 | memcpy(&audiobuffer[0], &guardbuf[0], copy_n); |
548 | audiobuffer_fillpos = copy_n; | 553 | audiobuffer_fillpos = copy_n; |
549 | goto try_flush; | 554 | goto try_flush; |
@@ -551,16 +556,16 @@ void pcm_flush_buffer(size_t length) | |||
551 | pcm_flush_fillpos(); | 556 | pcm_flush_fillpos(); |
552 | } | 557 | } |
553 | 558 | ||
554 | bool pcm_insert_buffer(char *buf, size_t length) | 559 | bool pcm_insert_buffer(char *buf, long length) |
555 | { | 560 | { |
556 | size_t copy_n = 0; | 561 | long copy_n = 0; |
557 | 562 | ||
558 | if (!prepare_insert(length)) | 563 | if (!prepare_insert(length)) |
559 | return false; | 564 | return false; |
560 | 565 | ||
561 | while (length > 0) { | 566 | while (length > 0) { |
562 | if (crossfade_active) { | 567 | if (crossfade_active) { |
563 | copy_n = MIN(length, PCMBUF_SIZE - (unsigned int)crossfade_pos); | 568 | copy_n = MIN(length, PCMBUF_SIZE - crossfade_pos); |
564 | 569 | ||
565 | copy_n = 2 * crossfade((short *)&audiobuffer[crossfade_pos], | 570 | copy_n = 2 * crossfade((short *)&audiobuffer[crossfade_pos], |
566 | (const short *)buf, copy_n/2); | 571 | (const short *)buf, copy_n/2); |