Merge pull request #352 from NicknineTheEagle/ea-sbr

Ea sbr
This commit is contained in:
Christopher Snowhill 2019-01-14 18:04:58 -08:00 committed by GitHub
commit c6280d85b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 283 additions and 22 deletions

View File

@ -349,6 +349,7 @@ static const char* extension_list[] = {
"sb5",
"sb6",
"sb7",
"sbr",
"sm0",
"sm1",
"sm2",

View File

@ -134,7 +134,7 @@ fail:
}
/* EA ABK - ABK header seems to be same as in the old games but the sound table is different and it contains SNR/SNS sounds instead */
VGMSTREAM * init_vgmstream_ea_abk_new(STREAMFILE *streamFile) {
VGMSTREAM * init_vgmstream_ea_abk_eaac(STREAMFILE *streamFile) {
int is_dupe, total_sounds = 0, target_stream = streamFile->stream_index;
off_t bnk_offset, header_table_offset, base_offset, unk_struct_offset, table_offset, snd_entry_offset, ast_offset;
off_t num_entries_off, base_offset_off, entries_off, sound_table_offset_off;
@ -314,7 +314,90 @@ fail:
return NULL;
}
/* EA HDR/STH/DAT - seen in early 7th-gen games, used for storing speech */
/* EA SBR/SBS - used in older 7th gen games for storing SFX */
VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
uint32_t num_sounds, type_desc;
uint16_t num_metas, meta_type;
uint32_t i;
off_t table_offset, types_offset, entry_offset, metas_offset, data_offset, snr_offset, sns_offset;
STREAMFILE *sbsFile = NULL, *streamData = NULL;
VGMSTREAM *vgmstream = NULL;
int target_stream = streamFile->stream_index;
if (!check_extensions(streamFile, "sbr"))
goto fail;
if (read_32bitBE(0x00, streamFile) != 0x53424B52) /* "SBKR" */
goto fail;
/* SBR files are always big endian */
num_sounds = read_32bitBE(0x1c, streamFile);
table_offset = read_32bitBE(0x24, streamFile);
types_offset = read_32bitBE(0x28, streamFile);
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || num_sounds == 0 || target_stream > num_sounds)
goto fail;
entry_offset = table_offset + 0x0a * (target_stream - 1);
num_metas = read_16bitBE(entry_offset + 0x04, streamFile);
metas_offset = read_32bitBE(entry_offset + 0x06, streamFile);
snr_offset = 0xFFFFFFFF;
sns_offset = 0xFFFFFFFF;
for (i = 0; i < num_metas; i++) {
entry_offset = metas_offset + 0x06 * i;
meta_type = read_16bitBE(entry_offset, streamFile);
data_offset = read_32bitBE(entry_offset + 0x02, streamFile);
type_desc = read_32bitBE(types_offset + 0x06 * meta_type, streamFile);
switch (type_desc) {
case 0x534E5231: /* "SNR1" */
snr_offset = data_offset;
break;
case 0x534E5331: /* "SNS1" */
sns_offset = read_32bitBE(data_offset, streamFile);
break;
default:
break;
}
}
if (snr_offset == 0xFFFFFFFF)
goto fail;
if (sns_offset == 0xFFFFFFFF) {
/* RAM asset */
streamData = streamFile;
sns_offset = snr_offset + get_snr_size(streamFile, snr_offset);
} else {
/* streamed asset */
sbsFile = open_streamfile_by_ext(streamFile, "sbs");
if (!sbsFile)
goto fail;
if (read_32bitBE(0x00, sbsFile) != 0x53424B53) /* "SBKS" */
goto fail;
streamData = sbsFile;
}
vgmstream = init_vgmstream_eaaudiocore_header(streamFile, streamData, snr_offset, sns_offset, meta_EA_SNR_SNS);
if (!vgmstream)
goto fail;
vgmstream->num_streams = num_sounds;
close_streamfile(sbsFile);
return vgmstream;
fail:
close_streamfile(sbsFile);
return NULL;
}
/* EA HDR/STH/DAT - seen in older 7th gen games, used for storing speech */
VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
int target_stream = streamFile->stream_index;
uint32_t i;
@ -372,7 +455,7 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
sns_offset = 0;
for (i = 0; i < total_sounds; i++) {
snr_offset = (off_t)read_16bitBE(0x10 + (0x02+userdata_size) * i, streamFile) + 0x04;
snr_offset = (uint16_t)read_16bitBE(0x10 + (0x02+userdata_size) * i, streamFile) + 0x04;
if (i == target_stream - 1)
break;
@ -416,7 +499,7 @@ fail:
}
/* EA MPF/MUS combo - used in older 7th gen games for storing music */
VGMSTREAM * init_vgmstream_ea_mpf_mus_new(STREAMFILE *streamFile) {
VGMSTREAM * init_vgmstream_ea_mpf_mus_eaac(STREAMFILE *streamFile) {
uint32_t num_sounds;
uint8_t version, sub_version, block_id;
off_t table_offset, entry_offset, snr_offset, sns_offset;
@ -491,6 +574,179 @@ fail:
return NULL;
}
/* EA Harmony Sample Bank - used in 8th gen EA Sports games */
VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
uint32_t num_dsets, set_sounds, chunk_id;
uint32_t i;
uint8_t set_type, flag, offset_size;
off_t data_offset, table_offset, dset_offset, base_offset, sound_table_offset, sound_offset, header_offset, start_offset;
STREAMFILE *sbsFile = NULL, *streamData = NULL;
VGMSTREAM *vgmstream = NULL;
int target_stream = streamFile->stream_index, total_sounds, local_target, is_streamed;
int32_t(*read_32bit)(off_t, STREAMFILE*);
int16_t(*read_16bit)(off_t, STREAMFILE*);
if (!check_extensions(streamFile, "sbr"))
goto fail;
if (read_32bitBE(0x00, streamFile) == 0x53426C65) { /* "SBle" */
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
/* Logically, big endian version starts with SBbe. However, this format is
* only used on 8th gen systems so far so big endian version probably doesn't exist. */
#if 0
} else if (read_32bitBE(0x00, streamFile) == 0x53426265) { /* "SBbe" */
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
#endif
} else {
goto fail;
}
num_dsets = read_16bit(0x0a, streamFile);
data_offset = read_32bit(0x20, streamFile);
table_offset = read_32bit(0x24, streamFile);
if (target_stream == 0) target_stream = 1;
if (target_stream < 0)
goto fail;
total_sounds = 0;
sound_offset = 0xFFFFFFFF;
/* The bank is split into DSET sections each of which references one or multiple sounds. */
/* Each set can contain RAM sounds (stored in SBR in data section) or streamed sounds (stored separately in SBS file). */
for (i = 0; i < num_dsets; i++) {
dset_offset = read_32bit(table_offset + 0x08 * i, streamFile);
if (read_32bit(dset_offset, streamFile) != 0x44534554) /* "DSET" */
goto fail;
set_sounds = read_32bit(dset_offset + 0x38, streamFile);
local_target = target_stream - total_sounds - 1;
dset_offset += 0x48;
/* Find RAM or OFF chunk */
while(1) {
chunk_id = read_32bit(dset_offset, streamFile);
if (chunk_id == 0x2E52414D) { /* ".RAM" */
break;
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
break;
} else if (chunk_id == 0x2E4C4452 || /* ".LDR" */
chunk_id == 0x2E4F424A || /* ".OBJ" */
(chunk_id & 0xFF00FFFF) == 0x2E00534C) { /* ".?SL */
dset_offset += 0x18;
} else {
goto fail;
}
}
/* Different set types store offsets differently */
set_type = read_8bit(dset_offset + 0x05, streamFile);
if (set_type == 0x00) {
total_sounds++;
if (local_target < 0 || local_target > 0)
continue;
sound_offset = read_32bit(dset_offset + 0x08, streamFile);
} else if (set_type == 0x01) {
total_sounds += 2;
if (local_target < 0 || local_target > 1)
continue;
base_offset = read_32bit(dset_offset + 0x08, streamFile);
if (local_target == 0) {
sound_offset = base_offset;
} else {
sound_offset = base_offset + (uint16_t)read_16bit(dset_offset + 0x06, streamFile);
}
} else if (set_type == 0x02 || set_type == 0x03) {
flag = read_8bit(dset_offset + 0x06, streamFile);
offset_size = read_8bit(dset_offset + 0x07, streamFile);
base_offset = read_32bit(dset_offset + 0x08, streamFile);
sound_table_offset = read_32bit(dset_offset + 0x10, streamFile);
if (offset_size == 0x04 && flag != 0x00) {
set_sounds = base_offset;
}
total_sounds += set_sounds;
if (local_target < 0 || local_target >= set_sounds)
continue;
if (offset_size == 0x02) {
sound_offset = (uint16_t)read_16bit(sound_table_offset + 0x02 * local_target, streamFile);
if (flag != 0x00) sound_offset *= (off_t)pow(2, flag);
sound_offset += base_offset;
} else if (offset_size == 0x04) {
sound_offset = read_32bit(sound_table_offset + 0x04 * local_target, streamFile);
if (flag == 0x00) sound_offset += base_offset;
}
} else if (set_type == 0x04) {
total_sounds += set_sounds;
if (local_target < 0 || local_target >= set_sounds)
continue;
sound_table_offset = read_32bit(dset_offset + 0x10, streamFile);
sound_offset = read_32bit(sound_table_offset + 0x08 * local_target, streamFile);
} else {
goto fail;
}
if (chunk_id == 0x2E52414D) { /* ".RAM" */
is_streamed = 0;
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
is_streamed = 1;
}
}
if (sound_offset == 0xFFFFFFFF)
goto fail;
if (!is_streamed) {
/* RAM asset */
if (read_32bitBE(data_offset, streamFile) != 0x64617461) /* "data" */
goto fail;
streamData = streamFile;
sound_offset += data_offset;
} else {
/* streamed asset */
sbsFile = open_streamfile_by_ext(streamFile, "sbs");
if (!sbsFile)
goto fail;
if (read_32bitBE(0x00, sbsFile) != 0x64617461) /* "data" */
goto fail;
streamData = sbsFile;
if (read_32bitBE(sound_offset, streamData) == 0x736C6F74) {
/* skip "slot" section */
sound_offset += 0x30;
}
}
if (read_8bit(sound_offset, streamData) != EAAC_BLOCKID1_HEADER)
goto fail;
header_offset = sound_offset + 0x04;
start_offset = sound_offset + (read_32bitBE(sound_offset, streamData) & 0x00FFFFFF);
vgmstream = init_vgmstream_eaaudiocore_header(streamData, streamData, header_offset, start_offset, meta_EA_SNR_SNS);
if (!vgmstream)
goto fail;
vgmstream->num_streams = total_sounds;
close_streamfile(sbsFile);
return vgmstream;
fail:
close_streamfile(sbsFile);
return NULL;
}
/* ************************************************************************* */
typedef struct {

View File

@ -358,14 +358,14 @@ VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
userdata_size = read_8bit(0x04, streamFile) & 0x0F;
total_sounds = read_8bit(0x05, streamFile);
offset_mult = (off_t)read_8bit(0x07, streamFile) * 0x0100 + 0x0100;
offset_mult = (uint8_t)read_8bit(0x07, streamFile) * 0x0100 + 0x0100;
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || total_sounds == 0 || target_stream > total_sounds)
goto fail;
/* offsets are always big endian */
schl_offset = (off_t)read_16bitBE(0x0C + (0x02+userdata_size) * (target_stream-1), streamFile) * offset_mult;
schl_offset = (uint16_t)read_16bitBE(0x0C + (0x02+userdata_size) * (target_stream-1), streamFile) * offset_mult;
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
goto fail;
@ -555,7 +555,7 @@ VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE *streamFile) {
/* get the last entry offset */
section_offset = 0x24;
entry_offset = read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
entry_offset = (uint16_t)read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
subentry_num = read_8bit(entry_offset + 0x0b, streamFile);
section_offset = entry_offset + 0x0c + subentry_num * 0x04;
@ -577,7 +577,7 @@ VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE *streamFile) {
/* get the last entry offset */
section_offset = 0x24;
entry_offset = read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
entry_offset = (uint16_t)read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
if (big_endian) {
subentry_num = (read_32bitBE(entry_offset + 0x04, streamFile) >> 19) & 0xFF;
} else {
@ -601,7 +601,7 @@ VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE *streamFile) {
/* get the last entry offset */
section_offset = 0x20;
entry_offset = read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
entry_offset = (uint16_t)read_16bit(section_offset + (sec1_num - 1) * 0x02, streamFile) * 0x04;
if (big_endian) {
subentry_num = (read_32bitBE(entry_offset + 0x04, streamFile) >> 15) & 0xFF;
} else {
@ -609,7 +609,7 @@ VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE *streamFile) {
}
section_offset = entry_offset + 0x10 + subentry_num * 0x04;
entry_offset = read_16bit(section_offset + (sec2_num - 1) * 0x02, streamFile) * 0x04;
entry_offset = (uint16_t)read_16bit(section_offset + (sec2_num - 1) * 0x02, streamFile) * 0x04;
if (big_endian) {
subentry_num = (read_32bitBE(entry_offset + 0x0c, streamFile) >> 10) & 0xFF;
} else {
@ -1423,15 +1423,15 @@ static void update_ea_stream_size_and_samples(STREAMFILE* streamFile, off_t star
multiple_schl = 1;
}
/* 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;
if (vgmstream->current_block_samples > 0) {
/* 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 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;
/* Stream size is almost never provided in bank files so we have to calc it manually */
stream_size += vgmstream->next_block_offset - vgmstream->ch[0].offset;
}
}

View File

@ -678,9 +678,11 @@ VGMSTREAM * init_vgmstream_vxn(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_snu(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_snr_sns(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_sps(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_abk_new(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_abk_eaac(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_mpf_mus_new(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_mpf_mus_eaac(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_ngc_vid1(STREAMFILE * streamFile);

View File

@ -375,9 +375,11 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_vxn,
init_vgmstream_ea_snr_sns,
init_vgmstream_ea_sps,
init_vgmstream_ea_abk_new,
init_vgmstream_ea_abk_eaac,
init_vgmstream_ea_hdr_sth_dat,
init_vgmstream_ea_mpf_mus_new,
init_vgmstream_ea_mpf_mus_eaac,
init_vgmstream_ea_sbr,
init_vgmstream_ea_sbr_harmony,
init_vgmstream_ngc_vid1,
init_vgmstream_flx,
init_vgmstream_mogg,