mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 19:19:16 +01:00
Fix some .sgt DMSG with streams
This commit is contained in:
parent
8819cbf0b3
commit
f9ef1f2d89
@ -155,7 +155,7 @@ static const char* extension_list[] = {
|
|||||||
"de2",
|
"de2",
|
||||||
"dec",
|
"dec",
|
||||||
"diva",
|
"diva",
|
||||||
"dmsg",
|
"dmsg", //fake extension/header id for .sgt (to be removed)
|
||||||
"ds2", //txth/reserved [Star Wars Bounty Hunter (GC)]
|
"ds2", //txth/reserved [Star Wars Bounty Hunter (GC)]
|
||||||
"dsb",
|
"dsb",
|
||||||
"dsf",
|
"dsf",
|
||||||
@ -402,7 +402,7 @@ static const char* extension_list[] = {
|
|||||||
"rad",
|
"rad",
|
||||||
"rak",
|
"rak",
|
||||||
"ras",
|
"ras",
|
||||||
"raw",
|
"raw", //txth/reserved [Madden NHL 97 (PC)-pcm8u]
|
||||||
"rda", //FFmpeg/reserved [Rhythm Destruction (PC)]
|
"rda", //FFmpeg/reserved [Rhythm Destruction (PC)]
|
||||||
"rkv",
|
"rkv",
|
||||||
"rnd",
|
"rnd",
|
||||||
@ -464,6 +464,7 @@ static const char* extension_list[] = {
|
|||||||
"sfx",
|
"sfx",
|
||||||
"sgb",
|
"sgb",
|
||||||
"sgd",
|
"sgd",
|
||||||
|
"sgt",
|
||||||
"sgx",
|
"sgx",
|
||||||
"sl3",
|
"sl3",
|
||||||
"slb", //txth/reserved [THE Nekomura no Hitobito (PS2)]
|
"slb", //txth/reserved [THE Nekomura no Hitobito (PS2)]
|
||||||
@ -1114,7 +1115,7 @@ static const meta_info meta_info_list[] = {
|
|||||||
{meta_HIS, "Her Interactive HIS header"},
|
{meta_HIS, "Her Interactive HIS header"},
|
||||||
{meta_PS2_AST, "KOEI AST header"},
|
{meta_PS2_AST, "KOEI AST header"},
|
||||||
{meta_CAPDSP, "Capcom DSP header"},
|
{meta_CAPDSP, "Capcom DSP header"},
|
||||||
{meta_DMSG, "RIFF/DMSGsegh header"},
|
{meta_DMSG, "Microsoft RIFF DMSG header"},
|
||||||
{meta_PONA_3DO, "Policenauts BGM header"},
|
{meta_PONA_3DO, "Policenauts BGM header"},
|
||||||
{meta_PONA_PSX, "Policenauts BGM header"},
|
{meta_PONA_PSX, "Policenauts BGM header"},
|
||||||
{meta_NGC_DSP_AAAP, "Acclaim Austin AAAp DSP header"},
|
{meta_NGC_DSP_AAAP, "Acclaim Austin AAAp DSP header"},
|
||||||
|
@ -1,110 +1,159 @@
|
|||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../util.h"
|
#include "../coding/coding.h"
|
||||||
|
|
||||||
/* DMSG
|
typedef struct {
|
||||||
found in: Nightcaster II - Equinox
|
uint32_t type;
|
||||||
2010-01-05 (manakoAT): Seems it's a corrupted "SGT" file, but I'm not sure...
|
uint32_t size;
|
||||||
*/
|
uint32_t offset;
|
||||||
VGMSTREAM * init_vgmstream_dmsg(STREAMFILE *streamFile) {
|
off_t current;
|
||||||
|
off_t max;
|
||||||
|
int le_type;
|
||||||
|
int be_size;
|
||||||
|
int full_size;
|
||||||
|
} chunk_t;
|
||||||
|
|
||||||
|
static int next_chunk(chunk_t* chunk, STREAMFILE* sf) {
|
||||||
|
uint32_t (*read_u32type)(off_t,STREAMFILE*) = !chunk->le_type ? read_u32be : read_u32le;
|
||||||
|
uint32_t (*read_u32size)(off_t,STREAMFILE*) = chunk->be_size ? read_u32be : read_u32le;
|
||||||
|
|
||||||
|
if (chunk->max == 0)
|
||||||
|
chunk->max = get_streamfile_size(sf);
|
||||||
|
|
||||||
|
if (chunk->current >= chunk->max)
|
||||||
|
return 0;
|
||||||
|
/* can be used to signal "stop" */
|
||||||
|
if (chunk->current < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
chunk->type = read_u32type(chunk->current + 0x00,sf);
|
||||||
|
chunk->size = read_u32size(chunk->current + 0x04,sf);
|
||||||
|
|
||||||
|
chunk->offset = chunk->current + 0x04 + 0x04;
|
||||||
|
chunk->current += chunk->full_size ? chunk->size : 0x08 + chunk->size;
|
||||||
|
//;VGM_LOG("CHUNK: %x, %x, %x\n", dc.offset, chunk->type, chunk->size);
|
||||||
|
|
||||||
|
/* read past data */
|
||||||
|
if (chunk->type == 0xFFFFFFFF || chunk->size == 0xFFFFFFFF)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* empty chunk with 0 size, seen in some formats (XVAG uses it as end marker, Wwise doesn't) */
|
||||||
|
if (chunk->type == 0 || chunk->size == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* more chunks remain */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CHUNK_RIFF = 0x52494646, /* "RIFF" */
|
||||||
|
CHUNK_LIST = 0x4C495354, /* "LIST" */
|
||||||
|
CHUNK_segh = 0x73656768, /* "segh" */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* DMSG - DirectMusic Segment with streams [Nightcaster II: Equinox (Xbox), Wildfire (PC)] */
|
||||||
|
VGMSTREAM* init_vgmstream_dmsg(STREAMFILE* sf) {
|
||||||
VGMSTREAM* vgmstream = NULL;
|
VGMSTREAM* vgmstream = NULL;
|
||||||
char filename[PATH_LIMIT];
|
//int loop_flag, channels, sample_rate;
|
||||||
int loop_flag = 0;
|
//int found_data = 0;
|
||||||
int frequency;
|
//int32_t num_samples, loop_start, loop_end;
|
||||||
int channel_count;
|
//off_t start_offset;
|
||||||
int dataBuffer = 0;
|
off_t offset = 0, name_offset = 0, name_size = 0;
|
||||||
int Founddata = 0;
|
|
||||||
size_t file_size;
|
|
||||||
off_t current_chunk;
|
|
||||||
off_t start_offset;
|
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
|
||||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
||||||
if (strcasecmp("dmsg",filename_extension(filename))) goto fail;
|
|
||||||
|
|
||||||
/* check header */
|
/* checks */
|
||||||
if (read_32bitBE(0x00,streamFile) != 0x52494646) /* "RIFF" */
|
/* .sgt: common
|
||||||
goto fail;
|
* .dmsg: header id */
|
||||||
if (read_32bitBE(0x08,streamFile) != 0x444D5347) /* "DMSG" */
|
if (!check_extensions(sf, "sgt,dmsg"))
|
||||||
goto fail;
|
|
||||||
if (read_32bitBE(0x0C,streamFile) != 0x73656768) /* "segh" */
|
|
||||||
goto fail;
|
|
||||||
if (read_32bitBE(0x10,streamFile) != 0x38000000) /* "0x38" */
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* scan file until we find a "data" string */
|
if (!is_id32be(0x00,sf, "RIFF"))
|
||||||
file_size = get_streamfile_size(streamFile);
|
goto fail;
|
||||||
|
if (!is_id32be(0x08,sf, "DMSG"))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
/* A DirectMusic segment usually has lots of chunks then data pointing to .dls soundbank.
|
||||||
|
* This accepts .sgt with a RIFF WAVE inside (less common). */
|
||||||
{
|
{
|
||||||
current_chunk = 0;
|
chunk_t rc = {0};
|
||||||
/* Start at 0 and loop until we reached the
|
chunk_t dc = {0};
|
||||||
file size, or until we found a "data string */
|
|
||||||
while (!Founddata && current_chunk < file_size) {
|
rc.current = 0x0c;
|
||||||
dataBuffer = (read_32bitBE(current_chunk,streamFile));
|
while (next_chunk(&rc, sf)) {
|
||||||
if (dataBuffer == 0x64617461) { /* "data" */
|
switch(rc.type) {
|
||||||
/* if "data" string found, retrieve the needed infos */
|
/* "segh" has loopnum/samplesloop */
|
||||||
Founddata = 1;
|
case CHUNK_segh:
|
||||||
/* We will cancel the search here if we have a match */
|
//todo: missing TMusicTime format
|
||||||
|
/* 0x00: dwRepeats (>0 or -1=inf)
|
||||||
|
* 0x04: mtLength
|
||||||
|
* 0x08: mtPlayStart
|
||||||
|
* 0x0c: mtLoopStart
|
||||||
|
* 0x10: mtLoopEnd
|
||||||
|
* 0x14: dwResolution
|
||||||
|
* 0x18: rtLength (optional)
|
||||||
|
* .. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHUNK_LIST:
|
||||||
|
if (is_id32be(rc.offset + 0x00, sf, "UNFO") && is_id32be(rc.offset + 0x04, sf, "UNAM")) {
|
||||||
|
name_offset = rc.offset + 0x0c;
|
||||||
|
name_size = read_u32le(rc.offset + 0x08, sf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CHUNK_RIFF:
|
||||||
|
if (!is_id32be(rc.offset, sf, "DMCN"))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
dc.current = rc.offset + 0x04;
|
||||||
|
while (next_chunk(&dc, sf)) {
|
||||||
|
switch(dc.type) {
|
||||||
|
case CHUNK_LIST:
|
||||||
|
/* abridged, there are some sublists */
|
||||||
|
if (is_id32be(dc.offset + 0x00, sf, "cosl") && is_id32be(dc.offset + 0x30, sf, "WAVE")) {
|
||||||
|
offset = dc.offset + 0x34;
|
||||||
|
dc.current = -1;
|
||||||
|
rc.current = -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* else we will increase the search offset by 1 */
|
|
||||||
current_chunk = current_chunk + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Founddata == 0) {
|
if (!offset)
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (Founddata == 1) {
|
|
||||||
channel_count = (uint16_t)read_16bitLE(current_chunk-0x10,streamFile);
|
|
||||||
frequency = read_32bitLE(current_chunk-0xE,streamFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
loop_flag = 1;
|
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* subfile has a few extra chunks (guid, wavh) but otherwise standard (seen PCM and MS-ADPCM, with fact chunks) */
|
||||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
{
|
||||||
|
STREAMFILE* temp_sf = NULL;
|
||||||
|
off_t subfile_offset = offset;
|
||||||
|
size_t subfile_size = read_u32le(offset + 0x04, sf) + 0x08;
|
||||||
|
|
||||||
|
temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "wav");
|
||||||
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
|
vgmstream = init_vgmstream_riff(temp_sf);
|
||||||
|
close_streamfile(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
/* fill in the vital statistics */
|
if (name_offset) {
|
||||||
if (Founddata == 0) {
|
if (name_size >= STREAM_NAME_SIZE)
|
||||||
goto fail;
|
name_size = STREAM_NAME_SIZE;
|
||||||
} else if (Founddata == 1) {
|
read_string_utf16le(vgmstream->stream_name,name_size, name_offset, sf);
|
||||||
start_offset = current_chunk+0x8;
|
|
||||||
vgmstream->channels = channel_count;
|
|
||||||
vgmstream->sample_rate = frequency;
|
|
||||||
vgmstream->coding_type = coding_PCM16LE;
|
|
||||||
vgmstream->num_samples = (read_32bitLE(current_chunk+0x4,streamFile)/2/channel_count);
|
|
||||||
if (loop_flag) {
|
|
||||||
vgmstream->loop_start_sample = 0;
|
|
||||||
vgmstream->loop_end_sample = (read_32bitLE(current_chunk+0x4,streamFile)/2/channel_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel_count == 1) {
|
|
||||||
vgmstream->layout_type = layout_none;
|
|
||||||
} else if (channel_count > 1) {
|
|
||||||
vgmstream->layout_type = layout_interleave;
|
|
||||||
vgmstream->interleave_block_size = 0x2;
|
|
||||||
}
|
|
||||||
|
|
||||||
vgmstream->meta_type = meta_DMSG;
|
|
||||||
|
|
||||||
/* open the file for reading */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
STREAMFILE * file;
|
|
||||||
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
if (!file) goto fail;
|
|
||||||
for (i=0;i<channel_count;i++) {
|
|
||||||
vgmstream->ch[i].streamfile = file;
|
|
||||||
vgmstream->ch[i].channel_start_offset=
|
|
||||||
vgmstream->ch[i].offset=start_offset+
|
|
||||||
vgmstream->interleave_block_size*i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
}
|
||||||
|
|
||||||
/* clean up anything we may have opened */
|
|
||||||
fail:
|
fail:
|
||||||
if (vgmstream) close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user