vgmstream/src/meta/gin.c

56 lines
1.7 KiB
C
Raw Normal View History

#include "meta.h"
#include "../coding/coding.h"
/* .gin - EA engine sounds [Need for Speed: Most Wanted (multi)] */
2021-07-28 15:57:09 +02:00
VGMSTREAM * init_vgmstream_gin(STREAMFILE *sf) {
VGMSTREAM *vgmstream = NULL;
2019-02-11 10:37:11 +01:00
off_t start_offset;
int loop_flag, channel_count, sample_rate, num_samples;
2021-07-28 15:57:09 +02:00
if (!check_extensions(sf, "gin"))
goto fail;
2019-02-11 10:37:11 +01:00
/* checks */
2021-07-28 15:57:09 +02:00
if (!is_id32be(0x00, sf, "Gnsu") && /* original */
!is_id32be(0x00, sf, "Octn")) /* later (2013+) games, looks same as "Gnsu" */
goto fail;
/* contains mapped values for engine RPM sounds but we'll just play the whole thing */
/* 0x04: size? "20\00\00"? */
/* 0x08/0c: min/max float RPM? */
/* 0x10: RPM up? (pitch/frequency) table size */
/* 0x14: RPM ??? table size */
/* always LE even on X360/PS3 */
2021-07-28 15:57:09 +02:00
num_samples = read_u32le(0x18, sf);
sample_rate = read_u32le(0x1c, sf);
start_offset = 0x20 +
2021-07-28 15:57:09 +02:00
(read_u32le(0x10, sf) + 1) * 0x04 +
(read_u32le(0x14, sf) + 1) * 0x04;
channel_count = 1;
loop_flag = 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_GIN;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->coding_type = coding_EA_XAS_V0;
2019-02-11 10:37:11 +01:00
vgmstream->layout_type = layout_none;
2019-02-18 11:02:58 +01:00
/* calculate size for TMX */
vgmstream->stream_size = (align_size_to_block(num_samples, 32) / 32) * 0x13;
2021-07-28 15:57:09 +02:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}