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)] */
|
2024-07-14 20:24:53 +02:00
|
|
|
VGMSTREAM* init_vgmstream_vpk(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
int loop_flag, channels;
|
2019-06-15 13:02:24 +02:00
|
|
|
off_t start_offset, loop_channel_offset;
|
2008-06-07 23:11:33 +02:00
|
|
|
|
|
|
|
|
2018-08-12 02:19:17 +02:00
|
|
|
/* checks */
|
2024-07-14 20:24:53 +02:00
|
|
|
if (!is_id32be(0x00,sf, " KPV"))
|
|
|
|
return NULL;
|
|
|
|
if (!check_extensions(sf, "vpk"))
|
|
|
|
return NULL;
|
2018-08-12 02:19:17 +02:00
|
|
|
|
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 */
|
2024-07-14 20:24:53 +02:00
|
|
|
size_t channel_size = read_u32le(0x04,sf);
|
2018-08-12 02:19:17 +02:00
|
|
|
|
2024-07-14 20:24:53 +02:00
|
|
|
start_offset = read_u32le(0x08,sf);
|
|
|
|
channels = read_s32le(0x14,sf);
|
2020-04-05 13:09:05 +02:00
|
|
|
/* 0x18+: channel config(?), 0x04 per channel */
|
2024-07-14 20:24:53 +02:00
|
|
|
loop_channel_offset = read_u32le(0x7FC,sf);
|
2019-06-15 13:02:24 +02:00
|
|
|
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 */
|
2024-07-14 20:24:53 +02:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-06-07 23:11:33 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2024-07-14 20:24:53 +02:00
|
|
|
vgmstream->sample_rate = read_s32le(0x10,sf);
|
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(channel_size * channels, channels);
|
2018-08-12 02:19:17 +02:00
|
|
|
if (vgmstream->loop_flag) {
|
2024-07-14 20:24:53 +02:00
|
|
|
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_channel_offset * channels, 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;
|
2024-07-14 20:24:53 +02:00
|
|
|
vgmstream->interleave_block_size = read_u32le(0x0C,sf) / 2; /* even in >2ch */
|
2008-06-07 23:11:33 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
|
2024-07-14 20:24:53 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2018-08-12 02:19:17 +02:00
|
|
|
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;
|
|
|
|
}
|