diff options
Diffstat (limited to 'firmware/mp3data.c')
-rw-r--r-- | firmware/mp3data.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/firmware/mp3data.c b/firmware/mp3data.c index 44c298a463..6f4c560578 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c | |||
@@ -607,8 +607,8 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
607 | static const char cooltext[] = "Rockbox - rocks your box"; | 607 | static const char cooltext[] = "Rockbox - rocks your box"; |
608 | 608 | ||
609 | int create_xing_header(int fd, int startpos, int filesize, | 609 | int create_xing_header(int fd, int startpos, int filesize, |
610 | unsigned char *buf, int num_frames, | 610 | unsigned char *buf, /* must be at least 288 bytes */ |
611 | unsigned long header_template, | 611 | int num_frames, unsigned long header_template, |
612 | void (*progressfunc)(int), bool generate_toc) | 612 | void (*progressfunc)(int), bool generate_toc) |
613 | { | 613 | { |
614 | unsigned long header = 0; | 614 | unsigned long header = 0; |
@@ -691,35 +691,40 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
691 | last_pos = pos; | 691 | last_pos = pos; |
692 | } | 692 | } |
693 | } | 693 | } |
694 | 694 | ||
695 | /* Use the template header and create a new one. | 695 | /* Check the template header for validity and get some preliminary info. */ |
696 | We ignore the Protection bit even if the rest of the stream is | 696 | if (!mp3headerinfo(&info, xing_header_template)) |
697 | protected. (fixme?) */ | 697 | return 0; /* invalid header */ |
698 | header = xing_header_template & ~(BITRATE_MASK | PROTECTION_MASK); | ||
699 | header |= 8 << 12; /* This gives us plenty of space, at least 192 bytes */ | ||
700 | |||
701 | if (!mp3headerinfo(&info, header)) | ||
702 | return 0; /* invalid header */ | ||
703 | 698 | ||
704 | /* Clear the frame */ | 699 | /* Clear the frame */ |
705 | memset(buf, 0, 1500); | 700 | memset(buf, 0, MAX_XING_HEADER_SIZE); |
706 | 701 | ||
707 | /* Write the header to the buffer */ | 702 | /* Use the template header and create a new one. */ |
708 | long2bytes(buf, header); | 703 | header = xing_header_template & ~(BITRATE_MASK | PROTECTION_MASK); |
709 | 704 | ||
710 | /* calculate position of VBR header */ | 705 | /* Calculate position of VBR header and required frame bitrate */ |
711 | if ( info.version == MPEG_VERSION1 ) { | 706 | if (info.version == MPEG_VERSION1) { |
707 | header |= 5 << 12; | ||
712 | if (info.channel_mode == 3) /* mono */ | 708 | if (info.channel_mode == 3) /* mono */ |
713 | index = 21; | 709 | index = 21; |
714 | else | 710 | else |
715 | index = 36; | 711 | index = 36; |
716 | } | 712 | } |
717 | else { | 713 | else { |
714 | if (info.version == MPEG_VERSION2) | ||
715 | header |= 8 << 12; | ||
716 | else /* MPEG_VERSION2_5 */ | ||
717 | header |= 4 << 12; | ||
718 | if (info.channel_mode == 3) /* mono */ | 718 | if (info.channel_mode == 3) /* mono */ |
719 | index = 13; | 719 | index = 13; |
720 | else | 720 | else |
721 | index = 21; | 721 | index = 21; |
722 | } | 722 | } |
723 | mp3headerinfo(&info, header); /* Get final header info */ | ||
724 | /* Size is now always one of 192, 208 or 288 bytes */ | ||
725 | |||
726 | /* Write the header to the buffer */ | ||
727 | long2bytes(buf, header); | ||
723 | 728 | ||
724 | /* Create the Xing data */ | 729 | /* Create the Xing data */ |
725 | memcpy(&buf[index], "Xing", 4); | 730 | memcpy(&buf[index], "Xing", 4); |