2020-07-16 23:16:52 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
|
|
|
/* CXS - found in Eternal Sonata (X360) */
|
2023-01-20 16:32:32 +01:00
|
|
|
VGMSTREAM* init_vgmstream_cxs(STREAMFILE* sf) {
|
2020-07-16 23:16:52 +02:00
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2023-01-20 16:32:32 +01:00
|
|
|
int loop_flag, channels;
|
2020-07-16 23:16:52 +02:00
|
|
|
|
|
|
|
/* checks */
|
2023-01-20 16:32:32 +01:00
|
|
|
if (!is_id32be(0x00,sf, "CXS "))
|
2020-07-16 23:16:52 +02:00
|
|
|
goto fail;
|
2023-01-20 16:32:32 +01:00
|
|
|
if (!check_extensions(sf,"cxs"))
|
2020-07-16 23:16:52 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
loop_flag = read_32bitBE(0x18,sf) > 0;
|
2023-01-20 16:32:32 +01:00
|
|
|
channels = read_32bitBE(0x0c,sf);
|
2020-07-16 23:16:52 +02:00
|
|
|
start_offset = read_32bitBE(0x04,sf) + read_32bitBE(0x28,sf); /* assumed, seek table always at 0x800 */
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2023-01-20 16:32:32 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2020-07-16 23:16:52 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* 0x04: data start? */
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x08,sf);
|
|
|
|
vgmstream->num_samples = read_32bitBE(0x10,sf);
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x14,sf);
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x18,sf);
|
|
|
|
/* 0x1c: below */
|
|
|
|
|
2023-01-20 16:32:32 +01:00
|
|
|
vgmstream->meta_type = meta_CXS;
|
2020-07-16 23:16:52 +02:00
|
|
|
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
{
|
|
|
|
uint8_t buf[0x100];
|
|
|
|
size_t bytes, datasize, block_size, block_count;
|
|
|
|
|
|
|
|
block_count = read_32bitBE(0x1c,sf);
|
|
|
|
block_size = read_32bitBE(0x20,sf);
|
|
|
|
datasize = read_32bitBE(0x24,sf);
|
|
|
|
|
|
|
|
bytes = ffmpeg_make_riff_xma2(buf,100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size);
|
|
|
|
if (bytes <= 0) goto fail;
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf,bytes, start_offset,datasize);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
xma_fix_raw_samples(vgmstream, sf, start_offset,datasize, 0, 0,1); /* num samples are ok */
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
|
2023-01-20 16:32:32 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2020-07-16 23:16:52 +02:00
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|