From 3ea177e1d712a108d9c6158764cb72dec3dad217 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 6 Jun 2020 16:15:06 +0200 Subject: [PATCH] Add Success PCM [Metal Saga (PS2), Duel Masters: RoSD (PS2)] --- src/formats.c | 1 + src/libvgmstream.vcproj | 4 ++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/meta.h | 2 + src/meta/pcm_success.c | 68 ++++++++++++++++++++++++++++++++ src/vgmstream.c | 1 + src/vgmstream.h | 1 + 8 files changed, 81 insertions(+) create mode 100644 src/meta/pcm_success.c diff --git a/src/formats.c b/src/formats.c index 8cce5e9e..8288c003 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1299,6 +1299,7 @@ static const meta_info meta_info_list[] = { {meta_IMUSE, "LucasArts iMUSE header"}, {meta_KTSR, "Koei Tecmo KTSR header"}, {meta_KAT, "Sega KAT header"}, + {meta_PCM_SUCCESS, "Success PCM header"}, }; void get_vgmstream_coding_description(VGMSTREAM *vgmstream, char *out, size_t out_size) { diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index e35b8e49..224bcc15 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -1137,6 +1137,10 @@ + + + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 91fe276f..6b59a50f 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -724,6 +724,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/meta.h b/src/meta/meta.h index bfd26910..27e4d3d3 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -905,4 +905,6 @@ VGMSTREAM* init_vgmstream_mups(STREAMFILE* sf); VGMSTREAM* init_vgmstream_kat(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_pcm_success(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/src/meta/pcm_success.c b/src/meta/pcm_success.c new file mode 100644 index 00000000..e4c2bd4d --- /dev/null +++ b/src/meta/pcm_success.c @@ -0,0 +1,68 @@ +#include "meta.h" +#include "../coding/coding.h" + + +/* PCM - from Success (related) games [Metal Saga (PS2), Tetris Kiwamemichi (PS2), Duel Masters: Rebirth of Super Dragon (PS2)] */ +VGMSTREAM* init_vgmstream_pcm_success(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + off_t start_offset; + int loop_flag, channels, sample_rate, interleave; + size_t data_size, loop_start, loop_end, loop_adjust; + + + /* checks */ + if (!check_extensions(sf, "pcm")) + goto fail; + + if (read_u32be(0x00,sf) != 0x50434D20) /* "PCM " */ + goto fail; + if (read_u32le(0x04,sf) != 0x00010000) /* version? */ + goto fail; + if (read_u32le(0x08,sf) + 0x8000 < get_streamfile_size(sf)) /* data size without padding */ + goto fail; + + interleave = 0x800; + start_offset = 0x800; + + sample_rate = read_s32le(0x0c,sf); + channels = read_s32le(0x10,sf); + loop_flag = read_s32le(0x14,sf); + + data_size = read_s32le(0x18,sf) * interleave * channels; + /* loops seems slightly off, so 'adjust' meaning may need to be tweaked */ + loop_adjust = read_s32le(0x1c,sf) * channels; /* from 0..<0x800 */ + loop_start = read_s32le(0x20,sf) * interleave * channels + loop_adjust; + loop_adjust = read_s32le(0x24,sf) * channels; /* always 0x800 (0 if no loop flag) */ + loop_end = read_s32le(0x28,sf) * interleave * channels + (interleave * channels - loop_adjust); + + /* 0x2c: always 1? */ + /* 0x30/40: padding garbage (also at file end) */ + + /* not always accurate and has padding */ + if (data_size > get_streamfile_size(sf) - start_offset) + data_size = get_streamfile_size(sf) - start_offset; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_PCM_SUCCESS; + vgmstream->sample_rate = sample_rate; + + vgmstream->num_samples = ps_bytes_to_samples(data_size, channels); + vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels); + vgmstream->loop_end_sample = ps_bytes_to_samples(loop_end, channels); + + vgmstream->coding_type = coding_PSX; + vgmstream->layout_type = layout_interleave; + vgmstream->interleave_block_size = interleave; + + 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 4bc02404..c8662148 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -500,6 +500,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_ktsr, init_vgmstream_mups, init_vgmstream_kat, + init_vgmstream_pcm_success, /* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */ init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */ diff --git a/src/vgmstream.h b/src/vgmstream.h index b88df9ee..db55def8 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -732,6 +732,7 @@ typedef enum { meta_IMUSE, meta_KTSR, meta_KAT, + meta_PCM_SUCCESS, } meta_t; /* standard WAVEFORMATEXTENSIBLE speaker positions */