2017-06-24 23:30:10 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
2018-02-25 12:17:35 +01:00
|
|
|
/* XA30 - found in Reflections games [Driver: Parallel Lines (PC), Driver 3 (PC)] */
|
2017-06-24 23:30:10 +02:00
|
|
|
VGMSTREAM * init_vgmstream_pc_xa30(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
|
|
|
int loop_flag, channel_count, codec;
|
2018-02-25 12:17:35 +01:00
|
|
|
size_t stream_size;
|
|
|
|
int total_subsongs, target_subsong = streamFile->stream_index;
|
2017-06-24 23:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2018-02-25 12:17:35 +01:00
|
|
|
/* ".xa30/e4x" is just the ID, the real filename should be .XA */
|
|
|
|
if (!check_extensions(streamFile,"xa,xa30,e4x"))
|
2017-06-24 23:30:10 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
2018-02-25 12:17:35 +01:00
|
|
|
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 */
|
2017-06-24 23:30:10 +02:00
|
|
|
goto fail;
|
|
|
|
|
2018-02-25 12:17:35 +01:00
|
|
|
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;
|
2017-06-24 23:30:10 +02:00
|
|
|
|
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = 2; /* 0x04: channels? (always 2 in practice) */
|
2018-02-25 12:17:35 +01:00
|
|
|
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);
|
2017-06-24 23:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
|
2018-02-25 12:17:35 +01:00
|
|
|
/* 0x20: always IMA=00016000, PCM=00056000 PCM?, rest of the header is null */
|
|
|
|
vgmstream->num_streams = total_subsongs;
|
|
|
|
vgmstream->stream_size = stream_size;
|
2017-06-24 23:30:10 +02:00
|
|
|
vgmstream->meta_type = meta_PC_XA30;
|
|
|
|
|
|
|
|
switch(codec) {
|
2018-02-25 12:17:35 +01:00
|
|
|
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;
|
|
|
|
|
2017-06-24 23:30:10 +02:00
|
|
|
case 0x01: /* MS-IMA variation */
|
|
|
|
vgmstream->coding_type = coding_REF_IMA;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x24,streamFile);
|
2018-02-25 12:17:35 +01:00
|
|
|
vgmstream->num_samples = ms_ima_bytes_to_samples(stream_size, vgmstream->interleave_block_size, channel_count);
|
2017-06-24 23:30:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* open the file for reading */
|
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|