diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2004-01-13 14:06:18 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2004-01-13 14:06:18 +0000 |
commit | 1936c413a8242027a5430d844ddf308e451e8a2c (patch) | |
tree | 4a8a553dcad0d24c64f7e586c84dfddafa404fe8 /firmware | |
parent | bc9f60deb79c319ee257f84c09b5566d9a1244d4 (diff) | |
download | rockbox-1936c413a8242027a5430d844ddf308e451e8a2c.tar.gz rockbox-1936c413a8242027a5430d844ddf308e451e8a2c.zip |
Slightly improved VBR fixer, now uses the same template header throughout the entire file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4225 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/mp3data.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/firmware/mp3data.c b/firmware/mp3data.c index 896ecda7f0..5b56c6f6e4 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c | |||
@@ -246,7 +246,7 @@ static unsigned long __find_next_frame(int fd, int *offset, int max_offset, unsi | |||
246 | 246 | ||
247 | *offset = pos - 4; | 247 | *offset = pos - 4; |
248 | 248 | ||
249 | #ifdef DEBUG | 249 | #if defined(DEBUG) || defined(SIMULATOR) |
250 | if(*offset) | 250 | if(*offset) |
251 | DEBUGF("Warning: skipping %d bytes of garbage\n", *offset); | 251 | DEBUGF("Warning: skipping %d bytes of garbage\n", *offset); |
252 | #endif | 252 | #endif |
@@ -547,6 +547,7 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
547 | int progress_cnt = 0; | 547 | int progress_cnt = 0; |
548 | bool is_vbr = false; | 548 | bool is_vbr = false; |
549 | int last_bitrate = 0; | 549 | int last_bitrate = 0; |
550 | int header_template = 0; | ||
550 | 551 | ||
551 | if(lseek(fd, startpos, SEEK_SET) < 0) | 552 | if(lseek(fd, startpos, SEEK_SET) < 0) |
552 | return -1; | 553 | return -1; |
@@ -557,9 +558,12 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
557 | num_frames = 0; | 558 | num_frames = 0; |
558 | cnt = 0; | 559 | cnt = 0; |
559 | 560 | ||
560 | while((header = buf_find_next_frame(fd, &bytes, -1, header))) { | 561 | while((header = buf_find_next_frame(fd, &bytes, -1, header_template))) { |
561 | mp3headerinfo(&info, header); | 562 | mp3headerinfo(&info, header); |
562 | 563 | ||
564 | if(!header_template) | ||
565 | header_template = header; | ||
566 | |||
563 | /* See if this really is a VBR file */ | 567 | /* See if this really is a VBR file */ |
564 | if(last_bitrate && info.bitrate != last_bitrate) | 568 | if(last_bitrate && info.bitrate != last_bitrate) |
565 | { | 569 | { |
@@ -607,8 +611,12 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
607 | int x; | 611 | int x; |
608 | int index; | 612 | int index; |
609 | unsigned char toc[100]; | 613 | unsigned char toc[100]; |
614 | unsigned long xing_header_template = 0; | ||
610 | 615 | ||
611 | DEBUGF("create_xing_header()\n"); | 616 | DEBUGF("create_xing_header()\n"); |
617 | |||
618 | if(header_template) | ||
619 | xing_header_template = header_template; | ||
612 | 620 | ||
613 | if(generate_toc) | 621 | if(generate_toc) |
614 | { | 622 | { |
@@ -627,19 +635,22 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
627 | /* Advance from the last seek point to this one */ | 635 | /* Advance from the last seek point to this one */ |
628 | for(j = 0;j < pos - last_pos;j++) | 636 | for(j = 0;j < pos - last_pos;j++) |
629 | { | 637 | { |
630 | DEBUGF("fpos: %x frame no: %x\n", filepos, x++); | 638 | header = buf_find_next_frame(fd, &bytes, -1, header_template); |
631 | header = buf_find_next_frame(fd, &bytes, -1, header); | 639 | filepos += bytes; |
632 | mp3headerinfo(&info, header); | 640 | mp3headerinfo(&info, header); |
633 | buf_seek(fd, info.frame_size-4); | 641 | buf_seek(fd, info.frame_size-4); |
634 | filepos += info.frame_size; | 642 | filepos += info.frame_size; |
643 | |||
644 | if(!header_template) | ||
645 | header_template = header; | ||
635 | } | 646 | } |
636 | 647 | ||
637 | /* Save a header for later use if header_template is empty. | 648 | /* Save a header for later use if header_template is empty. |
638 | We only save one header, and we want to save one in the | 649 | We only save one header, and we want to save one in the |
639 | middle of the stream, just in case the first and the last | 650 | middle of the stream, just in case the first and the last |
640 | headers are corrupt. */ | 651 | headers are corrupt. */ |
641 | if(!header_template && i == 1) | 652 | if(!xing_header_template && i == 1) |
642 | header_template = header; | 653 | xing_header_template = header; |
643 | 654 | ||
644 | if(progressfunc) | 655 | if(progressfunc) |
645 | { | 656 | { |
@@ -676,7 +687,7 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
676 | memset(buf, 0, 1500); | 687 | memset(buf, 0, 1500); |
677 | 688 | ||
678 | /* Use the template header and create a new one */ | 689 | /* Use the template header and create a new one */ |
679 | mp3headerinfo(&info, header_template); | 690 | mp3headerinfo(&info, xing_header_template); |
680 | 691 | ||
681 | /* calculate position of VBR header */ | 692 | /* calculate position of VBR header */ |
682 | if ( info.version == MPEG_VERSION1 ) { | 693 | if ( info.version == MPEG_VERSION1 ) { |
@@ -694,7 +705,7 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
694 | 705 | ||
695 | /* We ignore the Protection bit even if the rest of the stream is | 706 | /* We ignore the Protection bit even if the rest of the stream is |
696 | protected. (fixme?) */ | 707 | protected. (fixme?) */ |
697 | header = header_template & ~(BITRATE_MASK | PROTECTION_MASK); | 708 | header = xing_header_template & ~(BITRATE_MASK | PROTECTION_MASK); |
698 | header |= 8 << 12; /* This gives us plenty of space, at least 192 bytes */ | 709 | header |= 8 << 12; /* This gives us plenty of space, at least 192 bytes */ |
699 | 710 | ||
700 | /* Write the header to the buffer */ | 711 | /* Write the header to the buffer */ |