This commit is contained in:
bnnm 2021-06-20 10:54:00 +02:00
parent 5e55e78979
commit 48283a0f8e
5 changed files with 77 additions and 72 deletions

View File

@ -929,7 +929,7 @@ static const meta_info meta_info_list[] = {
{meta_CWAV, "Nintendo CWAV header"},
{meta_FWAV, "Nintendo FWAV header"},
{meta_XA, "Sony XA header"},
{meta_PS2_RXWS, "Sony RXWS header"},
{meta_RXWS, "Sony RXWS header"},
{meta_RAW_INT, "PS2 .int raw header"},
{meta_PS2_OMU, "Alter Echo OMU Header"},
{meta_DSP_STM, "Intelligent Systems STM header"},

View File

@ -79,8 +79,8 @@ VGMSTREAM * init_vgmstream_rwsd(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_xa(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_ps2_rxw(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_rxws(STREAMFILE* sf);
VGMSTREAM * init_vgmstream_rxws_badrip(STREAMFILE* sf);
VGMSTREAM * init_vgmstream_raw_int(STREAMFILE *streamFile);

View File

@ -3,52 +3,53 @@
#include "../coding/coding.h"
/* RXWS - from Sony SCEI PS2 games (Okage: Shadow King, Genji, Bokura no Kazoku) */
VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
STREAMFILE * streamHeader = NULL;
VGMSTREAM* init_vgmstream_rxws(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* sh = NULL;
off_t start_offset, chunk_offset, name_offset = 0;
size_t stream_size, chunk_size;
int loop_flag = 0, channel_count, is_separate = 0, type, sample_rate;
int loop_flag = 0, channels, is_separate = 0, type, sample_rate;
int32_t num_samples, loop_start;
int total_subsongs, target_subsong = streamFile->stream_index;
int total_subsongs, target_subsong = sf->stream_index;
/* checks */
/* .xws: header and data
* .xwh+xwb: header + data (.bin+dat are also found in Wild Arms 4/5) */
if (!check_extensions(streamFile,"xws,xwb"))
if (!check_extensions(sf,"xws,xwb"))
goto fail;
is_separate = check_extensions(streamFile,"xwb");
is_separate = check_extensions(sf,"xwb");
/* xwh+xwb: use xwh as header; otherwise use the current file */
if (is_separate) {
/* extra check to reject Microsoft's XWB faster */
if ((read_32bitBE(0x00,streamFile) == 0x57424E44) || /* "WBND" (LE) */
(read_32bitBE(0x00,streamFile) == 0x444E4257)) /* "DNBW" (BE) */
if (is_id32be(0x00,sf,"WBND") || /* (LE) */
is_id32be(0x00,sf,"DNBW")) /* (BE) */
goto fail;
streamHeader = open_streamfile_by_ext(streamFile, "xwh");
if (!streamHeader) goto fail;
sh = open_streamfile_by_ext(sf, "xwh");
if (!sh) goto fail;
} else {
streamHeader = streamFile;
sh = sf;
}
if (read_32bitBE(0x00,streamHeader) != 0x52585753) /* "RXWS" */
if (!is_id32be(0x00,sh,"RXWS"))
goto fail;
/* file size (just the .xwh/xws) */
if (read_32bitLE(0x04,streamHeader)+0x10 != get_streamfile_size(streamHeader))
if (read_u32le(0x04,sh) + 0x10 != get_streamfile_size(sh))
goto fail;
/* 0x08(4): version (0x100/0x200), 0x0C: null */
/* 0x08: version (0x100/0x200)
* 0x0C: null */
/* typical chunks: FORM, FTXT, MARK, BODY (for .xws) */
if (read_32bitBE(0x10,streamHeader) != 0x464F524D) /* "FORM", main header (always first) */
if (!is_id32be(0x10,sh,"FORM")) /* main header (always first) */
goto fail;
chunk_size = read_32bitLE(0x10+0x04,streamHeader); /* size - 0x10 */
chunk_size = read_u32le(0x10+0x04,sh); /* size - 0x10 */
/* 0x08 version (0x100), 0x0c: null */
chunk_offset = 0x20;
/* check multi-streams */
total_subsongs = read_32bitLE(chunk_offset+0x00,streamHeader);
total_subsongs = read_s32le(chunk_offset+0x00,sh);
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
@ -58,15 +59,18 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
off_t header_offset = chunk_offset + 0x4 + 0x1c * (target_subsong-1); /* position in FORM */
off_t stream_offset, next_stream_offset, data_offset = 0;
type = read_8bit(header_offset+0x00, streamHeader);
/* 0x01(1): unknown (always 0x1c), 0x02(2): flags? (usually 8002/0002, & 0x01 if looped) */
/* 0x04(4): vol/pan stuff? (0x00007F7F), 0x08(1): null?, 0x0c(4): null? */
channel_count = read_8bit(header_offset+0x09, streamHeader);
sample_rate = (uint16_t)read_16bitLE(header_offset+0x0a,streamHeader);
stream_offset = read_32bitLE(header_offset+0x10,streamHeader);
num_samples = read_32bitLE(header_offset+0x14,streamHeader);
loop_start = read_32bitLE(header_offset+0x18,streamHeader);
loop_flag = (loop_start != 0xFFFFFFFF);
type = read_u8(header_offset+0x00, sh);
/* 0x01: unknown (always 0x1c) */
/* 0x02: flags? (usually 8002/0002, & 0x01 if looped) */
/* 0x04: vol/pan stuff? (0x00007F7F) */
/* 0x08: null? */
channels = read_u8(header_offset+0x09, sh);
/* 0x0c: null? */
sample_rate = read_u16le(header_offset+0x0a,sh);
stream_offset = read_u32le(header_offset+0x10,sh);
num_samples = read_s32le(header_offset+0x14,sh);
loop_start = read_s32le(header_offset+0x18,sh);
loop_flag = (loop_start >= 0);
/* find data start and size */
if (is_separate) {
@ -75,21 +79,21 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
else {
off_t current_chunk = 0x10;
/* note the extra 0x10 in chunk_size/offsets */
while (current_chunk < get_streamfile_size(streamFile)) {
if (read_32bitBE(current_chunk,streamFile) == 0x424F4459) { /* "BODY" chunk_type */
while (current_chunk < get_streamfile_size(sf)) {
if (is_id32be(current_chunk,sf, "BODY")) {
data_offset = 0x10 + current_chunk;
break;
}
current_chunk += 0x10 + read_32bitLE(current_chunk+4,streamFile);
current_chunk += 0x10 + read_u32le(current_chunk+4,sf);
}
if (!data_offset) goto fail;
}
if (target_subsong == total_subsongs) {
next_stream_offset = get_streamfile_size(is_separate ? streamFile : streamHeader) - data_offset;
next_stream_offset = get_streamfile_size(is_separate ? sf : sh) - data_offset;
} else {
off_t next_header_offset = chunk_offset + 0x4 + 0x1c * (target_subsong);
next_stream_offset = read_32bitLE(next_header_offset+0x10,streamHeader);
next_stream_offset = read_u32le(next_header_offset+0x10,sh);
}
stream_size = next_stream_offset - stream_offset;
@ -97,24 +101,24 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
}
/* get stream name (always follows FORM) */
if (read_32bitBE(0x10+0x10 + chunk_size,streamHeader) == 0x46545854) { /* "FTXT" */
if (is_id32be(0x10+0x10 + chunk_size,sh, "FTXT")) {
chunk_offset = 0x10+0x10 + chunk_size + 0x10;
if (read_32bitLE(chunk_offset+0x00,streamHeader) == total_subsongs) {
name_offset = chunk_offset + read_32bitLE(chunk_offset+0x04 + (target_subsong-1)*0x04,streamHeader);
if (read_s32le(chunk_offset+0x00,sh) == total_subsongs) {
name_offset = chunk_offset + read_u32le(chunk_offset+0x04 + (target_subsong-1)*0x04,sh);
}
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels,loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_RXWS;
vgmstream->sample_rate = sample_rate;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
vgmstream->meta_type = meta_PS2_RXWS;
if (name_offset)
read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,streamHeader);
read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,sh);
switch (type) {
case 0x00: /* PS-ADPCM */
@ -122,8 +126,8 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
vgmstream->num_samples = ps_bytes_to_samples(num_samples, channel_count);
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channel_count);
vgmstream->num_samples = ps_bytes_to_samples(num_samples, channels);
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels);
vgmstream->loop_end_sample = vgmstream->num_samples;
break;
@ -132,8 +136,8 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x2;
vgmstream->num_samples = pcm_bytes_to_samples(num_samples, channel_count, 16);
vgmstream->loop_start_sample = pcm_bytes_to_samples(loop_start, channel_count, 16);
vgmstream->num_samples = pcm_bytes_to_samples(num_samples, channels, 16);
vgmstream->loop_start_sample = pcm_bytes_to_samples(loop_start, channels, 16);
vgmstream->loop_end_sample = vgmstream->num_samples;
break;
@ -141,11 +145,11 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
case 0x02: { /* ATRAC3 */
int block_align, encoder_delay;
block_align = 0xc0 * channel_count;
block_align = 0xc0 * channels;
encoder_delay = 1024 + 69*2; /* observed default */
vgmstream->num_samples = num_samples - encoder_delay;
vgmstream->codec_data = init_ffmpeg_atrac3_raw(streamFile, start_offset,stream_size, vgmstream->num_samples,vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
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;
@ -160,57 +164,58 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
}
/* open the file for reading */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
if (is_separate && streamHeader) close_streamfile(streamHeader);
if (is_separate && sh) close_streamfile(sh);
return vgmstream;
fail:
if (is_separate && streamHeader) close_streamfile(streamHeader);
if (is_separate && sh) close_streamfile(sh);
close_vgmstream(vgmstream);
return NULL;
}
/* .RXW - legacy fake ext/header for poorly split XWH+XWB files generated by old tools (incorrect header/chunk sizes) */
VGMSTREAM * init_vgmstream_ps2_rxw(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
int loop_flag=0, channel_count;
VGMSTREAM* init_vgmstream_rxws_badrip(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int loop_flag=0, channels;
off_t start_offset;
/* check extension, case insensitive */
if (!check_extensions(streamFile,"rxw")) goto fail;
/* check RXWS/FORM Header */
if (!((read_32bitBE(0x00,streamFile) == 0x52585753) &&
(read_32bitBE(0x10,streamFile) == 0x464F524D)))
if (!check_extensions(sf,"rxw"))
goto fail;
loop_flag = (read_32bitLE(0x3C,streamFile)!=0xFFFFFFFF);
channel_count=2; /* Always stereo files */
/* check RXWS/FORM Header */
if (!((read_32bitBE(0x00,sf) == 0x52585753) &&
(read_32bitBE(0x10,sf) == 0x464F524D)))
goto fail;
loop_flag = (read_32bitLE(0x3C,sf)!=0xFFFFFFFF);
channels=2; /* Always stereo files */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels,loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = read_32bitLE(0x2E,streamFile);
vgmstream->num_samples = (read_32bitLE(0x38,streamFile)*28/16)/2;
vgmstream->sample_rate = read_32bitLE(0x2E,sf);
vgmstream->num_samples = (read_32bitLE(0x38,sf)*28/16)/2;
/* Get loop point values */
if(vgmstream->loop_flag) {
vgmstream->loop_start_sample = read_32bitLE(0x3C,streamFile)/16*14;
vgmstream->loop_end_sample = read_32bitLE(0x38,streamFile)/16*14;
vgmstream->loop_start_sample = read_32bitLE(0x3C,sf)/16*14;
vgmstream->loop_end_sample = read_32bitLE(0x38,sf)/16*14;
}
vgmstream->interleave_block_size = read_32bitLE(0x1c,streamFile)+0x10;
vgmstream->interleave_block_size = read_32bitLE(0x1c,sf)+0x10;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_PS2_RXWS;
vgmstream->meta_type = meta_RXWS;
start_offset = 0x40;
/* open the file for reading */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;

View File

@ -44,8 +44,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_nps,
init_vgmstream_rwsd,
init_vgmstream_xa,
init_vgmstream_ps2_rxws,
init_vgmstream_ps2_rxw,
init_vgmstream_rxws,
init_vgmstream_ngc_dsp_stm,
init_vgmstream_exst,
init_vgmstream_svag_kcet,
@ -262,7 +261,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_sqex_scd,
init_vgmstream_ngc_nst_dsp,
init_vgmstream_baf,
init_vgmstream_baf_badrip,
init_vgmstream_msf,
init_vgmstream_ps3_past,
init_vgmstream_sgxd,
@ -539,6 +537,8 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_s14_sss, /* .s14/sss raw siren14 */
init_vgmstream_raw_al, /* .al/al2 raw A-LAW */
init_vgmstream_zwdsp, /* fake format */
init_vgmstream_baf_badrip, /* crap, to be removed */
init_vgmstream_rxws_badrip, /* crap, to be removed */
#ifdef VGM_USE_FFMPEG
init_vgmstream_ffmpeg, /* may play anything incorrectly, since FFmpeg doesn't check extensions */
#endif

View File

@ -359,7 +359,7 @@ typedef enum {
meta_XA, /* CD-ROM XA */
meta_PS2_SShd, /* .ADS with SShd header */
meta_NPS,
meta_PS2_RXWS, /* Sony games (Genji, Okage Shadow King, Arc The Lad Twilight of Spirits) */
meta_RXWS,
meta_RAW_INT,
meta_EXST,
meta_SVAG_KCET,