mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-14 18:47:39 +01:00
Fix some Ubi .ckd [Rayman Origins (PS3/X360/PC)]
This commit is contained in:
parent
2288370d8b
commit
115c6363b8
@ -2,39 +2,107 @@
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
/* CKD RIFF - Ubisoft audio [Rayman Origins (Wii)] */
|
||||
VGMSTREAM * init_vgmstream_ubi_ckd(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset, first_offset = 0xc, chunk_offset;
|
||||
typedef enum { MSADPCM, DSP, MP3, XMA2 } ckd_codec;
|
||||
|
||||
/* CKD RIFF - UbiArt Framework (v1) audio [Rayman Origins (Wii/X360/PS3/PC)] */
|
||||
VGMSTREAM* init_vgmstream_ubi_ckd(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset, first_offset = 0x0c, chunk_offset;
|
||||
size_t chunk_size, data_size;
|
||||
int loop_flag, channel_count, interleave;
|
||||
int loop_flag, channel_count, interleave = 0, format;
|
||||
ckd_codec codec;
|
||||
int big_endian;
|
||||
uint32_t (*read_u32)(off_t,STREAMFILE*);
|
||||
uint16_t (*read_u16)(off_t,STREAMFILE*);
|
||||
|
||||
|
||||
/* check extension, case insensitive */
|
||||
if (!check_extensions(streamFile,"ckd")) goto fail;
|
||||
|
||||
/* check header */
|
||||
if (read_32bitBE(0x0,streamFile) != 0x52494646) /* RIFF */
|
||||
goto fail;
|
||||
if (read_32bitBE(0x26,streamFile) != 0x6473704C) /* dspL */
|
||||
/* checks */
|
||||
/* .wav.ckd: main (other files are called .xxx.ckd too) */
|
||||
if (!check_extensions(sf,"ckd"))
|
||||
goto fail;
|
||||
|
||||
/* another slighly funny RIFF */
|
||||
if (read_u32be(0x00,sf) != 0x52494646) /* "RIFF" */
|
||||
goto fail;
|
||||
if (read_u32be(0x08,sf) != 0x57415645) /* "WAVE" */
|
||||
goto fail;
|
||||
/* RIFF size is normal */
|
||||
|
||||
big_endian = guess_endianness32bit(0x04, sf);
|
||||
read_u32 = big_endian ? read_u32be : read_u32le;
|
||||
read_u16 = big_endian ? read_u16be : read_u16le;
|
||||
|
||||
loop_flag = 0;
|
||||
channel_count = read_16bitBE(0x16,streamFile);
|
||||
|
||||
/* 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;
|
||||
format = read_u16(0x14,sf);
|
||||
channel_count = read_u16(0x16,sf);
|
||||
|
||||
switch(format) {
|
||||
case 0x0002:
|
||||
if (big_endian) {
|
||||
if (read_u32(0x26,sf) != 0x6473704C) /* "dspL" */
|
||||
goto fail;
|
||||
|
||||
/* find data chunk, in 2 variants */
|
||||
if (find_chunk_be(sf, 0x64617453,first_offset,0, &chunk_offset,&chunk_size)) { /* "datS" */
|
||||
/* normal interleave */
|
||||
start_offset = chunk_offset;
|
||||
data_size = chunk_size;
|
||||
interleave = 0x08;
|
||||
} else if (find_chunk_be(sf, 0x6461744C,first_offset,0, &chunk_offset,&chunk_size)) { /* "datL" */
|
||||
/* mono "datL" or full interleave with a "datR" after the "datL" (no check, pretend it exists) */
|
||||
start_offset = chunk_offset;
|
||||
data_size = chunk_size * channel_count;
|
||||
interleave = (0x4+0x4) + chunk_size; /* don't forget to skip the "datR"+size chunk */
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
codec = DSP;
|
||||
}
|
||||
else {
|
||||
/* PC has MS-ADPCM, same as wav's except without "fact" (recommended by MS), kinda useless
|
||||
* but might as well have it here */
|
||||
if (find_chunk_le(sf, 0x64617461,first_offset,0, &chunk_offset,&chunk_size)) { /* "data" */
|
||||
start_offset = chunk_offset;
|
||||
data_size = chunk_size;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
interleave = read_u16(0x20, sf);
|
||||
if (!msadpcm_check_coefs(sf, 0x28))
|
||||
goto fail;
|
||||
|
||||
/* there is also a "smpl" chunk with full loops too, but other codecs don't have it for the same tracks... */
|
||||
|
||||
codec = MSADPCM;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0055:
|
||||
if (read_u32(0x26,sf) != 0x6D736620) /* "msf " */
|
||||
goto fail;
|
||||
start_offset = 0x26;
|
||||
data_size = read_u32(0x2A,sf);
|
||||
codec = MP3;
|
||||
break;
|
||||
|
||||
case 0x0166:
|
||||
if (read_u32(0x48,sf) != 0x7365656B && /* "seek */
|
||||
read_u32(0x48,sf) != 0x7365656B) /* "data" */
|
||||
goto fail;
|
||||
|
||||
if (find_chunk_be(sf, 0x64617461,first_offset,0, &chunk_offset,&chunk_size)) { /* "data" */
|
||||
start_offset = chunk_offset;
|
||||
data_size = chunk_size;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
codec = XMA2;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
@ -42,18 +110,59 @@ VGMSTREAM * init_vgmstream_ubi_ckd(STREAMFILE *streamFile) {
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->sample_rate = read_32bitBE(0x18,streamFile);
|
||||
vgmstream->sample_rate = read_u32(0x18,sf);
|
||||
vgmstream->num_samples = dsp_bytes_to_samples(data_size, channel_count);
|
||||
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = channel_count==1 ? layout_none : layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
vgmstream->meta_type = meta_UBI_CKD;
|
||||
|
||||
dsp_read_coefs_be(vgmstream,streamFile, 0x4A, (4+4)+0x60);
|
||||
switch(codec) {
|
||||
case MSADPCM:
|
||||
vgmstream->coding_type = coding_MSADPCM;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->frame_size = interleave;
|
||||
break;
|
||||
|
||||
case DSP:
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
dsp_read_coefs_be(vgmstream,sf, 0x4A, (4+4)+0x60);
|
||||
break;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
#ifdef VGM_USE_MPEG
|
||||
case MP3: {
|
||||
vgmstream->codec_data = init_mpeg(sf, start_offset, &vgmstream->coding_type, vgmstream->channels);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
vgmstream->num_samples = mpeg_bytes_to_samples(data_size, vgmstream->codec_data);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
case XMA2: {
|
||||
uint8_t buf[0x100];
|
||||
int bytes;
|
||||
|
||||
bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf, sizeof(buf), 0x14, 0x34, data_size, sf, 1);
|
||||
vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf,bytes, start_offset,data_size);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
vgmstream->num_samples = read_u32(0x14+0x18,sf);
|
||||
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset,data_size, 0, 0,0); /* should apply to num_samples? */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user