2008-06-07 23:11:33 +02:00
|
|
|
#include "meta.h"
|
2018-07-14 23:04:04 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-06-07 23:11:33 +02:00
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
/* VPK - from SCE America second party devs [God of War (PS2), NBA 08 (PS3)] */
|
2020-04-05 13:09:05 +02:00
|
|
|
VGMSTREAM * init_vgmstream_vpk(STREAMFILE *streamFile) {
|
2008-06-07 23:11:33 +02:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2018-08-12 02:19:17 +02:00
|
|
|
int loop_flag, channel_count;
|
2019-06-15 13:02:24 +02:00
|
|
|
off_t start_offset, loop_channel_offset;
|
2018-08-12 02:19:17 +02:00
|
|
|
size_t channel_size;
|
2008-06-07 23:11:33 +02:00
|
|
|
|
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "vpk"))
|
2008-06-07 23:11:33 +02:00
|
|
|
goto fail;
|
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x204B5056) /* " KPV" */
|
|
|
|
goto fail;
|
|
|
|
|
2020-04-05 13:09:05 +02:00
|
|
|
/* files are padded with garbage/silent 0xC00000..00 frames, and channel_size sometimes
|
|
|
|
* has extra size into the padding: +0x10 (NBA08), +0x20 (GoW), or none (Sly 2, loops ok).
|
|
|
|
* Could detect and remove to slightly improve full loops, but maybe this is just how the game works */
|
|
|
|
channel_size = read_32bitLE(0x04,streamFile);
|
2018-08-12 02:19:17 +02:00
|
|
|
|
|
|
|
start_offset = read_32bitLE(0x08,streamFile);
|
|
|
|
channel_count = read_32bitLE(0x14,streamFile);
|
2020-04-05 13:09:05 +02:00
|
|
|
/* 0x18+: channel config(?), 0x04 per channel */
|
2019-06-15 13:02:24 +02:00
|
|
|
loop_channel_offset = read_32bitLE(0x7FC,streamFile);
|
|
|
|
loop_flag = (loop_channel_offset != 0); /* found in Sly 2/3 */
|
2018-08-12 02:19:17 +02:00
|
|
|
|
|
|
|
|
2017-11-10 22:22:04 +01:00
|
|
|
/* build the VGMSTREAM */
|
2008-06-07 23:11:33 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x10,streamFile);
|
2018-08-12 02:19:17 +02:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(channel_size*vgmstream->channels,vgmstream->channels);
|
|
|
|
if (vgmstream->loop_flag) {
|
2019-06-15 13:02:24 +02:00
|
|
|
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_channel_offset*vgmstream->channels,vgmstream->channels);
|
2017-11-10 22:22:04 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
2008-06-07 23:11:33 +02:00
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
vgmstream->meta_type = meta_VPK;
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x0C,streamFile) / 2; /* even in >2ch */
|
2008-06-07 23:11:33 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2008-06-07 23:11:33 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-08-12 02:19:17 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-06-07 23:11:33 +02:00
|
|
|
return NULL;
|
|
|
|
}
|