EA TMX: Use setup_subfile_streamfile for GIN sounds

This commit is contained in:
NicknineTheEagle 2020-11-15 03:40:16 +03:00
parent da1ef3eb16
commit df6212d5e7
2 changed files with 17 additions and 21 deletions

View File

@ -36,7 +36,6 @@
static VGMSTREAM * init_vgmstream_eaaudiocore_header(STREAMFILE* sf_head, STREAMFILE* sf_data, off_t header_offset, off_t start_offset, meta_t meta_type, int standalone);
static VGMSTREAM *parse_s10a_header(STREAMFILE* sf, off_t offset, uint16_t target_index, off_t ast_offset);
VGMSTREAM * init_vgmstream_gin_header(STREAMFILE* sf, off_t offset);
/* .SNR+SNS - from EA latest games (~2005-2010), v0 header */
@ -741,6 +740,7 @@ fail:
VGMSTREAM * init_vgmstream_ea_tmx(STREAMFILE* sf) {
uint32_t num_sounds, sound_type, table_offset, data_offset, entry_offset, sound_offset;
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_sf = NULL;
int target_stream = sf->stream_index;
uint32_t(*read_u32)(off_t, STREAMFILE *);
@ -769,8 +769,12 @@ VGMSTREAM * init_vgmstream_ea_tmx(STREAMFILE* sf) {
switch (sound_type) {
case 0x47494E20: /* "GIN " */
vgmstream = init_vgmstream_gin_header(sf, sound_offset);
temp_sf = setup_subfile_streamfile(sf, sound_offset, get_streamfile_size(sf) - sound_offset, "gin");
if (!temp_sf) goto fail;
vgmstream = init_vgmstream_gin(temp_sf);
if (!vgmstream) goto fail;
close_streamfile(temp_sf);
break;
case 0x534E5220: /* "SNR " */
vgmstream = init_vgmstream_eaaudiocore_header(sf, NULL, sound_offset, 0x00, meta_EA_SNR_SNS, 0);
@ -784,6 +788,7 @@ VGMSTREAM * init_vgmstream_ea_tmx(STREAMFILE* sf) {
return vgmstream;
fail:
close_streamfile(temp_sf);
return NULL;
}

View File

@ -1,26 +1,17 @@
#include "meta.h"
#include "../coding/coding.h"
VGMSTREAM * init_vgmstream_gin_header(STREAMFILE *streamFile, off_t offset);
/* .gin - EA engine sounds [Need for Speed: Most Wanted (multi)] */
VGMSTREAM * init_vgmstream_gin(STREAMFILE *streamFile) {
if (!check_extensions(streamFile, "gin"))
goto fail;
return init_vgmstream_gin_header(streamFile, 0x00);
fail:
return NULL;
}
VGMSTREAM * init_vgmstream_gin_header(STREAMFILE *streamFile, off_t offset) {
VGMSTREAM * vgmstream = NULL;
VGMSTREAM *vgmstream = NULL;
off_t start_offset;
int loop_flag, channel_count, sample_rate, num_samples;
if (!check_extensions(streamFile, "gin"))
goto fail;
/* checks */
if (read_32bitBE(offset + 0x00, streamFile) != 0x476E7375) /* "Gnsu" */
if (read_32bitBE(0x00, streamFile) != 0x476E7375) /* "Gnsu" */
goto fail;
/* contains mapped values for engine RPM sounds but we'll just play the whole thing */
@ -30,11 +21,11 @@ VGMSTREAM * init_vgmstream_gin_header(STREAMFILE *streamFile, off_t offset) {
/* 0x14: RPM ??? table size */
/* always LE even on X360/PS3 */
num_samples = read_32bitLE(offset + 0x18, streamFile);
sample_rate = read_32bitLE(offset + 0x1c, streamFile);
start_offset = offset + 0x20 +
(read_32bitLE(offset + 0x10, streamFile) + 1) * 0x04 +
(read_32bitLE(offset + 0x14, streamFile) + 1) * 0x04;
num_samples = read_32bitLE(0x18, streamFile);
sample_rate = read_32bitLE(0x1c, streamFile);
start_offset = 0x20 +
(read_32bitLE(0x10, streamFile) + 1) * 0x04 +
(read_32bitLE(0x14, streamFile) + 1) * 0x04;
channel_count = 1;
loop_flag = 0;