summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/mp3data.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/firmware/mp3data.c b/firmware/mp3data.c
index 5baa9ec149..38fae384e0 100644
--- a/firmware/mp3data.c
+++ b/firmware/mp3data.c
@@ -646,7 +646,23 @@ int create_xing_header(int fd, int startpos, int filesize,
646 } 646 }
647 647
648 /* Fill in the TOC entry */ 648 /* Fill in the TOC entry */
649 toc[i] = filepos * 256 / filesize; 649 /* each toc is a single byte indicating how many 256ths of the
650 * way through the file, is that percent of the way through the
651 * song. the easy method, filepos*256/filesize, chokes when
652 * the upper 8 bits of the file position are nonzero
653 * (i.e. files over 16mb in size).
654 */
655 if (filepos > 0xFFFFFF)
656 {
657 /* instead of multiplying filepos by 256, we divide
658 * filesize by 256.
659 */
660 toc[i] = filepos / (filesize >> 8);
661 }
662 else
663 {
664 toc[i] = filepos * 256 / filesize;
665 }
650 666
651 DEBUGF("Pos %d: %d relpos: %d filepos: %x tocentry: %x\n", 667 DEBUGF("Pos %d: %d relpos: %d filepos: %x tocentry: %x\n",
652 i, pos, pos-last_pos, filepos, toc[i]); 668 i, pos, pos-last_pos, filepos, toc[i]);