2008-06-07 23:11:33 +02:00
|
|
|
#include "meta.h"
|
2008-06-08 04:03:05 +02:00
|
|
|
#include "../layout/layout.h"
|
2008-06-07 23:11:33 +02:00
|
|
|
#include "../util.h"
|
|
|
|
|
2018-03-08 23:26:10 +01:00
|
|
|
/* CAF - from tri-Crescendo games [Baten Kaitos 1/2 (GC), Fragile (Wii)] */
|
2008-06-07 23:11:33 +02:00
|
|
|
VGMSTREAM * init_vgmstream_caf(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2018-03-08 23:26:10 +01:00
|
|
|
off_t start_offset, offset;
|
|
|
|
size_t file_size;
|
|
|
|
int channel_count, loop_flag;
|
|
|
|
int32_t num_samples = 0;
|
|
|
|
uint32_t loop_start = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* checks */
|
|
|
|
/* .caf: header id, .cfn: fake extension? , "" is accepted as files don't have extensions in the disc */
|
|
|
|
if (!check_extensions(streamFile,"caf,cfn,"))
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x43414620) /* "CAF " */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* get total samples */
|
|
|
|
offset = 0;
|
|
|
|
file_size = get_streamfile_size(streamFile);
|
|
|
|
while (offset < file_size) {
|
|
|
|
off_t next_block = read_32bitBE(offset+0x04,streamFile);
|
|
|
|
num_samples += read_32bitBE(offset+0x14,streamFile)/8*14;
|
|
|
|
|
|
|
|
if(read_32bitBE(offset+0x20,streamFile)==read_32bitBE(offset+0x08,streamFile)) {
|
|
|
|
loop_start = num_samples - read_32bitBE(offset+0x14,streamFile)/8*14;
|
|
|
|
}
|
|
|
|
offset += next_block;
|
|
|
|
}
|
2008-06-03 20:41:26 +02:00
|
|
|
|
2018-03-08 23:26:10 +01:00
|
|
|
start_offset = 0x00;
|
|
|
|
channel_count = 2; /* always stereo */
|
|
|
|
loop_flag = (loop_start!=-1);
|
2008-06-03 20:41:26 +02:00
|
|
|
|
2008-06-07 23:11:33 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2018-03-08 23:26:10 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
2008-06-07 23:11:33 +02:00
|
|
|
if (!vgmstream) goto fail;
|
2008-06-03 20:41:26 +02:00
|
|
|
|
2018-03-08 23:26:10 +01:00
|
|
|
vgmstream->sample_rate = 32000;
|
|
|
|
vgmstream->num_samples = num_samples;
|
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
vgmstream->loop_end_sample = num_samples;
|
|
|
|
}
|
2008-06-03 20:41:26 +02:00
|
|
|
|
2018-03-08 23:26:10 +01:00
|
|
|
vgmstream->meta_type = meta_CAF;
|
2008-06-07 23:11:33 +02:00
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
2018-03-08 23:26:10 +01:00
|
|
|
vgmstream->layout_type = layout_blocked_caf;
|
2008-06-07 23:11:33 +02:00
|
|
|
|
2018-03-08 23:26:10 +01:00
|
|
|
if ( !vgmstream_open_stream(vgmstream,streamFile,start_offset) )
|
|
|
|
goto fail;
|
2008-06-07 23:11:33 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-03-08 23:26:10 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-06-07 23:11:33 +02:00
|
|
|
return NULL;
|
2008-06-08 04:03:05 +02:00
|
|
|
}
|