summaryrefslogtreecommitdiff
path: root/apps/metadata/mp4.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata/mp4.c')
-rw-r--r--apps/metadata/mp4.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/apps/metadata/mp4.c b/apps/metadata/mp4.c
index c9c691f0c4..a3721f0e9a 100644
--- a/apps/metadata/mp4.c
+++ b/apps/metadata/mp4.c
@@ -639,7 +639,10 @@ static bool read_mp4_container(int fd, struct mp3entry* id3,
639 { 639 {
640 uint32_t entries; 640 uint32_t entries;
641 unsigned int i; 641 unsigned int i;
642 642
643 /* Reset to false. */
644 id3->needs_upsampling_correction = true;
645
643 lseek(fd, 4, SEEK_CUR); 646 lseek(fd, 4, SEEK_CUR);
644 read_uint32be(fd, &entries); 647 read_uint32be(fd, &entries);
645 id3->samples = 0; 648 id3->samples = 0;
@@ -651,7 +654,21 @@ static bool read_mp4_container(int fd, struct mp3entry* id3,
651 654
652 read_uint32be(fd, &n); 655 read_uint32be(fd, &n);
653 read_uint32be(fd, &l); 656 read_uint32be(fd, &l);
654 id3->samples += n * l; 657
658 /* Some SBR files use upsampling. In this case the number
659 * of output samples is doubled to a maximum of 2048
660 * samples per frame. This means that files which already
661 * report a frame size of 2048 in their header will not
662 * need any further special handling. */
663 if (SBR_upsampling_used && l<=1024)
664 {
665 id3->samples += n * l * 2;
666 id3->needs_upsampling_correction = true;
667 }
668 else
669 {
670 id3->samples += n * l;
671 }
655 } 672 }
656 673
657 size = 0; 674 size = 0;
@@ -760,12 +777,6 @@ bool get_mp4_metadata(int fd, struct mp3entry* id3)
760 logf("Not an ALAC or AAC file"); 777 logf("Not an ALAC or AAC file");
761 return false; 778 return false;
762 } 779 }
763
764 /* SBR upsampling will output double amount of samples per frame. */
765 if (SBR_upsampling_used)
766 {
767 id3->samples *= 2;
768 }
769 780
770 id3->length = ((int64_t) id3->samples * 1000) / id3->frequency; 781 id3->length = ((int64_t) id3->samples * 1000) / id3->frequency;
771 782