mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-08 07:18:17 +01:00
EA Harmony: Fixed dset handling, added stream name for clarity
This commit is contained in:
parent
c7c21dfd81
commit
7a9aa6c857
@ -773,36 +773,36 @@ fail:
|
|||||||
|
|
||||||
/* EA Harmony Sample Bank - used in 8th gen EA Sports games */
|
/* EA Harmony Sample Bank - used in 8th gen EA Sports games */
|
||||||
VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
||||||
uint32_t num_dsets, set_sounds, chunk_id;
|
uint32_t num_dsets, set_sounds, chunk_id, data_offset, table_offset, dset_offset, base_offset, sound_table_offset, sound_offset;
|
||||||
uint32_t i;
|
uint32_t i, j;
|
||||||
uint8_t set_type, flag, offset_size;
|
uint8_t set_type, flag, offset_size;
|
||||||
off_t data_offset, table_offset, dset_offset, base_offset, sound_table_offset, sound_offset;
|
char sound_name[STREAM_NAME_SIZE];
|
||||||
STREAMFILE *sbsFile = NULL, *streamData = NULL;
|
STREAMFILE *sbsFile = NULL, *streamData = NULL;
|
||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
int target_stream = streamFile->stream_index, total_sounds, local_target, is_streamed = 0;
|
int target_stream = streamFile->stream_index, total_sounds, local_target, is_streamed = 0;
|
||||||
int32_t(*read_32bit)(off_t, STREAMFILE*);
|
uint32_t(*read_u32)(off_t, STREAMFILE*);
|
||||||
int16_t(*read_16bit)(off_t, STREAMFILE*);
|
uint16_t(*read_u16)(off_t, STREAMFILE*);
|
||||||
|
|
||||||
if (!check_extensions(streamFile, "sbr"))
|
if (!check_extensions(streamFile, "sbr"))
|
||||||
goto fail;
|
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
|
/* 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. */
|
* only used on 8th gen systems so far so big endian version probably doesn't exist. */
|
||||||
|
if (read_32bitBE(0x00, streamFile) == 0x53426C65) { /* "SBle" */
|
||||||
|
read_u32 = read_u32le;
|
||||||
|
read_u16 = read_u16le;
|
||||||
#if 0
|
#if 0
|
||||||
} else if (read_32bitBE(0x00, streamFile) == 0x53426265) { /* "SBbe" */
|
} else if (read_32bitBE(0x00, streamFile) == 0x53426265) { /* "SBbe" */
|
||||||
read_32bit = read_32bitBE;
|
read_32bit = read_u32be;
|
||||||
read_16bit = read_16bitBE;
|
read_16bit = read_u16be;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_dsets = read_16bit(0x0a, streamFile);
|
num_dsets = read_u16(0x0a, streamFile);
|
||||||
data_offset = read_32bit(0x20, streamFile);
|
data_offset = read_u32(0x20, streamFile);
|
||||||
table_offset = read_32bit(0x24, streamFile);
|
table_offset = read_u32(0x24, streamFile);
|
||||||
|
|
||||||
if (target_stream == 0) target_stream = 1;
|
if (target_stream == 0) target_stream = 1;
|
||||||
if (target_stream < 0)
|
if (target_stream < 0)
|
||||||
@ -814,23 +814,24 @@ VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
|||||||
/* The bank is split into DSET sections each of which references one or multiple sounds. */
|
/* 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). */
|
/* 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++) {
|
for (i = 0; i < num_dsets; i++) {
|
||||||
dset_offset = read_32bit(table_offset + 0x08 * i, streamFile);
|
dset_offset = read_u32(table_offset + 0x08 * i, streamFile);
|
||||||
if (read_32bit(dset_offset, streamFile) != 0x44534554) /* "DSET" */
|
if (read_u32(dset_offset, streamFile) != 0x44534554) /* "DSET" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
set_sounds = read_32bit(dset_offset + 0x38, streamFile);
|
set_sounds = read_u32(dset_offset + 0x38, streamFile);
|
||||||
local_target = target_stream - total_sounds - 1;
|
local_target = target_stream - total_sounds - 1;
|
||||||
dset_offset += 0x48;
|
dset_offset += 0x48;
|
||||||
|
|
||||||
/* Find RAM or OFF chunk */
|
/* Find RAM or OFF chunk */
|
||||||
while(1) {
|
while(1) {
|
||||||
chunk_id = read_32bit(dset_offset, streamFile);
|
chunk_id = read_u32(dset_offset, streamFile);
|
||||||
if (chunk_id == 0x2E52414D) { /* ".RAM" */
|
if (chunk_id == 0x2E52414D) { /* ".RAM" */
|
||||||
break;
|
break;
|
||||||
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
|
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
|
||||||
break;
|
break;
|
||||||
} else if (chunk_id == 0x2E4C4452 || /* ".LDR" */
|
} else if (chunk_id == 0x2E4C4452 || /* ".LDR" */
|
||||||
chunk_id == 0x2E4F424A || /* ".OBJ" */
|
chunk_id == 0x2E4F424A || /* ".OBJ" */
|
||||||
|
chunk_id == 0x2E445552 || /* ".DUR" */
|
||||||
(chunk_id & 0xFF00FFFF) == 0x2E00534C) { /* ".?SL */
|
(chunk_id & 0xFF00FFFF) == 0x2E00534C) { /* ".?SL */
|
||||||
dset_offset += 0x18;
|
dset_offset += 0x18;
|
||||||
} else {
|
} else {
|
||||||
@ -839,59 +840,76 @@ VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Different set types store offsets differently */
|
/* Different set types store offsets differently */
|
||||||
set_type = read_8bit(dset_offset + 0x05, streamFile);
|
set_type = read_u8(dset_offset + 0x05, streamFile);
|
||||||
|
|
||||||
if (set_type == 0x00) {
|
if (set_type == 0x00) {
|
||||||
total_sounds++;
|
total_sounds++;
|
||||||
if (local_target < 0 || local_target > 0)
|
if (local_target < 0 || local_target > 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sound_offset = read_32bit(dset_offset + 0x08, streamFile);
|
sound_offset = read_u32(dset_offset + 0x08, streamFile);
|
||||||
} else if (set_type == 0x01) {
|
} else if (set_type == 0x01) {
|
||||||
total_sounds += 2;
|
total_sounds += 2;
|
||||||
if (local_target < 0 || local_target > 1)
|
if (local_target < 0 || local_target > 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
base_offset = read_32bit(dset_offset + 0x08, streamFile);
|
base_offset = read_u32(dset_offset + 0x08, streamFile);
|
||||||
|
|
||||||
if (local_target == 0) {
|
if (local_target == 0) {
|
||||||
sound_offset = base_offset;
|
sound_offset = base_offset;
|
||||||
} else {
|
} else {
|
||||||
sound_offset = base_offset + (uint16_t)read_16bit(dset_offset + 0x06, streamFile);
|
sound_offset = base_offset + read_u16(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;
|
|
||||||
}
|
}
|
||||||
|
} else if (set_type == 0x02) {
|
||||||
|
flag = read_u8(dset_offset + 0x06, streamFile);
|
||||||
|
offset_size = read_u8(dset_offset + 0x07, streamFile);
|
||||||
|
base_offset = read_u32(dset_offset + 0x08, streamFile);
|
||||||
|
sound_table_offset = read_u32(dset_offset + 0x10, streamFile);
|
||||||
|
|
||||||
total_sounds += set_sounds;
|
total_sounds += set_sounds;
|
||||||
if (local_target < 0 || local_target >= set_sounds)
|
if (local_target < 0 || local_target >= set_sounds)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (offset_size == 0x02) {
|
if (offset_size == 0x01) {
|
||||||
sound_offset = (uint16_t)read_16bit(sound_table_offset + 0x02 * local_target, streamFile);
|
sound_offset = read_u8(sound_table_offset + 0x01 * local_target, streamFile);
|
||||||
if (flag != 0x00) sound_offset *= (off_t)pow(2, flag);
|
for (j = 0; j < flag; j++) sound_offset *= 2;
|
||||||
sound_offset += base_offset;
|
} else if (offset_size == 0x02) {
|
||||||
|
sound_offset = read_u16(sound_table_offset + 0x02 * local_target, streamFile);
|
||||||
|
for (j = 0; j < flag; j++) sound_offset *= 2;
|
||||||
} else if (offset_size == 0x04) {
|
} else if (offset_size == 0x04) {
|
||||||
sound_offset = read_32bit(sound_table_offset + 0x04 * local_target, streamFile);
|
sound_offset = read_u32(sound_table_offset + 0x04 * local_target, streamFile);
|
||||||
if (flag == 0x00) sound_offset += base_offset;
|
}
|
||||||
|
|
||||||
|
sound_offset += base_offset;
|
||||||
|
} else if (set_type == 0x03) {
|
||||||
|
offset_size = read_u8(dset_offset + 0x07, streamFile);
|
||||||
|
set_sounds = read_u32(dset_offset + 0x08, streamFile);
|
||||||
|
sound_table_offset = read_u32(dset_offset + 0x10, streamFile);
|
||||||
|
|
||||||
|
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, streamFile);
|
||||||
|
} else if (offset_size == 0x02) {
|
||||||
|
sound_offset = read_u16(sound_table_offset + 0x02 * local_target, streamFile);
|
||||||
|
} else if (offset_size == 0x04) {
|
||||||
|
sound_offset = read_u32(sound_table_offset + 0x04 * local_target, streamFile);
|
||||||
}
|
}
|
||||||
} else if (set_type == 0x04) {
|
} else if (set_type == 0x04) {
|
||||||
total_sounds += set_sounds;
|
total_sounds += set_sounds;
|
||||||
if (local_target < 0 || local_target >= set_sounds)
|
if (local_target < 0 || local_target >= set_sounds)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sound_table_offset = read_32bit(dset_offset + 0x10, streamFile);
|
sound_table_offset = read_u32(dset_offset + 0x10, streamFile);
|
||||||
sound_offset = read_32bit(sound_table_offset + 0x08 * local_target, streamFile);
|
sound_offset = read_u32(sound_table_offset + 0x08 * local_target, streamFile);
|
||||||
} else {
|
} else {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snprintf(sound_name, STREAM_NAME_SIZE, "DSET %02d/%04d", i, local_target);
|
||||||
|
|
||||||
if (chunk_id == 0x2E52414D) { /* ".RAM" */
|
if (chunk_id == 0x2E52414D) { /* ".RAM" */
|
||||||
is_streamed = 0;
|
is_streamed = 0;
|
||||||
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
|
} else if (chunk_id == 0x2E4F4646) { /* ".OFF" */
|
||||||
@ -931,6 +949,7 @@ VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
vgmstream->num_streams = total_sounds;
|
vgmstream->num_streams = total_sounds;
|
||||||
|
strncpy(vgmstream->stream_name, sound_name, STREAM_NAME_SIZE);
|
||||||
close_streamfile(sbsFile);
|
close_streamfile(sbsFile);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user