ESF: Added more versions

This commit is contained in:
NicknineTheEagle 2022-09-09 14:04:23 +03:00
parent 43bd1eac84
commit 50cc33c4ae

View File

@ -1,38 +1,81 @@
#include "meta.h"
#include "../coding/coding.h"
/* .ESF - from Mortal Kombat 4 (PC) */
/* .ESF - found in old Eurocom PC games [Mortal Kombat 4 (PC), Disney's Tarzan (PC)] */
VGMSTREAM* init_vgmstream_esf(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
uint32_t pcm_size;
uint8_t version;
off_t start_offset;
int loop_flag, bps_flag, hq_flag, channels, bps;
int loop_flag = 0, bps_flag = 0, hq_flag = 0, codec_flag = 0,
sample_rate = 0, channels, bps;
/* checks */
if (!is_id32be(0x00, sf, "ESF\x06"))
if (!is_id32be(0x00, sf, "ESF\x03") &&
!is_id32be(0x00, sf, "ESF\x06") &&
!is_id32be(0x00, sf, "ESF\x08"))
goto fail;
if (!check_extensions(sf, "esf"))
goto fail;
version = read_u8(0x03, sf);
pcm_size = read_u32le(0x04, sf);
bps_flag = pcm_size & 0x20000000;
hq_flag = pcm_size & 0x40000000;
loop_flag = pcm_size & 0x80000000;
pcm_size &= 0x1FFFFFFF;
if (version == 3) {
/* Disney's Hercules */
sample_rate = read_u32le(0x08, sf);
loop_flag = read_u8(0x0c, sf);
bps_flag = read_u8(0x0d, sf);
//bps = bps_flag ? 8 : 16;
bps = 16;
start_offset = 0x10;
} else if (version == 6) {
/* Mortal Kombat 4 */
bps_flag = pcm_size & 0x20000000;
hq_flag = pcm_size & 0x40000000;
loop_flag = pcm_size & 0x80000000;
pcm_size &= 0x1FFFFFFF;
bps = bps_flag ? 16 : 8;
sample_rate = hq_flag ? 22050 : 11025;
start_offset = 0x08;
} else if (version == 8) {
/* Disney's Tarzan, Hydro Thunder */
bps_flag = pcm_size & 0x10000000;
hq_flag = pcm_size & 0x20000000;
loop_flag = pcm_size & 0x40000000;
codec_flag = pcm_size & 0x80000000;
pcm_size &= 0x0FFFFFFF;
bps = bps_flag ? 16 : 8;
sample_rate = hq_flag ? 22050 : 11025;
start_offset = 0x08;
} else {
goto fail;
}
channels = 1; /* mono only */
start_offset = 0x08;
bps = bps_flag ? 16 : 8; /* 16 is supposed to mean PCM16 but is actually IMA */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_ESF;
vgmstream->sample_rate = hq_flag ? 22050 : 11025;
vgmstream->coding_type = (bps == 8) ? coding_PCM8_U : coding_DVI_IMA;
vgmstream->num_samples = pcm_bytes_to_samples(pcm_size, 1, bps);
vgmstream->sample_rate = sample_rate;
if (version == 3) {
vgmstream->coding_type = coding_DVI_IMA;
} else if (version == 6) {
vgmstream->coding_type = (bps == 8) ? coding_PCM8_U : coding_DVI_IMA;
} else if (version == 8) {
if (bps == 8) {
vgmstream->coding_type = coding_PCM8_U;
} else {
vgmstream->coding_type = codec_flag ? coding_DVI_IMA : coding_PCM16LE;
}
}
vgmstream->num_samples = pcm_bytes_to_samples(pcm_size, channels, bps);
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = vgmstream->num_samples;