Fix some .stx [Phantom Dust Remaster (PC)]

This commit is contained in:
bnnm 2024-05-11 15:32:00 +02:00
parent f7c272d892
commit 18a7137439
2 changed files with 58 additions and 22 deletions

View File

@ -216,6 +216,9 @@ void block_update(off_t block_offset, VGMSTREAM* vgmstream) {
}
void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset) {
if (vgmstream == NULL)
return;
int block_samples;
off_t max_offset = get_streamfile_size(sf);
@ -231,9 +234,11 @@ void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset) {
}
else {
switch(vgmstream->coding_type) {
case coding_PCM16LE:
case coding_PCM16_int: block_samples = pcm16_bytes_to_samples(vgmstream->current_block_size, 1); break;
case coding_PCM8_int:
case coding_PCM8_U_int: block_samples = pcm8_bytes_to_samples(vgmstream->current_block_size, 1); break;
case coding_XBOX_IMA_int:
case coding_XBOX_IMA: block_samples = xbox_ima_bytes_to_samples(vgmstream->current_block_size, 1); break;
case coding_NGC_DSP: block_samples = dsp_bytes_to_samples(vgmstream->current_block_size, 1); break;
case coding_PSX: block_samples = ps_bytes_to_samples(vgmstream->current_block_size,1); break;

View File

@ -2,35 +2,58 @@
#include "../coding/coding.h"
#include "../layout/layout.h"
/* STHD - Dream Factory .stx [Kakuto Chojin (Xbox)] */
VGMSTREAM * init_vgmstream_sthd(STREAMFILE *sf) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag, channel_count;
/* STHD - Dream Factory .stx [Kakuto Chojin (Xbox), Dinosaur Hunting (Xbox), Phantom Dust Remaster (PC)] */
VGMSTREAM* init_vgmstream_sthd(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
uint32_t start_offset;
int loop_flag, channels, sample_rate;
int loop_start_block, loop_end_block;
uint32_t build_date;
/* checks */
if (!is_id32be(0x00,sf, "STHD"))
goto fail;
return NULL;
if (!check_extensions(sf, "stx"))
goto fail;
/* first block has special values */
if (read_u16le(0x04,sf) != 0x0800 ||
read_u32le(0x14,sf) != 0x0000)
goto fail;
return NULL;
/* all blocks have STHD and have these values up to 0x20, size 0x800 */
start_offset = read_u16le(0x04,sf); /* next block in header, data offset in other blocks */
channels = read_s16le(0x06,sf);
build_date = read_u32le(0x08,sf); /* in hex (0x20030610 = 2003-06-10) */
/* 0x0c: ? (1 in Dinosaur Hunting, otherwise 0) */
if (start_offset != 0x0800 || channels > 8)
return NULL;
/* 0x10: total blocks */
/* 0x12: block number */
/* 0x14: null */
/* 0x16: channel size (0 in header block) */
/* 0x18: block number + 1? */
loop_start_block = read_u16le(0x1a,sf);
loop_end_block = read_u16le(0x1c,sf);
loop_flag = loop_start_block != 0xFFFF;
/* may be a bug since STHD blocks don't reach max (loop start seems fine) [Phantom Dust Remaster (PC)] */
if (build_date >= 0x20170000)
loop_end_block--;
/* channel info (first block only), seem to be repeated up to max 8 channels */
sample_rate = read_s32le(0x20, sf);
/* 0x24/28: volume/pan? (not always set) */
/* 0x210: stream name for both channels (same as file) */
channel_count = read_s16le(0x06,sf);
loop_flag = read_s16le(0x18,sf) != -1;
start_offset = read_u16le(0x04,sf);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_STHD;
vgmstream->sample_rate = read_s32le(0x20, sf); /* repeated ~8 times? */
vgmstream->sample_rate = sample_rate;
vgmstream->coding_type = coding_XBOX_IMA_int;
vgmstream->coding_type = build_date >= 0x20170000 ? /* no apparent flags [Phantom Dust Remaster (PC)] */
coding_PCM16LE :
coding_XBOX_IMA_int;
vgmstream->layout_type = layout_blocked_sthd;
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
@ -39,19 +62,27 @@ VGMSTREAM * init_vgmstream_sthd(STREAMFILE *sf) {
/* calc num_samples manually (blocks data varies in size) */
{
/* loop values may change to +1 in first actual block, but this works ok enough */
int loop_start_block = (uint16_t)read_16bitLE(0x1a,sf);
int loop_end_block = (uint16_t)read_16bitLE(0x1c,sf);
int block_count = 1; /* header block = 0 */
vgmstream->next_block_offset = start_offset;
do {
block_update(vgmstream->next_block_offset,vgmstream);
block_update(vgmstream->next_block_offset, vgmstream);
if (vgmstream->current_block_samples < 0 || vgmstream->current_block_size == 0xFFFFFFFF)
break;
if (block_count == loop_start_block)
vgmstream->loop_start_sample = vgmstream->num_samples;
if (block_count == loop_end_block)
vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->num_samples += xbox_ima_bytes_to_samples(vgmstream->current_block_size, 1);
int block_samples = 0;
switch(vgmstream->coding_type) {
case coding_PCM16LE: block_samples = pcm16_bytes_to_samples(vgmstream->current_block_size, 1); break;
case coding_XBOX_IMA_int: block_samples = xbox_ima_bytes_to_samples(vgmstream->current_block_size, 1); break;
default: goto fail;
}
vgmstream->num_samples += block_samples;
block_count++;
}
while (vgmstream->next_block_offset < get_streamfile_size(sf));