Added streamed ABK version support (ABK/AST combo)

This commit is contained in:
NicknineTheEagle 2018-07-18 02:39:47 +03:00
parent 2056155c6b
commit 5af027e5f9
2 changed files with 74 additions and 43 deletions

View File

@ -23,9 +23,10 @@ void block_update_ea_schl(off_t block_offset, VGMSTREAM * vgmstream) {
{
uint32_t block_id = read_32bitBE(block_offset+0x00,streamFile);
block_size = read_32bitLE(block_offset+0x04,streamFile);
if (block_size > 0x00F00000) /* size is always LE, except in early SAT/MAC */
block_size = read_32bitBE(block_offset+0x04,streamFile);
if (guess_endianness32bit(block_offset + 0x04,streamFile)) /* size is always LE, except in early SS/MAC */
block_size = read_32bitBE(block_offset + 0x04,streamFile);
else
block_size = read_32bitLE(block_offset + 0x04,streamFile);
switch(block_id) {
case 0x5343446C: /* "SCDl" */

View File

@ -72,6 +72,7 @@ typedef struct {
int codec_version;
} ea_header;
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int total_streams);
static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset);
static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t begin_offset, int max_length);
static uint32_t read_patch(STREAMFILE* streamFile, off_t* offset);
@ -79,14 +80,8 @@ static int get_ea_stream_total_samples(STREAMFILE* streamFile, off_t start_offse
static off_t get_ea_stream_mpeg_start_offset(STREAMFILE* streamFile, off_t start_offset, const ea_header* ea);
static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_header *ea, off_t start_offset, int is_bnk, int total_streams);
/* EA SCHl with variable header - from EA games (roughly 1997~2010); generated by EA Canada's sx.exe/Sound eXchange */
VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile) {
off_t start_offset, header_offset;
size_t header_size;
ea_header ea = {0};
/* check extension; exts don't seem enforced by EA's tools, but usually:
* STR/ASF/MUS ~early, EAM ~mid, SNG/AUD ~late, rest uncommon/one game (ex. STRM: MySims Kingdom Wii) */
if (!check_extensions(streamFile,"str,asf,mus,eam,sng,aud,sx,strm,xa,xsf,exa,stm,ast,trj,trm"))
@ -106,33 +101,15 @@ VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile) {
/* Stream is divided into blocks/chunks: SCHl=audio header, SCCl=count of SCDl, SCDl=data xN, SCLl=loop end, SCEl=end.
* Video uses picture blocks (MVhd/MV0K/etc) and sometimes multiaudio blocks (SHxx/SCxx/SDxx/SExx where xx=language=EN/FR/GE/IT/SP/RU/JA).
* The number/size is affected by: block rate setting, sample rate, channels, CPU location (SPU/main/DSP/others), etc */
header_size = read_32bitLE(0x04,streamFile);
if (header_size > 0x00F00000) /* size is always LE, except in early SS/MAC */
header_size = read_32bitBE(0x04,streamFile);
header_offset = 0x08;
if (!parse_variable_header(streamFile,&ea, 0x08, header_size - header_offset))
goto fail;
start_offset = header_size; /* starts in "SCCl" (skipped in block layout) or very rarely "SCDl" and maybe movie blocks */
/* rest is common */
return init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, 0, 1);
return parse_schl_block(streamFile, 0x00, 0);
fail:
return NULL;
}
/* EA BNK with variable header - from EA games SFXs; also created by sx.exe */
VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE *streamFile) {
off_t start_offset, header_offset, test_offset, offset, table_offset;
size_t header_size;
ea_header ea = {0};
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
int i, bnk_version;
int total_streams, real_streams = 0, target_stream = streamFile->stream_index;
off_t offset;
/* check extension */
/* .bnk: sfx, .sdt: speech, .mus: streams/jingles (rare) */
@ -154,9 +131,12 @@ fail:
return NULL;
}
/* EA ABK - contains embedded BNK file */
/* EA ABK - contains embedded BNK file or references streams in AST file */
VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
off_t bnk_offset;
off_t bnk_offset, unk_table_size, stream_table_offset, schl_offset;
int total_streams, target_stream = streamFile->stream_index;
STREAMFILE * astData;
VGMSTREAM * vgmstream;
/* check extension */
if (!check_extensions(streamFile, "abk"))
@ -166,13 +146,63 @@ VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
goto fail;
bnk_offset = read_32bitLE(0x20,streamFile);
if (bnk_offset == 0) /* TODO: handle streamed version (ABK/AST) */
if (bnk_offset != 0) {
/* normal version */
if (read_32bitBE(bnk_offset, streamFile) != 0x424E4B6C) /* "BNKl" */
goto fail;
if (read_32bitBE(bnk_offset,streamFile) != 0x424E4B6C) /* "BNKl" */
return parse_bnk_header(streamFile, bnk_offset);
}
else {
/* streamed version */
astData = open_streamfile_by_ext(streamFile, "ast");
if (!astData) goto fail;
/* skip uknown table */
unk_table_size = read_32bitLE(0x8c, streamFile);
stream_table_offset = read_32bitLE(0x98 + unk_table_size, streamFile);
total_streams = read_32bitLE(stream_table_offset, streamFile);
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || target_stream > total_streams || total_streams < 1) goto fail;
/* entry structure: 0x00: always 1, 0x04: offset, 0x08: always 0 */
schl_offset = read_32bitLE(stream_table_offset + 0x04 + 0x0C * (target_stream-1) + 0x04, streamFile);
if (read_32bitBE(schl_offset,astData) != 0x5343486C) /* "SCHl */
goto fail;
return parse_bnk_header(streamFile,bnk_offset);
vgmstream = parse_schl_block(astData, schl_offset, total_streams);
if (!vgmstream) goto fail;
close_streamfile(astData);
return vgmstream;
}
fail:
close_streamfile(astData);
return NULL;
}
/* EA SCHl with variable header - from EA games (roughly 1997~2010); generated by EA Canada's sx.exe/Sound eXchange */
static VGMSTREAM * parse_schl_block(STREAMFILE *streamFile, off_t offset, int total_streams) {
off_t start_offset, header_offset;
size_t header_size;
ea_header ea = { 0 };
if (guess_endianness32bit(offset + 0x04, streamFile)) /* size is always LE, except in early SS/MAC */
header_size = read_32bitBE(offset + 0x04, streamFile);
else
header_size = read_32bitLE(offset + 0x04, streamFile);
header_offset = offset + 0x08;
if (!parse_variable_header(streamFile, &ea, header_offset, header_size))
goto fail;
start_offset = offset + header_size; /* starts in "SCCl" (skipped in block layout) or very rarely "SCDl" and maybe movie blocks */
/* rest is common */
return init_vgmstream_ea_variable_header(streamFile, &ea, start_offset, 0, total_streams);
fail:
return NULL;
@ -310,7 +340,6 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
vgmstream->layout_type = layout_blocked_ea_schl;
}
if (is_bnk)
vgmstream->num_streams = total_streams;
/* EA usually implements their codecs in all platforms (PS2/WII do EAXA/MT/EALAYER3) and
@ -466,16 +495,17 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
}
}
else {
/* fix num_samples for streams with multiple SCHl */
if (total_streams == 0) {
/* HACK: fix num_samples for streams with multiple SCHl. Need to eventually get rid of this */
int total_samples = get_ea_stream_total_samples(streamFile, start_offset, vgmstream);
if (total_samples > vgmstream->num_samples)
vgmstream->num_samples = total_samples;
}
/* setup first block to update offsets */
block_update_ea_schl(start_offset,vgmstream);
}
return vgmstream;
fail: