mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-29 19:37:30 +01:00
EA SCHl: fixed stream size calc not working with merged sound files
This commit is contained in:
parent
7418e32482
commit
9b29ba9599
@ -103,8 +103,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
|
||||
static uint32_t read_patch(STREAMFILE* streamFile, off_t* offset);
|
||||
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 standalone);
|
||||
static int get_ea_stream_size(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM *vgmstream);
|
||||
static int get_ea_stream_total_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream);
|
||||
static void update_ea_stream_size_and_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream, int standalone);
|
||||
|
||||
/* 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) {
|
||||
@ -866,15 +865,7 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
|
||||
/* TODO: Figure out how to get stream size for BNK sounds */
|
||||
}
|
||||
else {
|
||||
vgmstream->stream_size = get_ea_stream_size(streamFile, start_offset, vgmstream);
|
||||
|
||||
/* regular SCHls, except ATRAC3plus */
|
||||
if (standalone) {
|
||||
/* 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;
|
||||
}
|
||||
update_ea_stream_size_and_samples(streamFile, start_offset, vgmstream, standalone);
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
@ -1264,65 +1255,52 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Stream size is almost never provided in bank files so we have to calc it manually */
|
||||
static int get_ea_stream_size(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM *vgmstream) {
|
||||
size_t stream_size, block_size;
|
||||
static void update_ea_stream_size_and_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM *vgmstream, int standalone) {
|
||||
uint32_t block_id;
|
||||
off_t block_offset;
|
||||
int32_t num_samples;
|
||||
size_t stream_size, file_size;
|
||||
int multiple_schl;
|
||||
|
||||
stream_size = 0;
|
||||
block_offset = start_offset;
|
||||
stream_size = 0, num_samples = 0, multiple_schl = 0;
|
||||
file_size = get_streamfile_size(streamFile);
|
||||
vgmstream->next_block_offset = start_offset;
|
||||
|
||||
while (1) {
|
||||
block_id = read_32bitBE(block_offset + 0x00, streamFile);
|
||||
if (block_id == EA_BLOCKID_END)
|
||||
break;
|
||||
while (vgmstream->next_block_offset < file_size) {
|
||||
block_update_ea_schl(vgmstream->next_block_offset, vgmstream);
|
||||
|
||||
if (vgmstream->codec_config & 0x02) /* 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);
|
||||
block_id = read_32bitBE(vgmstream->current_block_offset + 0x00, streamFile);
|
||||
if (block_id == EA_BLOCKID_END) { /* banks should never contain movie "SHxx" */
|
||||
if (!standalone)
|
||||
break;
|
||||
}
|
||||
else if (block_id == EA_BLOCKID_HEADER) { /* "SCHl" start block (movie "SHxx" shouldn't use multi files) */
|
||||
multiple_schl = 1;
|
||||
}
|
||||
|
||||
if (block_size == 0x00 || block_size > 0xFFFFF) /* EOF read */
|
||||
break;
|
||||
/* HACK: fix num_samples for streams with multiple SCHl. Need to eventually get rid of this.
|
||||
* Get total samples by parsing block headers, needed when multiple files are stitched together.
|
||||
* Some EA files (.mus/eam/sng/etc) concat many small subfiles, used for interactive/mapped
|
||||
* music (.map/lin). Subfiles always share header, except num_samples. */
|
||||
num_samples += vgmstream->current_block_samples;
|
||||
|
||||
stream_size += block_size - 0x12;
|
||||
block_offset += block_size;
|
||||
}
|
||||
|
||||
return stream_size;
|
||||
}
|
||||
|
||||
/* Get total samples by parsing block headers, needed when multiple files are stitched together.
|
||||
* Some EA files (.mus/eam/sng/etc) concat many small subfiles, used for interactive/mapped
|
||||
* music (.map/lin). Subfiles always share header, except num_samples. */
|
||||
static int get_ea_stream_total_samples(STREAMFILE* streamFile, off_t start_offset, VGMSTREAM* vgmstream) {
|
||||
int num_samples = 0;
|
||||
int multiple_schl = 0;
|
||||
|
||||
/* calc num_samples as playable data size varies between files/blocks */
|
||||
{
|
||||
vgmstream->next_block_offset = start_offset;
|
||||
do {
|
||||
uint32_t block_id = read_32bitBE(vgmstream->next_block_offset + 0x00, streamFile);
|
||||
if (block_id == EA_BLOCKID_HEADER) /* "SCHl" start block (movie "SHxx" shouldn't use multi files) */
|
||||
multiple_schl = 1;
|
||||
|
||||
block_update_ea_schl(vgmstream->next_block_offset, vgmstream);
|
||||
num_samples += vgmstream->current_block_samples;
|
||||
} while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
|
||||
|
||||
/* reset after getting samples */
|
||||
block_update(start_offset, vgmstream);
|
||||
/* Stream size is almost never provided in bank files so we have to calc it manually */
|
||||
if (vgmstream->current_block_samples != 0) {
|
||||
stream_size += vgmstream->next_block_offset - vgmstream->current_block_offset - 0x0c;
|
||||
}
|
||||
}
|
||||
|
||||
/* reset once we're done */
|
||||
block_update(start_offset, vgmstream);
|
||||
|
||||
/* only use calculated samples with multiple subfiles (rarely header samples may be less due to padding) */
|
||||
if (multiple_schl) {
|
||||
; VGM_LOG("EA SCHl: multiple SCHl found\n");
|
||||
return num_samples;
|
||||
} else {
|
||||
return 0;
|
||||
if (standalone && multiple_schl) {
|
||||
VGM_LOG("EA SCHl: multiple SCHl found\n");
|
||||
if (num_samples > vgmstream->num_samples) {
|
||||
vgmstream->num_samples = num_samples;
|
||||
}
|
||||
}
|
||||
|
||||
vgmstream->stream_size = stream_size;
|
||||
}
|
||||
|
||||
/* find data start offset inside the first SCDl; not very elegant but oh well */
|
||||
|
Loading…
x
Reference in New Issue
Block a user