Add GTD support [Knights Contract X360]

This commit is contained in:
bnnm 2017-05-13 01:55:31 +02:00
parent 64b4631ded
commit e2cc352238
8 changed files with 103 additions and 0 deletions

View File

@ -109,6 +109,7 @@ static const char* extension_list[] = {
"genh",
"gms",
"gsb",
"gtd",
"hca",
"hgc1",
@ -851,6 +852,7 @@ static const meta_info meta_info_list[] = {
{meta_SXD, "Sony SXD header"},
{meta_OGL, "Shin'en OGL header"},
{meta_MC3, "Paradigm MC3 header"},
{meta_GTD, "GTD/GHS header"},
#ifdef VGM_USE_VORBIS
{meta_OGG_VORBIS, "Ogg Vorbis"},

View File

@ -396,6 +396,10 @@
RelativePath=".\meta\gsp_gsb.c"
>
</File>
<File
RelativePath=".\meta\gtd.c"
>
</File>
<File
RelativePath=".\meta\halpst.c"
>

View File

@ -216,6 +216,7 @@
<ClCompile Include="meta\genh.c" />
<ClCompile Include="meta\gh3_bar.c" />
<ClCompile Include="meta\gsp_gsb.c" />
<ClCompile Include="meta\gtd.c" />
<ClCompile Include="meta\halpst.c" />
<ClCompile Include="meta\hca.c" />
<ClCompile Include="meta\his.c" />

View File

@ -220,6 +220,9 @@
<ClCompile Include="meta\gsp_gsb.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\gtd.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\halpst.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

86
src/meta/gtd.c Normal file
View File

@ -0,0 +1,86 @@
#include "meta.h"
#include "../coding/coding.h"
typedef enum { XMA2 } gtd_codec;
/* GTD - found in Knights Contract (X360, PS3), Valhalla Knights 3 (PSV) */
VGMSTREAM * init_vgmstream_gtd(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset, chunk_offset;
size_t data_size, chunk_size;
int loop_flag, channel_count, sample_rate;
int num_samples, loop_start_sample, loop_end_sample;
gtd_codec codec;
/* check extension, case insensitive */
if ( !check_extensions(streamFile,"gtd"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x47485320) /* "GHS " */
goto fail;
VGM_LOG("1");
/* header type, not formally specified */
if (read_32bitBE(0x04,streamFile) == 1 && read_16bitBE(0x0C,streamFile) == 0x0166) { /* XMA2 */
/* 0x08(4): seek table size */
chunk_offset = 0x0c; /* custom header with a "fmt " data chunk inside */
chunk_size = 0x34;
channel_count = read_16bitBE(chunk_offset+0x02,streamFile);
sample_rate = read_32bitBE(chunk_offset+0x04,streamFile);
xma2_parse_fmt_chunk_extra(streamFile, chunk_offset, &loop_flag, &num_samples, &loop_start_sample, &loop_end_sample, 1);
start_offset = read_32bitBE(0x58,streamFile); /* always 0x800 */
data_size = read_32bitBE(0x5c,streamFile);
/* 0x40(18): null, 0x60(4): header size (0x70), 0x64(4): seek table size again, 0x68(8): null */
/* 0x70: seek table; then a "STPR" chunk with the file ID and filename */
codec = XMA2;
}
else {
/* there are PSV (LE, ATRAC9) and PS3 (MSF inside?) variations, somewhat-but-not-quite similar
* (contain the "STPR" chunk but the rest is mostly different) */
goto fail;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start_sample;
vgmstream->loop_end_sample = loop_end_sample;
vgmstream->meta_type = meta_GTD;
switch(codec) {
case XMA2: {
#ifdef VGM_USE_FFMPEG
uint8_t buf[0x100];
size_t bytes;
bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf,0x100, chunk_offset,chunk_size, data_size, streamFile, 1);
if (bytes <= 0) goto fail;
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,data_size);
if ( !vgmstream->codec_data ) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
break;
}
#endif
default:
goto fail;
}
/* open the file for reading */
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -688,4 +688,7 @@ VGMSTREAM * init_vgmstream_ogl(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_mc3(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_gtd(STREAMFILE *streamFile);
#endif /*_META_H*/

View File

@ -354,6 +354,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
init_vgmstream_sxd,
init_vgmstream_ogl,
init_vgmstream_mc3,
init_vgmstream_gtd,
#ifdef VGM_USE_FFMPEG
init_vgmstream_mp4_aac_ffmpeg,
@ -931,6 +932,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
}
}
/* get the size in samples of a single frame (1 or N channels), for interleaved/blocked layouts */
int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
switch (vgmstream->coding_type) {
case coding_CRI_ADX:
@ -1081,6 +1083,7 @@ int get_vgmstream_samples_per_shortframe(VGMSTREAM * vgmstream) {
}
}
/* get the data size of a single frame (1 or N channels), for interleaved/blocked layouts */
int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
switch (vgmstream->coding_type) {
case coding_CRI_ADX:

View File

@ -609,6 +609,7 @@ typedef enum {
meta_SXD, /* Sony SXD (Gravity Rush, Freedom Wars PSV) */
meta_OGL, /* Shin'en Wii/WiiU (Jett Rocket (Wii), FAST Racing NEO (WiiU)) */
meta_MC3, /* Paradigm games (T3 PS2, MX Rider PS2, MI: Operation Surma PS2) */
meta_GTD, /* Knights Contract (X360/PS3), Valhalla Knights 3 (PSV) */
#ifdef VGM_USE_VORBIS
meta_OGG_VORBIS, /* Ogg Vorbis */