From c4d8853ff6c5890ea09edcd40fdf5e001c6d90f7 Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 24 Jun 2021 22:34:41 +0200 Subject: [PATCH] Fix some .vgs [Ishikura Noboru no Igo Kouza: Chuukyuuhen (PS2)] --- src/formats.c | 2 +- src/meta/meta.h | 2 +- src/meta/vgs_ps.c | 114 +++++++++++++++++++++++++--------------------- src/vgmstream.c | 2 +- src/vgmstream.h | 2 +- 5 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/formats.c b/src/formats.c index 946a16a9..b6b0e4d5 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1153,7 +1153,7 @@ static const meta_info meta_info_list[] = { {meta_WII_RAS, "RAS header"}, {meta_SPM, "Square SPM header"}, {meta_X360_TRA, "Terminal Reality .TRA raw header"}, - {meta_PS2_VGS, "Princess Soft VGS header"}, + {meta_VGS_PS, "Princess Soft VGS header"}, {meta_PS2_IAB, "Runtime .IAB header"}, {meta_VS_STR, "Square .VS STR* header"}, {meta_LSF_N1NJ4N, ".lsf !n1nj4n header"}, diff --git a/src/meta/meta.h b/src/meta/meta.h index f27a70bb..38066974 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -390,7 +390,7 @@ VGMSTREAM * init_vgmstream_ps2_mcg(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_zsd(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_ps2_vgs(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_vgs_ps(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_redspark(STREAMFILE *streamFile); diff --git a/src/meta/vgs_ps.c b/src/meta/vgs_ps.c index 9af59737..221213bc 100644 --- a/src/meta/vgs_ps.c +++ b/src/meta/vgs_ps.c @@ -1,51 +1,63 @@ -#include "meta.h" -#include "../coding/coding.h" - -/* VGS - from Princess Soft games [Gin no Eclipse (PS2), Metal Wolf REV (PS2)] */ -VGMSTREAM * init_vgmstream_ps2_vgs(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - size_t data_size, channel_size, interleave; - int loop_flag, channel_count; - int32_t loop_start = 0, loop_end = 0; - - - /* check */ - if ( !check_extensions(streamFile,"vgs") ) - goto fail; - if (read_32bitBE(0x00,streamFile) != 0x56475300) /* "VGS\0" ('VAG stereo', presumably) */ - goto fail; - - start_offset = 0x30; - data_size = get_streamfile_size(streamFile) - start_offset; - interleave = 0x20000; - channel_count = 2; - channel_size = read_32bitBE(0x0c,streamFile); - loop_flag = 0; /* all files have loop flags but simply fade out normally and repeat */ - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->meta_type = meta_PS2_VGS; - vgmstream->sample_rate = read_32bitBE(0x10,streamFile); - vgmstream->num_samples = ps_bytes_to_samples(channel_size,1); - vgmstream->loop_start_sample = loop_start; - vgmstream->loop_end_sample = loop_end; - - vgmstream->coding_type = coding_PSX; - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = interleave; - if (vgmstream->interleave_block_size) - vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size*vgmstream->channels)) / vgmstream->channels; - read_string(vgmstream->stream_name,0x10+1, 0x20,streamFile); /* always, can be null */ - - if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) ) - goto fail; - return vgmstream; - -fail: - close_vgmstream(vgmstream); - return NULL; -} +#include "meta.h" +#include "../coding/coding.h" + +/* VGS - from Princess Soft games [Gin no Eclipse (PS2), Metal Wolf REV (PS2)] */ +VGMSTREAM* init_vgmstream_vgs_ps(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset; + size_t data_size, channel_size, interleave, sample_rate; + int loop_flag, channels; + int32_t loop_start = 0, loop_end = 0; + + + /* check */ + if (!check_extensions(sf,"vgs")) + goto fail; + if (!is_id32be(0x00,sf, "VGS\0")) /* 'VAG stereo', presumably (simple VAG clone) */ + goto fail; + + start_offset = 0x30; + data_size = get_streamfile_size(sf) - start_offset; + + /* test PS-ADPCM null frame for 2nd channel to detect interleave */ + if (read_u32be(0x20000 + start_offset,sf) == 0) { + interleave = 0x20000; /* common */ + } + else if (read_u32be(0x8000 + start_offset,sf) == 0) { + interleave = 0x8000; /* Ishikura Noboru no Igo Kouza: Chuukyuuhen (PS2) */ + } + else { + goto fail; + } + + channels = 2; + channel_size = read_u32be(0x0c,sf); + sample_rate = read_s32be(0x10,sf); + loop_flag = 0; /* all files have loop flags but simply fade out normally and repeat */ + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_VGS_PS; + vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = ps_bytes_to_samples(channel_size, 1); + vgmstream->loop_start_sample = loop_start; + vgmstream->loop_end_sample = loop_end; + + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = interleave; + if (vgmstream->interleave_block_size) + vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size * channels)) / channels; + read_string(vgmstream->stream_name,0x10+1, 0x20,sf); /* always, can be null */ + + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/vgmstream.c b/src/vgmstream.c index 5ff88c29..54c23e02 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -196,7 +196,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_ads_midway, init_vgmstream_ps2_mcg, init_vgmstream_zsd, - init_vgmstream_ps2_vgs, + init_vgmstream_vgs_ps, init_vgmstream_redspark, init_vgmstream_ivaud, init_vgmstream_wii_wsd, diff --git a/src/vgmstream.h b/src/vgmstream.h index e5d97216..05259b50 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -566,7 +566,7 @@ typedef enum { meta_WII_RAS, /* Donkey Kong Country Returns (Wii) */ meta_SPM, meta_X360_TRA, /* Def Jam Rapstar */ - meta_PS2_VGS, /* Princess Soft PS2 games */ + meta_VGS_PS, meta_PS2_IAB, /* Ueki no Housoku - Taosu ze Robert Juudan!! (PS2) */ meta_VS_STR, /* The Bouncer */ meta_LSF_N1NJ4N, /* .lsf n1nj4n Fastlane Street Racing (iPhone) */