diff --git a/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj b/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj index 1b177405e..6c05eac08 100644 --- a/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj +++ b/Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj @@ -97,8 +97,6 @@ 831BA6211EAC61A500CF89B0 /* x360_pasx.c in Sources */ = {isa = PBXBuildFile; fileRef = 831BA6171EAC61A500CF89B0 /* x360_pasx.c */; }; 831BA6281EAC61CB00CF89B0 /* coding_utils.c in Sources */ = {isa = PBXBuildFile; fileRef = 831BA6221EAC61CB00CF89B0 /* coding_utils.c */; }; 8322ECE7240268BB009E9429 /* raw_al.c in Sources */ = {isa = PBXBuildFile; fileRef = 8322ECE6240268BA009E9429 /* raw_al.c */; }; - 8323894A1D22419B00482226 /* clHCA.c in Sources */ = {isa = PBXBuildFile; fileRef = 832389481D22419B00482226 /* clHCA.c */; }; - 8323894B1D22419B00482226 /* clHCA.h in Headers */ = {isa = PBXBuildFile; fileRef = 832389491D22419B00482226 /* clHCA.h */; settings = {ATTRIBUTES = (Public, ); }; }; 832389501D2246C300482226 /* hca.c in Sources */ = {isa = PBXBuildFile; fileRef = 8323894F1D2246C300482226 /* hca.c */; }; 832389521D224C0800482226 /* hca_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 832389511D224C0800482226 /* hca_decoder.c */; }; 83269DD22399F5DE00F49FE3 /* nus3bank_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 83269DD02399F5DD00F49FE3 /* nus3bank_streamfile.h */; }; @@ -655,6 +653,9 @@ 83FC176E23AC58D100E1025F /* csb.c in Sources */ = {isa = PBXBuildFile; fileRef = 83FC176B23AC58D100E1025F /* csb.c */; }; 83FC176F23AC58D100E1025F /* cri_utf.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FC176C23AC58D100E1025F /* cri_utf.h */; }; 83FC177123AC59A800E1025F /* cri_utf.c in Sources */ = {isa = PBXBuildFile; fileRef = 83FC177023AC59A800E1025F /* cri_utf.c */; }; + 83FC417026D32FF5009A2022 /* hca_decoder_clhca.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FC416E26D32FF5009A2022 /* hca_decoder_clhca.h */; }; + 83FC417126D32FF5009A2022 /* hca_decoder_clhca.c in Sources */ = {isa = PBXBuildFile; fileRef = 83FC416F26D32FF5009A2022 /* hca_decoder_clhca.c */; }; + 83FC417326D3304D009A2022 /* xsh_xsd_xss.c in Sources */ = {isa = PBXBuildFile; fileRef = 83FC417226D3304D009A2022 /* xsh_xsd_xss.c */; }; 83FF0EBC1E93282100C58054 /* wwise.c in Sources */ = {isa = PBXBuildFile; fileRef = 83FF0EBB1E93282100C58054 /* wwise.c */; }; /* End PBXBuildFile section */ @@ -898,8 +899,6 @@ 831BA6221EAC61CB00CF89B0 /* coding_utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = coding_utils.c; sourceTree = ""; }; 831BD11F1EEE1CF200198540 /* ngc_ulw.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ngc_ulw.c; sourceTree = ""; }; 8322ECE6240268BA009E9429 /* raw_al.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = raw_al.c; sourceTree = ""; }; - 832389481D22419B00482226 /* clHCA.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = clHCA.c; sourceTree = ""; }; - 832389491D22419B00482226 /* clHCA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clHCA.h; sourceTree = ""; }; 8323894F1D2246C300482226 /* hca.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hca.c; sourceTree = ""; }; 832389511D224C0800482226 /* hca_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hca_decoder.c; sourceTree = ""; }; 83269DD02399F5DD00F49FE3 /* nus3bank_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nus3bank_streamfile.h; sourceTree = ""; }; @@ -1452,6 +1451,9 @@ 83FC176B23AC58D100E1025F /* csb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = csb.c; sourceTree = ""; }; 83FC176C23AC58D100E1025F /* cri_utf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cri_utf.h; sourceTree = ""; }; 83FC177023AC59A800E1025F /* cri_utf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cri_utf.c; sourceTree = ""; }; + 83FC416E26D32FF5009A2022 /* hca_decoder_clhca.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hca_decoder_clhca.h; sourceTree = ""; }; + 83FC416F26D32FF5009A2022 /* hca_decoder_clhca.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hca_decoder_clhca.c; sourceTree = ""; }; + 83FC417226D3304D009A2022 /* xsh_xsd_xss.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xsh_xsd_xss.c; sourceTree = ""; }; 83FF0EBB1E93282100C58054 /* wwise.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = wwise.c; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1494,15 +1496,6 @@ name = Products; sourceTree = ""; }; - 832389471D22419B00482226 /* ext_libs */ = { - isa = PBXGroup; - children = ( - 832389481D22419B00482226 /* clHCA.c */, - 832389491D22419B00482226 /* clHCA.h */, - ); - path = ext_libs; - sourceTree = ""; - }; 835FC6C223F62AEE006960FA /* Products */ = { isa = PBXGroup; children = ( @@ -1567,7 +1560,6 @@ 836F6B4218BDB8880095E648 /* vgmstream */ = { isa = PBXGroup; children = ( - 832389471D22419B00482226 /* ext_libs */, 836F6DDE18BDC2180095E648 /* src */, 836F6B4318BDB8880095E648 /* Supporting Files */, ); @@ -1654,6 +1646,8 @@ 8373341323F60C7B00DE14DC /* g7221_decoder_lib.c */, 8373341523F60C7B00DE14DC /* g7221_decoder_lib.h */, 836F6DE818BDC2180095E648 /* g7221_decoder.c */, + 83FC416F26D32FF5009A2022 /* hca_decoder_clhca.c */, + 83FC416E26D32FF5009A2022 /* hca_decoder_clhca.h */, 832389511D224C0800482226 /* hca_decoder.c */, 836F6DEA18BDC2180095E648 /* ima_decoder.c */, 83F1EE28245D4FB10076E182 /* imuse_decoder.c */, @@ -2211,6 +2205,7 @@ 832BF80A21E05148006F50F1 /* xpcm.c */, 832BF80C21E05148006F50F1 /* xps.c */, 83A8BAE225667AA7000F5F3F /* xse.c */, + 83FC417226D3304D009A2022 /* xsh_xsd_xss.c */, 836F6F1218BDC2190095E648 /* xss.c */, 83AFABB923795201002F3947 /* xssb.c */, 834FE0C6215C79E7000A5D3D /* xvag_streamfile.h */, @@ -2312,7 +2307,6 @@ 836F705418BDC2190095E648 /* streamfile.h in Headers */, 83A3F0761E3AD8B900D6A794 /* stack_alloc.h in Headers */, 8373342723F60CDC00DE14DC /* lrmd_streamfile.h in Headers */, - 8323894B1D22419B00482226 /* clHCA.h in Headers */, 83C7281122BC893D00678B4A /* 9tav_streamfile.h in Headers */, 83C7280F22BC893D00678B4A /* xwb_xsb.h in Headers */, 83AA7F732519BFEA004C5298 /* mpeg_bitreader.h in Headers */, @@ -2346,6 +2340,7 @@ 83031EDD243C510500C3F3E0 /* xnb_streamfile.h in Headers */, 83D2007B248DDB770048BD24 /* mups_streamfile.h in Headers */, 83AA7F8B2519C076004C5298 /* render.h in Headers */, + 83FC417026D32FF5009A2022 /* hca_decoder_clhca.h in Headers */, 8373341623F60C7B00DE14DC /* g7221_decoder_aes.h in Headers */, 8373341923F60C7B00DE14DC /* g7221_decoder_lib_data.h in Headers */, 83AFABBD23795202002F3947 /* ea_eaac_opus_streamfile.h in Headers */, @@ -2615,6 +2610,7 @@ 83299FD01E7660C7003A3242 /* bik.c in Sources */, 8346D97C25BF838C00D1A8B0 /* mjb_mjh.c in Sources */, 8373341823F60C7B00DE14DC /* tgcadpcm_decoder.c in Sources */, + 83FC417326D3304D009A2022 /* xsh_xsd_xss.c in Sources */, 836F6F3318BDC2190095E648 /* ngc_dtk_decoder.c in Sources */, 83E7FD6525EF2B2400683FD2 /* tac.c in Sources */, 83C7281322BC893D00678B4A /* mta2.c in Sources */, @@ -2674,6 +2670,7 @@ 834FE107215C79ED000A5D3D /* mib_mih.c in Sources */, 836F703618BDC2190095E648 /* thp.c in Sources */, 836F6F7818BDC2190095E648 /* Cstr.c in Sources */, + 83FC417126D32FF5009A2022 /* hca_decoder_clhca.c in Sources */, 83F1EE30245D4FC10076E182 /* imuse.c in Sources */, 8346D98625BF83B300D1A8B0 /* compresswave_decoder.c in Sources */, 836F6F1E18BDC2190095E648 /* acm_decoder.c in Sources */, @@ -2998,7 +2995,6 @@ 836F702618BDC2190095E648 /* s14_sss.c in Sources */, 834FE102215C79ED000A5D3D /* rfrm.c in Sources */, 83AA5D1D1F6E2F800020821C /* blocked_vgs.c in Sources */, - 8323894A1D22419B00482226 /* clHCA.c in Sources */, 836F702E18BDC2190095E648 /* sli.c in Sources */, 83AA7F822519C042004C5298 /* ktsc.c in Sources */, 836F6FDE18BDC2190095E648 /* ps2_ild.c in Sources */, diff --git a/Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c b/Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c index 0a5c5c0df..3362ca82d 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c @@ -131,7 +131,7 @@ static void transform(int32_t* invbuf, int32_t* tmpbuf) { for (lpc1 = 0; lpc1 < 12 - 2; lpc1++) { int sub1, sub2; int i1, i2, i3, i4; - int64_t cos1, sin1, cos2, sin2; /* needs i64 to force 64b ops (avoid overflows) */ + int64_t cos1, sin1, cos2, sin2; /* needs i64 to force 64b ops (avoid overflows) then converted to i32 */ cos1 = (int64_t)sincos_table[sc1 + 1024]; sin1 = (int64_t)sincos_table[sc1 + 0]; @@ -153,8 +153,8 @@ static void transform(int32_t* invbuf, int32_t* tmpbuf) { sub2 = tmpbuf[i1 + 1] - tmpbuf[i2 + 1]; invbuf[i1 + 1] += invbuf[i2 + 1]; tmpbuf[i1 + 1] += tmpbuf[i2 + 1]; - invbuf[i2 + 1] = ((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12); - tmpbuf[i2 + 1] = ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12); + invbuf[i2 + 1] = (int32_t)( ((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12) ); + tmpbuf[i2 + 1] = (int32_t)( ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12) ); sub1 = invbuf[i3 + 0] - invbuf[i4 + 0]; sub2 = tmpbuf[i3 + 0] - tmpbuf[i4 + 0]; @@ -167,8 +167,8 @@ static void transform(int32_t* invbuf, int32_t* tmpbuf) { sub2 = tmpbuf[i3 + 1] - tmpbuf[i4 + 1]; invbuf[i3 + 1] += invbuf[i4 + 1]; tmpbuf[i3 + 1] += tmpbuf[i4 + 1]; - invbuf[i4 + 1] = ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12); - tmpbuf[i4 + 1] = -(((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12)); + invbuf[i4 + 1] = (int32_t)( ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12) ); + tmpbuf[i4 + 1] = (int32_t)( -(((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12)) ); i1 += step1; i2 += step1; @@ -194,15 +194,15 @@ static void transform(int32_t* invbuf, int32_t* tmpbuf) { sub2 = tmpbuf[i1] - tmpbuf[i2]; invbuf[i1] += invbuf[i2]; tmpbuf[i1] += tmpbuf[i2]; - invbuf[i2] = ((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12); - tmpbuf[i2] = ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12); + invbuf[i2] = (int32_t)( ((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12) ); + tmpbuf[i2] = (int32_t)( ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12) ); sub1 = invbuf[i3] - invbuf[i4]; sub2 = tmpbuf[i3] - tmpbuf[i4]; invbuf[i3] += invbuf[i4]; tmpbuf[i3] += tmpbuf[i4]; - invbuf[i4] = ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12); - tmpbuf[i4] = -(((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12)); + invbuf[i4] = (int32_t)( ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12) ); + tmpbuf[i4] = (int32_t)( -(((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12)) ); i1 += step1; i2 += step1; diff --git a/Frameworks/vgmstream/vgmstream/src/coding/coding.h b/Frameworks/vgmstream/vgmstream/src/coding/coding.h index ecd74e912..5ea384f64 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/coding.h +++ b/Frameworks/vgmstream/vgmstream/src/coding/coding.h @@ -2,6 +2,8 @@ #define _CODING_H #include "../vgmstream.h" +//todo remove +#include "hca_decoder_clhca.h" /* adx_decoder */ void decode_adx(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int32_t frame_bytes, coding_t coding_type); @@ -442,8 +444,10 @@ typedef struct { int channels; /* max channels */ int fsb_padding; /* fsb padding mode */ int chunk_size; /* size of a data portion */ + int max_chunks; int data_size; /* playable size */ int interleave; /* size of stream interleave */ + int interleave_last; int encryption; /* encryption mode */ int big_endian; int skip_samples; diff --git a/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder.c b/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder.c index 023e0fdd4..e807ec63f 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder.c @@ -1,5 +1,5 @@ #include "coding.h" -#include "clHCA.h" +#include "hca_decoder_clhca.h" struct hca_codec_data { diff --git a/Frameworks/vgmstream/vgmstream/ext_libs/clHCA.c b/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder_clhca.c similarity index 99% rename from Frameworks/vgmstream/vgmstream/ext_libs/clHCA.c rename to Frameworks/vgmstream/vgmstream/src/coding/hca_decoder_clhca.c index 79ca3178a..09294066c 100644 --- a/Frameworks/vgmstream/vgmstream/ext_libs/clHCA.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder_clhca.c @@ -25,7 +25,7 @@ //-------------------------------------------------- // Includes //-------------------------------------------------- -#include "clHCA.h" +#include "hca_decoder_clhca.h" #include #include #include diff --git a/Frameworks/vgmstream/vgmstream/ext_libs/clHCA.h b/Frameworks/vgmstream/vgmstream/src/coding/hca_decoder_clhca.h similarity index 100% rename from Frameworks/vgmstream/vgmstream/ext_libs/clHCA.h rename to Frameworks/vgmstream/vgmstream/src/coding/hca_decoder_clhca.h diff --git a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_custom_utils.c b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_custom_utils.c index 451b1d1cc..82abed465 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_custom_utils.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_custom_utils.c @@ -51,6 +51,7 @@ int mpeg_custom_setup_init_default(STREAMFILE* sf, off_t start_offset, mpeg_code } break; + //todo simplify/unify XVAG/P3D/SCD/LYN and just feed arbitrary chunks to the decoder case MPEG_P3D: case MPEG_SCD: if (data->config.interleave <= 0) @@ -61,7 +62,8 @@ int mpeg_custom_setup_init_default(STREAMFILE* sf, off_t start_offset, mpeg_code if (data->config.interleave <= 0) goto fail; /* needs external fixed size */ data->default_buffer_size = data->config.interleave; - //todo simplify/unify XVAG/P3D/SCD/LYN and just feed arbitrary chunks to the decoder + if (data->default_buffer_size < data->config.interleave_last) + data->default_buffer_size = data->config.interleave_last; break; case MPEG_STANDARD: @@ -179,7 +181,6 @@ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL* stream, mpeg_codec_data* d case MPEG_P3D: /* fixed interleave, not frame-aligned (ie. blocks may end/start in part of a frame) */ case MPEG_SCD: - case MPEG_LYN: current_interleave = data->config.interleave; /* check if current interleave block is short */ @@ -197,6 +198,23 @@ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL* stream, mpeg_codec_data* d current_data_size = current_interleave; break; + case MPEG_LYN: + /* after N interleaves last block is bigger */ + if (ms->current_size_count < data->config.max_chunks) + current_interleave = data->config.interleave; + else if (ms->current_size_count == data->config.max_chunks) + current_interleave = data->config.interleave_last; + else + goto fail; + + current_interleave_pre = current_interleave*num_stream; + current_interleave_post = current_interleave*(data->streams_size-1) - current_interleave_pre; + //VGM_LOG("o=%lx, %i: %x, %x, %x, %x\n", stream->offset, num_stream, ms->current_size_count, current_interleave, current_interleave_pre, current_interleave_post ); + + current_data_size = current_interleave; + ms->current_size_count++; + break; + default: /* standard frames (CBR or VBR) */ if ( !mpeg_get_frame_info(stream->streamfile, stream->offset, &info) ) goto fail; @@ -232,7 +250,9 @@ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL* stream, mpeg_codec_data* d fail: return 0; } +#endif +//TODO: move to a better place /*****************/ /* FRAME HELPERS */ @@ -475,5 +495,3 @@ fail: VGM_LOG("MPEG: sample reader failed at %lx\n", offset); return 0; } - -#endif diff --git a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.c b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.c index d158f823f..f93da4bf4 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.c @@ -144,7 +144,11 @@ mpeg_codec_data* init_mpeg_custom(STREAMFILE* sf, off_t start_offset, coding_t* if (channels <= 0 || channels > 16) goto fail; /* arbitrary max */ if (channels < data->channels_per_frame) goto fail; //todo simplify/unify XVAG/P3D/SCD/LYN and just feed arbitrary chunks to the decoder - if (data->default_buffer_size > 0x10000) goto fail; /* max for some Ubi Lyn */ + /* max for some Ubi Lyn */ + if (data->default_buffer_size > 0x20000) { + VGM_LOG("MPEG: buffer size too big %x\n", data->default_buffer_size); + goto fail; + } /* init streams */ diff --git a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.h b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.h index 721dabf29..c818d0f73 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.h +++ b/Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.h @@ -1,21 +1,13 @@ #ifndef _MPEG_DECODER_H_ #define _MPEG_DECODER_H_ -#include #include "../vgmstream.h" #include "../coding/coding.h" + /* used by mpeg_decoder.c, but scattered in other .c files */ #ifdef VGM_USE_MPEG -typedef struct { - int version; - int layer; - int bit_rate; - int sample_rate; - int frame_samples; - int frame_size; /* bytes */ - int channels; -} mpeg_frame_info; +#include /* represents a single MPEG stream */ typedef struct { @@ -70,19 +62,29 @@ struct mpeg_codec_data { }; -int mpeg_get_frame_info(STREAMFILE *streamfile, off_t offset, mpeg_frame_info * info); - -int mpeg_custom_setup_init_default(STREAMFILE *streamFile, off_t start_offset, mpeg_codec_data *data, coding_t *coding_type); -int mpeg_custom_setup_init_ealayer3(STREAMFILE *streamFile, off_t start_offset, mpeg_codec_data *data, coding_t *coding_type); -int mpeg_custom_setup_init_awc(STREAMFILE *streamFile, off_t start_offset, mpeg_codec_data *data, coding_t *coding_type); -int mpeg_custom_setup_init_eamp3(STREAMFILE *streamFile, off_t start_offset, mpeg_codec_data *data, coding_t *coding_type); - -int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL *stream, mpeg_codec_data *data, int num_stream); -int mpeg_custom_parse_frame_ahx(VGMSTREAMCHANNEL *stream, mpeg_codec_data *data, int num_stream); -int mpeg_custom_parse_frame_ealayer3(VGMSTREAMCHANNEL *stream, mpeg_codec_data *data, int num_stream); -int mpeg_custom_parse_frame_awc(VGMSTREAMCHANNEL *stream, mpeg_codec_data *data, int num_stream); -int mpeg_custom_parse_frame_eamp3(VGMSTREAMCHANNEL *stream, mpeg_codec_data *data, int num_stream); +int mpeg_custom_setup_init_default(STREAMFILE* sf, off_t start_offset, mpeg_codec_data* data, coding_t* coding_type); +int mpeg_custom_setup_init_ealayer3(STREAMFILE* sf, off_t start_offset, mpeg_codec_data* data, coding_t* coding_type); +int mpeg_custom_setup_init_awc(STREAMFILE* sf, off_t start_offset, mpeg_codec_data* data, coding_t* coding_type); +int mpeg_custom_setup_init_eamp3(STREAMFILE* sf, off_t start_offset, mpeg_codec_data* data, coding_t* coding_type); +int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream); +int mpeg_custom_parse_frame_ahx(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream); +int mpeg_custom_parse_frame_ealayer3(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream); +int mpeg_custom_parse_frame_awc(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream); +int mpeg_custom_parse_frame_eamp3(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream); #endif/* VGM_USE_MPEG */ + +typedef struct { + int version; + int layer; + int bit_rate; + int sample_rate; + int frame_samples; + int frame_size; /* bytes */ + int channels; +} mpeg_frame_info; + +int mpeg_get_frame_info(STREAMFILE* sf, off_t offset, mpeg_frame_info* info); + #endif/*_MPEG_DECODER_H_ */ diff --git a/Frameworks/vgmstream/vgmstream/src/coding/relic_decoder_lib.c b/Frameworks/vgmstream/vgmstream/src/coding/relic_decoder_lib.c index c2f4ed47d..7e0501469 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/relic_decoder_lib.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/relic_decoder_lib.c @@ -238,9 +238,9 @@ static void init_dequantization(float* scales) { static int unpack_frame(uint8_t* buf, int buf_size, float* freq1, float* freq2, const float* scales, uint8_t* exponents, int freq_size) { uint8_t flags, cb_bits, ev_bits, ei_bits, qv_bits; - int qv; + int qv, pos; uint8_t ev; - uint8_t move, pos; + uint8_t move; uint32_t bit_offset, max_offset; int i, j; int freq_half = freq_size >> 1; diff --git a/Frameworks/vgmstream/vgmstream/src/coding/speex_decoder.c b/Frameworks/vgmstream/vgmstream/src/coding/speex_decoder.c index 0b908ad65..5bac10387 100644 --- a/Frameworks/vgmstream/vgmstream/src/coding/speex_decoder.c +++ b/Frameworks/vgmstream/vgmstream/src/coding/speex_decoder.c @@ -100,7 +100,7 @@ fail: /* for simple style speex (seen in EA-Speex and libspeex's sampledec.c) */ static int read_frame(speex_codec_data* data, VGMSTREAMCHANNEL* stream) { - uint8_t bytes; + size_t bytes; data->frame_size = read_u8(stream->offset, stream->streamfile); stream->offset += 0x01; diff --git a/Frameworks/vgmstream/vgmstream/src/formats.c b/Frameworks/vgmstream/vgmstream/src/formats.c index 364807695..1da3f6754 100644 --- a/Frameworks/vgmstream/vgmstream/src/formats.c +++ b/Frameworks/vgmstream/vgmstream/src/formats.c @@ -155,7 +155,7 @@ static const char* extension_list[] = { "de2", "dec", "diva", - "dmsg", + "dmsg", //fake extension/header id for .sgt (to be removed) "ds2", //txth/reserved [Star Wars Bounty Hunter (GC)] "dsb", "dsf", @@ -402,7 +402,7 @@ static const char* extension_list[] = { "rad", "rak", "ras", - "raw", + "raw", //txth/reserved [Madden NHL 97 (PC)-pcm8u] "rda", //FFmpeg/reserved [Rhythm Destruction (PC)] "rkv", "rnd", @@ -464,6 +464,7 @@ static const char* extension_list[] = { "sfx", "sgb", "sgd", + "sgt", "sgx", "sl3", "slb", //txth/reserved [THE Nekomura no Hitobito (PS2)] @@ -518,6 +519,7 @@ static const char* extension_list[] = { "tad", "tec", "tgq", + "tgv", "thp", "tk5", "tmx", @@ -610,6 +612,7 @@ static const char* extension_list[] = { "xma2", "xmu", "xnb", + "xsh", "xsf", "xse", "xsew", @@ -1113,7 +1116,7 @@ static const meta_info meta_info_list[] = { {meta_HIS, "Her Interactive HIS header"}, {meta_PS2_AST, "KOEI AST header"}, {meta_CAPDSP, "Capcom DSP header"}, - {meta_DMSG, "RIFF/DMSGsegh header"}, + {meta_DMSG, "Microsoft RIFF DMSG header"}, {meta_PONA_3DO, "Policenauts BGM header"}, {meta_PONA_PSX, "Policenauts BGM header"}, {meta_NGC_DSP_AAAP, "Acclaim Austin AAAp DSP header"}, @@ -1356,6 +1359,7 @@ static const meta_info meta_info_list[] = { {meta_PIFF_TPCM, "Tantalus PIFF TPCM header"}, {meta_WXD_WXH, "Relic WXD+WXH header"}, {meta_BNK_RELIC, "Relic BNK header"}, + {meta_XSH_XSD_XSS, "Treyarch XSH+XSD/XSS header"}, }; void get_vgmstream_coding_description(VGMSTREAM* vgmstream, char* out, size_t out_size) { diff --git a/Frameworks/vgmstream/vgmstream/src/layout/blocked.c b/Frameworks/vgmstream/vgmstream/src/layout/blocked.c index c28c4fe06..14b4e3354 100644 --- a/Frameworks/vgmstream/vgmstream/src/layout/blocked.c +++ b/Frameworks/vgmstream/vgmstream/src/layout/blocked.c @@ -1,6 +1,7 @@ #include "layout.h" #include "../vgmstream.h" #include "../decode.h" +#include "../coding/coding.h" /* Decodes samples for blocked streams. @@ -90,7 +91,7 @@ void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* } /* helper functions to parse new block */ -void block_update(off_t block_offset, VGMSTREAM * vgmstream) { +void block_update(off_t block_offset, VGMSTREAM* vgmstream) { switch (vgmstream->layout_type) { case layout_blocked_ast: block_update_ast(block_offset,vgmstream); @@ -216,3 +217,38 @@ void block_update(off_t block_offset, VGMSTREAM * vgmstream) { break; } } + +void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset) { + int block_samples; + off_t max_offset = get_streamfile_size(sf); + + vgmstream->next_block_offset = offset; + do { + block_update(vgmstream->next_block_offset, vgmstream); + + if (vgmstream->current_block_samples < 0 || vgmstream->current_block_size == 0xFFFFFFFF) + break; + + if (vgmstream->current_block_samples) { + block_samples = vgmstream->current_block_samples; + } + else { + switch(vgmstream->coding_type) { + case coding_PCM16_int: block_samples = pcm16_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_PCM8_int: + case coding_PCM8_U_int: block_samples = pcm8_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_XBOX_IMA: block_samples = xbox_ima_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_NGC_DSP: block_samples = dsp_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_PSX: block_samples = ps_bytes_to_samples(vgmstream->current_block_size,1); break; + default: + VGM_LOG("BLOCKED: missing codec\n"); + return; + } + } + + vgmstream->num_samples += block_samples; + } + while (vgmstream->next_block_offset < max_offset); + + block_update(offset, vgmstream); /* reset */ +} diff --git a/Frameworks/vgmstream/vgmstream/src/layout/blocked_ea_wve_ad10.c b/Frameworks/vgmstream/vgmstream/src/layout/blocked_ea_wve_ad10.c index 4a680a35a..6ef597aef 100644 --- a/Frameworks/vgmstream/vgmstream/src/layout/blocked_ea_wve_ad10.c +++ b/Frameworks/vgmstream/vgmstream/src/layout/blocked_ea_wve_ad10.c @@ -6,17 +6,20 @@ void block_update_ea_wve_ad10(off_t block_offset, VGMSTREAM* vgmstream) { STREAMFILE* sf = vgmstream->ch[0].streamfile; int i; - size_t block_size, channel_size = 0, interleave = 0; - uint32_t block_id; + size_t channel_size = 0, interleave = 0; + uint32_t block_id, block_size; - block_id = read_32bitBE(block_offset+0x00, sf); - block_size = read_32bitBE(block_offset+0x04, sf); + int flag_be = (vgmstream->codec_config & 0x01); + uint32_t (*read_u32)(off_t,STREAMFILE*) = flag_be ? read_u32be : read_u32le; + + block_id = read_u32be(block_offset+0x00, sf); + block_size = read_u32 (block_offset+0x04, sf); /* accept "Ad10/Ad11" audio block/footer */ if (block_id == 0x41643130 || block_id == 0x41643131) { channel_size = block_size - 0x08; /* one block per channel */ interleave = block_size; - block_size = block_size*vgmstream->channels; + block_size = block_size * vgmstream->channels; } /* rest could be "MDEC" video blocks with 0 size/samples */ diff --git a/Frameworks/vgmstream/vgmstream/src/layout/layout.h b/Frameworks/vgmstream/vgmstream/src/layout/layout.h index 0a1ae872d..79dc63b55 100644 --- a/Frameworks/vgmstream/vgmstream/src/layout/layout.h +++ b/Frameworks/vgmstream/vgmstream/src/layout/layout.h @@ -7,6 +7,7 @@ /* blocked layouts */ void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* vgmstream); void block_update(off_t block_offset, VGMSTREAM* vgmstream); +void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset); void block_update_ast(off_t block_ofset, VGMSTREAM* vgmstream); void block_update_mxch(off_t block_ofset, VGMSTREAM* vgmstream); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/cpk.c b/Frameworks/vgmstream/vgmstream/src/meta/cpk.c index 3e59c8aca..b04e7d80e 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/cpk.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/cpk.c @@ -3,7 +3,7 @@ #include "cri_utf.h" -typedef enum { HCA, CWAV, } cpk_type_t; +typedef enum { HCA, CWAV, ADX } cpk_type_t; static void load_cpk_name(STREAMFILE* sf, STREAMFILE* sf_acb, VGMSTREAM* vgmstream, int waveid); @@ -28,9 +28,9 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { /* checks */ if (!check_extensions(sf, "awb")) goto fail; - if (read_u32be(0x00,sf) != 0x43504B20) /* "CPK " */ + if (!is_id32be(0x00,sf, "CPK ")) goto fail; - if (read_u32be(0x10,sf) != 0x40555446) /* "@UTF" */ + if (!is_id32be(0x10,sf, "@UTF")) goto fail; /* 04: 0xFF? */ /* 08: 0x02A0? */ @@ -176,14 +176,18 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { //;VGM_LOG("CPK: subfile offset=%lx + %x, id=%i\n", subfile_offset, subfile_size, subfile_id); - if ((read_u32be(subfile_offset,sf) & 0x7f7f7f7f) == 0x48434100) { /* "HCA\0" */ + if ((read_u32be(subfile_offset,sf) & 0x7f7f7f7f) == get_id32be("HCA\0")) { type = HCA; extension = "hca"; } - else if (read_u32be(subfile_offset,sf) == 0x43574156) { /* "CWAV" */ + else if (is_id32be(subfile_offset,sf, "CWAV")) { type = CWAV; extension = "bcwav"; } + else if (read_u16be(subfile_offset, sf) == 0x8000) { + type = ADX; + extension = "adx"; + } else { goto fail; } @@ -200,6 +204,10 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) { vgmstream = init_vgmstream_rwsd(temp_sf); if (!vgmstream) goto fail; break; + case ADX: /* Sonic Generations (3DS) */ + vgmstream = init_vgmstream_adx(temp_sf); + if (!vgmstream) goto fail; + break; default: goto fail; } @@ -238,7 +246,7 @@ static void load_cpk_name(STREAMFILE* sf, STREAMFILE* sf_acb, VGMSTREAM* vgmstre if (!sf_acb) return; - /* companion .acb probably loaded */ + /* companion .acb probably loaded */ load_acb_wave_name(sf_acb, vgmstream, waveid, port, is_memory); close_streamfile(sf_acb); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/dmsg_segh.c b/Frameworks/vgmstream/vgmstream/src/meta/dmsg_segh.c index 5757ff1c8..900d7188b 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/dmsg_segh.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/dmsg_segh.c @@ -1,110 +1,159 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* DMSG - found in: Nightcaster II - Equinox - 2010-01-05 (manakoAT): Seems it's a corrupted "SGT" file, but I'm not sure... - */ -VGMSTREAM * init_vgmstream_dmsg(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - int loop_flag = 0; - int frequency; - int channel_count; - int dataBuffer = 0; - int Founddata = 0; - size_t file_size; - off_t current_chunk; - off_t start_offset; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("dmsg",filename_extension(filename))) goto fail; +typedef struct { + uint32_t type; + uint32_t size; + uint32_t offset; + off_t current; + off_t max; + int le_type; + int be_size; + int full_size; +} chunk_t; - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x52494646) /* "RIFF" */ - goto fail; - if (read_32bitBE(0x08,streamFile) != 0x444D5347) /* "DMSG" */ - goto fail; - if (read_32bitBE(0x0C,streamFile) != 0x73656768) /* "segh" */ - goto fail; - if (read_32bitBE(0x10,streamFile) != 0x38000000) /* "0x38" */ - goto fail; +static int next_chunk(chunk_t* chunk, STREAMFILE* sf) { + uint32_t (*read_u32type)(off_t,STREAMFILE*) = !chunk->le_type ? read_u32be : read_u32le; + uint32_t (*read_u32size)(off_t,STREAMFILE*) = chunk->be_size ? read_u32be : read_u32le; - /* scan file until we find a "data" string */ - file_size = get_streamfile_size(streamFile); + if (chunk->max == 0) + chunk->max = get_streamfile_size(sf); + + if (chunk->current >= chunk->max) + return 0; + /* can be used to signal "stop" */ + if (chunk->current < 0) + return 0; + + chunk->type = read_u32type(chunk->current + 0x00,sf); + chunk->size = read_u32size(chunk->current + 0x04,sf); + + chunk->offset = chunk->current + 0x04 + 0x04; + chunk->current += chunk->full_size ? chunk->size : 0x08 + chunk->size; + //;VGM_LOG("CHUNK: %x, %x, %x\n", dc.offset, chunk->type, chunk->size); + + /* read past data */ + if (chunk->type == 0xFFFFFFFF || chunk->size == 0xFFFFFFFF) + return 0; + + /* empty chunk with 0 size, seen in some formats (XVAG uses it as end marker, Wwise doesn't) */ + if (chunk->type == 0 || chunk->size == 0) + return 0; + + /* more chunks remain */ + return 1; +} + +enum { + CHUNK_RIFF = 0x52494646, /* "RIFF" */ + CHUNK_LIST = 0x4C495354, /* "LIST" */ + CHUNK_segh = 0x73656768, /* "segh" */ +}; + +/* DMSG - DirectMusic Segment with streams [Nightcaster II: Equinox (Xbox), Wildfire (PC)] */ +VGMSTREAM* init_vgmstream_dmsg(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + //int loop_flag, channels, sample_rate; + //int found_data = 0; + //int32_t num_samples, loop_start, loop_end; + //off_t start_offset; + off_t offset = 0, name_offset = 0, name_size = 0; + + + /* checks */ + /* .sgt: common + * .dmsg: header id */ + if (!check_extensions(sf, "sgt,dmsg")) + goto fail; + + if (!is_id32be(0x00,sf, "RIFF")) + goto fail; + if (!is_id32be(0x08,sf, "DMSG")) + goto fail; + + /* A DirectMusic segment usually has lots of chunks then data pointing to .dls soundbank. + * This accepts .sgt with a RIFF WAVE inside (less common). */ { - current_chunk = 0; - /* Start at 0 and loop until we reached the - file size, or until we found a "data string */ - while (!Founddata && current_chunk < file_size) { - dataBuffer = (read_32bitBE(current_chunk,streamFile)); - if (dataBuffer == 0x64617461) { /* "data" */ - /* if "data" string found, retrieve the needed infos */ - Founddata = 1; - /* We will cancel the search here if we have a match */ - break; + chunk_t rc = {0}; + chunk_t dc = {0}; + + rc.current = 0x0c; + while (next_chunk(&rc, sf)) { + switch(rc.type) { + /* "segh" has loopnum/samplesloop */ + case CHUNK_segh: + //todo: missing TMusicTime format + /* 0x00: dwRepeats (>0 or -1=inf) + * 0x04: mtLength + * 0x08: mtPlayStart + * 0x0c: mtLoopStart + * 0x10: mtLoopEnd + * 0x14: dwResolution + * 0x18: rtLength (optional) + * .. */ + break; + + case CHUNK_LIST: + if (is_id32be(rc.offset + 0x00, sf, "UNFO") && is_id32be(rc.offset + 0x04, sf, "UNAM")) { + name_offset = rc.offset + 0x0c; + name_size = read_u32le(rc.offset + 0x08, sf); + } + break; + + case CHUNK_RIFF: + if (!is_id32be(rc.offset, sf, "DMCN")) + goto fail; + + dc.current = rc.offset + 0x04; + while (next_chunk(&dc, sf)) { + switch(dc.type) { + case CHUNK_LIST: + /* abridged, there are some sublists */ + if (is_id32be(dc.offset + 0x00, sf, "cosl") && is_id32be(dc.offset + 0x30, sf, "WAVE")) { + offset = dc.offset + 0x34; + dc.current = -1; + rc.current = -1; + } + break; + default: + break; + } + } + + break; + default: + break; } - /* else we will increase the search offset by 1 */ - current_chunk = current_chunk + 1; } } - if (Founddata == 0) { - goto fail; - } else if (Founddata == 1) { - channel_count = (uint16_t)read_16bitLE(current_chunk-0x10,streamFile); - frequency = read_32bitLE(current_chunk-0xE,streamFile); - } + if (!offset) + goto fail; - loop_flag = 1; - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - /* fill in the vital statistics */ - if (Founddata == 0) { - goto fail; - } else if (Founddata == 1) { - start_offset = current_chunk+0x8; - vgmstream->channels = channel_count; - vgmstream->sample_rate = frequency; - vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = (read_32bitLE(current_chunk+0x4,streamFile)/2/channel_count); - if (loop_flag) { - vgmstream->loop_start_sample = 0; - vgmstream->loop_end_sample = (read_32bitLE(current_chunk+0x4,streamFile)/2/channel_count); - } - } - - if (channel_count == 1) { - vgmstream->layout_type = layout_none; - } else if (channel_count > 1) { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x2; - } - - vgmstream->meta_type = meta_DMSG; - - /* open the file for reading */ + /* subfile has a few extra chunks (guid, wavh) but otherwise standard (seen PCM and MS-ADPCM, with fact chunks) */ { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; + STREAMFILE* temp_sf = NULL; + off_t subfile_offset = offset; + size_t subfile_size = read_u32le(offset + 0x04, sf) + 0x08; + + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "wav"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_riff(temp_sf); + close_streamfile(temp_sf); + if (!vgmstream) goto fail; + + if (name_offset) { + if (name_size >= STREAM_NAME_SIZE) + name_size = STREAM_NAME_SIZE; + read_string_utf16le(vgmstream->stream_name,name_size, name_offset, sf); } + + return vgmstream; } - return vgmstream; - - /* clean up anything we may have opened */ fail: - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ea_schl.c b/Frameworks/vgmstream/vgmstream/src/meta/ea_schl.c index 292f78a4c..2bab4a253 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ea_schl.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ea_schl.c @@ -30,11 +30,11 @@ /* CODEC1 values were used early, then they migrated to CODEC2 values */ #define EA_CODEC1_NONE -1 #define EA_CODEC1_PCM 0x00 -#define EA_CODEC1_VAG 0x01 /* unsure */ +//#define EA_CODEC1_IMA 0x02 /* not used (sx.exe internal defs) */ +#define EA_CODEC1_N64 0x05 +#define EA_CODEC1_VAG 0x06 #define EA_CODEC1_EAXA 0x07 #define EA_CODEC1_MT10 0x09 -#define EA_CODEC1_N64 0x64 /* unknown but probably before MT10 */ - #define EA_CODEC2_NONE -1 #define EA_CODEC2_S16LE_INT 0x00 @@ -1809,6 +1809,7 @@ static int parse_variable_header(STREAMFILE* sf, ea_header* ea, off_t begin_offs else ea->codec2 = ea->bps==8 ? EA_CODEC2_S8 : (ea->big_endian ? EA_CODEC2_S16BE : EA_CODEC2_S16LE); break; + case EA_CODEC1_N64: ea->codec2 = EA_CODEC2_N64; break; case EA_CODEC1_VAG: ea->codec2 = EA_CODEC2_VAG; break; case EA_CODEC1_EAXA: if (ea->platform == EA_PLATFORM_PC || ea->platform == EA_PLATFORM_MAC) @@ -1817,7 +1818,6 @@ static int parse_variable_header(STREAMFILE* sf, ea_header* ea, off_t begin_offs ea->codec2 = EA_CODEC2_EAXA; break; case EA_CODEC1_MT10: ea->codec2 = EA_CODEC2_MT10; break; - case EA_CODEC1_N64: ea->codec2 = EA_CODEC2_N64; break; default: VGM_LOG("EA SCHl: unknown codec1 0x%02x\n", ea->codec1); goto fail; @@ -1830,6 +1830,7 @@ static int parse_variable_header(STREAMFILE* sf, ea_header* ea, off_t begin_offs case EA_PLATFORM_GENERIC: ea->codec2 = EA_CODEC2_EAXA; break; case EA_PLATFORM_PC: ea->codec2 = EA_CODEC2_EAXA; break; case EA_PLATFORM_PSX: ea->codec2 = EA_CODEC2_VAG; break; + case EA_PLATFORM_N64: ea->codec2 = EA_CODEC2_N64; break; case EA_PLATFORM_MAC: ea->codec2 = EA_CODEC2_EAXA; break; case EA_PLATFORM_PS2: ea->codec2 = EA_CODEC2_VAG; break; case EA_PLATFORM_GC: ea->codec2 = EA_CODEC2_S16BE; break; @@ -1837,7 +1838,7 @@ static int parse_variable_header(STREAMFILE* sf, ea_header* ea, off_t begin_offs case EA_PLATFORM_X360: ea->codec2 = EA_CODEC2_EAXA; break; case EA_PLATFORM_PSP: ea->codec2 = EA_CODEC2_EAXA; break; case EA_PLATFORM_PS3: ea->codec2 = EA_CODEC2_EAXA; break; - //case EA_PLATFORM_WII: ea->codec2 = EA_CODEC2_EAXA; break; /* not set? */ + case EA_PLATFORM_WII: ea->codec2 = EA_CODEC2_GCADPCM; break; case EA_PLATFORM_3DS: ea->codec2 = EA_CODEC2_GCADPCM; break; default: VGM_LOG("EA SCHl: unknown default codec2 for platform 0x%02x\n", ea->platform); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ea_wve_ad10.c b/Frameworks/vgmstream/vgmstream/src/meta/ea_wve_ad10.c index 53a2a6ac1..110af3177 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ea_wve_ad10.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ea_wve_ad10.c @@ -1,54 +1,68 @@ -#include "meta.h" -#include "../coding/coding.h" -#include "../layout/layout.h" - -/* EA WVE (Ad10) - from Electronic Arts PS movies [Wing Commander 3/4 (PS)] */ -VGMSTREAM * init_vgmstream_ea_wve_ad10(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count; - - - /* checks */ - if (!check_extensions(streamFile, "wve")) - goto fail; - - start_offset = 0x00; - if (read_32bitBE(start_offset, streamFile) != 0x41643130 && /* "Ad10" */ - read_32bitBE(start_offset, streamFile) != 0x41643131) /* "Ad11" (last block, but could be first) */ - goto fail; - loop_flag = 0; - /* no header = no channels, but seems if the first PS-ADPCM header is 00 then it's mono, somehow - * (ex. Wing Commander 3 intro / Wing Commander 4 = stereo, rest of Wing Commander 3 = mono) */ - channel_count = read_8bit(start_offset+0x08,streamFile) != 0 ? 2 : 1; - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = 22050; - vgmstream->meta_type = meta_EA_WVE_AD10; - vgmstream->coding_type = coding_PSX; - vgmstream->layout_type = layout_blocked_ea_wve_ad10; - - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) - goto fail; - - /* calc num_samples manually */ - { - vgmstream->next_block_offset = start_offset; - do { - block_update(vgmstream->next_block_offset,vgmstream); - vgmstream->num_samples += ps_bytes_to_samples(vgmstream->current_block_size, 1); - } - while (vgmstream->next_block_offset < get_streamfile_size(streamFile)); - block_update(start_offset, vgmstream); - } - - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} +#include "meta.h" +#include "../coding/coding.h" +#include "../layout/layout.h" + +/* EA WVE (Ad10) - from early Electronic Arts movies [Wing Commander 3/4 (PS1), Madden NHL 97 (PC)-w95] */ +VGMSTREAM* init_vgmstream_ea_wve_ad10(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset; + int loop_flag, channels; + int big_endian, is_ps1; + + + /* checks */ + /* .wve: common + * .mov: Madden NHL 97 (also uses .wve) */ + if (!check_extensions(sf, "wve,mov")) + goto fail; + + start_offset = 0x00; + if (!is_id32be(0x00, sf, "AABB") && /* video block */ + !is_id32be(0x00, sf, "Ad10") && /* audio block */ + !is_id32be(0x00, sf, "Ad11")) /* last audio block, but could be first */ + goto fail; + + big_endian = guess_endianness32bit(0x04, sf); + + if (is_id32be(0x00, sf, "AABB")) + start_offset += big_endian ? read_u32be(0x04, sf) : read_u32le(0x04, sf); + + loop_flag = 0; + + if (ps_check_format(sf, start_offset + 0x08, 0x40)) { + /* no header = no channels, but seems if the first PS-ADPCM header is 00 then it's mono, somehow + * (ex. Wing Commander 3 intro / Wing Commander 4 = stereo, rest of Wing Commander 3 = mono) */ + channels = read_u8(start_offset + 0x08,sf) != 0 ? 2 : 1; + is_ps1 = 1; + VGM_LOG("ps1"); + } + else { + channels = 1; + is_ps1 = 0; + } + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->sample_rate = 22050; + vgmstream->meta_type = meta_EA_WVE_AD10; + vgmstream->layout_type = layout_blocked_ea_wve_ad10; + vgmstream->codec_config = big_endian; + if (is_ps1) + vgmstream->coding_type = coding_PSX; + else + vgmstream->coding_type = coding_PCM8_U_int; + + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; + + blocked_count_samples(vgmstream, sf, start_offset); + + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ffmpeg.c b/Frameworks/vgmstream/vgmstream/src/meta/ffmpeg.c index 606df9213..748d1ae3b 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ffmpeg.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ffmpeg.c @@ -80,7 +80,6 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) { } } -#ifdef VGM_USE_MPEG /* hack for MP3 files (will return 0 samples if not an actual file) * .mus: Marc Ecko's Getting Up (PC) */ if (!num_samples && check_extensions(sf, "mp3,lmp3,mus")) { @@ -89,7 +88,6 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) { /* this seems correct thankfully */ //ffmpeg_set_skip_samples(data, encoder_delay); } -#endif /* hack for MPC */ if (is_id32be(0x00, sf, "MP+\x07") || /* Musepack V7 */ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/hca.c b/Frameworks/vgmstream/vgmstream/src/meta/hca.c index 75a172d53..f199872d0 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/hca.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/hca.c @@ -1,7 +1,7 @@ #include "meta.h" #include "hca_keys.h" #include "../coding/coding.h" -#include "clHCA.h" +#include "../coding/hca_decoder_clhca.h" //#define HCA_BRUTEFORCE #ifdef HCA_BRUTEFORCE diff --git a/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h b/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h index 51ed01b36..c072bb12a 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h @@ -718,7 +718,10 @@ static const hcakey_info hcakey_list[] = { {0xfea0d6adff136868}, //music_9050001 // Mini 4WD Hyper Dash Grand Prix (Android) - {7957824642808300098}, // 6E6FDF59AB704242 + {7957824642808300098}, // 6E6FDF59AB704242 + + // m HOLD'EM (Android) + {369211553984367}, // 00014FCBC385AF6F }; #endif/*_HCA_KEYS_H_*/ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/meta.h b/Frameworks/vgmstream/vgmstream/src/meta/meta.h index 9b31037f2..25c232f1c 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/meta.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/meta.h @@ -4,6 +4,7 @@ #include "../vgmstream.h" VGMSTREAM* init_vgmstream_silence(int channels, int sample_rate, int32_t num_samples); +VGMSTREAM* init_vgmstream_silence_container(int total_subsongs); VGMSTREAM* init_vgmstream_adx(STREAMFILE* sf); @@ -959,4 +960,6 @@ VGMSTREAM* init_vgmstream_wxd_wxh(STREAMFILE* sf); VGMSTREAM* init_vgmstream_bnk_relic(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_xsh_xsd_xss(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/riff.c b/Frameworks/vgmstream/vgmstream/src/meta/riff.c index 0f75b1bda..e0b1fda64 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/riff.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/riff.c @@ -27,8 +27,8 @@ static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE* sf, lon off_t current_chunk = adtl_offset+0x04; while (current_chunk < adtl_offset + adtl_length) { - uint32_t chunk_type = read_32bitBE(current_chunk+0x00,sf); - off_t chunk_size = read_32bitLE(current_chunk+0x04,sf); + uint32_t chunk_type = read_u32be(current_chunk+0x00,sf); + uint32_t chunk_size = read_u32le(current_chunk+0x04,sf); if (current_chunk+0x08+chunk_size > adtl_offset+adtl_length) return; @@ -81,7 +81,7 @@ typedef struct { off_t size; uint32_t codec; int sample_rate; - int channel_count; + int channels; uint32_t block_size; int bps; off_t extra_size; @@ -95,38 +95,38 @@ typedef struct { int is_at9; } riff_fmt_chunk; -static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fmt_chunk* fmt, int mwv) { - int32_t (*read_32bit)(off_t,STREAMFILE*) = big_endian ? read_32bitBE : read_32bitLE; - int16_t (*read_16bit)(off_t,STREAMFILE*) = big_endian ? read_16bitBE : read_16bitLE; +static int read_fmt(int big_endian, STREAMFILE* sf, off_t offset, riff_fmt_chunk* fmt, int mwv) { + uint32_t (*read_u32)(off_t,STREAMFILE*) = big_endian ? read_u32be : read_u32le; + uint16_t (*read_u16)(off_t,STREAMFILE*) = big_endian ? read_u16be : read_u16le; - fmt->offset = current_chunk; - fmt->size = read_32bit(current_chunk+0x04,sf); + fmt->offset = offset; + fmt->size = read_u32(offset+0x04,sf); /* WAVEFORMAT */ - fmt->codec = (uint16_t)read_16bit(current_chunk+0x08,sf); - fmt->channel_count = read_16bit(current_chunk+0x0a,sf); - fmt->sample_rate = read_32bit(current_chunk+0x0c,sf); - //fmt->avg_bps = read_32bit(current_chunk+0x10,sf); - fmt->block_size = read_16bit(current_chunk+0x14,sf); - fmt->bps = read_16bit(current_chunk+0x16,sf); + fmt->codec = read_u16(offset+0x08,sf); + fmt->channels = read_u16(offset+0x0a,sf); + fmt->sample_rate = read_u32(offset+0x0c,sf); + //fmt->avg_bps = read_u32(offset+0x10,sf); + fmt->block_size = read_u16(offset+0x14,sf); + fmt->bps = read_u16(offset+0x16,sf); /* WAVEFORMATEX */ if (fmt->size >= 0x10) { - fmt->extra_size = read_16bit(current_chunk+0x18,sf); + fmt->extra_size = read_u16(offset+0x18,sf); /* 0x1a+ depends on codec (ex. coef table for MSADPCM, samples_per_frame in MS-IMA, etc) */ } /* WAVEFORMATEXTENSIBLE */ if (fmt->codec == 0xFFFE && fmt->extra_size >= 0x16) { - //fmt->extra_samples = read_16bit(current_chunk+0x1a,sf); /* valid_bits_per_sample or samples_per_block */ - fmt->channel_layout = read_32bit(current_chunk+0x1c,sf); + //fmt->extra_samples = read_u16(offset+0x1a,sf); /* valid_bits_per_sample or samples_per_block */ + fmt->channel_layout = read_u32(offset+0x1c,sf); /* 0x10 guid at 0x20 */ /* happens in various .at3/at9, may be a bug in their encoder b/c MS's defs set mono as FC */ - if (fmt->channel_count == 1 && fmt->channel_layout == speaker_FL) { /* other channels are fine */ + if (fmt->channels == 1 && fmt->channel_layout == speaker_FL) { /* other channels are fine */ fmt->channel_layout = speaker_FC; } /* happens in few at3p, may be a bug in older tools as other games have ok flags [Ridge Racer 7 (PS3)] */ - if (fmt->channel_count == 6 && fmt->channel_layout == 0x013f) { + if (fmt->channels == 6 && fmt->channel_layout == 0x013f) { fmt->channel_layout = 0x3f; } } @@ -134,8 +134,8 @@ static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fm switch (fmt->codec) { case 0x00: /* Yamaha AICA ADPCM [Headhunter (DC), Bomber hehhe (DC), Rayman 2 (DC)] (unofficial) */ if (fmt->bps != 4) goto fail; - if (fmt->block_size != 0x02*fmt->channel_count && - fmt->block_size != 0x01*fmt->channel_count) goto fail; + if (fmt->block_size != 0x02*fmt->channels && + fmt->block_size != 0x01*fmt->channels) goto fail; fmt->coding_type = coding_AICA_int; fmt->interleave = 0x01; break; @@ -161,7 +161,7 @@ static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fm if (!msadpcm_check_coefs(sf, fmt->offset + 0x08 + 0x14)) goto fail; } - else if (fmt->bps == 16 && fmt->block_size == 0x02 * fmt->channel_count && fmt->size == 0x14) { + else if (fmt->bps == 16 && fmt->block_size == 0x02 * fmt->channels && fmt->size == 0x14) { fmt->coding_type = coding_IMA; /* MX vs ATV Unleashed (PC) codec hijack */ } else { @@ -201,9 +201,9 @@ static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fm case 0x0300: /* IMA ADPCM [Chrono Ma:gia (Android)] (unofficial) */ if (fmt->bps != 4) goto fail; - if (fmt->block_size != 0x0400*fmt->channel_count) goto fail; + if (fmt->block_size != 0x0400*fmt->channels) goto fail; if (fmt->size != 0x14) goto fail; - if (fmt->channel_count != 1) goto fail; /* not seen */ + if (fmt->channels != 1) goto fail; /* not seen */ fmt->coding_type = coding_DVI_IMA; /* real 0x300 is "Fujitsu FM Towns SND" with block align 0x01 */ break; @@ -218,25 +218,21 @@ static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fm case 0x6771: /* Ogg Vorbis (mode 3+) */ fmt->coding_type = coding_OGG_VORBIS; break; -#else - goto fail; #endif - case 0x0270: /* ATRAC3 */ #ifdef VGM_USE_FFMPEG + case 0x0270: /* ATRAC3 */ fmt->coding_type = coding_FFmpeg; fmt->is_at3 = 1; break; -#else - goto fail; #endif case 0xFFFE: { /* WAVEFORMATEXTENSIBLE (see ksmedia.h for known GUIDs) */ - uint32_t guid1 = (uint32_t)read_32bit (current_chunk+0x20,sf); - uint32_t guid2 = ((uint16_t)read_16bit (current_chunk+0x24,sf) << 16u) | - ((uint16_t)read_16bit (current_chunk+0x26,sf)); - uint32_t guid3 = (uint32_t)read_32bitBE(current_chunk+0x28,sf); - uint32_t guid4 = (uint32_t)read_32bitBE(current_chunk+0x2c,sf); + uint32_t guid1 = read_u32 (offset+0x20,sf); + uint32_t guid2 = (read_u16 (offset+0x24,sf) << 16u) | + (read_u16 (offset+0x26,sf)); + uint32_t guid3 = read_u32be(offset+0x28,sf); + uint32_t guid4 = read_u32be(offset+0x2c,sf); //;VGM_LOG("RIFF: guid %08x %08x %08x %08x\n", guid1, guid2, guid3, guid4); /* PCM GUID (0x00000001,0000,0010,80,00,00,AA,00,38,9B,71) */ @@ -254,32 +250,30 @@ static int read_fmt(int big_endian, STREAMFILE* sf, off_t current_chunk, riff_fm /* ATRAC3plus GUID (0xE923AABF,CB58,4471,A1,19,FF,FA,01,E4,CE,62) */ if (guid1 == 0xE923AABF && guid2 == 0xCB584471 && guid3 == 0xA119FFFA && guid4 == 0x01E4CE62) { -#ifdef VGM_USE_MAIATRAC3PLUS - uint16_t bztmp = read_16bit(current_chunk+0x32,sf); +#ifdef VGM_USE_FFMPEG + fmt->coding_type = coding_FFmpeg; + fmt->is_at3p = 1; + break; +#elif defined(VGM_USE_MAIATRAC3PLUS) + uint16_t bztmp = read_u16(offset+0x32,sf); bztmp = (bztmp >> 8) | (bztmp << 8); fmt->coding_type = coding_AT3plus; fmt->block_size = (bztmp & 0x3FF) * 8 + 8; /* should match fmt->block_size */ fmt->is_at3p = 1; break; -#elif defined(VGM_USE_FFMPEG) - fmt->coding_type = coding_FFmpeg; - fmt->is_at3p = 1; - break; #else goto fail; #endif } +#ifdef VGM_USE_ATRAC9 /* ATRAC9 GUID (0x47E142D2,36BA,4D8D,88,FC,61,65,4F,8C,83,6C) */ if (guid1 == 0x47E142D2 && guid2 == 0x36BA4D8D && guid3 == 0x88FC6165 && guid4 == 0x4F8C836C) { -#ifdef VGM_USE_ATRAC9 fmt->coding_type = coding_ATRAC9; fmt->is_at9 = 1; break; -#else - goto fail; -#endif } +#endif goto fail; /* unknown GUID */ } @@ -370,7 +364,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { /* some games have wonky sizes, selectively fix to catch bad rips and new mutations */ if (file_size != riff_size + 0x08) { - uint16_t codec = read_16bitLE(0x14,sf); + uint16_t codec = read_u16le(0x14,sf); if (codec == 0x6771 && riff_size + 0x08 + 0x01 == file_size) riff_size += 0x01; /* [Shikkoku no Sharnoth (PC)] (Sony Sound Forge?) */ @@ -397,11 +391,10 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { riff_size += 0x18; /* [F1 2011 (Vita)] (adds a "pada" chunk but RIFF size wasn't updated) */ else if (mwv) { - int channels = read_16bitLE(0x16, sf); /* [Dragon Quest VIII (PS2), Rogue Galaxy (PS2)] */ + int channels = read_u16le(0x16, sf); /* [Dragon Quest VIII (PS2), Rogue Galaxy (PS2)] */ size_t file_size_fixed = riff_size + 0x08 + 0x04 * (channels - 1); - if (file_size_fixed <= file_size && file_size - file_size_fixed < 0x10) - { + if (file_size_fixed <= file_size && file_size - file_size_fixed < 0x10) { /* files inside HD6/DAT are also padded to 0x10 so need to fix file_size */ file_size = file_size_fixed; riff_size = file_size - 0x08; @@ -617,7 +610,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag); + vgmstream = allocate_vgmstream(fmt.channels,loop_flag); if (!vgmstream) goto fail; vgmstream->sample_rate = fmt.sample_rate; @@ -661,7 +654,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { /* samples, codec init (after setting coding to ensure proper close on failure) */ switch (fmt.coding_type) { case coding_PCM16LE: - vgmstream->num_samples = pcm_bytes_to_samples(data_size, fmt.channel_count, 16); + vgmstream->num_samples = pcm_bytes_to_samples(data_size, fmt.channels, 16); break; case coding_PCM8_U: @@ -670,7 +663,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { case coding_L5_555: if (!mwv) goto fail; - vgmstream->num_samples = data_size / 0x12 / fmt.channel_count * 32; + vgmstream->num_samples = data_size / 0x12 / fmt.channels * 32; /* coefs */ { @@ -684,7 +677,7 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { read_32bitLE(mwv_pflt_offset+0x04, sf) < 8 + filter_count * 4 * filter_order) goto fail; - for (ch = 0; ch < fmt.channel_count; ch++) { + for (ch = 0; ch < fmt.channels; ch++) { for (i = 0; i < filter_count * filter_order; i++) { int coef = read_32bitLE(mwv_pflt_offset+0x10+i*0x04, sf); vgmstream->ch[ch].adpcm_coef_3by32[i] = coef; @@ -695,31 +688,31 @@ VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) { break; case coding_MSADPCM: - vgmstream->num_samples = msadpcm_bytes_to_samples(data_size, fmt.block_size, fmt.channel_count); + vgmstream->num_samples = msadpcm_bytes_to_samples(data_size, fmt.block_size, fmt.channels); if (fact_sample_count && fact_sample_count < vgmstream->num_samples) vgmstream->num_samples = fact_sample_count; break; case coding_MS_IMA: - vgmstream->num_samples = ms_ima_bytes_to_samples(data_size, fmt.block_size, fmt.channel_count); + vgmstream->num_samples = ms_ima_bytes_to_samples(data_size, fmt.block_size, fmt.channels); if (fact_sample_count && fact_sample_count < vgmstream->num_samples) vgmstream->num_samples = fact_sample_count; break; case coding_AICA: case coding_AICA_int: - vgmstream->num_samples = yamaha_bytes_to_samples(data_size, fmt.channel_count); + vgmstream->num_samples = yamaha_bytes_to_samples(data_size, fmt.channels); break; case coding_XBOX_IMA: - vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, fmt.channel_count); + vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, fmt.channels); if (fact_sample_count && fact_sample_count < vgmstream->num_samples) vgmstream->num_samples = fact_sample_count; /* some (converted?) Xbox games have bigger fact_samples */ break; case coding_IMA: case coding_DVI_IMA: - vgmstream->num_samples = ima_bytes_to_samples(data_size, fmt.channel_count); + vgmstream->num_samples = ima_bytes_to_samples(data_size, fmt.channels); break; #ifdef VGM_USE_FFMPEG @@ -873,7 +866,7 @@ fail: static int is_ue4_msadpcm(STREAMFILE* sf, riff_fmt_chunk* fmt, int fact_sample_count, off_t start) { /* multichannel ok */ - if (fmt->channel_count < 2) + if (fmt->channels < 2) goto fail; /* UE4 class is "ADPCM", assume it's the extension too */ @@ -902,7 +895,7 @@ static int is_ue4_msadpcm(STREAMFILE* sf, riff_fmt_chunk* fmt, int fact_sample_c /* their encoder doesn't calculate optimal coefs and uses fixed values every frame * (could do it for fmt size 0x36 too but maybe they'll fix it in the future) */ while (offset <= max_offset) { - if (read_8bit(offset+0x00, sf) != 0 || read_16bitLE(offset+0x01, sf) != 0x00E6) + if (read_u8(offset+0x00, sf) != 0 || read_u16le(offset+0x01, sf) != 0x00E6) goto fail; offset += fmt->block_size; } @@ -916,7 +909,7 @@ fail: /* for maximum annoyance later UE4 versions (~v4.2x?) interleave single frames instead of * half interleave, but don't have flags to detect so we need some heuristics */ static size_t get_ue4_msadpcm_interleave(STREAMFILE* sf, riff_fmt_chunk* fmt, off_t start, size_t size) { - size_t v1_interleave = size / fmt->channel_count; + size_t v1_interleave = size / fmt->channels; size_t v2_interleave = fmt->block_size; uint8_t nibbles1[0x08] = {0}; uint8_t nibbles2[0x08] = {0}; @@ -927,7 +920,7 @@ static size_t get_ue4_msadpcm_interleave(STREAMFILE* sf, riff_fmt_chunk* fmt, of return v1_interleave; /* 6ch only observed in later versions [Fortnite (PC)], not padded */ - if (fmt->channel_count > 2) + if (fmt->channels > 2) return v2_interleave; read_streamfile(nibbles1, start + size - 0x08, sizeof(nibbles2), sf); @@ -1053,7 +1046,7 @@ VGMSTREAM* init_vgmstream_rifx(STREAMFILE* sf) { /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag); + vgmstream = allocate_vgmstream(fmt.channels,loop_flag); if (!vgmstream) goto fail; vgmstream->sample_rate = fmt.sample_rate; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/silence.c b/Frameworks/vgmstream/vgmstream/src/meta/silence.c index 28f7d0198..f2ca65bf5 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/silence.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/silence.c @@ -27,3 +27,19 @@ fail: close_vgmstream(vgmstream); return NULL; } + +/* silent stream - for containers that have dummy streams but it's a hassle to detect/filter out */ +VGMSTREAM* init_vgmstream_silence_container(int total_subsongs) { + VGMSTREAM* vgmstream = NULL; + + vgmstream = init_vgmstream_silence(0, 0, 0); + if (!vgmstream) goto fail; + + vgmstream->num_streams = total_subsongs; + snprintf(vgmstream->stream_name, STREAM_NAME_SIZE, "%s", "dummy"); + + return vgmstream; +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ubi_bao.c b/Frameworks/vgmstream/vgmstream/src/meta/ubi_bao.c index 830121c7d..3268bab0d 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ubi_bao.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ubi_bao.c @@ -35,6 +35,7 @@ typedef struct { int audio_fix_psx_samples; int audio_external_and; int audio_loop_and; + int audio_ignore_resource_size; off_t sequence_sequence_loop; off_t sequence_sequence_single; @@ -1116,9 +1117,12 @@ static int parse_offsets(ubi_bao_header* bao, STREAMFILE* sf) { read_string(bao->resource_name,255, resources_offset + 0x04+0x04 + name_offset, sf); if (bao->stream_size != resource_size - bao->stream_skip + bao->prefetch_size) { - VGM_ASSERT(bao->stream_size != resource_size - bao->stream_skip + bao->prefetch_size, - "UBI BAO: stream vs resource size mismatch at %lx\n", offset+0x10*i); - goto fail; + VGM_LOG("UBI BAO: stream vs resource size mismatch at %lx (%x vs %x, %x, %x)\n", offset+0x10*i, bao->stream_size, resource_size, bao->stream_skip, bao->prefetch_size); + + /* rarely resource has more data than stream (sometimes a few bytes, others +0x100000) + * sometimes short song versions, but not accessed? no samples/sizes/cues/etc in header seem to refer to that [Just Dance (Wii)] */ + if (!bao->cfg.audio_ignore_resource_size || bao->prefetch_size) + goto fail; } break; } @@ -1755,6 +1759,9 @@ static int config_bao_version(ubi_bao_header* bao, STREAMFILE* sf) { bao->cfg.codec_map[0x09] = RAW_DSP; bao->cfg.file_type = UBI_FORGE_b; + + if (version == 0x0022000D) /* Just Dance (Wii) oddity */ + bao->cfg.audio_ignore_resource_size = 1; return 1; case 0x00220015: /* James Cameron's Avatar: The Game (PSP)-package */ diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn.c b/Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn.c index ceafaa04b..f518e930f 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn.c @@ -5,38 +5,40 @@ /* LyN RIFF - from Ubisoft LyN engine games [Red Steel 2 (Wii), Adventures of Tintin (Multi), From Dust (Multi), Just Dance 3/4 (multi)] */ -VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { +VGMSTREAM* init_vgmstream_ubi_lyn(STREAMFILE* sf) { VGMSTREAM * vgmstream = NULL; off_t start_offset, first_offset = 0xc; off_t fmt_offset, data_offset, fact_offset; size_t fmt_size, data_size, fact_size; - int loop_flag, channel_count, sample_rate, codec; + int loop_flag, channels, sample_rate, codec; int num_samples; /* checks */ - /* .sns: Red Steel 2, .wav: Tintin, .son: From Dust */ - if (!check_extensions(streamFile,"sns,wav,lwav,son")) + /* .sns: Red Steel 2 + * .wav: Tintin, Just Dance + * .son: From Dust */ + if (!check_extensions(sf,"sns,wav,lwav,son")) goto fail; /* a slightly eccentric RIFF with custom codecs */ - if (read_32bitBE(0x00,streamFile) != 0x52494646 || /* "RIFF" */ - read_32bitBE(0x08,streamFile) != 0x57415645) /* "WAVE" */ + if (!is_id32be(0x00,sf, "RIFF") || + !is_id32be(0x08,sf, "WAVE")) goto fail; - if (read_32bitLE(0x04,streamFile)+0x04+0x04 != get_streamfile_size(streamFile)) + if (read_32bitLE(0x04,sf) + 0x04 + 0x04 != get_streamfile_size(sf)) goto fail; - if (!find_chunk(streamFile, 0x666d7420,first_offset,0, &fmt_offset,&fmt_size, 0, 0)) /* "fmt " */ + if (!find_chunk(sf, 0x666d7420,first_offset,0, &fmt_offset,&fmt_size, 0, 0)) /* "fmt " */ goto fail; - if (!find_chunk(streamFile, 0x64617461,first_offset,0, &data_offset,&data_size, 0, 0)) /* "data" */ + if (!find_chunk(sf, 0x64617461,first_offset,0, &data_offset,&data_size, 0, 0)) /* "data" */ goto fail; /* always found, even with PCM (LyN subchunk seems to contain the engine version, ex. 0x0d/10) */ - if (!find_chunk(streamFile, 0x66616374,first_offset,0, &fact_offset,&fact_size, 0, 0)) /* "fact" */ + if (!find_chunk(sf, 0x66616374,first_offset,0, &fact_offset,&fact_size, 0, 0)) /* "fact" */ goto fail; - if (fact_size != 0x10 || read_32bitBE(fact_offset+0x04, streamFile) != 0x4C794E20) /* "LyN " */ + if (fact_size != 0x10 || read_32bitBE(fact_offset+0x04, sf) != 0x4C794E20) /* "LyN " */ goto fail; - num_samples = read_32bitLE(fact_offset+0x00, streamFile); + num_samples = read_32bitLE(fact_offset+0x00, sf); /* sometimes there is a LySE chunk */ @@ -44,9 +46,9 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { { if (fmt_size < 0x12) goto fail; - codec = (uint16_t)read_16bitLE(fmt_offset+0x00,streamFile); - channel_count = read_16bitLE(fmt_offset+0x02,streamFile); - sample_rate = read_32bitLE(fmt_offset+0x04,streamFile); + codec = read_u16le(fmt_offset+0x00,sf); + channels = read_u16le(fmt_offset+0x02,sf); + sample_rate = read_s32le(fmt_offset+0x04,sf); /* 0x08: average bytes, 0x0c: block align, 0x0e: bps, etc */ /* fake WAVEFORMATEX, used with > 2ch */ @@ -54,10 +56,10 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { if (fmt_size < 0x28) goto fail; /* fake GUID with first value doubling as codec */ - codec = read_32bitLE(fmt_offset+0x18,streamFile); - if (read_32bitBE(fmt_offset+0x1c,streamFile) != 0x00001000 && - read_32bitBE(fmt_offset+0x20,streamFile) != 0x800000AA && - read_32bitBE(fmt_offset+0x24,streamFile) != 0x00389B71) { + codec = read_32bitLE(fmt_offset+0x18,sf); + if (read_32bitBE(fmt_offset+0x1c,sf) != 0x00001000 && + read_32bitBE(fmt_offset+0x20,sf) != 0x800000AA && + read_32bitBE(fmt_offset+0x24,sf) != 0x00389B71) { goto fail; } } @@ -70,7 +72,7 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; vgmstream->sample_rate = sample_rate; @@ -99,7 +101,7 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { }; int i, ch; - for (ch = 0; ch < channel_count; ch++) { + for (ch = 0; ch < channels; ch++) { for (i = 0; i < 16; i++) { vgmstream->ch[ch].adpcm_coef[i] = coef[i]; } @@ -114,27 +116,27 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { layered_layout_data* data = NULL; int i; - if (read_32bitLE(start_offset+0x00,streamFile) != 1) /* id? */ + if (read_32bitLE(start_offset+0x00,sf) != 1) /* id? */ goto fail; - interleave_size = read_32bitLE(start_offset+0x04,streamFile); + interleave_size = read_32bitLE(start_offset+0x04,sf); /* interleave is adjusted so there is no smaller last block, it seems */ vgmstream->coding_type = coding_OGG_VORBIS; vgmstream->layout_type = layout_layered; /* init layout */ - data = init_layout_layered(channel_count); + data = init_layout_layered(channels); if (!data) goto fail; vgmstream->layout_data = data; /* open each layer subfile */ - for (i = 0; i < channel_count; i++) { + for (i = 0; i < channels; i++) { STREAMFILE* temp_sf = NULL; - size_t logical_size = read_32bitLE(start_offset+0x08 + 0x04*i,streamFile); - off_t layer_offset = start_offset + 0x08 + 0x04*channel_count; //+ interleave_size*i; + size_t logical_size = read_32bitLE(start_offset+0x08 + 0x04*i,sf); + off_t layer_offset = start_offset + 0x08 + 0x04*channels; //+ interleave_size*i; - temp_sf = setup_ubi_lyn_streamfile(streamFile, layer_offset, interleave_size, i, channel_count, logical_size); + temp_sf = setup_ubi_lyn_streamfile(sf, layer_offset, interleave_size, i, channels, logical_size); if (!temp_sf) goto fail; data->layers[i] = init_vgmstream_ogg_vorbis(temp_sf); @@ -155,17 +157,23 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { #ifdef VGM_USE_MPEG case 0x5051: { /* MPEG (PS3/PC), interleaved 1ch */ mpeg_custom_config cfg = {0}; - int i; + int i, frame_samples; - cfg.interleave = read_32bitLE(start_offset+0x04,streamFile); - cfg.chunk_size = read_32bitLE(start_offset+0x08,streamFile); /* frame size (not counting MPEG padding?) */ - /* 0x00: id? (2=Tintin, 3=Michael Jackson), 0x0c: frame per interleave, 0x10: samples per frame */ + /* 0x00: config? (related to chunk size? 2=Tintin, some JD4?, 3=Michael Jackson, JD4) */ + cfg.interleave = read_u32le(start_offset+0x04,sf); + /* 0x08: CBR frame size (not counting MPEG padding) */ + /* 0x0c: bps (32) */ + frame_samples = read_s32le(start_offset+0x10,sf); /* skip seek tables and find actual start */ + /* table: entries per channel (1 per chunk, but not chunk-aligned?) */ + /* - 0x00: offset but same for both channels? */ + /* - 0x04: flag? (-1~-N) */ + /* - 0x06: flag? (-1~-N) */ start_offset += 0x14; data_size -= 0x14; - for (i = 0; i < channel_count; i++) { - int entries = read_32bitLE(start_offset,streamFile); + for (i = 0; i < channels; i++) { + int entries = read_s32le(start_offset,sf); start_offset += 0x04 + entries*0x08; data_size -= 0x04 + entries*0x08; @@ -173,8 +181,25 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { cfg.data_size = data_size; - //todo data parsing looks correct but some files decode a bit wrong at the end (ex. Tintin: Music~Boss~Allan~Victory~02) - vgmstream->codec_data = init_mpeg_custom(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_LYN, &cfg); + /* last interleave is half remaining data */ + cfg.max_chunks = (cfg.data_size / (cfg.interleave * channels)); + /* somehow certain interleaves don't work: + * - 0xB400: 0x2D00 ko, 0xE100 ok (max-1) + * - 0x8000: 0x3ec7 ko, 0xbec7 ok (max-1) + * - 0x8000: 0x5306 ok, 0xd306 ko (max-1) !!! + * (doesn't seem related to anything like data size/frame samples/sample rate/etc) */ + cfg.max_chunks--; + cfg.interleave_last = (cfg.data_size - cfg.max_chunks * cfg.interleave * channels) / channels; + if (cfg.interleave <= 0x8000 && cfg.interleave_last > 0xD000) { + cfg.max_chunks++; + cfg.interleave_last = (cfg.data_size - cfg.max_chunks * cfg.interleave * channels) / channels; + } + + /* for some reason num_samples may be +1 or +2 of max possible samples (no apparent meaning) */ + vgmstream->num_samples = vgmstream->num_samples / frame_samples * frame_samples; + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->codec_data = init_mpeg_custom(sf, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_LYN, &cfg); if (!vgmstream->codec_data) goto fail; vgmstream->layout_type = layout_none; @@ -192,13 +217,13 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { /* skip standard XMA header + seek table */ /* 0x00: version? no apparent differences (0x1=Just Dance 4, 0x3=others) */ chunk_offset = start_offset + 0x04 + 0x04; - chunk_size = read_32bitLE(start_offset + 0x04, streamFile); - seek_size = read_32bitLE(chunk_offset+chunk_size, streamFile); + chunk_size = read_32bitLE(start_offset + 0x04, sf); + seek_size = read_32bitLE(chunk_offset+chunk_size, sf); start_offset += (0x04 + 0x04 + chunk_size + 0x04 + seek_size); data_size -= (0x04 + 0x04 + chunk_size + 0x04 + seek_size); - bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf,0x100, chunk_offset,chunk_size, data_size, streamFile, 1); - vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,data_size); + bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf,0x100, chunk_offset,chunk_size, data_size, sf, 1); + vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf,bytes, start_offset,data_size); if ( !vgmstream->codec_data ) goto fail; vgmstream->coding_type = coding_FFmpeg; vgmstream->layout_type = layout_none; @@ -212,7 +237,7 @@ VGMSTREAM * init_vgmstream_ubi_lyn(STREAMFILE *streamFile) { } - if ( !vgmstream_open_stream(vgmstream,streamFile,start_offset) ) + if ( !vgmstream_open_stream(vgmstream,sf,start_offset) ) goto fail; return vgmstream; @@ -223,7 +248,7 @@ fail: /* LyN RIFF in containers */ -VGMSTREAM * init_vgmstream_ubi_lyn_container(STREAMFILE *streamFile) { +VGMSTREAM * init_vgmstream_ubi_lyn_container(STREAMFILE *sf) { VGMSTREAM *vgmstream = NULL; STREAMFILE *temp_sf = NULL; off_t subfile_offset; @@ -233,29 +258,29 @@ VGMSTREAM * init_vgmstream_ubi_lyn_container(STREAMFILE *streamFile) { * data before the RIFF. Might as well support them in case the RIFF wasn't extracted. */ /* checks */ - if (!check_extensions(streamFile,"sns,wav,lwav,son")) + if (!check_extensions(sf,"sns,wav,lwav,son")) goto fail; /* find "RIFF" position */ - if (read_32bitBE(0x00,streamFile) == 0x4C795345 && /* "LySE" */ - read_32bitBE(0x14,streamFile) == 0x52494646) { /* "RIFF" */ + if (read_32bitBE(0x00,sf) == 0x4C795345 && /* "LySE" */ + read_32bitBE(0x14,sf) == 0x52494646) { /* "RIFF" */ subfile_offset = 0x14; /* Adventures of Tintin */ } - else if (read_32bitBE(0x20,streamFile) == 0x4C795345 && /* "LySE" */ - read_32bitBE(0x34,streamFile) == 0x52494646) { /* "RIFF" */ + else if (read_32bitBE(0x20,sf) == 0x4C795345 && /* "LySE" */ + read_32bitBE(0x34,sf) == 0x52494646) { /* "RIFF" */ subfile_offset = 0x34; /* Michael Jackson The Experience (Wii) */ } - else if (read_32bitLE(0x00,streamFile)+0x20 == get_streamfile_size(streamFile) && - read_32bitBE(0x20,streamFile) == 0x52494646) { /* "RIFF" */ + else if (read_32bitLE(0x00,sf)+0x20 == get_streamfile_size(sf) && + read_32bitBE(0x20,sf) == 0x52494646) { /* "RIFF" */ subfile_offset = 0x20; /* Red Steel 2, From Dust */ } else { goto fail; } - subfile_size = read_32bitLE(subfile_offset+0x04,streamFile) + 0x04+0x04; + subfile_size = read_32bitLE(subfile_offset+0x04,sf) + 0x04+0x04; - temp_sf = setup_subfile_streamfile(streamFile, subfile_offset, subfile_size, NULL); + temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, NULL); if (!temp_sf) goto fail; vgmstream = init_vgmstream_ubi_lyn(temp_sf); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/xsh_xsd_xss.c b/Frameworks/vgmstream/vgmstream/src/meta/xsh_xsd_xss.c new file mode 100644 index 000000000..2c7dfc48b --- /dev/null +++ b/Frameworks/vgmstream/vgmstream/src/meta/xsh_xsd_xss.c @@ -0,0 +1,170 @@ +#include "meta.h" +#include "../coding/coding.h" + + +/* XSH+XSD/XSS - from Treyarch games [Spider-Man 2002 (Xbox), Kelly Slater's Pro Surfer (Xbox)] */ +VGMSTREAM* init_vgmstream_xsh_xsd_xss(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* sf_body = NULL; + uint32_t offset; + uint32_t stream_type, stream_offset, stream_size; + uint32_t name_offset, name_size; + uint32_t flags; + int32_t num_samples; + int version = 0; + int loop_flag, channels, codec, sample_rate; + int total_subsongs, target_subsong = sf->stream_index; + + + /* checks */ + if (!check_extensions(sf, "xsh")) + goto fail; + + version = read_u32le(0x00, sf); + + if (read_u32le(0x04, sf) != 0) + goto fail; + + total_subsongs = read_u32le(0x08, sf); + if (target_subsong == 0) target_subsong = 1; + if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail; + + switch(version) { + case 0x009D: + offset = 0x0c + (target_subsong-1) * 0x60; + + name_offset = offset + 0x00; + name_size = 0x20; + stream_type = read_u32le(offset + 0x20,sf); + stream_offset = read_u32le(offset + 0x24,sf); + stream_size = read_u32le(offset + 0x28,sf); + flags = read_u32le(offset + 0x34,sf); + /* 0x38: flags? */ + num_samples = 0; + + offset = offset + 0x3c; + break; + + case 0x0100: + offset = 0x0c + (target_subsong-1) * 0x64; + + name_offset = offset + 0x00; + name_size = 0x20; + stream_type = read_u32le(offset + 0x20,sf); + stream_offset = read_u32le(offset + 0x24,sf); + stream_size = read_u32le(offset + 0x28,sf); + flags = read_u32le(offset + 0x34,sf); + num_samples = read_u32le(offset + 0x38,sf); + /* 0x3c: flags? */ + + offset = offset + 0x40; + break; + + default: + goto fail; + } + + loop_flag = 0; + + if (stream_type < 0 || stream_type > 2) + goto fail; + + /* 0x00: floats x4 (volume/pan/etc? usually 1.0, 1.0, 10.0, 10.0) */ + codec = read_u16le(offset + 0x10,sf); + channels = read_u16le(offset + 0x12,sf); + sample_rate = read_u32le(offset + 0x14,sf); + /* 0x18: avg bitrate */ + /* 0x1c: block size */ + /* 0x1e: bps */ + /* 0x20: 2? */ + + if (stream_type == 0) { + vgmstream = init_vgmstream_silence_container(total_subsongs); + if (!vgmstream) goto fail; + + close_streamfile(sf_body); + return vgmstream; + } + + if (flags & 0x04) { + char filename[255]; + switch (version) { + case 0x009D: + /* stream is a named .xss, with stream_offset/size = 0 (Spider-Man) */ + read_string(filename, name_size, name_offset,sf); + strcat(filename, ".xss"); + + sf_body = open_streamfile_by_filename(sf,filename); + if (!sf_body) { + VGM_LOG("XSH: can't find %s\n", filename); + goto fail; + } + + /* xss is playable externally, so this is mostly for show */ + vgmstream = init_vgmstream_riff(sf_body); + if (!vgmstream) goto fail; + + vgmstream->num_streams = total_subsongs; + read_string(vgmstream->stream_name, name_size, name_offset,sf); + + close_streamfile(sf_body); + return vgmstream; + //break; + + case 0x0100: + /* bigfile with all streams (Kelly Slater) */ + snprintf(filename, sizeof(filename), "%s", "STREAMS.XSS"); + sf_body = open_streamfile_by_filename(sf,filename); + if (!sf_body) { + VGM_LOG("XSH: can't find %s\n", filename); + goto fail; + } + break; + + default: + goto fail; + } + + } + else { + sf_body = open_streamfile_by_ext(sf,"xsd"); + if (!sf_body) { + VGM_LOG("XSH: can't find XSD"); + goto fail; + } + } + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_XSH_XSD_XSS; + vgmstream->sample_rate = sample_rate; + vgmstream->num_streams = total_subsongs; + vgmstream->stream_size = stream_size; + + switch(codec) { + case 0x0069: + vgmstream->coding_type = coding_XBOX_IMA; + vgmstream->layout_type = layout_none; + + if (!num_samples) + num_samples = xbox_ima_bytes_to_samples(stream_size, channels); + + vgmstream->num_samples = num_samples; + break; + } + + read_string(vgmstream->stream_name, name_size, name_offset,sf); + + if (!vgmstream_open_stream(vgmstream, sf_body, stream_offset)) + goto fail; + close_streamfile(sf_body); + return vgmstream; + +fail: + close_streamfile(sf_body); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.c b/Frameworks/vgmstream/vgmstream/src/vgmstream.c index 85f5aba8b..fa85e4d60 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.c +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.c @@ -528,6 +528,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_piff_tpcm, init_vgmstream_wxd_wxh, init_vgmstream_bnk_relic, + init_vgmstream_xsh_xsd_xss, /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */ @@ -819,7 +820,7 @@ void close_vgmstream(VGMSTREAM* vgmstream) { void vgmstream_force_loop(VGMSTREAM* vgmstream, int loop_flag, int loop_start_sample, int loop_end_sample) { if (!vgmstream) return; - /* ignore bad values (may happen with layers + TXTP loop install) */ + /* ignore bad values (may happen with layers + TXTP loop install) */ if (loop_flag && (loop_start_sample < 0 || loop_start_sample > loop_end_sample || loop_end_sample > vgmstream->num_samples)) diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.h b/Frameworks/vgmstream/vgmstream/src/vgmstream.h index d76edf31a..1ed7e0a29 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.h +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.h @@ -42,8 +42,6 @@ enum { #include #endif -#include "clHCA.h" - #ifdef BUILD_VGMSTREAM #include "coding/g72x_state.h" #else @@ -749,6 +747,8 @@ typedef enum { meta_PIFF_TPCM, meta_WXD_WXH, meta_BNK_RELIC, + meta_XSH_XSD_XSS, + } meta_t; /* standard WAVEFORMATEXTENSIBLE speaker positions */