diff --git a/src/formats.c b/src/formats.c index 9514b32e..f132d1c0 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1072,7 +1072,7 @@ static const meta_info meta_info_list[] = { {meta_RSTM_ROCKSTAR, "Rockstar Games RSTM Header"}, {meta_ACM, "InterPlay ACM Header"}, {meta_MUS_ACM, "InterPlay MUS ACM header"}, - {meta_PS2_KCES, "Konami KCES Header"}, + {meta_VIG_KCES, "Konami .VIG Header"}, {meta_HXD, "Tecmo HXD Header"}, {meta_VSV, "Square Enix .vsv Header"}, {meta_RIFF_WAVE_labl, "RIFF WAVE header (labl looping)"}, diff --git a/src/meta/gbts.c b/src/meta/gbts.c index 882ea667..d0ff789b 100644 --- a/src/meta/gbts.c +++ b/src/meta/gbts.c @@ -2,11 +2,11 @@ #include "../coding/coding.h" -/* GbTs - from KCES games [Pop'n Music 9/10 (PS2)] */ +/* GbTs - from Konami/KCE Studio games [Pop'n Music 9/10 (PS2)] */ VGMSTREAM* init_vgmstream_gbts(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; - int loop_flag, channels; - uint32_t data_offset, sample_rate, data_size; + uint32_t data_offset, data_size; + int loop_flag, channels, sample_rate; uint32_t loop_start, loop_end; @@ -17,17 +17,19 @@ VGMSTREAM* init_vgmstream_gbts(STREAMFILE* sf) { if (!check_extensions(sf, "gbts")) return NULL; + /* 04: always 0x24 */ data_offset = read_u32le(0x08,sf); - data_size = read_u32le(0x0C,sf); + data_size = read_u32le(0x0C,sf); /* without padding */ loop_start = read_u32le(0x10,sf); /* (0x20 = start frame if not set) */ loop_end = read_u32le(0x14,sf); /* (0x00 if not set) */ sample_rate = read_s32le(0x18,sf); channels = read_s32le(0x1C,sf); /* 20: 1? */ - /* 24: block size? */ + /* 24: block size (interleave * channels) */ + /* 30+: empty */ - loop_flag = loop_end > 0; + loop_flag = (loop_end > 0); loop_end += loop_start; /* loop region matches PS-ADPCM flags */ @@ -36,7 +38,6 @@ VGMSTREAM* init_vgmstream_gbts(STREAMFILE* sf) { if (!vgmstream) goto fail; vgmstream->sample_rate = sample_rate; - vgmstream->num_samples = ps_bytes_to_samples(data_size, channels); vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels); vgmstream->loop_end_sample = ps_bytes_to_samples(loop_end, channels); diff --git a/src/meta/meta.h b/src/meta/meta.h index f030d521..ca0eb458 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -234,7 +234,7 @@ VGMSTREAM* init_vgmstream_rstm_rockstar(STREAMFILE* sf); VGMSTREAM * init_vgmstream_acm(STREAMFILE * streamFile); -VGMSTREAM * init_vgmstream_ps2_kces(STREAMFILE * streamFile); +VGMSTREAM* init_vgmstream_vig_kces(STREAMFILE* sf); VGMSTREAM* init_vgmstream_hxd(STREAMFILE* sf); diff --git a/src/meta/ps2_kces.c b/src/meta/ps2_kces.c index 6be6840c..ecc29a36 100644 --- a/src/meta/ps2_kces.c +++ b/src/meta/ps2_kces.c @@ -1,71 +1,57 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* KCES (from Dance Dance Revolution) */ -VGMSTREAM * init_vgmstream_ps2_kces(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - off_t start_offset; - int loop_flag = 0; - int channel_count; +/* .vig - from Konami/KCE Studio games [Pop'n Music 11~14 (PS2), Dance Dance Revolution SuperNova/X (PS2)] */ +VGMSTREAM* init_vgmstream_vig_kces(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + uint32_t data_offset, data_size; + int loop_flag, channels, sample_rate, interleave; + uint32_t loop_start, loop_end; - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("kces",filename_extension(filename)) && - strcasecmp("vig",filename_extension(filename))) goto fail; - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x01006408) - goto fail; + /* checks */ + if (read_u32be(0x00,sf) != 0x01006408) + return NULL; + /* .vig: actual extension from DDR exes */ + if (!check_extensions(sf, "vig")) + return NULL; + + /* note this is almost the same as GbTs, may be fused later */ + /* 04: null */ + data_offset = read_u32le(0x08,sf); + data_size = read_u32le(0x0C,sf); /* without padding */ + loop_start = read_u32le(0x10,sf); /* (0x00 if not set) */ + loop_end = read_u32le(0x14,sf); /* (0x00 if not set) */ + sample_rate = read_s32le(0x18,sf); + channels = read_s32le(0x1C,sf); + /* 20: 0? */ + interleave = read_u32le(0x24,sf); /* 0 for mono */ + /* 30+: garbage from other data */ + + loop_flag = (loop_end > 0); + loop_end += loop_start; /* loop region matches PS-ADPCM flags */ - loop_flag = (read_32bitLE(0x14,streamFile)!=0); - channel_count = read_32bitLE(0x1C,streamFile); - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ - start_offset = read_32bitLE(0x08,streamFile); - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x18,streamFile); + vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = ps_bytes_to_samples(data_size, channels); + vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels); + vgmstream->loop_end_sample = ps_bytes_to_samples(loop_end, channels); + vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = read_32bitLE(0x0C,streamFile)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = (read_32bitLE(0x0C,streamFile)-read_32bitLE(0x14,streamFile))*28/16/channel_count; - vgmstream->loop_end_sample = read_32bitLE(0x0C,streamFile)*28/16/channel_count; - } + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = interleave; + vgmstream->meta_type = meta_VIG_KCES; - if(vgmstream->channels==1) { - vgmstream->layout_type=layout_none; - } else { - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitLE(0x24,streamFile); - } - vgmstream->meta_type = meta_PS2_KCES; - - /* open the file for reading */ - { - 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; - - } - } - + if (!vgmstream_open_stream(vgmstream, sf, data_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/vgmstream.c b/src/vgmstream.c index 198ea8ee..5d0753fd 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -93,7 +93,7 @@ init_vgmstream_t init_vgmstream_functions[] = { init_vgmstream_rstm_rockstar, init_vgmstream_acm, init_vgmstream_mus_acm, - init_vgmstream_ps2_kces, + init_vgmstream_vig_kces, init_vgmstream_hxd, init_vgmstream_vsv, init_vgmstream_ps2_pcm, diff --git a/src/vgmstream_types.h b/src/vgmstream_types.h index 0367f338..0fe63960 100644 --- a/src/vgmstream_types.h +++ b/src/vgmstream_types.h @@ -337,7 +337,7 @@ typedef enum { meta_STER, meta_BG00, /* Ibara, Mushihimesama */ meta_RSTM_ROCKSTAR, - meta_PS2_KCES, /* Dance Dance Revolution */ + meta_VIG_KCES, meta_HXD, meta_VSV, meta_SCD_PCM, /* Lunar - Eternal Blue */