diff --git a/src/formats.c b/src/formats.c index 6a7b245f..49b20582 100644 --- a/src/formats.c +++ b/src/formats.c @@ -138,7 +138,7 @@ static const char* extension_list[] = { "cps", "csa", //txth/reserved [LEGO Racers 2 (PS2)] "csmp", - "cvs", + "cvs", //txth/reserved [Aladdin in Nasira's Revenge (PS1)] "cwav", "cxs", @@ -599,7 +599,7 @@ static const char* extension_list[] = { "wic", //txth/reserved [Road Rash (SAT)-videos] "wip", //txth/reserved [Colin McRae DiRT (PC)] "wlv", //txth/reserved [ToeJam & Earl III: Mission to Earth (DC)] - "wmus", + "wmus", //fake extension (to be removed) "wp2", "wpd", "wsd", @@ -618,7 +618,7 @@ static const char* extension_list[] = { "xa", "xa2", "xa30", - "xag", + "xag", //txth/reserved [Tamsoft's PS2 games] "xau", "xav", "xb", //txth/reserved [Scooby-Doo! Unmasked (Xbox)] @@ -937,7 +937,7 @@ static const meta_info meta_info_list[] = { {meta_AGSC, "Retro Studios AGSC header"}, {meta_CSMP, "Retro Studios CSMP header"}, {meta_RFRM, "Retro Studios RFRM header"}, - {meta_NGC_ADPDTK, "Nintendo ADP raw header"}, + {meta_DTK, "Nintendo DTK raw header"}, {meta_RSF, "Retro Studios RSF raw header"}, {meta_AFC, "Nintendo .AFC header"}, {meta_AST, "Nintendo AST header"}, @@ -976,7 +976,7 @@ static const meta_info meta_info_list[] = { {meta_PS2_VAGp_AAAP, "Acclaim Austin AAAp VAG header"}, {meta_SEB, "Game Arts .SEB header"}, {meta_STR_WAV, "Blitz Games .STR+WAV header"}, - {meta_PS2_ILD, "ILD header"}, + {meta_ILD, "Tose ILD header"}, {meta_PS2_PNB, "assumed PNB (PsychoNauts Bgm File) by .pnb extension"}, {meta_RAW_WAVM, "Xbox .wavm raw header"}, {meta_DSP_STR, "assumed Conan Gamecube STR File by .str extension"}, diff --git a/src/meta/meta.h b/src/meta/meta.h index 740df350..0b22dc92 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -28,7 +28,7 @@ VGMSTREAM * init_vgmstream_halpst(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_nds_strm(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_ngc_adpdtk(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_dtk(STREAMFILE* sf); VGMSTREAM* init_vgmstream_ngc_dsp_std(STREAMFILE* sf); VGMSTREAM* init_vgmstream_ngc_mdsp_std(STREAMFILE* sf); @@ -77,7 +77,7 @@ VGMSTREAM * init_vgmstream_nps(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_rs03(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_rsf(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_rsf(STREAMFILE* sf); VGMSTREAM * init_vgmstream_rwsd(STREAMFILE *streamFile); @@ -94,9 +94,9 @@ VGMSTREAM * init_vgmstream_svag_kcet(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_ps_headerless(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_mib_mih(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_mib_mih(STREAMFILE* sf); -VGMSTREAM * init_vgmstream_ps2_mic(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_mic_koei(STREAMFILE* sf); VGMSTREAM * init_vgmstream_raw_pcm(STREAMFILE *streamFile); @@ -105,7 +105,7 @@ VGMSTREAM * init_vgmstream_vag_aaap(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_seb(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_ps2_ild(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_ild(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_ps2_pnb(STREAMFILE *streamFile); diff --git a/src/meta/ngc_adpdtk.c b/src/meta/ngc_adpdtk.c index 63db6433..982cd45a 100644 --- a/src/meta/ngc_adpdtk.c +++ b/src/meta/ngc_adpdtk.c @@ -3,7 +3,7 @@ #include "../util.h" /* DTK - headerless Nintendo GC DTK file [Harvest Moon: Another Wonderful Life (GC), XGRA (GC)] */ -VGMSTREAM* init_vgmstream_ngc_adpdtk(STREAMFILE* sf) { +VGMSTREAM* init_vgmstream_dtk(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; off_t start_offset; int channels, loop_flag; @@ -22,12 +22,12 @@ VGMSTREAM* init_vgmstream_ngc_adpdtk(STREAMFILE* sf) { for (i = 0; i < 10; i++) { /* try a bunch of frames */ /* header 0x00/01 are repeated in 0x02/03 (for error correction?), * could also test header values (upper nibble should be 0..3, and lower nibble 0..C) */ - if (read_8bit(0x00 + i*0x20,sf) != read_8bit(0x02 + i*0x20,sf) || - read_8bit(0x01 + i*0x20,sf) != read_8bit(0x03 + i*0x20,sf)) + if (read_u8(0x00 + i*0x20,sf) != read_u8(0x02 + i*0x20,sf) || + read_u8(0x01 + i*0x20,sf) != read_u8(0x03 + i*0x20,sf)) goto fail; /* frame headers for silent frames are 0x0C, never null */ - if (read_8bit(0x00 + i*0x20,sf) == 0x00) + if (read_u8(0x00 + i*0x20,sf) == 0x00) goto fail; } } @@ -48,13 +48,11 @@ VGMSTREAM* init_vgmstream_ngc_adpdtk(STREAMFILE* sf) { vgmstream->sample_rate = 48000; /* due to a GC hardware defect this may be closer to 48043 */ vgmstream->coding_type = coding_NGC_DTK; vgmstream->layout_type = layout_none; - vgmstream->meta_type = meta_NGC_ADPDTK; + vgmstream->meta_type = meta_DTK; - if ( !vgmstream_open_stream(vgmstream, sf, start_offset) ) + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) goto fail; - return vgmstream; - fail: close_vgmstream(vgmstream); return NULL; diff --git a/src/meta/ps2_ild.c b/src/meta/ps2_ild.c index 761ea4ec..d7b1146e 100644 --- a/src/meta/ps2_ild.c +++ b/src/meta/ps2_ild.c @@ -1,69 +1,58 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* ILD */ - -VGMSTREAM * init_vgmstream_ps2_ild(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - int loop_flag=0; - int channel_count; +/* ILD - from Tose(?) games [Battle of Sunrise (PS2), Nightmare Before Christmas: Oogie's Revenge (PS2)] */ +VGMSTREAM* init_vgmstream_ild(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + int channels, loop_flag; + uint32_t data_size; off_t start_offset; - int i; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("ild",filename_extension(filename))) goto fail; /* check ILD Header */ - if (read_32bitBE(0x00,streamFile) != 0x494C4400) + if (!is_id32be(0x00,sf, "ILD\0")) goto fail; - /* check loop */ - loop_flag = (read_32bitLE(0x2C,streamFile)!=0); - channel_count=read_32bitLE(0x04,streamFile); - + if (!check_extensions(sf, "ild")) + goto fail; + + channels = read_u32le(0x04,sf); /* tracks (seen 2 and 4) */ + start_offset = read_u32le(0x08,sf); + data_size = read_u32le(0x0C,sf); + /* 0x10: headers size / 2? */ + /* 0x14: header per channel */ + /* - 0x00: null */ + /* - 0x04: header size? (always 0x20) */ + /* - 0x08: size (may vary a bit between channel pairs) */ + /* - 0x0c: interleave? */ + /* - 0x10: channels per track (1) */ + /* - 0x14: sample rate */ + /* - 0x18: loop start */ + /* - 0x1c: loop end (also varies) */ + + + loop_flag = (read_s32le(0x2C,sf) > 0); + + /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ - vgmstream->channels = read_32bitLE(0x04,streamFile); - vgmstream->sample_rate = read_32bitLE(0x28,streamFile); + vgmstream->meta_type = meta_ILD; + + vgmstream->num_samples = ps_bytes_to_samples(data_size, channels); + vgmstream->interleave_block_size = read_u32le(0x14 + 0x0c,sf); + vgmstream->sample_rate = read_u32le(0x14 + 0x14,sf); + vgmstream->loop_start_sample = ps_bytes_to_samples(read_u32le(0x14 + 0x18,sf), 1); + vgmstream->loop_end_sample = ps_bytes_to_samples(read_u32le(0x14 + 0x1c,sf), 1); - /* Check for Compression Scheme */ vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = read_32bitLE(0x0C,streamFile)/16*28/vgmstream->channels; - - /* Get loop point values */ - if(vgmstream->loop_flag) { - vgmstream->loop_start_sample = read_32bitLE(0x2C,streamFile)/16*28; - vgmstream->loop_end_sample = read_32bitLE(0x30,streamFile)/16*28; - } - - vgmstream->interleave_block_size = read_32bitLE(0x18,streamFile)/2; vgmstream->layout_type = layout_interleave; - vgmstream->meta_type = meta_PS2_ILD; - - start_offset = (off_t)read_32bitLE(0x08,streamFile); - - /* open the file for reading by each channel */ - { - for (i=0;ich[i].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - - if (!vgmstream->ch[i].streamfile) goto fail; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset= - (off_t)(start_offset+vgmstream->interleave_block_size*i); - } - } + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; return vgmstream; - /* clean up anything we may have opened */ fail: - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/src/meta/ps2_mic.c b/src/meta/ps2_mic.c index 14850d20..84bbfff4 100644 --- a/src/meta/ps2_mic.c +++ b/src/meta/ps2_mic.c @@ -2,29 +2,37 @@ #include "../coding/coding.h" /* .MIC - from KOEI games [Crimson Sea 2 (PS2), Dynasty Tactics 2 (PS2)] */ -VGMSTREAM * init_vgmstream_ps2_mic(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_mic_koei(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channel_count, loop_start, loop_end, sample_rate; + int loop_flag, channels, loop_start, loop_end, sample_rate; size_t interleave, block_size; /* checks */ - if (!check_extensions(streamFile, "mic")) + if (!check_extensions(sf, "mic")) goto fail; - start_offset = read_32bitLE(0x00,streamFile); + /* simple header so throws some extra in some checks */ + start_offset = read_u32le(0x00,sf); if (start_offset != 0x800) goto fail; - sample_rate = read_32bitLE(0x04,streamFile); - channel_count = read_32bitLE(0x08,streamFile); - interleave = read_32bitLE(0x0c,streamFile); - loop_end = read_32bitLE(0x10,streamFile); - loop_start = read_32bitLE(0x14,streamFile); + sample_rate = read_u32le(0x04,sf); + channels = read_u32le(0x08,sf); + if (channels > 2) goto fail; + interleave = read_u32le(0x0c,sf); + if (interleave != 0x10) goto fail; + + loop_end = read_32bitLE(0x10,sf); + loop_start = read_32bitLE(0x14,sf); + if (read_u32le(0x18,sf) != 0) goto fail; + if (read_u32le(0x1c,sf) != 0) goto fail; + loop_flag = (loop_start != 1); - block_size = interleave * channel_count; + block_size = interleave * channels; + /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; vgmstream->meta_type = meta_PS2_MIC; @@ -34,11 +42,11 @@ VGMSTREAM * init_vgmstream_ps2_mic(STREAMFILE *streamFile) { vgmstream->interleave_block_size = interleave; vgmstream->layout_type = layout_interleave; - vgmstream->num_samples = ps_bytes_to_samples(loop_end * block_size, channel_count); - vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start * block_size, channel_count); + vgmstream->num_samples = ps_bytes_to_samples(loop_end * block_size, channels); + vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start * block_size, channels); vgmstream->loop_end_sample = vgmstream->num_samples; - if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) goto fail; return vgmstream; diff --git a/src/meta/rsf.c b/src/meta/rsf.c index 864fb07a..d6fdeedf 100644 --- a/src/meta/rsf.c +++ b/src/meta/rsf.c @@ -4,42 +4,47 @@ /* .rsf - from Metroid Prime */ -VGMSTREAM * init_vgmstream_rsf(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; +VGMSTREAM* init_vgmstream_rsf(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + int channels, loop_flag; + uint32_t interleave, file_size; - size_t file_size; + /* checks */ + if (!check_extensions(sf,"rsf")) + goto fail; - /* check extension, case insensitive */ /* this is all we have to go on, rsf is completely headerless */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("rsf",filename_extension(filename))) goto fail; - file_size = get_streamfile_size(streamFile); + file_size = get_streamfile_size(sf); + interleave = (file_size + 1) / 2; + /* G.721 has no zero nibbles, so we look at the first few bytes + * (known files start with 0xFFFFFFFF, but probably an oddity of the codec) */ { - /* extra check: G.721 has no zero nibbles, so we look at - * the first few bytes*/ - int8_t test_byte; + uint8_t test_byte; off_t i; + /* 0x20 is arbitrary, all files are much larger */ - for (i=0;i<0x20;i++) { - test_byte = read_8bit(i,streamFile); + for (i = 0; i < 0x20; i++) { + test_byte = read_u8(i,sf); if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail; } + /* and also check start of second channel */ - for (i=(file_size+1)/2;i<(file_size+1)/2+0x20;i++) { - test_byte = read_8bit(i,streamFile); + for (i = interleave; i < interleave + 0x20; i++) { + test_byte = read_u8(i,sf); if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail; } } - /* build the VGMSTREAM */ + channels = 2; + loop_flag = 0; - vgmstream = allocate_vgmstream(2,0); + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ vgmstream->num_samples = file_size; vgmstream->sample_rate = 32000; @@ -47,27 +52,20 @@ VGMSTREAM * init_vgmstream_rsf(STREAMFILE *streamFile) { vgmstream->layout_type = layout_none; vgmstream->meta_type = meta_RSF; + if (!vgmstream_open_stream(vgmstream, sf, 0)) + goto fail; + /* open the file for reading by each channel */ { int i; - for (i=0;i<2;i++) { - vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - - if (!vgmstream->ch[i].streamfile) goto fail; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset= - (file_size+1)/2*i; - - + for (i = 0; i < channels; i++) { + vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].offset = interleave * i; g72x_init_state(&(vgmstream->ch[i].g72x_state)); } } return vgmstream; - - /* clean up anything we may have opened */ fail: - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/src/vgmstream.c b/src/vgmstream.c index d3932700..33543614 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -23,9 +23,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_brstm, init_vgmstream_bfwav, init_vgmstream_nds_strm, - init_vgmstream_agsc, - init_vgmstream_ngc_adpdtk, - init_vgmstream_rsf, init_vgmstream_afc, init_vgmstream_ast, init_vgmstream_halpst, @@ -45,15 +42,11 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_ngc_dsp_stm, init_vgmstream_exst, init_vgmstream_svag_kcet, - init_vgmstream_mib_mih, init_vgmstream_ngc_mpdsp, - init_vgmstream_ps2_mic, init_vgmstream_ngc_dsp_std_int, init_vgmstream_vag, init_vgmstream_vag_aaap, - init_vgmstream_seb, - init_vgmstream_ps2_ild, - init_vgmstream_ps2_pnb, + init_vgmstream_ild, init_vgmstream_ngc_str, init_vgmstream_ea_schl, init_vgmstream_caf, @@ -257,7 +250,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_lsf_n1nj4n, init_vgmstream_xwav_new, init_vgmstream_xwav_old, - init_vgmstream_ps2_wmus, init_vgmstream_hyperscan_kvag, init_vgmstream_ios_psnd, init_vgmstream_adp_bos, @@ -528,6 +520,16 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_wbk_nslb, init_vgmstream_dsp_apex, + /* lower priority metas (no clean header identity, somewhat ambiguous, or need extension/companion file to identify) */ + init_vgmstream_agsc, + init_vgmstream_dtk, + init_vgmstream_rsf, + init_vgmstream_ps2_wmus, + init_vgmstream_mib_mih, + init_vgmstream_mic_koei, + init_vgmstream_seb, + init_vgmstream_ps2_pnb, + /* 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 */ init_vgmstream_encrypted, /* encrypted stuff */ diff --git a/src/vgmstream.h b/src/vgmstream.h index 69ab3540..713b3700 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -333,8 +333,8 @@ typedef enum { meta_AAX, /* CRI AAX */ meta_UTF_DSP, /* CRI ADPCM_WII, like AAX with DSP */ - meta_NGC_ADPDTK, /* NGC DTK/ADP (.adp/dkt DTK) [no header_id] */ - meta_RSF, /* Retro Studios RSF (Metroid Prime .rsf) [no header_id] */ + meta_DTK, + meta_RSF, meta_HALPST, /* HAL Labs HALPST */ meta_GCSW, /* GCSW (PCM) */ meta_CAF, /* tri-Crescendo CAF */ @@ -358,7 +358,7 @@ typedef enum { meta_PS2_VAGp_AAAP, /* Acclaim Austin Audio VAG header */ meta_SEB, meta_STR_WAV, /* Blitz Games STR+WAV files */ - meta_PS2_ILD, /* ILD File */ + meta_ILD, meta_PS2_PNB, /* PsychoNauts Bgm File */ meta_VPK, /* VPK Audio File */ meta_PS2_BMDX, /* Beatmania thing */