diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/mpeg.c | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 9906620fdb..7966625f72 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -523,7 +523,7 @@ static void mpeg_thread(void) | |||
523 | while(1) | 523 | while(1) |
524 | { | 524 | { |
525 | DEBUGF("S R:%x W:%x SW:%x\n", | 525 | DEBUGF("S R:%x W:%x SW:%x\n", |
526 | mp3buf_read, mp3buf_write, mp3buf_swapwrite); | 526 | mp3buf_read, mp3buf_write, mp3buf_swapwrite); |
527 | yield(); | 527 | yield(); |
528 | queue_wait(&mpeg_queue, &ev); | 528 | queue_wait(&mpeg_queue, &ev); |
529 | switch(ev.id) | 529 | switch(ev.id) |
@@ -595,16 +595,16 @@ static void mpeg_thread(void) | |||
595 | close(mpeg_file); | 595 | close(mpeg_file); |
596 | last_tag=0; | 596 | last_tag=0; |
597 | if (new_file(true) < 0) { | 597 | if (new_file(true) < 0) { |
598 | DEBUGF("Finished Playing!\n"); | 598 | DEBUGF("Finished Playing!\n"); |
599 | filling = false; | 599 | filling = false; |
600 | } else { | 600 | } else { |
601 | /* Make it read more data */ | 601 | /* Make it read more data */ |
602 | filling = true; | 602 | filling = true; |
603 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | 603 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); |
604 | 604 | ||
605 | /* Tell the file loading code that we want to start playing | 605 | /* Tell the file loading code that we want to start playing |
606 | as soon as we have some data */ | 606 | as soon as we have some data */ |
607 | play_pending = true; | 607 | play_pending = true; |
608 | } | 608 | } |
609 | break; | 609 | break; |
610 | 610 | ||
@@ -621,16 +621,16 @@ static void mpeg_thread(void) | |||
621 | close(mpeg_file); | 621 | close(mpeg_file); |
622 | last_tag=0; | 622 | last_tag=0; |
623 | if (new_file(false) < 0) { | 623 | if (new_file(false) < 0) { |
624 | DEBUGF("Finished Playing!\n"); | 624 | DEBUGF("Finished Playing!\n"); |
625 | filling = false; | 625 | filling = false; |
626 | } else { | 626 | } else { |
627 | /* Make it read more data */ | 627 | /* Make it read more data */ |
628 | filling = true; | 628 | filling = true; |
629 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | 629 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); |
630 | 630 | ||
631 | /* Tell the file loading code that we want to start playing | 631 | /* Tell the file loading code that we want to start playing |
632 | as soon as we have some data */ | 632 | as soon as we have some data */ |
633 | play_pending = true; | 633 | play_pending = true; |
634 | } | 634 | } |
635 | break; | 635 | break; |
636 | 636 | ||
@@ -643,13 +643,13 @@ static void mpeg_thread(void) | |||
643 | if(free_space_left < 0) | 643 | if(free_space_left < 0) |
644 | free_space_left = mp3buflen + free_space_left; | 644 | free_space_left = mp3buflen + free_space_left; |
645 | 645 | ||
646 | amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); | 646 | amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); |
647 | if(mp3buf_write < mp3buf_swapwrite) | 647 | if(mp3buf_write < mp3buf_swapwrite) |
648 | amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite, | 648 | amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite, |
649 | amount_to_swap); | 649 | amount_to_swap); |
650 | else | 650 | else |
651 | amount_to_swap = MIN(mp3buf_write - mp3buf_swapwrite, | 651 | amount_to_swap = MIN(mp3buf_write - mp3buf_swapwrite, |
652 | amount_to_swap); | 652 | amount_to_swap); |
653 | 653 | ||
654 | DEBUGF("B %x\n", amount_to_swap); | 654 | DEBUGF("B %x\n", amount_to_swap); |
655 | bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite), | 655 | bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite), |
@@ -669,20 +669,20 @@ static void mpeg_thread(void) | |||
669 | playing yet. If not, do it. */ | 669 | playing yet. If not, do it. */ |
670 | if(play_pending) | 670 | if(play_pending) |
671 | { | 671 | { |
672 | if((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER) | 672 | if((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER) |
673 | { | 673 | { |
674 | DEBUGF("P\n"); | 674 | DEBUGF("P\n"); |
675 | play_pending = false; | 675 | play_pending = false; |
676 | playing = true; | 676 | playing = true; |
677 | 677 | ||
678 | last_dma_tick = current_tick; | 678 | last_dma_tick = current_tick; |
679 | init_dma(); | 679 | init_dma(); |
680 | start_dma(); | 680 | start_dma(); |
681 | 681 | ||
682 | /* Tell ourselves that we need more data */ | 682 | /* Tell ourselves that we need more data */ |
683 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | 683 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); |
684 | 684 | ||
685 | } | 685 | } |
686 | } | 686 | } |
687 | break; | 687 | break; |
688 | 688 | ||
@@ -693,7 +693,7 @@ static void mpeg_thread(void) | |||
693 | if(free_space_left <= 0) | 693 | if(free_space_left <= 0) |
694 | free_space_left = mp3buflen + free_space_left; | 694 | free_space_left = mp3buflen + free_space_left; |
695 | 695 | ||
696 | unplayed_space_left = mp3buflen - free_space_left; | 696 | unplayed_space_left = mp3buflen - free_space_left; |
697 | 697 | ||
698 | /* Make sure that we don't fill the entire buffer */ | 698 | /* Make sure that we don't fill the entire buffer */ |
699 | free_space_left -= 2; | 699 | free_space_left -= 2; |
@@ -713,11 +713,11 @@ static void mpeg_thread(void) | |||
713 | } | 713 | } |
714 | else | 714 | else |
715 | { | 715 | { |
716 | if(unplayed_space_left < MPEG_LOW_WATER) | 716 | if(unplayed_space_left < MPEG_LOW_WATER) |
717 | amount_to_read = MIN(MPEG_LOW_WATER_CHUNKSIZE, | 717 | amount_to_read = MIN(MPEG_LOW_WATER_CHUNKSIZE, |
718 | free_space_left); | 718 | free_space_left); |
719 | else | 719 | else |
720 | amount_to_read = MIN(MPEG_CHUNKSIZE, free_space_left); | 720 | amount_to_read = MIN(MPEG_CHUNKSIZE, free_space_left); |
721 | } | 721 | } |
722 | amount_to_read = MIN(mp3buflen - mp3buf_write, amount_to_read); | 722 | amount_to_read = MIN(mp3buflen - mp3buf_write, amount_to_read); |
723 | 723 | ||
@@ -731,10 +731,15 @@ static void mpeg_thread(void) | |||
731 | len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); | 731 | len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); |
732 | if(len > 0) | 732 | if(len > 0) |
733 | { | 733 | { |
734 | DEBUGF("R: %x\n", len); | 734 | DEBUGF("R: %x\n", len); |
735 | /* Tell ourselves that we need to swap some data */ | 735 | /* Tell ourselves that we need to swap some data */ |
736 | queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0); | 736 | queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0); |
737 | 737 | ||
738 | /* Make sure that the write pointer is at a word | ||
739 | boundary when we reach the end of the file */ | ||
740 | if(len < amount_to_read) | ||
741 | mp3buf_write = (mp3buf_write + 1) & 0xfffffffe; | ||
742 | |||
738 | mp3buf_write += len; | 743 | mp3buf_write += len; |
739 | if(mp3buf_write >= mp3buflen) | 744 | if(mp3buf_write >= mp3buflen) |
740 | { | 745 | { |
@@ -742,11 +747,11 @@ static void mpeg_thread(void) | |||
742 | DEBUGF("W\n"); | 747 | DEBUGF("W\n"); |
743 | } | 748 | } |
744 | 749 | ||
745 | if(!play_pending) | 750 | if(!play_pending) |
746 | { | 751 | { |
747 | /* Tell ourselves that we want more data */ | 752 | /* Tell ourselves that we want more data */ |
748 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | 753 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); |
749 | } | 754 | } |
750 | } | 755 | } |
751 | else | 756 | else |
752 | { | 757 | { |