From e0fe91735673765f404bebe5dbe8216958437f89 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Fri, 14 Mar 2014 22:43:51 -0700 Subject: [PATCH] Updated vgmstream --- .../vgmstream/vgmstream/src/meta/bcstm.c | 82 +++++++++++++++---- .../vgmstream/src/meta/dc_dcsw_dcs.c | 2 +- .../vgmstream/src/meta/dsp_sth_str.c | 6 +- .../vgmstream/vgmstream/src/meta/gsp_gsb.c | 2 +- .../vgmstream/vgmstream/src/meta/ish_isd.c | 2 +- .../vgmstream/vgmstream/src/meta/mus_acm.c | 2 +- .../vgmstream/src/meta/ngc_sck_dsp.c | 2 +- Frameworks/vgmstream/vgmstream/src/meta/nwa.c | 8 +- Frameworks/vgmstream/vgmstream/src/meta/pos.c | 2 +- .../vgmstream/vgmstream/src/meta/ps2_mib.c | 2 +- .../vgmstream/vgmstream/src/meta/ps2_wmus.c | 2 +- .../vgmstream/src/meta/ps3_sgh_sgb.c | 2 +- Frameworks/vgmstream/vgmstream/src/meta/sfl.c | 2 +- Frameworks/vgmstream/vgmstream/src/meta/sli.c | 4 +- .../vgmstream/vgmstream/src/meta/spt_spd.c | 2 +- .../vgmstream/vgmstream/src/meta/sqex_scd.c | 2 + 16 files changed, 86 insertions(+), 38 deletions(-) diff --git a/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c b/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c index 2773a48eb..9ee9d544f 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/bcstm.c @@ -8,9 +8,11 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { coding_t coding_type; off_t head_offset; + off_t seek_offset; int codec_number; int channel_count; int loop_flag; + int ima = 0; off_t start_offset; /* check extension, case insensitive */ @@ -29,11 +31,15 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { /* get head offset, check */ head_offset = read_32bitLE(0x18, streamFile); - + if ((uint32_t)read_32bitBE(head_offset, streamFile) != 0x494E464F) /* "INFO" */ goto fail; - + seek_offset = read_32bitLE(0x24, streamFile); + + if ((uint32_t)read_32bitBE(seek_offset, streamFile) != 0x5345454B) /* "SEEK" If this header doesn't exist, assuming that the file is IMA */ + ima = 1; + /* check type details */ codec_number = read_8bit(head_offset + 0x20, streamFile); loop_flag = read_8bit(head_offset + 0x21, streamFile); @@ -47,7 +53,10 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { coding_type = coding_PCM16BE; break; case 2: - coding_type = coding_NGC_DSP; + if (ima) + coding_type = coding_INT_IMA; + else + coding_type = coding_NGC_DSP; break; default: goto fail; @@ -64,30 +73,59 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { vgmstream->num_samples = read_32bitLE(head_offset + 0x2c, streamFile); vgmstream->sample_rate = (uint16_t)read_16bitLE(head_offset + 0x24, streamFile); /* channels and loop flag are set by allocate_vgmstream */ - vgmstream->loop_start_sample = read_32bitLE(head_offset + 0x28, streamFile); - vgmstream->loop_end_sample = vgmstream->num_samples; + if (ima) //Shift the loop points back slightly to avoid stupid pops in some IMA streams due to DC offsetting + { + vgmstream->loop_start_sample = read_32bitLE(head_offset + 0x28, streamFile); + if (vgmstream->loop_start_sample > 10000) + { + vgmstream->loop_start_sample -= 5000; + vgmstream->loop_end_sample = vgmstream->num_samples - 5000; + } + else + vgmstream->loop_end_sample = vgmstream->num_samples; + } + else + { + vgmstream->loop_start_sample = read_32bitLE(head_offset + 0x28, streamFile); + vgmstream->loop_end_sample = vgmstream->num_samples; + } vgmstream->coding_type = coding_type; if (channel_count == 1) vgmstream->layout_type = layout_none; else - vgmstream->layout_type = layout_interleave_shortblock; + { + if (ima) + vgmstream->layout_type = layout_interleave; + else + vgmstream->layout_type = layout_interleave_shortblock; + } vgmstream->meta_type = meta_CSTM; - - vgmstream->interleave_block_size = read_32bitLE(head_offset + 0x34, streamFile); - vgmstream->interleave_smallblock_size = read_32bitLE(head_offset + 0x44, streamFile); - + + if (ima) + vgmstream->interleave_block_size = 0x200; + else { + vgmstream->interleave_block_size = read_32bitLE(head_offset + 0x34, streamFile); + vgmstream->interleave_smallblock_size = read_32bitLE(head_offset + 0x44, streamFile); + } + if (vgmstream->coding_type == coding_NGC_DSP) { off_t coef_offset; - off_t coef_offset1; - off_t coef_offset2; + off_t tempoffset = head_offset; + int foundcoef = 0; int i, j; int coef_spacing = 0x2E; - - coef_offset1 = read_32bitLE(head_offset + 0x1c, streamFile); - coef_offset = coef_offset1 + 0x40; - + while (!(foundcoef)) + { + if ((uint32_t)read_32bitLE(tempoffset, streamFile) == 0x00004102) + { + coef_offset = read_32bitLE(tempoffset + 4, streamFile) + tempoffset + (channel_count * 8) - 4 - head_offset; + foundcoef++; + break; + } + tempoffset++; + } for (j = 0; jchannels; j++) { for (i = 0; i<16; i++) { @@ -95,8 +133,13 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { } } } - - start_offset = read_32bitLE(0x30, streamFile) + 0x20; + + if (ima) // No SEEK (ADPC) header, so just start where the SEEK header is supposed to be. + start_offset = seek_offset; + else + start_offset = read_32bitLE(0x30, streamFile) + 0x20; + + /* open the file for reading by each channel */ { @@ -105,6 +148,9 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) { if (vgmstream->layout_type == layout_interleave_shortblock) vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename, vgmstream->interleave_block_size); + else if (vgmstream->layout_type == layout_interleave) + vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename, + STREAMFILE_DEFAULT_BUFFER_SIZE); else vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename, 0x1000); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/dc_dcsw_dcs.c b/Frameworks/vgmstream/vgmstream/src/meta/dc_dcsw_dcs.c index 128c7a7d0..23105fd07 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/dc_dcsw_dcs.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/dc_dcsw_dcs.c @@ -13,7 +13,7 @@ VGMSTREAM * init_vgmstream_dc_dcsw_dcs(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileDCSW = NULL; char filename[PATH_LIMIT]; - char filenameDCSW[260]; + char filenameDCSW[PATH_LIMIT]; int i; int channel_count; int loop_flag; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/dsp_sth_str.c b/Frameworks/vgmstream/vgmstream/src/meta/dsp_sth_str.c index e601b6b17..4db018c13 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/dsp_sth_str.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/dsp_sth_str.c @@ -10,7 +10,7 @@ VGMSTREAM * init_vgmstream_ngc_dsp_sth_str1(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileSTR = NULL; char filename[PATH_LIMIT]; - char filenameSTR[260]; + char filenameSTR[PATH_LIMIT]; int i, j; int channel_count; int loop_flag; @@ -116,7 +116,7 @@ VGMSTREAM * init_vgmstream_ngc_dsp_sth_str2(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileSTR = NULL; char filename[PATH_LIMIT]; - char filenameSTR[260]; + char filenameSTR[PATH_LIMIT]; int i, j; int channel_count; int loop_flag; @@ -222,7 +222,7 @@ VGMSTREAM * init_vgmstream_ngc_dsp_sth_str3(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileSTR = NULL; char filename[PATH_LIMIT]; - char filenameSTR[260]; + char filenameSTR[PATH_LIMIT]; int i, j; int channel_count; int loop_flag; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/gsp_gsb.c b/Frameworks/vgmstream/vgmstream/src/meta/gsp_gsb.c index 6847b88c5..dba787108 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/gsp_gsb.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/gsp_gsb.c @@ -9,7 +9,7 @@ VGMSTREAM * init_vgmstream_gsp_gsb(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileGSP = NULL; char filename[PATH_LIMIT]; - char filenameGSP[260]; + char filenameGSP[PATH_LIMIT]; int channel_count; int loop_flag; int header_len; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ish_isd.c b/Frameworks/vgmstream/vgmstream/src/meta/ish_isd.c index 7078a093a..6b3c734a9 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ish_isd.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ish_isd.c @@ -10,7 +10,7 @@ VGMSTREAM * init_vgmstream_ish_isd(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileISH = NULL; char filename[PATH_LIMIT]; - char filenameISH[260]; + char filenameISH[PATH_LIMIT]; int i; int channel_count; int loop_flag; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/mus_acm.c b/Frameworks/vgmstream/vgmstream/src/meta/mus_acm.c index 7bd10a8b6..6d488785b 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/mus_acm.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/mus_acm.c @@ -13,7 +13,7 @@ #define DIRSEP '/' #endif -#define NAME_LENGTH 260 +#define NAME_LENGTH PATH_LIMIT int exists(char *filename, STREAMFILE *streamfile) { STREAMFILE * temp = diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ngc_sck_dsp.c b/Frameworks/vgmstream/vgmstream/src/meta/ngc_sck_dsp.c index 7f5610c32..ad9e1498a 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ngc_sck_dsp.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ngc_sck_dsp.c @@ -11,7 +11,7 @@ VGMSTREAM * init_vgmstream_ngc_sck_dsp(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileDSP = NULL; char filename[PATH_LIMIT]; - char filenameDSP[260]; + char filenameDSP[PATH_LIMIT]; int i; int channel_count; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/nwa.c b/Frameworks/vgmstream/vgmstream/src/meta/nwa.c index d3f809935..d4743a5c1 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/nwa.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/nwa.c @@ -57,9 +57,9 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) { /* try to locate NWAINFO.INI in the same directory */ { - char ininame[260]; + char ininame[PATH_LIMIT]; char * ini_lastslash; - char namebase_array[260]; + char namebase_array[PATH_LIMIT]; char *namebase; STREAMFILE *inistreamfile; @@ -134,9 +134,9 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) { /* try to locate Gameexe.ini in the same directory */ { - char ininame[260]; + char ininame[PATH_LIMIT]; char * ini_lastslash; - char namebase_array[260]; + char namebase_array[PATH_LIMIT]; char * namebase; STREAMFILE *inistreamfile; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/pos.c b/Frameworks/vgmstream/vgmstream/src/meta/pos.c index 153f7b11b..c5ca20e0f 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/pos.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/pos.c @@ -15,7 +15,7 @@ VGMSTREAM * init_vgmstream_pos(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileWAV = NULL; char filename[PATH_LIMIT]; - char filenameWAV[260]; + char filenameWAV[PATH_LIMIT]; int i; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ps2_mib.c b/Frameworks/vgmstream/vgmstream/src/meta/ps2_mib.c index a509d2db1..26b669a22 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ps2_mib.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ps2_mib.c @@ -51,7 +51,7 @@ VGMSTREAM * init_vgmstream_ps2_mib(STREAMFILE *streamFile) { off_t readOffset = 0; - char filenameMIH[260]; + char filenameMIH[PATH_LIMIT]; off_t loopStartPoints[0x10]; int loopStartPointsCount=0; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ps2_wmus.c b/Frameworks/vgmstream/vgmstream/src/meta/ps2_wmus.c index f669f78a1..58f64d409 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ps2_wmus.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ps2_wmus.c @@ -20,7 +20,7 @@ VGMSTREAM * init_vgmstream_ps2_wmus(STREAMFILE *streamFile) int shortBlockSize; int lastBlockLocation; - char filenameWHED[260]; + char filenameWHED[PATH_LIMIT]; STREAMFILE * streamFileWHED = NULL; //_TCHAR szBuffer[100]; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ps3_sgh_sgb.c b/Frameworks/vgmstream/vgmstream/src/meta/ps3_sgh_sgb.c index 3b9b0fb05..a99348a63 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ps3_sgh_sgb.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ps3_sgh_sgb.c @@ -7,7 +7,7 @@ VGMSTREAM * init_vgmstream_ps3_sgh_sgb(STREAMFILE *streamFile) { off_t start_offset = 0; STREAMFILE * streamFileSGH = NULL; char filename[PATH_LIMIT]; - char filenameSGH[260]; + char filenameSGH[PATH_LIMIT]; int channel_count; int loop_flag; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sfl.c b/Frameworks/vgmstream/vgmstream/src/meta/sfl.c index 388c9c858..c656142b0 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/sfl.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/sfl.c @@ -73,7 +73,7 @@ static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *stream VGMSTREAM * init_vgmstream_sfl(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileOGG = NULL; - char filenameOGG[260]; + char filenameOGG[PATH_LIMIT]; char filename[PATH_LIMIT]; off_t file_size = -1; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sli.c b/Frameworks/vgmstream/vgmstream/src/meta/sli.c index 621cfb84f..78d2950d7 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/sli.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/sli.c @@ -19,8 +19,8 @@ VGMSTREAM * init_vgmstream_sli_ogg(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileOGG = NULL; char filename[PATH_LIMIT]; - char filenameOGG[260]; - char linebuffer[260]; + char filenameOGG[PATH_LIMIT]; + char linebuffer[PATH_LIMIT]; off_t bytes_read; off_t sli_offset; int done; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/spt_spd.c b/Frameworks/vgmstream/vgmstream/src/meta/spt_spd.c index 53d73c8f9..04b1a0a0f 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/spt_spd.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/spt_spd.c @@ -11,7 +11,7 @@ VGMSTREAM * init_vgmstream_spt_spd(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; STREAMFILE * streamFileSPT = NULL; char filename[PATH_LIMIT]; - char filenameSPT[260]; + char filenameSPT[PATH_LIMIT]; int channel_count; int loop_flag; int i; diff --git a/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd.c b/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd.c index 11d1423a7..82422b2de 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/sqex_scd.c @@ -177,6 +177,8 @@ VGMSTREAM * init_vgmstream_sqex_scd(STREAMFILE *streamFile) { if (vgmstream->sample_rate == 47999) vgmstream->sample_rate = 48000; + if (vgmstream->sample_rate == 44099) + vgmstream->sample_rate = 44100; mpeg_data = init_mpeg_codec_data(streamFile, start_offset, vgmstream->sample_rate, vgmstream->channels, &ct, NULL, NULL); if (!mpeg_data) goto fail;