Merge pull request #1222 from NicknineTheEagle/esf

ESF: Added more versions
This commit is contained in:
NicknineTheEagle 2022-09-09 14:15:19 +03:00 committed by GitHub
commit 708443df6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,38 +1,81 @@
#include "meta.h" #include "meta.h"
#include "../coding/coding.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* init_vgmstream_esf(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
uint32_t pcm_size; uint32_t pcm_size;
uint8_t version;
off_t start_offset; 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 */ /* 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; goto fail;
if (!check_extensions(sf, "esf")) if (!check_extensions(sf, "esf"))
goto fail; goto fail;
version = read_u8(0x03, sf);
pcm_size = read_u32le(0x04, sf); pcm_size = read_u32le(0x04, sf);
bps_flag = pcm_size & 0x20000000;
hq_flag = pcm_size & 0x40000000; if (version == 3) {
loop_flag = pcm_size & 0x80000000; /* Disney's Hercules */
pcm_size &= 0x1FFFFFFF; 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 */ 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 */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag); vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
vgmstream->meta_type = meta_ESF; vgmstream->meta_type = meta_ESF;
vgmstream->sample_rate = hq_flag ? 22050 : 11025; vgmstream->sample_rate = sample_rate;
vgmstream->coding_type = (bps == 8) ? coding_PCM8_U : coding_DVI_IMA; if (version == 3) {
vgmstream->num_samples = pcm_bytes_to_samples(pcm_size, 1, bps); 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_start_sample = 0;
vgmstream->loop_end_sample = vgmstream->num_samples; vgmstream->loop_end_sample = vgmstream->num_samples;