2013-09-03 20:14:14 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
2017-04-07 19:10:16 +02:00
|
|
|
|
|
|
|
/* CKD RIFF - Ubisoft audio [Rayman Origins (Wii)] */
|
2013-09-03 20:14:14 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ubi_ckd(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2017-04-07 19:10:16 +02:00
|
|
|
off_t start_offset, first_offset = 0xc, chunk_offset;
|
|
|
|
size_t chunk_size, data_size;
|
|
|
|
int loop_flag, channel_count, interleave;
|
2013-09-03 20:14:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-04-07 19:10:16 +02:00
|
|
|
if (!check_extensions(streamFile,"ckd")) goto fail;
|
2013-09-03 20:14:14 +02:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x0,streamFile) != 0x52494646) /* RIFF */
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x26,streamFile) != 0x6473704C) /* dspL */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = read_16bitBE(0x16,streamFile);
|
|
|
|
|
2017-04-07 19:10:16 +02:00
|
|
|
/* find data chunk, in 3 variants */
|
|
|
|
if (find_chunk_be(streamFile, 0x64617453,first_offset,0, &chunk_offset,&chunk_size)) { /*"datS"*/
|
|
|
|
/* normal interleave */
|
|
|
|
start_offset = chunk_offset;
|
|
|
|
data_size = chunk_size;
|
|
|
|
interleave = 8;
|
|
|
|
} else if (find_chunk_be(streamFile, 0x6461744C,first_offset,0, &chunk_offset,&chunk_size)) { /*"datL"*/
|
|
|
|
/* mono or full interleave (with a "datR" after the "datL", no check as we can just pretend it exists) */
|
|
|
|
start_offset = chunk_offset;
|
|
|
|
data_size = chunk_size * channel_count;
|
|
|
|
interleave = (4+4) + chunk_size; /* don't forget to skip the "datR"+size chunk */
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2013-09-03 20:14:14 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x18,streamFile);
|
2017-04-07 19:10:16 +02:00
|
|
|
vgmstream->num_samples = dsp_bytes_to_samples(data_size, channel_count);
|
2013-09-03 20:14:14 +02:00
|
|
|
|
2017-04-07 19:10:16 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = channel_count==1 ? layout_none : layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = interleave;
|
2013-09-03 20:14:14 +02:00
|
|
|
vgmstream->meta_type = meta_UBI_CKD;
|
|
|
|
|
2017-04-07 19:10:16 +02:00
|
|
|
dsp_read_coefs_be(vgmstream,streamFile, 0x4A, (4+4)+0x60);
|
2013-09-03 20:14:14 +02:00
|
|
|
|
|
|
|
|
2017-04-07 19:10:16 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2013-09-03 20:14:14 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-04-07 19:10:16 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2013-09-03 20:14:14 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|