2014-10-19 23:10:31 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
2017-01-18 21:28:14 +01:00
|
|
|
#include "../coding/coding.h"
|
2014-10-19 23:10:31 +02:00
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
static VGMSTREAM* init_vgmstream_kt_wiibgm_offset(STREAMFILE* sf, off_t offset);
|
2014-10-19 23:10:31 +02:00
|
|
|
|
2018-03-04 00:16:49 +01:00
|
|
|
/* Koei Tecmo G1L - container format, sometimes containing a single stream.
|
2017-01-18 21:28:14 +01:00
|
|
|
* It probably makes more sense to extract it externally, it's here mainly for Hyrule Warriors */
|
2021-11-18 00:17:17 +01:00
|
|
|
VGMSTREAM* init_vgmstream_kt_g1l(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
int type;
|
|
|
|
int total_streams, target_stream = sf->stream_index;
|
|
|
|
off_t stream_offset;
|
2017-01-18 21:28:14 +01:00
|
|
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
2014-10-19 23:10:31 +02:00
|
|
|
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
/* checks */
|
|
|
|
if (!is_id32be(0x00, sf, "G1L_") && /* BE */
|
|
|
|
!is_id32le(0x00, sf, "G1L_")) /* LE */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!check_extensions(sf,"g1l"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!is_id32be(0x04, sf, "0000")) /* version? */
|
|
|
|
goto fail;
|
2014-10-19 23:10:31 +02:00
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
if (is_id32be(0x00, sf, "G1L_")) {
|
|
|
|
read_32bit = read_32bitBE;
|
|
|
|
} else {
|
2017-01-18 21:28:14 +01:00
|
|
|
read_32bit = read_32bitLE;
|
2021-11-18 00:17:17 +01:00
|
|
|
}
|
2014-10-19 23:10:31 +02:00
|
|
|
|
|
|
|
|
2018-03-04 00:16:49 +01:00
|
|
|
/* 0x08: filesize, 0x0c: header size */
|
2021-11-18 00:17:17 +01:00
|
|
|
type = read_32bit(0x10,sf);
|
|
|
|
total_streams = read_32bit(0x14,sf);
|
2017-01-18 21:28:14 +01:00
|
|
|
if (target_stream==0) target_stream = 1;
|
2021-11-18 00:17:17 +01:00
|
|
|
if (target_stream < 0 || target_stream > total_streams || total_streams < 1) goto fail;
|
2017-03-18 17:17:24 +01:00
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
stream_offset = read_32bit(0x18 + 0x4*(target_stream-1),sf);
|
2018-03-04 00:16:49 +01:00
|
|
|
//stream_size = stream_offset - stream_next_offset;//not ok, sometimes entries are unordered/repeats */
|
2014-10-19 23:10:31 +02:00
|
|
|
|
2017-01-18 21:28:14 +01:00
|
|
|
switch(type) { /* type may not be correct */
|
|
|
|
case 0x09: /* DSP (WiiBGM) from Hyrule Warriors (Wii U) */
|
2021-11-18 00:17:17 +01:00
|
|
|
vgmstream = init_vgmstream_kt_wiibgm_offset(sf, stream_offset);
|
2017-01-18 21:28:14 +01:00
|
|
|
break;
|
2018-03-04 00:16:49 +01:00
|
|
|
case 0x06: /* ATRAC9 (RIFF) from One Piece Pirate Warriors 3 (Vita) */
|
2017-01-18 21:28:14 +01:00
|
|
|
case 0x01: /* ATRAC3plus (RIFF) from One Piece Pirate Warriors 2 (PS3) */
|
|
|
|
case 0x00: /* OGG (KOVS) from Romance Three Kindgoms 13 (PC)*/
|
2018-03-04 00:16:49 +01:00
|
|
|
case 0x0A: /* OGG (KOVS) from Dragon Quest Heroes (PC), Bladestorm (PC) w/ single files */
|
2017-01-18 21:28:14 +01:00
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-10-19 23:10:31 +02:00
|
|
|
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
return vgmstream;
|
2014-10-19 23:10:31 +02:00
|
|
|
fail:
|
2021-11-18 00:17:17 +01:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
2014-10-19 23:10:31 +02:00
|
|
|
}
|
2017-01-18 21:28:14 +01:00
|
|
|
|
|
|
|
/* Koei Tecmo "WiiBGM" DSP format - found in Hyrule Warriors, Romance of the Three Kingdoms 12 */
|
2021-11-18 00:17:17 +01:00
|
|
|
VGMSTREAM * init_vgmstream_kt_wiibgm(STREAMFILE *sf) {
|
|
|
|
return init_vgmstream_kt_wiibgm_offset(sf, 0x0);
|
2017-01-18 21:28:14 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
static VGMSTREAM* init_vgmstream_kt_wiibgm_offset(STREAMFILE* sf, off_t offset) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2017-01-18 21:28:14 +01:00
|
|
|
int loop_flag, channel_count;
|
|
|
|
off_t start_offset;
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
/* check */
|
|
|
|
if (!is_id64be(offset+0x0, sf, "WiiBGM\0\0") &&
|
|
|
|
read_32bitBE(offset+0x4, sf) != 0x474D0000)
|
2017-01-18 21:28:14 +01:00
|
|
|
goto fail;
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
if (!check_extensions(sf,"g1l,dsp"))
|
2017-01-18 21:28:14 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check type details */
|
2021-11-18 00:17:17 +01:00
|
|
|
loop_flag = read_32bitBE(offset+0x14, sf) > 0;
|
|
|
|
channel_count = read_u8(offset+0x23, sf);
|
2017-01-18 21:28:14 +01:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
vgmstream->num_samples = read_32bitBE(offset+0x10, sf);
|
|
|
|
vgmstream->sample_rate = (uint16_t)read_16bitBE(offset+0x26, sf);
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(offset+0x14, sf);
|
2017-01-18 21:28:14 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
2017-12-06 21:04:34 +01:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP_subint;
|
|
|
|
vgmstream->layout_type = layout_none;
|
2017-01-18 21:28:14 +01:00
|
|
|
vgmstream->interleave_block_size = 0x1;
|
2017-12-06 21:04:34 +01:00
|
|
|
vgmstream->meta_type = meta_KT_WIIBGM;
|
2017-01-18 21:28:14 +01:00
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
dsp_read_coefs_be(vgmstream,sf, offset+0x5C, 0x60);
|
2017-01-18 21:28:14 +01:00
|
|
|
start_offset = offset+0x800;
|
|
|
|
|
2021-11-18 00:17:17 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
|
2017-01-18 21:28:14 +01:00
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
2017-12-06 21:04:34 +01:00
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
2017-01-18 21:28:14 +01:00
|
|
|
}
|