From 15206915d1f64bc05c3c24bcb5ffb108a720b86f Mon Sep 17 00:00:00 2001 From: bnnm Date: Tue, 27 Mar 2018 22:20:20 +0200 Subject: [PATCH] Tweak VDS/VDM num_samples --- src/formats.c | 2 +- src/meta/ps2_vds_vdm.c | 41 ++++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/formats.c b/src/formats.c index e0f0b477..3f820f9d 100644 --- a/src/formats.c +++ b/src/formats.c @@ -912,7 +912,7 @@ static const meta_info meta_info_list[] = { {meta_XB3D_ADX, "Xenoblade 3D ADX header"}, {meta_HCA, "CRI MiddleWare HCA Header"}, {meta_PS2_SVAG_SNK, "SNK SVAG header"}, - {meta_PS2_VDS_VDM, "Graffiti Kingdom VDS/VDM header"}, + {meta_PS2_VDS_VDM, "Procyon Studio VDS/VDM header"}, {meta_X360_CXS, "tri-Crescendo CXS header"}, {meta_AKB, "Square-Enix AKB header"}, {meta_NUB_XMA, "Namco NUB XMA header"}, diff --git a/src/meta/ps2_vds_vdm.c b/src/meta/ps2_vds_vdm.c index dd29f9c8..1b4006a4 100644 --- a/src/meta/ps2_vds_vdm.c +++ b/src/meta/ps2_vds_vdm.c @@ -1,43 +1,46 @@ #include "meta.h" +#include "../coding/coding.h" -/* VDS/VDM - from Grafitti Kingdom / Rakugaki Oukoku 2 */ +/* VDS/VDM - from Procyon Studio games [Grafitti Kingdom / Rakugaki Oukoku 2 (PS2), Tsukiyo ni Saraba (PS2)] */ VGMSTREAM * init_vgmstream_ps2_vds_vdm(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; off_t start_offset; int loop_flag, channel_count; - /* check extension, case insensitive */ + + /* checks */ if ( !check_extensions(streamFile,"vds,vdm")) goto fail; - if (read_32bitBE(0x00,streamFile) != 0x56445320 && /* "VDS " (music)*/ read_32bitBE(0x00,streamFile) != 0x56444D20) /* "VDM " (voices) */ goto fail; loop_flag = read_8bit(0x20,streamFile); channel_count = read_32bitLE(0x10,streamFile); + start_offset = 0x800; - /* build the VGMSTREAM */ + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; - vgmstream->coding_type = coding_PSX; - vgmstream->layout_type = channel_count > 1 ? layout_interleave : layout_none; - vgmstream->meta_type = meta_PS2_VDS_VDM; - start_offset = 0x800; - vgmstream->num_samples = read_32bitLE(0x04,streamFile) * 28 / 16 / channel_count; - /* 0x08: unknown, always 10 */ + /* 0x08: unknown, always 0x10 */ vgmstream->sample_rate = read_32bitLE(0x0c,streamFile); - vgmstream->channels = channel_count; /*0x10*/ - vgmstream->interleave_block_size = read_32bitLE(0x14,streamFile); - vgmstream->loop_start_sample = (read_32bitLE(0x18,streamFile) - start_offset) * 28 / 16 / channel_count; - vgmstream->loop_end_sample = (read_32bitLE(0x1c,streamFile) - start_offset) * 28 / 16 / channel_count; - vgmstream->loop_flag = loop_flag; /*0x20*/ - /*0x21: volume? */ - /*0x22: pan? */ - /*0x23: 02=VDS 04=VDM? */ - /* open the file for reading */ + /* when looping (or maybe when stereo) data_size at 0x04 is actually smaller than file_size, + * sometimes cutting outros with loop disabled; doesn't affect looping though */ + if (!loop_flag) + vgmstream->num_samples = ps_bytes_to_samples(read_32bitLE(0x04,streamFile), channel_count); + else + vgmstream->num_samples = ps_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count); + vgmstream->loop_start_sample = ps_bytes_to_samples(read_32bitLE(0x18,streamFile) - start_offset, channel_count); + vgmstream->loop_end_sample = ps_bytes_to_samples(read_32bitLE(0x1c,streamFile) - start_offset, channel_count); + /* 0x21: volume?, 0x22: pan?, 0x23: 02=VDS 04=VDM? 02/05=VDM in Tsukiyo ni Saraba? */ + + vgmstream->meta_type = meta_PS2_VDS_VDM; + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = (channel_count == 1) ? layout_none : layout_interleave; + vgmstream->interleave_block_size = read_32bitLE(0x14,streamFile); + if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) ) goto fail; return vgmstream;