From cc537270c1f97faefaf3f854617bf2b5b22c7ca9 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 26 Aug 2018 19:16:24 +0200 Subject: [PATCH] Add RFRM .csmp and cleanup [Donkey Kong Country Tropical Freeze (Wii U)] --- src/formats.c | 5 +-- src/libvgmstream.vcproj | 12 ++++--- src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/agsc.c | 2 +- src/meta/csmp.c | 3 +- src/meta/meta.h | 2 ++ src/meta/rfrm.c | 60 ++++++++++++++++++++++++++++++++ src/meta/rs03.c | 8 ++--- src/vgmstream.c | 1 + src/vgmstream.h | 8 ++--- 11 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 src/meta/rfrm.c diff --git a/src/formats.c b/src/formats.c index d40fb921..ea243db4 100644 --- a/src/formats.c +++ b/src/formats.c @@ -672,8 +672,9 @@ static const meta_info meta_info_list[] = { {meta_AIX, "CRI AIX header"}, {meta_AAX, "CRI AAX header"}, {meta_UTF_DSP, "CRI ADPCM_WII header"}, - {meta_DSP_AGSC, "Retro Studios AGSC header"}, - {meta_DSP_CSMP, "Retro Studios CSMP header"}, + {meta_AGSC, "Retro Studios AGSC header"}, + {meta_CSMP, "Retro Studios CSMP header"}, + {meta_RFRM, "Retro Studios RFRM header"}, {meta_NGC_ADPDTK, "Nintendo ADP raw header"}, {meta_RSF, "Retro Studios RSF raw header"}, {meta_AFC, "Nintendo AFC header"}, diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index f06a644e..e345af4e 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -1198,10 +1198,14 @@ RelativePath=".\meta\raw.c" > - - + + + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 8bcf4ea9..e6bfecd5 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -386,6 +386,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 15da5f8c..54567362 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -730,6 +730,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/agsc.c b/src/meta/agsc.c index 72629315..e19922bc 100644 --- a/src/meta/agsc.c +++ b/src/meta/agsc.c @@ -42,7 +42,7 @@ VGMSTREAM * init_vgmstream_agsc(STREAMFILE *streamFile) { vgmstream->coding_type = coding_NGC_DSP; vgmstream->layout_type = layout_none; - vgmstream->meta_type = meta_DSP_AGSC; + vgmstream->meta_type = meta_AGSC; vgmstream->allow_dual_stereo = 1; for (i=0;i<16;i++) { diff --git a/src/meta/csmp.c b/src/meta/csmp.c index 52a55060..30915b29 100644 --- a/src/meta/csmp.c +++ b/src/meta/csmp.c @@ -32,7 +32,7 @@ VGMSTREAM * init_vgmstream_csmp(STREAMFILE *streamFile) { vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; - vgmstream->meta_type = meta_DSP_CSMP; + vgmstream->meta_type = meta_CSMP; vgmstream->sample_rate = read_32bitBE(chunk_offset+0x08,streamFile); vgmstream->num_samples = read_32bitBE(chunk_offset+0x00,streamFile); vgmstream->loop_start_sample = dsp_nibbles_to_samples(read_32bitBE(chunk_offset+0x10,streamFile)); @@ -53,4 +53,3 @@ fail: close_vgmstream(vgmstream); return NULL; } - diff --git a/src/meta/meta.h b/src/meta/meta.h index 8f975680..ab24b8f9 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -37,6 +37,8 @@ VGMSTREAM * init_vgmstream_ngc_dsp_std_int(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_csmp(STREAMFILE *streamFile); +VGMSTREAM * init_vgmstream_rfrm(STREAMFILE *streamFile); + VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_ps2_ads_container(STREAMFILE *streamFile); diff --git a/src/meta/rfrm.c b/src/meta/rfrm.c new file mode 100644 index 00000000..44327a09 --- /dev/null +++ b/src/meta/rfrm.c @@ -0,0 +1,60 @@ +#include "meta.h" +#include "../coding/coding.h" + + +/* RFTM - Retro Studios format [Donkey Kong Country Tropical Freeze (WiiU)] */ +VGMSTREAM * init_vgmstream_rfrm(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + off_t start_offset, header_offset; + size_t interleave; + int loop_flag, channel_count; + + + /* checks */ + if (!check_extensions(streamFile, "csmp")) + goto fail; + + /* format uses weird-sized chunks, quick hack until I get enough files */ + + if (read_32bitBE(0x00, streamFile) != 0x5246524D) /* "RFRM" */ + goto fail; + if (read_32bitBE(0x14, streamFile) != 0x43534D50) /* "CSMP" */ + goto fail; + if (read_32bitBE(0x3d, streamFile) != 0x44415441) /* "DATA" */ + goto fail; + + channel_count = read_32bitBE(0x35, streamFile); + + header_offset = 0x58; + loop_flag = read_16bitBE(header_offset+0x0c,streamFile); + + start_offset = header_offset + 0x60; + interleave = (get_streamfile_size(streamFile) - header_offset) / channel_count; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_RFRM; + vgmstream->sample_rate = read_32bitBE(header_offset+0x08,streamFile); + vgmstream->num_samples = read_32bitBE(header_offset+0x00,streamFile); + vgmstream->loop_start_sample = dsp_nibbles_to_samples(read_32bitBE(header_offset+0x10,streamFile)); + vgmstream->loop_end_sample = dsp_nibbles_to_samples(read_32bitBE(header_offset+0x14,streamFile))+1; + if (vgmstream->loop_end_sample > vgmstream->num_samples) /* ? */ + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = interleave; + dsp_read_coefs_be(vgmstream, streamFile, header_offset+0x1c, interleave); + dsp_read_hist_be(vgmstream, streamFile, header_offset+0x40, interleave); + + if (!vgmstream_open_stream(vgmstream,streamFile,start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/rs03.c b/src/meta/rs03.c index 6244e2ea..127e783f 100644 --- a/src/meta/rs03.c +++ b/src/meta/rs03.c @@ -27,11 +27,11 @@ VGMSTREAM * init_vgmstream_rs03(STREAMFILE *streamFile) { vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; - vgmstream->sample_rate = read_32bitBE(0xc,streamFile); - vgmstream->num_samples = read_32bitBE(8,streamFile); + vgmstream->sample_rate = read_32bitBE(0x0c,streamFile); + vgmstream->num_samples = read_32bitBE(0x08,streamFile); if (loop_flag) { - vgmstream->loop_start_sample = read_32bitBE(0x18,streamFile)/8*14; - vgmstream->loop_end_sample = read_32bitBE(0x1c,streamFile)/8*14; + vgmstream->loop_start_sample = dsp_bytes_to_samples(read_32bitBE(0x18,streamFile), 1); + vgmstream->loop_end_sample = dsp_bytes_to_samples(read_32bitBE(0x1c,streamFile), 1); } vgmstream->meta_type = meta_DSP_RS03; diff --git a/src/vgmstream.c b/src/vgmstream.c index 622e38dc..89e8558f 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -33,6 +33,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_ngc_dsp_std_le, init_vgmstream_ngc_mdsp_std, init_vgmstream_csmp, + init_vgmstream_rfrm, init_vgmstream_cstr, init_vgmstream_gcsw, init_vgmstream_ps2_ads, diff --git a/src/vgmstream.h b/src/vgmstream.h index a46230b4..8f179508 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -268,13 +268,14 @@ typedef enum { /* The meta type specifies how we know what we know about the file. * We may know because of a header we read, some of it may have been guessed from filenames, etc. */ typedef enum { - /* DSP-specific */ + meta_DSP_STD, /* Nintendo standard GC ADPCM (DSP) header */ - meta_DSP_CSMP, /* Retro: Metroid Prime 3, Donkey Kong Country Returns */ meta_DSP_CSTR, /* Star Fox Assault "Cstr" */ meta_DSP_RS03, /* Retro: Metroid Prime 2 "RS03" */ meta_DSP_STM, /* Paper Mario 2 STM */ - meta_DSP_AGSC, /* Retro: Metroid Prime 2 title */ + meta_AGSC, /* Retro: Metroid Prime 2 title */ + meta_CSMP, /* Retro: Metroid Prime 3 (Wii), Donkey Kong Country Returns (Wii) */ + meta_RFRM, /* Retro: Donkey Kong Country Tropical Freeze (Wii U) */ meta_DSP_MPDSP, /* Monopoly Party single header stereo */ meta_DSP_JETTERS, /* Bomberman Jetters .dsp */ meta_DSP_MSS, /* Free Radical GC games */ @@ -289,7 +290,6 @@ typedef enum { meta_DSP_YGO, /* Konami: Yu-Gi-Oh! The Falsebound Kingdom (NGC), Hikaru no Go 3 (NGC) */ meta_DSP_SADF, /* Procyon Studio SADF - Xenoblade Chronicles 2 (Switch) */ - /* Nintendo */ meta_STRM, /* Nintendo STRM */ meta_RSTM, /* Nintendo RSTM (Revolution Stream, similar to STRM) */ meta_AFC, /* AFC */