mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-19 00:04:04 +01:00
Improved EA Harmony bank support
This commit is contained in:
parent
0ad117e874
commit
52ceaef200
@ -809,10 +809,11 @@ fail:
|
||||
|
||||
/* EA Harmony Sample Bank - used in 8th gen EA Sports games */
|
||||
VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
uint64_t set_sounds, base_offset, sound_offset;
|
||||
uint32_t chunk_id, data_offset, table_offset, dset_offset, sound_table_offset;
|
||||
uint64_t base_offset, sound_offset, offset, prev_offset;
|
||||
uint32_t chunk_id, data_offset, table_offset, dset_offset, set_values, set_sounds, sound_table_offset;
|
||||
int32_t flag;
|
||||
uint16_t num_dsets;
|
||||
uint8_t set_type, flag, offset_size;
|
||||
uint8_t set_type, offset_size;
|
||||
uint32_t i, j;
|
||||
char sound_name[STREAM_NAME_SIZE];
|
||||
STREAMFILE *sf_sbs = NULL, *sf_data = NULL;
|
||||
@ -826,11 +827,11 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
goto fail;
|
||||
|
||||
/* check header */
|
||||
if (read_u32be(0x00, sf) == 0x53426C65) { /* "SBle" */
|
||||
if (is_id32be(0x00, sf, "SBle")) {
|
||||
read_u64 = read_u64le;
|
||||
read_u32 = read_u32le;
|
||||
read_u16 = read_u16le;
|
||||
} else if (read_u32be(0x00, sf) == 0x53426265) { /* "SBbe" */
|
||||
} else if (is_id32be(0x00, sf, "SBbe")) {
|
||||
read_u64 = read_u64be;
|
||||
read_u32 = read_u32be;
|
||||
read_u16 = read_u16be;
|
||||
@ -839,8 +840,8 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
}
|
||||
|
||||
num_dsets = read_u16(0x0a, sf);
|
||||
table_offset = read_u32(0x18, sf);
|
||||
data_offset = read_u32(0x20, sf);
|
||||
table_offset = read_u32(0x24, sf);
|
||||
|
||||
if (target_stream == 0) target_stream = 1;
|
||||
if (target_stream < 0)
|
||||
@ -849,14 +850,14 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
total_sounds = 0;
|
||||
sound_offset = 0;
|
||||
|
||||
/* 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). */
|
||||
/* 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_u32(table_offset + 0x08 * i, sf);
|
||||
if (read_u32(dset_offset, sf) != 0x44534554) /* "DSET" */
|
||||
goto fail;
|
||||
|
||||
set_sounds = read_u32(dset_offset + 0x38, sf);
|
||||
set_values = read_u32(dset_offset + 0x38, sf);
|
||||
local_target = target_stream - total_sounds - 1;
|
||||
dset_offset += 0x48;
|
||||
|
||||
@ -877,50 +878,60 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Different set types store offsets differently */
|
||||
/* different set types store offsets differently */
|
||||
set_type = read_u8(dset_offset + 0x05, sf);
|
||||
|
||||
/* data sets often contain duplicate offets, need to filter them out however we can */
|
||||
/* offsets are stored in ascending order which makes things easier */
|
||||
if (set_type == 0x00) {
|
||||
total_sounds++;
|
||||
set_sounds = 1;
|
||||
total_sounds += set_sounds;
|
||||
if (local_target < 0 || local_target > 0)
|
||||
continue;
|
||||
|
||||
sound_offset = read_u64(dset_offset + 0x08, sf);
|
||||
} else if (set_type == 0x01) {
|
||||
total_sounds += 2;
|
||||
if (local_target < 0 || local_target > 1)
|
||||
continue;
|
||||
|
||||
flag = (int16_t)read_u16(dset_offset + 0x06, sf);
|
||||
base_offset = read_u64(dset_offset + 0x08, sf);
|
||||
|
||||
if (local_target == 0) {
|
||||
sound_offset = base_offset;
|
||||
} else {
|
||||
sound_offset = base_offset + read_u16(dset_offset + 0x06, sf);
|
||||
}
|
||||
set_sounds = set_values;
|
||||
total_sounds += set_sounds;
|
||||
if (local_target < 0 || local_target >= set_sounds)
|
||||
continue;
|
||||
|
||||
sound_offset = base_offset + flag * local_target;
|
||||
} else if (set_type == 0x02) {
|
||||
flag = (read_u16(dset_offset + 0x06, sf) >> 0) & 0xFF;
|
||||
offset_size = (read_u16(dset_offset + 0x06, sf) >> 8) & 0xFF;
|
||||
base_offset = read_u64(dset_offset + 0x08, sf);
|
||||
sound_table_offset = read_u32(dset_offset + 0x10, sf);
|
||||
|
||||
set_sounds = 0;
|
||||
prev_offset = UINT64_MAX;
|
||||
for (j = 0; j < set_values; j++) {
|
||||
if (offset_size == 0x01) {
|
||||
offset = read_u8(sound_table_offset + 0x01 * j, sf);
|
||||
} else if (offset_size == 0x02) {
|
||||
offset = read_u16(sound_table_offset + 0x02 * j, sf);
|
||||
} else if (offset_size == 0x04) {
|
||||
offset = read_u32(sound_table_offset + 0x04 * j, sf);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
offset <<= flag;
|
||||
offset += base_offset;
|
||||
|
||||
if (offset != prev_offset) {
|
||||
if (set_sounds == local_target)
|
||||
sound_offset = offset;
|
||||
set_sounds++;
|
||||
}
|
||||
prev_offset = offset;
|
||||
}
|
||||
|
||||
total_sounds += set_sounds;
|
||||
if (local_target < 0 || local_target >= set_sounds)
|
||||
continue;
|
||||
|
||||
if (offset_size == 0x01) {
|
||||
sound_offset = read_u8(sound_table_offset + 0x01 * local_target, sf);
|
||||
for (j = 0; j < flag; j++) sound_offset *= 2;
|
||||
} else if (offset_size == 0x02) {
|
||||
sound_offset = read_u16(sound_table_offset + 0x02 * local_target, sf);
|
||||
for (j = 0; j < flag; j++) sound_offset *= 2;
|
||||
} else if (offset_size == 0x04) {
|
||||
sound_offset = read_u32(sound_table_offset + 0x04 * local_target, sf);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sound_offset += base_offset;
|
||||
} else if (set_type == 0x03) {
|
||||
offset_size = (read_u16(dset_offset + 0x06, sf) >> 8) & 0xFF;
|
||||
set_sounds = read_u64(dset_offset + 0x08, sf);
|
||||
@ -940,12 +951,24 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
goto fail;
|
||||
}
|
||||
} else if (set_type == 0x04) {
|
||||
sound_table_offset = read_u32(dset_offset + 0x10, sf);
|
||||
|
||||
set_sounds = 0;
|
||||
prev_offset = UINT64_MAX;
|
||||
for (j = 0; j < set_values; j++) {
|
||||
offset = read_u64(sound_table_offset + 0x08 * j, sf);
|
||||
|
||||
if (sound_offset != prev_offset) {
|
||||
if (set_sounds == local_target)
|
||||
sound_offset = offset;
|
||||
set_sounds++;
|
||||
}
|
||||
prev_offset = offset;
|
||||
}
|
||||
|
||||
total_sounds += set_sounds;
|
||||
if (local_target < 0 || local_target >= set_sounds)
|
||||
continue;
|
||||
|
||||
sound_table_offset = read_u32(dset_offset + 0x10, sf);
|
||||
sound_offset = read_u32(sound_table_offset + 0x08 * local_target, sf);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
@ -964,8 +987,8 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
|
||||
if (!is_streamed) {
|
||||
/* RAM asset */
|
||||
if (read_u32be(data_offset, sf) != 0x64617461 && /* "data" */
|
||||
read_u32be(data_offset, sf) != 0x44415441) /* "DATA" */
|
||||
if (!is_id32be(data_offset, sf, "data") &&
|
||||
!is_id32be(data_offset, sf, "DATA"))
|
||||
goto fail;
|
||||
|
||||
sf_data = sf;
|
||||
@ -976,13 +999,13 @@ VGMSTREAM* init_vgmstream_ea_sbr_harmony(STREAMFILE* sf) {
|
||||
if (!sf_sbs)
|
||||
goto fail;
|
||||
|
||||
if (read_u32be(0x00, sf_sbs) != 0x64617461 && /* "data" */
|
||||
read_u32be(0x00, sf_sbs) != 0x44415441) /* "DATA" */
|
||||
if (!is_id32be(0x00, sf_sbs, "data") &&
|
||||
!is_id32be(0x00, sf_sbs, "DATA"))
|
||||
goto fail;
|
||||
|
||||
sf_data = sf_sbs;
|
||||
|
||||
if (read_u32be(sound_offset, sf_data) == 0x736C6F74) {
|
||||
if (is_id32be(sound_offset, sf_data, "slot")) {
|
||||
/* skip "slot" section */
|
||||
sound_offset += 0x30;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user