2009-08-25 19:50:43 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2021-05-09 14:21:44 +02:00
|
|
|
/* Maxis XA - found in Sim City 3000 (PC), The Sims 2 (PC) */
|
2009-08-25 19:50:43 +02:00
|
|
|
VGMSTREAM * init_vgmstream_maxis_xa(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2021-05-09 14:21:44 +02:00
|
|
|
int avg_byte_rate, channel_count, loop_flag, resolution, sample_align, sample_rate;
|
2009-08-25 19:50:43 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-07-08 10:28:08 +02:00
|
|
|
if (!check_extensions(streamFile,"xa"))
|
|
|
|
goto fail;
|
2009-08-25 19:50:43 +02:00
|
|
|
|
|
|
|
/* check header */
|
2021-05-09 14:21:44 +02:00
|
|
|
if ((read_16bitBE(0x00,streamFile) != 0x5841)) /* "XA" */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check format tag */
|
|
|
|
if ((read_16bitLE(0x08,streamFile) != 0x0001))
|
2009-08-25 19:50:43 +02:00
|
|
|
goto fail;
|
2017-07-08 10:28:08 +02:00
|
|
|
|
|
|
|
channel_count = read_16bitLE(0x0A,streamFile);
|
2021-05-09 14:21:44 +02:00
|
|
|
sample_rate = read_32bitLE(0x0C,streamFile);
|
|
|
|
avg_byte_rate = read_32bitLE(0x10,streamFile);
|
|
|
|
sample_align = read_16bitLE(0x14,streamFile);
|
|
|
|
resolution = read_16bitLE(0x16,streamFile);
|
|
|
|
|
|
|
|
/* check alignment */
|
|
|
|
if (sample_align != (resolution/8)*channel_count)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check average byte rate */
|
|
|
|
if (avg_byte_rate != sample_rate*sample_align)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
loop_flag = 0;
|
2017-12-03 01:37:56 +01:00
|
|
|
start_offset = 0x18;
|
2017-07-08 10:28:08 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2009-08-25 19:50:43 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2021-05-09 14:21:44 +02:00
|
|
|
vgmstream->sample_rate = sample_rate;
|
2009-09-01 23:28:55 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x04,streamFile)/2/channel_count;
|
2009-08-25 19:50:43 +02:00
|
|
|
|
|
|
|
vgmstream->meta_type = meta_MAXIS_XA;
|
2017-12-03 01:37:56 +01:00
|
|
|
vgmstream->coding_type = coding_MAXIS_XA;
|
|
|
|
vgmstream->layout_type = layout_none;
|
2009-08-25 19:50:43 +02:00
|
|
|
|
2017-07-08 10:28:08 +02:00
|
|
|
/* open streams */
|
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2009-08-25 19:50:43 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-07-08 10:28:08 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2009-08-25 19:50:43 +02:00
|
|
|
return NULL;
|
|
|
|
}
|