Add .e4x [Driver 3 (PC)]

This commit is contained in:
bnnm 2018-02-25 12:17:35 +01:00
parent 5e50819778
commit 4331fb7685
2 changed files with 27 additions and 20 deletions

View File

@ -105,6 +105,7 @@ static const char* extension_list[] = {
"dvi",
"dxh",
"e4x",
"eam",
"emff",
"enth",

View File

@ -1,37 +1,36 @@
#include "meta.h"
#include "../coding/coding.h"
/* XA30 - found in Driver: Parallel Lines (PC) */
/* XA30 - found in Reflections games [Driver: Parallel Lines (PC), Driver 3 (PC)] */
VGMSTREAM * init_vgmstream_pc_xa30(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag, channel_count, codec;
size_t file_size, data_size;
size_t stream_size;
int total_subsongs, target_subsong = streamFile->stream_index;
/* check extension, case insensitive */
/* ".xa30" is just the ID, the real filename should be .XA */
if (!check_extensions(streamFile,"xa,xa30"))
/* ".xa30/e4x" is just the ID, the real filename should be .XA */
if (!check_extensions(streamFile,"xa,xa30,e4x"))
goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x58413330) /* "XA30" */
if (read_32bitBE(0x00,streamFile) != 0x58413330 && /* "XA30" [Driver: Parallel Lines (PC)]*/
read_32bitBE(0x00,streamFile) != 0x65347892) /* "e4x\92" [Driver 3 (PC)]*/
goto fail;
if (read_32bitLE(0x04,streamFile) != 2) /* channels?, also extra check to avoid PS2/PC XA30 mixup */
goto fail;
if (read_32bitLE(0x04,streamFile) > 2) goto fail; /* extra check to avoid PS2/PC XA30 mixup */
/* reportedly from XA2WAV those are offset+data from a second stream (not seen) */
if (read_32bitLE(0x14,streamFile) != 0 || read_32bitLE(0x1c,streamFile) != 0) goto fail;
total_subsongs = read_32bitLE(0x14,streamFile) != 0 ? 2 : 1; /* second stream offset (only in Driver 3) */
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
loop_flag = 0;
channel_count = 2; /* 0x04: channels? (always 2 in practice) */
codec = read_32bitLE(0x0c,streamFile); /* reportedly from XA2WAV (not seen) */
start_offset = read_32bitLE(0x10,streamFile);
file_size = get_streamfile_size(streamFile);
data_size = read_32bitLE(0x18,streamFile);
if (data_size+start_offset != file_size) goto fail;
codec = read_32bitLE(0x0c,streamFile);
start_offset = read_32bitLE(0x10 + 0x04*(target_subsong-1),streamFile);
stream_size = read_32bitLE(0x18 + 0x04*(target_subsong-1),streamFile);
/* build the VGMSTREAM */
@ -39,19 +38,26 @@ VGMSTREAM * init_vgmstream_pc_xa30(STREAMFILE *streamFile) {
if (!vgmstream) goto fail;
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
/* 0x20: always 00016000?, rest of the header is null */
/* 0x20: always IMA=00016000, PCM=00056000 PCM?, rest of the header is null */
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
vgmstream->meta_type = meta_PC_XA30;
switch(codec) {
case 0x00: /* PCM (rare, seen in Driver 3) */
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = read_32bitLE(0x24,streamFile) / 2;
vgmstream->num_samples = pcm_bytes_to_samples(stream_size, channel_count, 16);
break;
case 0x01: /* MS-IMA variation */
vgmstream->coding_type = coding_REF_IMA;
vgmstream->layout_type = layout_none;
vgmstream->interleave_block_size = read_32bitLE(0x24,streamFile);
vgmstream->num_samples = ms_ima_bytes_to_samples(data_size, vgmstream->interleave_block_size, channel_count);
vgmstream->num_samples = ms_ima_bytes_to_samples(stream_size, vgmstream->interleave_block_size, channel_count);
break;
case 0x00: /* PCM? */
default:
goto fail;
}