From 9bc9e4778102e0edcf7f48a260ef0b5757a57884 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Tue, 16 Sep 2014 16:46:42 -0700 Subject: [PATCH] Updated vgmstream to revision 1039 --- .../xcshareddata/Cog.xccheckout | 37 +++ Frameworks/vgmstream/vgmstream/src/meta/fsb.c | 8 +- .../vgmstream/vgmstream/src/meta/meta.h | 6 + .../vgmstream/src/meta/ngc_dsp_std.c | 248 ++++++++++++++++++ .../vgmstream/vgmstream/src/vgmstream.c | 11 +- .../vgmstream/vgmstream/src/vgmstream.h | 18 +- 6 files changed, 308 insertions(+), 20 deletions(-) create mode 100644 Cog.xcodeproj/project.xcworkspace/xcshareddata/Cog.xccheckout diff --git a/Cog.xcodeproj/project.xcworkspace/xcshareddata/Cog.xccheckout b/Cog.xcodeproj/project.xcworkspace/xcshareddata/Cog.xccheckout new file mode 100644 index 000000000..0d90643c9 --- /dev/null +++ b/Cog.xcodeproj/project.xcworkspace/xcshareddata/Cog.xccheckout @@ -0,0 +1,37 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 811E8515-6C50-44FF-ACDB-088BB9917E26 + IDESourceControlProjectOriginsDictionary + + EF1CF5E1F342919DE309B5C9DAEDDCF1D12D0402 + https://github.com/andymatuschak/Sparkle.git + + IDESourceControlProjectRelativeInstallPathDictionary + + EF1CF5E1F342919DE309B5C9DAEDDCF1D12D0402 + Sparkle/ + + IDESourceControlProjectURL + https://github.com/andymatuschak/Sparkle.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + EF1CF5E1F342919DE309B5C9DAEDDCF1D12D0402 + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + EF1CF5E1F342919DE309B5C9DAEDDCF1D12D0402 + IDESourceControlWCCName + Sparkle + + + + diff --git a/Frameworks/vgmstream/vgmstream/src/meta/fsb.c b/Frameworks/vgmstream/vgmstream/src/meta/fsb.c index 473df3e89..165d6d883 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/fsb.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/fsb.c @@ -581,8 +581,8 @@ VGMSTREAM * init_vgmstream_fsb_mpeg(STREAMFILE *streamFile) { start_offset = fsb_mainheader_len+fsb_subheader_len+0x10; /* Check the MPEG Sync Header */ - mp3ID = read_16bitLE(start_offset,streamFile); - if ((mp3ID&0x7FF) != 0x7FF) + mp3ID = read_16bitBE(start_offset,streamFile); + if ((mp3ID&0xFFE0) != 0xFFE0) goto fail; channel_count = read_16bitLE(fsb_mainheader_len+0x3E,streamFile); @@ -717,8 +717,8 @@ VGMSTREAM * init_vgmstream_fsb5_mpeg(STREAMFILE *streamFile) { start_offset = fsb_mainheader_len+fsb_subheader_len+0x10; /* Check the MPEG Sync Header */ - mp3ID = read_16bitLE(start_offset,streamFile); - if ((mp3ID&0x7FF) != 0x7FF) + mp3ID = read_16bitBE(start_offset,streamFile); + if ((mp3ID&0xFFE0) != 0xFFE0) goto fail; channel_count = read_16bitLE(fsb_mainheader_len+0x3E,streamFile); diff --git a/Frameworks/vgmstream/vgmstream/src/meta/meta.h b/Frameworks/vgmstream/vgmstream/src/meta/meta.h index bc4eab127..8dfe2162d 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/meta.h +++ b/Frameworks/vgmstream/vgmstream/src/meta/meta.h @@ -3,6 +3,8 @@ #include "../vgmstream.h" +VGMSTREAM * init_vgmstream_3ds_idsp(STREAMFILE *streamFile); + VGMSTREAM * init_vgmstream_adx(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_afc(STREAMFILE *streamFile); @@ -31,6 +33,8 @@ VGMSTREAM * init_vgmstream_ngc_mpdsp(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_ngc_dsp_std_int(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_ngc_dsp_csmp(STREAMFILE *streamFile); + VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_ps2_npsf(STREAMFILE *streamFile); @@ -632,4 +636,6 @@ VGMSTREAM * init_vgmstream_otm(STREAMFILE* streamFile); VGMSTREAM * init_vgmstream_bcstm(STREAMFILE* streamFile); +VGMSTREAM * init_vgmstream_bfwav(STREAMFILE* streamFile); + #endif diff --git a/Frameworks/vgmstream/vgmstream/src/meta/ngc_dsp_std.c b/Frameworks/vgmstream/vgmstream/src/meta/ngc_dsp_std.c index 249a56c42..5040f2466 100644 --- a/Frameworks/vgmstream/vgmstream/src/meta/ngc_dsp_std.c +++ b/Frameworks/vgmstream/vgmstream/src/meta/ngc_dsp_std.c @@ -596,6 +596,124 @@ fail: return NULL; } +/* 3DS IDSP two standard DSP headers (SSB4) */ +VGMSTREAM * init_vgmstream_3ds_idsp(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + char filename[PATH_LIMIT]; + + off_t start_offset; + off_t interleave; + + struct dsp_header ch0_header,ch1_header; + int i; + int channel_count; + + /* check extension, case insensitive */ + streamFile->get_name(streamFile,filename,sizeof(filename)); + if (strcasecmp("idsp",filename_extension(filename))) goto fail; + + /* check header magic */ + if (read_32bitBE(0x0,streamFile) != 0x49445350) goto fail; /* "IDSP" */ + + channel_count = read_32bitBE(0x8, streamFile); + if (channel_count != 2) goto fail; + + if (read_dsp_header(&ch0_header, 0x40, streamFile)) goto fail; + if (channel_count == 2 && read_dsp_header(&ch1_header, 0xa0, streamFile)) goto fail; + + start_offset = read_32bitBE(0x28,streamFile); + interleave = 16; + + /* check initial predictor/scale */ + if (ch0_header.initial_ps != (uint8_t)read_8bit(start_offset,streamFile)) + goto fail; + if (channel_count == 2 && ch1_header.initial_ps != (uint8_t)read_8bit(start_offset+interleave,streamFile)) + goto fail; + + /* check type==0 and gain==0 */ + if (ch0_header.format || ch0_header.gain || + (channel_count == 2 &&(ch1_header.format || ch1_header.gain))) + goto fail; + + /* check for agreement */ + if ( channel_count == 2 &&( + ch0_header.sample_count != ch1_header.sample_count || + ch0_header.nibble_count != ch1_header.nibble_count || + ch0_header.sample_rate != ch1_header.sample_rate || + ch0_header.sample_rate != read_32bitBE(0xc, streamFile) || + ch0_header.loop_flag != ch1_header.loop_flag || + ch0_header.loop_start_offset != ch1_header.loop_start_offset || + ch0_header.loop_end_offset != ch1_header.loop_end_offset + )) goto fail; + + if (ch0_header.loop_flag) { + off_t loop_off; + /* check loop predictor/scale */ + loop_off = ch0_header.loop_start_offset/8/channel_count*8; + loop_off = (loop_off/interleave*interleave*channel_count) + (loop_off%interleave); + if (ch0_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off,streamFile)) + goto fail; + if (channel_count == 2 && + ch1_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off+interleave,streamFile)) + goto fail; + } + + /* build the VGMSTREAM */ + + vgmstream = allocate_vgmstream(channel_count,ch0_header.loop_flag); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + vgmstream->num_samples = ch0_header.sample_count; + vgmstream->sample_rate = ch0_header.sample_rate; + + /* TODO: adjust for interleave? */ + vgmstream->loop_start_sample = dsp_nibbles_to_samples( + ch0_header.loop_start_offset); + vgmstream->loop_end_sample = dsp_nibbles_to_samples( + ch0_header.loop_end_offset)+1; + + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = channel_count == 2 ? layout_interleave : layout_none; + vgmstream->interleave_block_size = interleave; + vgmstream->meta_type = meta_3DS_IDSP; + + /* coeffs */ + for (i=0;i<16;i++) { + vgmstream->ch[0].adpcm_coef[i] = ch0_header.coef[i]; + if (channel_count == 2) + vgmstream->ch[1].adpcm_coef[i] = ch1_header.coef[i]; + } + + /* initial history */ + /* always 0 that I've ever seen, but for completeness... */ + vgmstream->ch[0].adpcm_history1_16 = ch0_header.initial_hist1; + vgmstream->ch[0].adpcm_history2_16 = ch0_header.initial_hist2; + + vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); + + if (channel_count == 2) { + vgmstream->ch[1].adpcm_history1_16 = ch1_header.initial_hist1; + vgmstream->ch[1].adpcm_history2_16 = ch1_header.initial_hist2; + vgmstream->ch[1].streamfile = vgmstream->ch[0].streamfile; + } + + if (!vgmstream->ch[0].streamfile) goto fail; + /* open the file for reading */ + for (i=0;ich[i].channel_start_offset= + vgmstream->ch[i].offset=start_offset+i*interleave; + } + + return vgmstream; + +fail: + /* clean up anything we may have opened */ + if (vgmstream) close_vgmstream(vgmstream); + return NULL; +} + + /* sadb - .SAD files, two standard DSP headers */ VGMSTREAM * init_vgmstream_sadb(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; @@ -2462,3 +2580,133 @@ fail: return NULL; } +/* the csmp format from Metroid Prime 3 and DKCR */ + +#define CSMP_MAGIC 0x43534D50 +#define CSMP_DATA 0x44415441 + +struct csmp_chunk { + uint32_t id; + uint32_t length; +}; + +VGMSTREAM * init_vgmstream_ngc_dsp_csmp(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + char filename[PATH_LIMIT]; + + struct dsp_header header; + const off_t start_offset = 0x60; + int i; + int csmp_magic; + int csmp_version; + + /* check extension, case insensitive */ + streamFile->get_name(streamFile,filename,sizeof(filename)); + if (strcasecmp("csmp",filename_extension(filename))) goto fail; + + off_t current_offset = 0; + + csmp_magic = read_32bitBE(current_offset, streamFile); + if (csmp_magic != CSMP_MAGIC) goto fail; + + current_offset += 4; + + csmp_version = read_32bitBE(current_offset, streamFile); + if (csmp_version != 1) goto fail; + + current_offset += 4; + + int tries =0; + while (1) + { + if (tries > 4) + goto fail; + + struct csmp_chunk chunk; + chunk.id = read_32bitBE(current_offset, streamFile); + chunk.length = read_32bitBE(current_offset + 4, streamFile); + current_offset += 8; + if (chunk.id != CSMP_DATA) + { + current_offset += chunk.length; + tries++; + continue; + } + + break; + } + + if (read_dsp_header(&header, current_offset, streamFile)) goto fail; + + /* check initial predictor/scale */ + /* Retro doesn't seem to abide by this */ + //if (header.initial_ps != (uint8_t)read_8bit(current_offset + start_offset,streamFile)) + // goto fail; + + /* check type==0 and gain==0 */ + if (header.format || header.gain) + goto fail; + + if (header.loop_flag) { + off_t loop_off; + /* check loop predictor/scale */ + loop_off = header.loop_start_offset/16*8; + /* Retro doesn't seem to abide by this */ +// if (header.loop_ps != (uint8_t)read_8bit(current_offset + start_offset+loop_off,streamFile)) +// goto fail; + } + + /* compare num_samples with nibble count */ + /* + fprintf(stderr,"num samples (literal): %d\n",read_32bitBE(0,streamFile)); + fprintf(stderr,"num samples (nibbles): %d\n",dsp_nibbles_to_samples(read_32bitBE(4,streamFile))); + */ + + /* build the VGMSTREAM */ + + + vgmstream = allocate_vgmstream(1,header.loop_flag); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + vgmstream->num_samples = header.sample_count; + vgmstream->sample_rate = header.sample_rate; + + vgmstream->loop_start_sample = dsp_nibbles_to_samples( + header.loop_start_offset); + vgmstream->loop_end_sample = dsp_nibbles_to_samples( + header.loop_end_offset)+1; + + /* don't know why, but it does happen*/ + if (vgmstream->loop_end_sample > vgmstream->num_samples) + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_none; + vgmstream->meta_type = meta_DSP_CSMP; + + /* coeffs */ + for (i=0;i<16;i++) + vgmstream->ch[0].adpcm_coef[i] = header.coef[i]; + + /* initial history */ + /* always 0 that I've ever seen, but for completeness... */ + vgmstream->ch[0].adpcm_history1_16 = header.initial_hist1; + vgmstream->ch[0].adpcm_history2_16 = header.initial_hist2; + + /* open the file for reading */ + vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); + + if (!vgmstream->ch[0].streamfile) goto fail; + + vgmstream->ch[0].channel_start_offset= + vgmstream->ch[0].offset=current_offset + start_offset; + + return vgmstream; + +fail: + /* clean up anything we may have opened */ + if (vgmstream) close_vgmstream(vgmstream); + return NULL; +} + diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.c b/Frameworks/vgmstream/vgmstream/src/vgmstream.c index 3ea9bc3d8..6c6dc3f4d 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.c +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.c @@ -17,6 +17,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = { init_vgmstream_adx, init_vgmstream_brstm, + init_vgmstream_bfwav, init_vgmstream_nds_strm, init_vgmstream_agsc, init_vgmstream_ngc_adpdtk, @@ -26,6 +27,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = { init_vgmstream_halpst, init_vgmstream_rs03, init_vgmstream_ngc_dsp_std, + init_vgmstream_ngc_dsp_csmp, init_vgmstream_Cstr, init_vgmstream_gcsw, init_vgmstream_ps2_ads, @@ -331,6 +333,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = { init_vgmstream_ps2_vbk, init_vgmstream_otm, init_vgmstream_bcstm, + init_vgmstream_3ds_idsp, }; #define INIT_VGMSTREAM_FCNS (sizeof(init_vgmstream_fcns)/sizeof(init_vgmstream_fcns[0])) @@ -2142,6 +2145,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { case meta_DSP_AGSC: snprintf(temp,TEMPSIZE,"Retro Studios AGSC header"); break; + case meta_DSP_CSMP: + snprintf(temp,TEMPSIZE,"Retro Studios CSMP header"); + break; case meta_NGC_ADPDTK: snprintf(temp,TEMPSIZE,"assumed Nintendo ADP by .adp extension and valid first frame"); break; @@ -3066,6 +3072,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { case meta_CSTM: snprintf(temp,TEMPSIZE,"Nintendo 3DS CSTM Header"); break; + case meta_3DS_IDSP: + snprintf(temp,TEMPSIZE,"Nintendo 3DS IDSP Header"); + break; default: snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET"); } @@ -3084,7 +3093,7 @@ const char * const dfs_pairs[][2] = { void try_dual_file_stereo(VGMSTREAM * opened_stream, STREAMFILE *streamFile) { char filename[PATH_LIMIT]; - char filename2[260]; + char filename2[PATH_LIMIT]; char * ext; int dfs_name= -1; /*-1=no stereo, 0=opened_stream is left, 1=opened_stream is right */ VGMSTREAM * new_stream = NULL; diff --git a/Frameworks/vgmstream/vgmstream/src/vgmstream.h b/Frameworks/vgmstream/vgmstream/src/vgmstream.h index 66381848e..ff47785be 100644 --- a/Frameworks/vgmstream/vgmstream/src/vgmstream.h +++ b/Frameworks/vgmstream/vgmstream/src/vgmstream.h @@ -16,23 +16,14 @@ enum { PATH_LIMIT = 32768 }; #define VGM_USE_MPEG /* disabled by default, defined for builds that support it */ //#define VGM_USE_G7221 -//#define VGM_USE_MP4V2 -//#define VGM_USE_FDKAAC #include "streamfile.h" -#ifdef BUILD_VGMSTREAM #include "coding/g72x_state.h" -#else -#include "g72x_state.h" -#endif #ifdef VGM_USE_VORBIS -#ifdef __APPLE__ -#define __MACOSX__ -#endif #include #endif #ifdef VGM_USE_MPEG -#include +#include #endif #ifdef VGM_USE_G7221 #include "g7221.h" @@ -51,13 +42,8 @@ enum { PATH_LIMIT = 32768 }; #include #endif -#ifdef BUILD_VGMSTREAM #include "coding/acm_decoder.h" #include "coding/nwa_decoder.h" -#else -#include "acm_decoder.h" -#include "nwa_decoder.h" -#endif /* The encoding type specifies the format the sound data itself takes */ typedef enum { @@ -227,6 +213,7 @@ typedef enum { typedef enum { /* DSP-specific */ meta_DSP_STD, /* standard GC ADPCM (DSP) header */ + meta_DSP_CSMP, /* Metroid Prime 3, Donkey Kong Country Returns */ meta_DSP_CSTR, /* Star Fox Assault "Cstr" */ meta_DSP_RS03, /* Metroid Prime 2 "RS03" */ meta_DSP_STM, /* Paper Mario 2 STM */ @@ -581,6 +568,7 @@ typedef enum { meta_PS2_VBK, meta_OTM, // Otomedius (Arcade) meta_CSTM, // Nintendo 3DS CSTM + meta_3DS_IDSP, // Nintendo 3DS IDSP #ifdef VGM_USE_MP4V2 meta_MP4, #endif