mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 19:19:16 +01:00
Fix some .xse [Mindjack (PS3/X360)]
This commit is contained in:
parent
dc98e1fbd8
commit
778ec9aa9e
188
src/meta/sdrh.c
188
src/meta/sdrh.c
@ -3,13 +3,12 @@
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
/* SDRH - banks for newer feelplus-related games [Mindjack (PS3/X360)] */
|
||||
/* SDRH - banks for newer feelplus-related ("FeelEngine") games [Mindjack (PS3/X360), Moon Diver (PS3/X360)] */
|
||||
VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset, data_size, stream_size;
|
||||
uint32_t start_offset, stream_size;
|
||||
int loop_flag = 0, channels, codec, sample_rate, seek_count;
|
||||
int32_t num_samples, loop_start, loop_end;
|
||||
off_t offset;
|
||||
int total_subsongs, target_subsong = sf->stream_index;
|
||||
|
||||
|
||||
@ -22,19 +21,19 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
/* similar to older version but BE and a bit less complex */
|
||||
/* 0x04: version/config?
|
||||
* 0x08: data size
|
||||
* 0x30: file name in some strange encoding/compression?
|
||||
* others: ? (change in old/new)
|
||||
*/
|
||||
* 0x30: file name in a custom 40-char (RADIX style) encoding
|
||||
* others: ?
|
||||
*/
|
||||
|
||||
/* parse section */
|
||||
{
|
||||
uint32_t offset, base_size, stream_offset, data_size = 0, entry_size = 0;
|
||||
int i;
|
||||
int tables = read_u16be(0x1C,sf);
|
||||
off_t base_size, stream_offset;
|
||||
int entries;
|
||||
|
||||
offset = 0;
|
||||
/* read sections (FE=cues?, WV=mini-headers?, XW=waves) */
|
||||
/* read sections: FE=cues? (same in platforms), WV=header position + sample rate?, FT=? (same in platforms), XW=waves */
|
||||
for (i = 0; i < tables; i++) {
|
||||
uint16_t id = read_u16be(0x40 + 0x10 * i + 0x00,sf);
|
||||
/* 0x02: offset in 0x40s */
|
||||
@ -48,7 +47,7 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
}
|
||||
|
||||
/* section header (other sections have a similar header) */
|
||||
/* 0x00: section size */
|
||||
/* 0x00: section size (including data) */
|
||||
base_size = read_u16be(offset + 0x04,sf);
|
||||
entries = read_u16be(offset + 0x06,sf);
|
||||
/* 0x08: null */
|
||||
@ -62,8 +61,7 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
|
||||
/* find stream header (entries can be variable-sized) */
|
||||
for (i = 0; i < entries; i++) {
|
||||
size_t seek_size = read_u16be(offset + 0x0a,sf) * 0x04;
|
||||
size_t entry_size = align_size_to_block(0x30 + seek_size, 0x10);
|
||||
entry_size = read_u16be(offset + 0x04,sf) * 0x10;
|
||||
|
||||
if (i + 1 == target_subsong)
|
||||
break;
|
||||
@ -71,27 +69,36 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
}
|
||||
|
||||
/* parse target header (similar to xwav) */
|
||||
stream_size = read_u32be(offset + 0x00,sf);
|
||||
/* 0x04: codec? (16=PS3, 03=X360) */
|
||||
codec = read_u8(offset + 0x06,sf); /* assumed */
|
||||
loop_flag = read_u8(offset + 0x07,sf); /* assumed */
|
||||
/* 0x08: bps? */
|
||||
channels = read_u8(offset + 0x09,sf);
|
||||
data_size = read_u32be(offset + 0x00,sf) - entry_size;
|
||||
/* 0x00: data/entry size */
|
||||
/* 0x04: entry size */
|
||||
codec = read_u8(offset + 0x06,sf); /* assumed */
|
||||
loop_flag = read_u8(offset + 0x07,sf); /* assumed */
|
||||
/* 0x08: bps? flags? */
|
||||
channels = read_u8(offset + 0x09,sf);
|
||||
seek_count = read_u16be(offset + 0x0a,sf);
|
||||
num_samples = read_u32be(offset + 0x0c,sf);
|
||||
|
||||
sample_rate = read_u32be(offset + 0x10,sf);
|
||||
loop_start = read_u32be(offset + 0x14,sf);
|
||||
loop_end = read_u32be(offset + 0x18,sf);
|
||||
/* 0x1c: ? */
|
||||
stream_offset = read_u32be(offset + 0x20,sf); /* within data */
|
||||
/* 0x24: ? */
|
||||
/* 0x26 seek entries */
|
||||
/* 0x28: ? */
|
||||
/* 0x2c: null? */
|
||||
/* 0x1c: flags? */
|
||||
|
||||
stream_offset = read_u32be(offset + 0x20,sf);
|
||||
|
||||
/* Mindjack uses full offsets here (aligned to 0x800), while Moon Diver points to a sub-offset
|
||||
* (offsets also aren't ordered) */
|
||||
if ((stream_offset & 0x000007FF) != 0) {
|
||||
stream_offset = read_u16be(offset + stream_offset, sf) * 0x800;
|
||||
//TODO some files that loop have wrong size/num_samples? (ex.MJ system.xse #23 #138)
|
||||
}
|
||||
|
||||
/* other values change per game (seek table, etc) */
|
||||
|
||||
start_offset += stream_offset;
|
||||
stream_size = data_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channels, loop_flag);
|
||||
@ -105,23 +112,26 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
vgmstream->num_streams = total_subsongs;
|
||||
|
||||
switch(codec) {
|
||||
case 2: /* Mindjack (PS3) */
|
||||
case 2: /* Mindjack (PS3), Moon Diver (PS3) */
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x10;
|
||||
|
||||
/* seen in a few Mindjack files */
|
||||
if (loop_end > num_samples && loop_end - 8 <= num_samples)
|
||||
loop_end = num_samples;
|
||||
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
break;
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
case 1: { /* Mindjack (X360) */
|
||||
case 1: { /* Mindjack (X360), Moon Diver (X360) */
|
||||
int block_size = 0x10000; /* XWAV new default */
|
||||
int block_count = seek_count;
|
||||
data_size = get_streamfile_size(sf) - start_offset;
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_xma2_raw(sf, start_offset, data_size, vgmstream->num_samples, vgmstream->channels, vgmstream->sample_rate, block_size, block_count);
|
||||
vgmstream->codec_data = init_ffmpeg_xma2_raw(sf, start_offset, stream_size, vgmstream->num_samples, vgmstream->channels, vgmstream->sample_rate, block_size, block_count);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
@ -129,9 +139,26 @@ VGMSTREAM* init_vgmstream_sdrh_new(STREAMFILE* sf) {
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
//todo fix loops/samples vs ATRAC3
|
||||
//TODO fix loops/samples vs ATRAC3
|
||||
/* may be only applying end_skip to num_samples? */
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset,data_size, 0, 0,0);
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset, stream_size, 0, 0,0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: { /* Mindjack (PS3) */
|
||||
int block_align, encoder_delay;
|
||||
|
||||
block_align = 0x98 * vgmstream->channels;
|
||||
encoder_delay = 1024 + 69*2; /* observed default, but seems files run out of space */
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_atrac3_raw(sf, start_offset, stream_size, vgmstream->num_samples, vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
/* set offset samples (offset 0 jumps to sample 0 > pre-applied delay, and offset end loops after sample end > adjusted delay) */
|
||||
vgmstream->loop_start_sample = atrac3_bytes_to_samples(loop_start, block_align); //- encoder_delay
|
||||
vgmstream->loop_end_sample = atrac3_bytes_to_samples(loop_end, block_align) - encoder_delay;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@ -153,10 +180,9 @@ fail:
|
||||
/* SDRH - banks for older feelplus-related games [Lost Odyssey (X360), Lost Odyssey Demo (X360)] */
|
||||
VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset, data_size, stream_size;
|
||||
int loop_flag = 0, channels, codec, sample_rate, seek_count;
|
||||
uint32_t start_offset, stream_size;
|
||||
int loop_flag = 0, channels = 0, codec, sample_rate, seek_count;
|
||||
int32_t num_samples, loop_start, loop_end;
|
||||
off_t offset;
|
||||
int total_subsongs, target_subsong = sf->stream_index;
|
||||
|
||||
|
||||
@ -171,19 +197,19 @@ VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
/* similar to older version but LE and a bit more complex */
|
||||
/* 0x04: version/config?
|
||||
* 0x08: data size
|
||||
* 0x30: file name in some strange encoding/compression?
|
||||
* 0x30: file name in a custom 40-char (RADIX style) encoding
|
||||
* others: ? (change in old/new)
|
||||
*/
|
||||
|
||||
/* parse section */
|
||||
{
|
||||
uint32_t offset, base_size, stream_offset, data_size = 0, entry_size = 0;
|
||||
int i;
|
||||
int tables = read_u8(0x15,sf);
|
||||
off_t base_size, stream_offset;
|
||||
int entries;
|
||||
|
||||
offset = 0x40;
|
||||
/* read sections (FE=cues?, WV=mini-headers?, FT=?, FQ=?, XW=waves) */
|
||||
/* read sections (FE=cues?, WV=mini-headers + XW offset, FT=?, FQ=?, XW=waves) */
|
||||
for (i = 0; i < tables; i++) {
|
||||
uint16_t id = read_u16be(0x40 + 0x08 * i + 0x00,sf);
|
||||
/* 0x02: null? */
|
||||
@ -195,7 +221,7 @@ VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
}
|
||||
|
||||
/* section header (other sections have a similar header) */
|
||||
/* 0x00: section size */
|
||||
/* 0x00: section size (including data) */
|
||||
base_size = read_u16le(offset + 0x04,sf);
|
||||
/* 0x06: ? */
|
||||
entries = read_u16le(offset + 0x08,sf);
|
||||
@ -210,39 +236,47 @@ VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
/* find stream header */
|
||||
stream_offset = 0;
|
||||
for (i = 0; i < entries; i++) {
|
||||
size_t data_size = read_u32le(offset + 0x00,sf) - 0x30;
|
||||
size_t seek_size = 0; //read_u16be(offset + 0x0a,sf) * 0x04; /* not seen */
|
||||
size_t entry_size = align_size_to_block(0x30 + seek_size, 0x10);
|
||||
data_size = read_u32le(offset + 0x00,sf);
|
||||
entry_size = read_u16le(offset + 0x04,sf) * 0x10;
|
||||
data_size -= entry_size;
|
||||
|
||||
if (i + 1 == target_subsong)
|
||||
break;
|
||||
offset += entry_size;
|
||||
stream_offset += data_size; /* no offset? */
|
||||
stream_offset += data_size; /* no offset */
|
||||
}
|
||||
|
||||
/* parse target header (similar to xwav) */
|
||||
stream_size = read_u32le(offset + 0x00,sf) - 0x30; /* adds entry size */
|
||||
/* 0x04: codec? (16=PS3, 03=X360) */
|
||||
/* 0x00: data size + entry size */
|
||||
/* 0x04: entry size */
|
||||
codec = read_u8(offset + 0x06,sf); /* assumed */
|
||||
/* 0x07: flag? */
|
||||
/* 0x08: bps? */
|
||||
/* 0x09: codec? */
|
||||
/* 0x0a: null */
|
||||
num_samples = read_u32le(offset + 0x0c,sf);
|
||||
seek_count = read_u16le(offset + 0x10,sf);
|
||||
sample_rate = read_u32le(offset + 0x14,sf);
|
||||
/* 0x0a: null (seek size?) */
|
||||
num_samples = read_u32le(offset + 0x0c,sf); /* XMA1: loop start/end info */
|
||||
|
||||
seek_count = read_u16le(offset + 0x10,sf); /* XMA1: loop start/end bytes? */
|
||||
sample_rate = read_u16le(offset + 0x14,sf);
|
||||
if (entry_size == 0x20) {
|
||||
channels = read_u8(offset + 0x17,sf);
|
||||
}
|
||||
loop_start = 0; //read_u32le(offset + 0x18,sf); /* ? */
|
||||
loop_end = 0; //read_u32le(offset + 0x1c,sf); /* ? */
|
||||
/* 0x20: null */
|
||||
/* 0x24: ? */
|
||||
/* 0x26: channel layout */
|
||||
channels = read_u8(offset + 0x27,sf);
|
||||
/* 0x28: ? */
|
||||
/* 0x2c: null? */
|
||||
|
||||
if (entry_size >= 0x30) {
|
||||
/* 0x20: null */
|
||||
/* 0x24: ? */
|
||||
/* 0x26: channel layout */
|
||||
channels = read_u8(offset + 0x27,sf);
|
||||
/* 0x28: ? */
|
||||
/* 0x2c: null? */
|
||||
}
|
||||
|
||||
loop_flag = loop_end > 0;
|
||||
|
||||
start_offset += stream_offset;
|
||||
stream_size = data_size;
|
||||
}
|
||||
|
||||
|
||||
@ -260,13 +294,8 @@ VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
switch(codec) {
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
case 4: { /* Lost Odyssey (X360) */
|
||||
int block_size = 0x8000; /* XWAV old default */
|
||||
int block_count = seek_count;
|
||||
|
||||
data_size = get_streamfile_size(sf) - start_offset;
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_xma2_raw(sf, start_offset, data_size, vgmstream->num_samples, vgmstream->channels, vgmstream->sample_rate, block_size, block_count);
|
||||
case 1: { /* Lost Odyssey Demo (X360) */
|
||||
vgmstream->codec_data = init_ffmpeg_xma1_raw(sf, start_offset, stream_size, vgmstream->channels, vgmstream->sample_rate, 0);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
@ -274,7 +303,44 @@ VGMSTREAM* init_vgmstream_sdrh_old(STREAMFILE* sf) {
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset, data_size, 0, 0, 1);
|
||||
{
|
||||
ms_sample_data msd = {0};
|
||||
|
||||
msd.xma_version = 1;
|
||||
msd.channels = channels;
|
||||
msd.data_offset = start_offset;
|
||||
msd.data_size = stream_size;
|
||||
msd.loop_flag = loop_flag;
|
||||
msd.loop_start_b= 0; //loop_start_b;
|
||||
msd.loop_end_b = 0; //loop_end_b;
|
||||
msd.loop_start_subframe = 0; //loop_subframe & 0xF; /* lower 4b: subframe where the loop starts, 0..4 */
|
||||
msd.loop_end_subframe = 0; //loop_subframe >> 4; /* upper 4b: subframe where the loop ends, 0..3 */
|
||||
msd.chunk_offset = 0;
|
||||
|
||||
xma_get_samples(&msd, sf);
|
||||
|
||||
vgmstream->num_samples = msd.num_samples;
|
||||
//loop_start_sample = msd.loop_start_sample;
|
||||
//loop_end_sample = msd.loop_end_sample;
|
||||
}
|
||||
|
||||
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset, stream_size, 0, 0, 1);
|
||||
break;
|
||||
}
|
||||
case 4: { /* Lost Odyssey (X360) */
|
||||
int block_size = 0x8000; /* XWAV old default */
|
||||
int block_count = seek_count;
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_xma2_raw(sf, start_offset, stream_size, vgmstream->num_samples, vgmstream->channels, vgmstream->sample_rate, block_size, block_count);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
|
||||
xma_fix_raw_samples(vgmstream, sf, start_offset, stream_size, 0, 0, 1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user