Fix some MP3 num_samples [Marc Ecko's Getting Up (PC)]

This commit is contained in:
bnnm 2019-12-08 00:00:04 +01:00
parent ce5bdedd2a
commit cca2a64a20
2 changed files with 41 additions and 31 deletions

View File

@ -365,41 +365,50 @@ size_t mpeg_get_samples(STREAMFILE *sf, off_t start_offset, size_t bytes) {
} }
/* detect Xing header (disguised as a normal frame) */ /* detect Xing header (disguised as a normal frame) */
if (frames < 3 && /* should be first after tags */ if (frames < 3) { /* should be first after tags */
info.frame_size >= 0x24 + 0x78 && /* frame is empty so Xing goes after MPEG side info */
read_u32be(offset + 0x04, sf) == 0 && off_t xing_offset;
(read_u32be(offset + 0x24, sf) == 0x58696E67 || /* "Xing" (mainly for VBR) */ if (info.version == 1)
read_u32be(offset + 0x24, sf) == 0x496E666F)) { /* "Info" (mainly for CBR) */ xing_offset = (info.channels == 2 ? 0x20 : 0x11) + 0x04;
uint32_t flags = read_u32be(offset + 0x28, sf); else
xing_offset = (info.channels == 2 ? 0x11 : 0x09) + 0x04;
if (flags & 1) { /* other flags indicate seek table and stuff */ if (info.frame_size >= xing_offset + 0x78 &&
uint32_t frame_count = read_u32be(offset + 0x2c, sf); read_u32be(offset + 0x04, sf) == 0 && /* empty frame */
samples = frame_count * info.frame_samples; (read_u32be(offset + xing_offset, sf) == 0x58696E67 || /* "Xing" (mainly for VBR) */
} read_u32be(offset + xing_offset, sf) == 0x496E666F)) { /* "Info" (mainly for CBR) */
uint32_t flags = read_u32be(offset + xing_offset + 0x04, sf);
/* vendor specific */ if (flags & 1) {
if (info.frame_size > 0x24 + 0x78 + 0x24 && uint32_t frame_count = read_u32be(offset + xing_offset + 0x08, sf);
read_u32be(offset + 0x9c, sf) == 0x4C414D45) { /* "LAME" */ samples = frame_count * info.frame_samples;
if (info.layer == 3) {
uint32_t delays = read_u32be(offset + 0xb0, sf);
encoder_delay = ((delays >> 12) & 0xFFF);
encoder_padding = ((delays >> 0) & 0xFFF);
encoder_delay += (528 + 1); /* implicit MDCT decoder delay (seen in LAME source) */
if (encoder_padding > 528 + 1)
encoder_padding -= (528 + 1);
} }
else { /* other flags indicate seek table and stuff */
encoder_delay = 240 + 1;
/* vendor specific */
if (info.frame_size > xing_offset + 0x78 + 0x24 &&
read_u32be(offset + xing_offset + 0x78, sf) == 0x4C414D45) { /* "LAME" */
if (info.layer == 3) {
uint32_t delays = read_u32be(offset + xing_offset + 0x8C, sf);
encoder_delay = ((delays >> 12) & 0xFFF);
encoder_padding = ((delays >> 0) & 0xFFF);
encoder_delay += (528 + 1); /* implicit MDCT decoder delay (seen in LAME source) */
if (encoder_padding > 528 + 1)
encoder_padding -= (528 + 1);
}
else {
encoder_delay = 240 + 1;
}
/* replay gain and stuff */
} }
/* replay gain and stuff */ /* there is also "iTunes" vendor with no apparent extra info, iTunes delays are in "iTunSMPB" ID3 tag */
}
/* there is also "iTunes" vendor with no apparent extra info, iTunes delays are in "iTunSMPB" ID3 tag */ ;VGM_LOG("MPEG: found Xing header\n");
break; /* we got samples */
;VGM_LOG("MPEG: found Xing header\n"); }
break; /* we got samples */
} }
//TODO: detect "VBRI" header (Fraunhofer encoder) //TODO: detect "VBRI" header (Fraunhofer encoder)

View File

@ -56,8 +56,9 @@ VGMSTREAM * init_vgmstream_ffmpeg_offset(STREAMFILE *streamFile, uint64_t start,
num_samples = aac_get_samples(streamFile, 0x00, get_streamfile_size(streamFile)); num_samples = aac_get_samples(streamFile, 0x00, get_streamfile_size(streamFile));
} }
/* hack for MP3 files (will return 0 samples if not an actual file) */ /* hack for MP3 files (will return 0 samples if not an actual file)
if (!num_samples && check_extensions(streamFile, "mp3,lmp3")) { * .mus: Marc Ecko's Getting Up (PC) */
if (!num_samples && check_extensions(streamFile, "mp3,lmp3,mus")) {
num_samples = mpeg_get_samples(streamFile, 0x00, get_streamfile_size(streamFile)); num_samples = mpeg_get_samples(streamFile, 0x00, get_streamfile_size(streamFile));
} }