From 8db9d8ead3d308e216eec370956400c4aed1816d Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 25 Jun 2023 00:59:10 +0200 Subject: [PATCH] cleanup: voi --- src/formats.c | 1 + src/meta/meta.h | 2 +- src/meta/ps2_voi.c | 89 ++++++++++++++++--------------------------- src/meta/ymf.c | 2 +- src/vgmstream.c | 2 +- src/vgmstream_types.h | 2 +- 6 files changed, 37 insertions(+), 61 deletions(-) diff --git a/src/formats.c b/src/formats.c index 56b4bc46..7566f1bf 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1179,6 +1179,7 @@ static const meta_info meta_info_list[] = { {meta_PS2_GCM, "Namco GCM header"}, {meta_SMPL, "Skonec SMPL header"}, {meta_PS2_MSA, "Success .MSA header"}, + {meta_VOI, "Irem .VOI header"}, {meta_NGC_PDT, "Hudson .PDT header"}, {meta_NGC_RKV, "Legacy of Kain - Blood Omen 2 RKV GC header"}, {meta_DSP_DDSP, ".DDSP header"}, diff --git a/src/meta/meta.h b/src/meta/meta.h index fe0ac610..e6f8131b 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -452,7 +452,7 @@ VGMSTREAM* init_vgmstream_smpl(STREAMFILE* sf); VGMSTREAM * init_vgmstream_ps2_msa(STREAMFILE* streamFile); -VGMSTREAM * init_vgmstream_ps2_voi(STREAMFILE* streamFile); +VGMSTREAM* init_vgmstream_voi(STREAMFILE* sf); VGMSTREAM * init_vgmstream_ngc_rkv(STREAMFILE* streamFile); diff --git a/src/meta/ps2_voi.c b/src/meta/ps2_voi.c index 2d5a3868..7cae0796 100644 --- a/src/meta/ps2_voi.c +++ b/src/meta/ps2_voi.c @@ -1,81 +1,56 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* VOI - found in "RAW Danger" (PS2) */ -VGMSTREAM * init_vgmstream_ps2_voi(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; - int loop_flag = 0; - int channel_count; + +/* .VOI - from Raw Danger (PS2) */ +VGMSTREAM* init_vgmstream_voi(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + int channels, loop_flag = 0; off_t start_offset; - - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("voi",filename_extension(filename))) goto fail; - /* check header */ - if (((read_32bitLE(0x04,streamFile)*2)+0x800) != (get_streamfile_size(streamFile))) - { - goto fail; - } + /* checks */ + if (read_u32le(0x00,sf) != 1 && read_u32le(0x00,sf) != 2) + return NULL; + + if (!check_extensions(sf, "voi")) + return NULL; + + /* probably number of samples of all channels */ + if ((read_u32le(0x04,sf) * 2 + 0x800) != get_streamfile_size(sf)) + return NULL; + + channels = read_s32le(0x00,sf); loop_flag = 0; - channel_count = read_32bitLE(0x00,streamFile); + start_offset = 0x800; - /* 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 = 0x800; - vgmstream->channels = channel_count; + vgmstream->meta_type = meta_VOI; + vgmstream->num_samples = pcm16_bytes_to_samples(get_streamfile_size(sf) - start_offset, channels); vgmstream->coding_type = coding_PCM16LE; - vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/channel_count/2; + vgmstream->layout_type = layout_interleave; - if (loop_flag) - { - vgmstream->loop_start_sample = 0; - vgmstream->loop_end_sample = (read_32bitLE(0x04,streamFile)/2); - } - - if (read_32bitLE(0x08,streamFile) == 0) - { + if (read_32bitLE(0x08,sf) == 0) { vgmstream->sample_rate = 48000; vgmstream->interleave_block_size = 0x200; } - else if (read_32bitLE(0x08,streamFile) == 1) - { + else if (read_32bitLE(0x08,sf) == 1) { vgmstream->sample_rate = 24000; vgmstream->interleave_block_size = 0x100; } - else - { - goto fail; - } - - vgmstream->layout_type = layout_interleave; - vgmstream->meta_type = meta_PS2_VOI; - - /* 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; - - } + else { + goto fail; } + 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/ymf.c b/src/meta/ymf.c index 357d6ec6..e326073a 100644 --- a/src/meta/ymf.c +++ b/src/meta/ymf.c @@ -20,7 +20,7 @@ VGMSTREAM* init_vgmstream_ymf(STREAMFILE* sf) { return NULL; /* .ymf can contain audio or video, but not both (videos start with 0x100 and change minor values), - * though it's are found in ./movie/*.* and probably are considered so */ + * though it's are found in ./movie/... and probably are considered so */ loop_flag = 0; channels = 2; diff --git a/src/vgmstream.c b/src/vgmstream.c index a9878383..5a3b0e09 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -209,7 +209,7 @@ init_vgmstream_t init_vgmstream_functions[] = { init_vgmstream_ps2_gcm, init_vgmstream_smpl, init_vgmstream_ps2_msa, - init_vgmstream_ps2_voi, + init_vgmstream_voi, init_vgmstream_ngc_rkv, init_vgmstream_dsp_ddsp, init_vgmstream_p3d, diff --git a/src/vgmstream_types.h b/src/vgmstream_types.h index 42cecc4b..516fca48 100644 --- a/src/vgmstream_types.h +++ b/src/vgmstream_types.h @@ -466,7 +466,7 @@ typedef enum { meta_PS2_GCM, /* NamCollection */ meta_SMPL, meta_PS2_MSA, /* Psyvariar -Complete Edition- */ - meta_PS2_VOI, /* RAW Danger (Zettaizetsumei Toshi 2 - Itetsuita Kiokutachi) [PS2] */ + meta_VOI, meta_P3D, /* Prototype P3D */ meta_NGC_RKV, /* Legacy of Kain - Blood Omen 2 (GC) */ meta_DSP_DDSP, /* Various (2 dsp files stuck together */