From 5673a3c63646f8441bdee37d38297ebeb11da674 Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 29 Jul 2021 18:38:07 +0200 Subject: [PATCH] cleanup: misc --- src/formats.c | 2 +- src/layout/blocked_xvag.c | 38 +++++++-------- src/meta/208.c | 95 ++++++++++++++++++------------------- src/meta/hca.c | 4 +- src/meta/ngc_str_cauldron.c | 92 +++++++++++++++++------------------ src/meta/ps2_sfs.c | 77 +++++++++++++----------------- 6 files changed, 149 insertions(+), 159 deletions(-) diff --git a/src/formats.c b/src/formats.c index 41fa1196..094cf344 100644 --- a/src/formats.c +++ b/src/formats.c @@ -999,7 +999,7 @@ static const meta_info meta_info_list[] = { {meta_LEG, "Legaia 2 - Duel Saga LEG Header"}, {meta_FILP, "Bio Hazard - Gun Survivor FILp Header"}, {meta_IKM, "MiCROViSiON IKM header"}, - {meta_SFS, "Baroque SFS Header"}, + {meta_SFS, "String .SFS header"}, {meta_SAT_DVI, "Konami KCEN DVI. header"}, {meta_DC_KCEY, "Konami KCEY KCEYCOMP header"}, {meta_BG00, "Falcom BG00 Header"}, diff --git a/src/layout/blocked_xvag.c b/src/layout/blocked_xvag.c index 1c1ab2d7..4559ad9f 100644 --- a/src/layout/blocked_xvag.c +++ b/src/layout/blocked_xvag.c @@ -1,19 +1,19 @@ -#include "layout.h" -#include "../coding/coding.h" -#include "../vgmstream.h" - - -/* XVAG with subsongs layers, interleaves chunks of each subsong (a hack to support them) */ -void block_update_xvag_subsong(off_t block_offset, VGMSTREAM * vgmstream) { - int i; - size_t channel_size = 0x10; - - /* set offsets */ - for (i = 0; i < vgmstream->channels; i++) { - vgmstream->ch[i].offset = block_offset + channel_size*i; - } - - //vgmstream->current_block_size = ; /* fixed */ - vgmstream->current_block_offset = block_offset; - vgmstream->next_block_offset = block_offset + vgmstream->full_block_size; -} +#include "layout.h" +#include "../coding/coding.h" +#include "../vgmstream.h" + + +/* XVAG with subsongs layers, interleaves chunks of each subsong (a hack to support them) */ +void block_update_xvag_subsong(off_t block_offset, VGMSTREAM* vgmstream) { + int i; + size_t channel_size = 0x10; + + /* set offsets */ + for (i = 0; i < vgmstream->channels; i++) { + vgmstream->ch[i].offset = block_offset + channel_size*i; + } + + //vgmstream->current_block_size = ; /* fixed */ + vgmstream->current_block_offset = block_offset; + vgmstream->next_block_offset = block_offset + vgmstream->full_block_size; +} diff --git a/src/meta/208.c b/src/meta/208.c index 10e6461b..3969d86d 100644 --- a/src/meta/208.c +++ b/src/meta/208.c @@ -1,48 +1,47 @@ -#include "meta.h" -#include "../coding/coding.h" - -/* .208 - from Ocean game(s?) [Last Rites (PC)] */ -VGMSTREAM * init_vgmstream_208(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int loop_flag, channel_count, sample_rate; - size_t data_size; - - - /* checks */ - if (!check_extensions(streamFile, "208")) - goto fail; - /* possible validation: (0x04 == 0 and 0xcc == 0x1F7D984D) or 0x04 == 0xf0 and 0xcc == 0) */ - if (!((read_32bitLE(0x04,streamFile) == 0x00 && read_32bitBE(0xcc,streamFile) == 0x1F7D984D) || - (read_32bitLE(0x04,streamFile) == 0xF0 && read_32bitBE(0xcc,streamFile) == 0x00000000))) - goto fail; - - start_offset = read_32bitLE(0x00,streamFile); - data_size = read_32bitLE(0x0c,streamFile); - sample_rate = read_32bitLE(0x34,streamFile); - channel_count = read_32bitLE(0x3C,streamFile); /* assumed */ - loop_flag = 0; - - if (start_offset + data_size != get_streamfile_size(streamFile)) - goto fail; - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); - if (!vgmstream) goto fail; - - vgmstream->meta_type = meta_208; - vgmstream->sample_rate = sample_rate; - vgmstream->num_samples = pcm_bytes_to_samples(data_size, channel_count, 8); - vgmstream->coding_type = coding_PCM8_U; - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = 0x1; - - 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" + +/* .208 - from Ocean game(s?) [Last Rites (PC)] */ +VGMSTREAM* init_vgmstream_208(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset, data_size; + int loop_flag, channels, sample_rate; + + + /* checks */ + if (!check_extensions(sf, "208")) + goto fail; + /* possible validation: (0x04 == 0 and 0xcc == 0x1F7D984D) or 0x04 == 0xf0 and 0xcc == 0) */ + if (!((read_u32le(0x04,sf) == 0x00 && read_u32be(0xcc,sf) == 0x1F7D984D) || + (read_u32le(0x04,sf) == 0xF0 && read_u32be(0xcc,sf) == 0x00000000))) + goto fail; + + start_offset = read_s32le(0x00,sf); + data_size = read_s32le(0x0c,sf); + sample_rate = read_s32le(0x34,sf); + channels = read_s32le(0x3C,sf); /* assumed */ + loop_flag = 0; + + if (start_offset + data_size != get_streamfile_size(sf)) + goto fail; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_208; + vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = pcm8_bytes_to_samples(data_size, channels); + vgmstream->coding_type = coding_PCM8_U; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = 0x1; + + if (!vgmstream_open_stream(vgmstream,sf,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/hca.c b/src/meta/hca.c index d73cf207..e2da0cdc 100644 --- a/src/meta/hca.c +++ b/src/meta/hca.c @@ -153,7 +153,7 @@ static inline void test_key(hca_codec_data* hca_data, uint64_t key, uint16_t sub static void find_hca_key(hca_codec_data* hca_data, uint64_t* p_keycode, uint16_t subkey) { const size_t keys_length = sizeof(hcakey_list) / sizeof(hcakey_info); int best_score = -1; - int i,j; + int i; *p_keycode = 0xCC55463930DBE1AB; /* defaults to PSO2 key, most common */ @@ -166,6 +166,8 @@ static void find_hca_key(hca_codec_data* hca_data, uint64_t* p_keycode, uint16_t #if 0 { + int j; + size_t subkeys_size = hcakey_list[i].subkeys_size; const uint16_t *subkeys = hcakey_list[i].subkeys; if (subkeys_size > 0 && subkey == 0) { diff --git a/src/meta/ngc_str_cauldron.c b/src/meta/ngc_str_cauldron.c index 7ef70aeb..15564821 100644 --- a/src/meta/ngc_str_cauldron.c +++ b/src/meta/ngc_str_cauldron.c @@ -1,46 +1,46 @@ -#include "meta.h" -#include "../coding/coding.h" - -/* .str - Cauldron/Conan mini-header + interleaved dsp data [Conan (GC)] */ -VGMSTREAM * init_vgmstream_ngc_str(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - off_t start_offset; - int channel_count, loop_flag; - - - /* checks */ - if (!check_extensions(streamFile, "str")) - goto fail; - if (read_32bitBE(0x00,streamFile) != 0xFAAF0001) /* header id */ - goto fail; - - channel_count = 2; /* always loop & stereo */ - loop_flag = 1; - start_offset = 0x60; - - - /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); - if (!vgmstream) goto fail; - - vgmstream->sample_rate = read_32bitBE(0x04,streamFile); - vgmstream->num_samples = read_32bitBE(0x08,streamFile); - vgmstream->loop_start_sample = 0; - vgmstream->loop_end_sample = vgmstream->num_samples; - - vgmstream->meta_type = meta_DSP_STR; - vgmstream->coding_type = coding_NGC_DSP; - vgmstream->layout_type = layout_interleave; - vgmstream->interleave_block_size = read_32bitBE(0x0C,streamFile); - - dsp_read_coefs_be(vgmstream, streamFile, 0x10, 0x20); - - - 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" + +/* .str - Cauldron/Conan mini-header + interleaved dsp data [Conan (GC)] */ +VGMSTREAM* init_vgmstream_ngc_str(STREAMFILE *sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset; + int channels, loop_flag; + + + /* checks */ + if (!check_extensions(sf, "str")) + goto fail; + if (read_u32be(0x00,sf) != 0xFAAF0001) /* header id */ + goto fail; + + channels = 2; /* always loop & stereo */ + loop_flag = 1; + start_offset = 0x60; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels,loop_flag); + if (!vgmstream) goto fail; + + vgmstream->sample_rate = read_s32be(0x04,sf); + vgmstream->num_samples = read_s32be(0x08,sf); + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->meta_type = meta_DSP_STR; + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = read_u32be(0x0C,sf); + + dsp_read_coefs_be(vgmstream, sf, 0x10, 0x20); + + + if (!vgmstream_open_stream(vgmstream,sf,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/ps2_sfs.c b/src/meta/ps2_sfs.c index ebe04561..97de7a32 100644 --- a/src/meta/ps2_sfs.c +++ b/src/meta/ps2_sfs.c @@ -1,64 +1,53 @@ #include "meta.h" -#include "../util.h" +#include "../coding/coding.h" -/* SFS (from Baroque) */ -VGMSTREAM * init_vgmstream_sfs(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; +/* SFS - from Sting games [Baroque (PS2)] */ +VGMSTREAM* init_vgmstream_sfs(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag; - int channel_count; + int loop_flag, channels, sample_rate; + size_t channel_size, loop_start; - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("sfs",filename_extension(filename))) goto fail; - /* check header */ - if (read_32bitBE(0x00,streamFile) != 0x53544552) /* "STER" */ + /* checks */ + /* .sfs: bigfile extension (no apparent names) */ + if (!check_extensions(sf, "sfs")) goto fail; - loop_flag = (read_32bitLE(0x08,streamFile)!=0xFFFFFFFF); - channel_count = 2; - + if (!is_id32be(0x00,sf, "STER")) + goto fail; + channel_size = read_u32le(0x04, sf); + loop_start = read_u32le(0x08, sf); /* absolute (ex. offset 0x50 for full loops) */ + /* 0x0c: data size BE */ + sample_rate = read_s32be(0x10,sf); + + loop_flag = loop_start != 0xFFFFFFFF; + channels = 2; + start_offset = 0x30; + + /* 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 */ - start_offset = 0x30; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitBE(0x10,streamFile); - vgmstream->coding_type = coding_PSX; - vgmstream->num_samples = (read_32bitLE(0x04,streamFile)*2)*28/16/channel_count; - if (loop_flag) { - vgmstream->loop_start_sample = read_32bitLE(0x08,streamFile)*28/16/channel_count; - vgmstream->loop_end_sample = (read_32bitLE(0x04,streamFile)*2)*28/16/channel_count; - } + vgmstream->meta_type = meta_SFS; + vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = ps_bytes_to_samples(channel_size, 1); + vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start - start_offset, channels); + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->coding_type = coding_PSX; vgmstream->layout_type = layout_interleave; vgmstream->interleave_block_size = 0x10; - vgmstream->meta_type = meta_SFS; - /* 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; - - } - } + read_string(vgmstream->stream_name,0x10+1, 0x20,sf); + 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; }