diff --git a/src/formats.c b/src/formats.c index 094cf344..e9b36d7f 100644 --- a/src/formats.c +++ b/src/formats.c @@ -594,6 +594,7 @@ static const char* extension_list[] = { "wve", "wvs", "wvx", + "wxd", "x", "x360audio", //fake extension for Unreal Engine 3 XMA (real extension unknown) @@ -1353,6 +1354,8 @@ static const meta_info meta_info_list[] = { {meta_DSP_KWA, "Kuju London .KWA header"}, {meta_OGV_3RDEYE, "3rdEye .OGV header"}, {meta_PIFF_TPCM, "Tantalus PIFF TPCM header"}, + {meta_WXD_WXH, "Relic WXD+WXH header"}, + {meta_BNK_RELIC, "Relic BNK header"}, }; void get_vgmstream_coding_description(VGMSTREAM* vgmstream, char* out, size_t out_size) { diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 6430a3ec..87dac9b8 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -309,6 +309,7 @@ + @@ -570,6 +571,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index dfb7230d..c3d1a54b 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -1207,6 +1207,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files @@ -1831,6 +1834,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/bnk_relic.c b/src/meta/bnk_relic.c new file mode 100644 index 00000000..38f176ab --- /dev/null +++ b/src/meta/bnk_relic.c @@ -0,0 +1,80 @@ +#include "meta.h" +#include "../coding/coding.h" + +/* BNK - sfx container from Relic's earlier games [Homeworld (PC), Homeworld Cataclysm (PC)] */ +VGMSTREAM* init_vgmstream_bnk_relic(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + uint32_t start_offset, offset, data_size, loop_start, loop_end; + int loop_flag, channels, bitrate, internal_rate, sample_rate; + int total_subsongs, target_subsong = sf->stream_index; + + + /* checks */ + if (!check_extensions(sf, "bnk")) + goto fail; + if (!is_id32be(0x00,sf, "BNK0")) + goto fail; + /* 0x04: flags? */ + + total_subsongs = read_u32le(0x08,sf); + if (target_subsong == 0) target_subsong = 1; + if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail; + + offset = 0x0c + (target_subsong-1) * 0x38; + if (!is_id32be(offset + 0x00,sf, "PCH0")) + goto fail; + /* 0x04: null */ + /* 0x08: 0/+-number? */ + start_offset = read_u32le(offset + 0x0c,sf); + data_size = read_u32le(offset + 0x10,sf); + loop_start = read_u32le(offset + 0x14,sf); /* 0x14: 0/offset? */ + loop_end = read_u32le(offset + 0x18,sf); /* 0x18: 0/offset? */ + bitrate = read_u16le(offset + 0x1c,sf); + loop_flag = read_u16le(offset + 0x1e,sf); + /* 0x20: volume? */ + /* 0x22: -1 */ + /* 0x24: fmt pcm codec 1 */ + channels = read_u16le(offset + 0x26,sf); + sample_rate = read_u32le(offset + 0x28,sf); + /* 0x2c: bitrate */ + /* 0x30: pcm block size */ + /* 0x32: pcm bps */ + /* 0x34: 0 */ + /* 0x36: -1 */ + + internal_rate = 44100; + + loop_flag = 0; //todo clicks on loop, wrong calcs? + + /* stream info */ + if (!is_id32be(start_offset - 0x04,sf, "DATA")) + goto fail; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_BNK_RELIC; + vgmstream->sample_rate = sample_rate; + + vgmstream->num_samples = relic_bytes_to_samples(data_size, channels, bitrate); + vgmstream->loop_start_sample = relic_bytes_to_samples(loop_start, channels, bitrate); + vgmstream->loop_end_sample = relic_bytes_to_samples(loop_end, channels, bitrate); + + vgmstream->num_streams = total_subsongs; + vgmstream->stream_size = data_size; + + vgmstream->codec_data = init_relic(channels, bitrate, internal_rate); + if (!vgmstream->codec_data) goto fail; + vgmstream->coding_type = coding_RELIC; + vgmstream->layout_type = layout_none; + + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/fda.c b/src/meta/fda.c index 57c9a0e1..36b671f3 100644 --- a/src/meta/fda.c +++ b/src/meta/fda.c @@ -1,22 +1,19 @@ #include "meta.h" #include "../coding/coding.h" - /* FDA - from Relic Entertainment games [Warhammer 4000: Dawn of War (PC)] */ -VGMSTREAM * init_vgmstream_fda(STREAMFILE *sf) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_fda(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channel_count, bitrate, sample_rate, num_samples; + int loop_flag, channels, bitrate, sample_rate, num_samples; /* checks */ if (!check_extensions(sf, "fda")) goto fail; - if (read_u32be(0x00, sf) != 0x52656C69 || /* "Reli" */ - read_u32be(0x04, sf) != 0x63204368 || /* "c Ch" */ - read_u32be(0x08, sf) != 0x756E6B79 || /* "unky" */ - read_u32be(0x0c, sf) != 0x0D0A1A00) /* "\r\n\1a\00"*/ + if (!is_id64be(0x00, sf, "Relic Ch") || + !is_id64be(0x08, sf, "unky\r\n\x1a\x00")) goto fail; /* version? (later .fda change this) */ @@ -38,18 +35,18 @@ VGMSTREAM * init_vgmstream_fda(STREAMFILE *sf) { offset += 0x14 + name_size + chunk_size; /* FOLD-FDA (folder of chunks) */ - if (read_u32be(offset + 0x04, sf) != 0x46444120) /* "FDA " */ + if (!is_id32be(offset + 0x04, sf, "FDA ")) goto fail; offset += 0x14; /* DATA-INFO (header) */ - if (read_u32be(offset + 0x04, sf) != 0x494E464F) /* "INFO" */ + if (!is_id32be(offset + 0x04, sf, "INFO")) goto fail; chunk_size = read_u32le(offset + 0x0c, sf); name_size = read_u32le(offset + 0x10, sf); offset += 0x14 + name_size; - channel_count = read_s32le(offset + 0x00, sf); + channels = read_s32le(offset + 0x00, sf); /* 0x04: bps */ bitrate = read_s32le(offset + 0x08, sf); sample_rate = read_s32le(offset + 0x0c, sf); @@ -60,28 +57,28 @@ VGMSTREAM * init_vgmstream_fda(STREAMFILE *sf) { offset += chunk_size; /* DATA-DATA (data) */ - if (read_u32be(offset + 0x04, sf) != 0x44415441) /* "DATA" */ + if (!is_id32be(offset + 0x04, sf, "DATA")) goto fail; chunk_size = read_u32le(offset + 0x0c, sf); name_size = read_u32le(offset + 0x10, sf); offset += 0x14 + name_size; - data_size = read_s32le(offset + 0x00, sf); + data_size = read_u32le(offset + 0x00, sf); start_offset = offset + 0x04; - num_samples = data_size / channel_count / (bitrate / 8) * 512; + num_samples = relic_bytes_to_samples(data_size, channels, bitrate); } /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count, loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; vgmstream->meta_type = meta_FDA; vgmstream->sample_rate = 44100; /* fixed output */ vgmstream->num_samples = num_samples; - vgmstream->codec_data = init_relic(channel_count, bitrate, sample_rate); + vgmstream->codec_data = init_relic(channels, bitrate, sample_rate); if (!vgmstream->codec_data) goto fail; vgmstream->coding_type = coding_RELIC; vgmstream->layout_type = layout_none; diff --git a/src/meta/meta.h b/src/meta/meta.h index 6f086522..1b3393dc 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -955,4 +955,8 @@ VGMSTREAM* init_vgmstream_sspr(STREAMFILE* sf); VGMSTREAM* init_vgmstream_piff_tpcm(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_wxd_wxh(STREAMFILE* sf); + +VGMSTREAM* init_vgmstream_bnk_relic(STREAMFILE* sf); + #endif /*_META_H*/ diff --git a/src/meta/wxd_wxh.c b/src/meta/wxd_wxh.c new file mode 100644 index 00000000..12a178c1 --- /dev/null +++ b/src/meta/wxd_wxh.c @@ -0,0 +1,76 @@ +#include "meta.h" +#include "../coding/coding.h" + +/* WXD+WXH - stream container from Relic's earlier games [Homeworld (PC), Homeworld Cataclysm (PC)] */ +VGMSTREAM* init_vgmstream_wxd_wxh(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* sh = NULL; + uint32_t start_offset, offset, data_size; + int loop_flag, channels, bitrate, internal_rate; + int total_subsongs, target_subsong = sf->stream_index; + + + /* checks */ + if (!check_extensions(sf, "wxd")) + goto fail; + if (!is_id32be(0x00,sf, "WXD1")) + goto fail; + /* 0x04: crc? */ + + /* companion .wxh found in .big bigfiles, must extract and put together */ + sh = open_streamfile_by_ext(sf,"wxh"); + if (!sh) goto fail; + + if (!is_id32be(0x00,sh, "WXH1")) + goto fail; + /* 0x04: crc? */ + + total_subsongs = read_u32le(0x08,sh); + if (target_subsong == 0) target_subsong = 1; + if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail; + + offset = 0x0c + (target_subsong-1) * 0x0c; + start_offset = read_u32le(offset + 0x00,sh); + loop_flag = read_u16le(offset + 0x04,sh); + bitrate = read_u16le(offset + 0x06,sh); + /* 0x08: volume (255=max) */ + channels = read_u8 (offset + 0x09,sh); + /* 0x0a: unused (-1) */ + internal_rate = 44100; + + /* stream info */ + if (!is_id32be(start_offset + 0x00,sf, "DATA")) + goto fail; + data_size = read_u32le(start_offset + 0x04,sf); + start_offset += 0x08; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channels, loop_flag); + if (!vgmstream) goto fail; + + vgmstream->meta_type = meta_WXD_WXH; + vgmstream->sample_rate = 44100; + + vgmstream->num_samples = relic_bytes_to_samples(data_size, channels, bitrate); + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = vgmstream->num_samples; + + vgmstream->num_streams = total_subsongs; + vgmstream->stream_size = data_size; + + vgmstream->codec_data = init_relic(channels, bitrate, internal_rate); + if (!vgmstream->codec_data) goto fail; + vgmstream->coding_type = coding_RELIC; + vgmstream->layout_type = layout_none; + + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) + goto fail; + close_streamfile(sh); + return vgmstream; + +fail: + close_streamfile(sh); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/vgmstream.c b/src/vgmstream.c index 3153c49c..10020537 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -526,6 +526,8 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_ogv_3rdeye, init_vgmstream_sspr, init_vgmstream_piff_tpcm, + init_vgmstream_wxd_wxh, + init_vgmstream_bnk_relic, /* 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 871e41ed..a2963086 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -741,6 +741,8 @@ typedef enum { meta_DSP_KWA, meta_OGV_3RDEYE, meta_PIFF_TPCM, + meta_WXD_WXH, + meta_BNK_RELIC, } meta_t; /* standard WAVEFORMATEXTENSIBLE speaker positions */