mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 15:00:11 +01:00
Merge branch 'master' of https://github.com/kode54/vgmstream into psf-etc
This commit is contained in:
commit
272aa78d45
@ -338,8 +338,8 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
|
||||
num_metas = read_16bitBE(entry_offset + 0x04, streamFile);
|
||||
metas_offset = read_32bitBE(entry_offset + 0x06, streamFile);
|
||||
|
||||
snr_offset = 0xFFFFFFFF;
|
||||
sns_offset = 0xFFFFFFFF;
|
||||
snr_offset = 0;
|
||||
sns_offset = 0;
|
||||
|
||||
for (i = 0; i < num_metas; i++) {
|
||||
entry_offset = metas_offset + 0x06 * i;
|
||||
@ -360,10 +360,10 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
|
||||
}
|
||||
}
|
||||
|
||||
if (snr_offset == 0xFFFFFFFF && sns_offset == 0xFFFFFFFF)
|
||||
if (snr_offset == 0 && sns_offset == 0)
|
||||
goto fail;
|
||||
|
||||
if (snr_offset == 0xFFFFFFFF) {
|
||||
if (snr_offset == 0) {
|
||||
/* SPS file */
|
||||
sbsFile = open_streamfile_by_ext(streamFile, "sbs");
|
||||
if (!sbsFile)
|
||||
@ -375,10 +375,10 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
|
||||
snr_offset = sns_offset;
|
||||
sns_offset = snr_offset + (read_32bitBE(snr_offset, sbsFile) & 0x00FFFFFF);
|
||||
snr_offset += 0x04;
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(sbsFile, sbsFile, snr_offset, sns_offset, meta_EA_SNR_SNS);
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(sbsFile, sbsFile, snr_offset, sns_offset, meta_EA_SPS);
|
||||
if (!vgmstream)
|
||||
goto fail;
|
||||
} else if (sns_offset == 0xFFFFFFFF) {
|
||||
} else if (sns_offset == 0) {
|
||||
/* RAM asset */
|
||||
sns_offset = snr_offset + get_snr_size(streamFile, snr_offset);
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(streamFile, streamFile, snr_offset, sns_offset, meta_EA_SNR_SNS);
|
||||
@ -410,12 +410,12 @@ fail:
|
||||
/* EA HDR/STH/DAT - seen in older 7th gen games, used for storing speech */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint32_t i;
|
||||
uint8_t userdata_size, total_sounds, block_id;
|
||||
off_t snr_offset, sns_offset;
|
||||
size_t file_size, block_size;
|
||||
off_t snr_offset, sns_offset, sth_offset, sth_offset2;
|
||||
size_t dat_size, block_size;
|
||||
STREAMFILE *datFile = NULL, *sthFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
int32_t(*read_32bit)(off_t, STREAMFILE*);
|
||||
|
||||
/* 0x00: ID */
|
||||
/* 0x02: userdata size */
|
||||
@ -423,10 +423,20 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
/* 0x04: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x08: alt number of files? */
|
||||
/* 0x09: zero */
|
||||
/* 0x0A: ??? */
|
||||
/* 0x0A: related to size? */
|
||||
/* 0x0C: zero */
|
||||
/* 0x10: table start */
|
||||
|
||||
if (read_8bit(0x09, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
if (read_32bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x10, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
sthFile = open_streamfile_by_ext(streamFile, "sth");
|
||||
if (!sthFile)
|
||||
goto fail;
|
||||
@ -436,7 +446,7 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
/* STH always starts with the first offset of zero */
|
||||
sns_offset = read_32bitLE(0x00, sthFile);
|
||||
sns_offset = read_32bitBE(0x00, sthFile);
|
||||
if (sns_offset != 0)
|
||||
goto fail;
|
||||
|
||||
@ -447,6 +457,7 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
|
||||
userdata_size = read_8bit(0x02, streamFile);
|
||||
total_sounds = read_8bit(0x03, streamFile);
|
||||
|
||||
if (read_8bit(0x08, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
@ -455,23 +466,25 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
/* offsets in HDR are always big endian */
|
||||
//snr_offset = (off_t)read_16bitBE(0x10 + (0x02+userdata_size) * (target_stream-1), streamFile) + 0x04;
|
||||
//sns_offset = read_32bit(snr_offset, sthFile);
|
||||
sth_offset = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * (target_stream - 1), streamFile);
|
||||
|
||||
#if 0
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = read_32bit(sth_offset + 0x00, sthFile);
|
||||
#else
|
||||
/* we can't reliably detect byte endianness so we're going to find the sound the hacky way */
|
||||
/* go through blocks until we reach the goal sound */
|
||||
file_size = get_streamfile_size(datFile);
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
snr_offset = 0;
|
||||
sns_offset = 0;
|
||||
|
||||
for (i = 0; i < total_sounds; i++) {
|
||||
snr_offset = (uint16_t)read_16bitBE(0x10 + (0x02+userdata_size) * i, streamFile) + 0x04;
|
||||
|
||||
if (i == target_stream - 1)
|
||||
break;
|
||||
|
||||
if (total_sounds == 1) {
|
||||
/* always 0 */
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = 0x00;
|
||||
} else {
|
||||
/* find the first sound size and match it up with the second sound offset to detect endianness */
|
||||
while (1) {
|
||||
if (sns_offset >= file_size)
|
||||
if (sns_offset >= dat_size)
|
||||
goto fail;
|
||||
|
||||
block_id = read_8bit(sns_offset, datFile);
|
||||
@ -487,8 +500,21 @@ VGMSTREAM * init_vgmstream_ea_hdr_sth_dat(STREAMFILE *streamFile) {
|
||||
if (block_id == EAAC_BLOCKID0_END)
|
||||
break;
|
||||
}
|
||||
|
||||
sth_offset2 = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * 1, streamFile);
|
||||
if (sns_offset == read_32bitBE(sth_offset2, sthFile)) {
|
||||
read_32bit = read_32bitBE;
|
||||
} else if (sns_offset == read_32bitLE(sth_offset2, sthFile)) {
|
||||
read_32bit = read_32bitLE;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
snr_offset = sth_offset + 0x04;
|
||||
sns_offset = read_32bit(sth_offset + 0x00, sthFile);
|
||||
}
|
||||
#endif
|
||||
|
||||
block_id = read_8bit(sns_offset, datFile);
|
||||
if (block_id != EAAC_BLOCKID0_DATA && block_id != EAAC_BLOCKID0_END)
|
||||
goto fail;
|
||||
@ -671,7 +697,7 @@ VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
|
||||
total_sounds = 0;
|
||||
sound_offset = 0xFFFFFFFF;
|
||||
sound_offset = 0;
|
||||
|
||||
/* The bank is split into DSET sections each of which references one or multiple sounds. */
|
||||
/* Each set can contain RAM sounds (stored in SBR in data section) or streamed sounds (stored separately in SBS file). */
|
||||
@ -761,7 +787,7 @@ VGMSTREAM * init_vgmstream_ea_sbr_harmony(STREAMFILE *streamFile) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sound_offset == 0xFFFFFFFF)
|
||||
if (sound_offset == 0)
|
||||
goto fail;
|
||||
|
||||
if (!is_streamed) {
|
||||
|
@ -458,26 +458,35 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* EA HDR/DAT combo - seen in late 6th-gen games, used for storing speech and other streamed sounds (except for music) */
|
||||
/* EA HDR/DAT v1 (2004-2005) - used for storing speech and other streamed sounds (except for music) */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint8_t userdata_size, total_sounds;
|
||||
size_t dat_size;
|
||||
off_t schl_offset, offset_mult;
|
||||
STREAMFILE *datFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
|
||||
/* main header's endianness is platform-native but we only care about one byte values */
|
||||
/* main header is machine endian but it's not important here */
|
||||
/* 0x00: ID */
|
||||
/* 0x02: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x04: (low nibble) userdata size */
|
||||
/* 0x04: (high nibble) ??? */
|
||||
/* 0x05: number of files */
|
||||
/* 0x06: ??? */
|
||||
/* 0x06: alt number of files? */
|
||||
/* 0x07: offset multiplier flag */
|
||||
/* 0x08: combined size of all sounds without padding divided by offset mult */
|
||||
/* 0x0C: table start */
|
||||
/* 0x0a: zero */
|
||||
/* 0x0c: table start */
|
||||
|
||||
/* no nice way to validate these so we do what we can */
|
||||
if (read_16bitBE(0x0a, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* must be accompanied by DAT file with SCHl sounds */
|
||||
datFile = open_streamfile_by_ext(streamFile, "dat");
|
||||
if (!datFile)
|
||||
@ -490,12 +499,90 @@ VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE *streamFile) {
|
||||
total_sounds = read_8bit(0x05, streamFile);
|
||||
offset_mult = (uint8_t)read_8bit(0x07, streamFile) * 0x0100 + 0x0100;
|
||||
|
||||
if (read_8bit(0x06, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
if ((uint16_t)read_16bitLE(0x08, streamFile) * offset_mult > dat_size &&
|
||||
(uint16_t)read_16bitBE(0x08, streamFile) * offset_mult > dat_size)
|
||||
goto fail;
|
||||
|
||||
if (target_stream == 0) target_stream = 1;
|
||||
if (target_stream < 0 || total_sounds == 0 || target_stream > total_sounds)
|
||||
goto fail;
|
||||
|
||||
/* offsets are always big endian */
|
||||
schl_offset = (uint16_t)read_16bitBE(0x0C + (0x02+userdata_size) * (target_stream-1), streamFile) * offset_mult;
|
||||
schl_offset = (uint16_t)read_16bitBE(0x0C + (0x02 + userdata_size) * (target_stream - 1), streamFile) * offset_mult;
|
||||
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
vgmstream = parse_schl_block(datFile, schl_offset, 0);
|
||||
if (!vgmstream)
|
||||
goto fail;
|
||||
|
||||
vgmstream->num_streams = total_sounds;
|
||||
close_streamfile(datFile);
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_streamfile(datFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* EA HDR/DAT v2 (2006-2014) */
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat_v2(STREAMFILE *streamFile) {
|
||||
int target_stream = streamFile->stream_index;
|
||||
uint8_t userdata_size, total_sounds;
|
||||
size_t dat_size;
|
||||
off_t schl_offset, offset_mult;
|
||||
STREAMFILE *datFile = NULL;
|
||||
VGMSTREAM *vgmstream;
|
||||
|
||||
/* main header is machine endian but it's not important here */
|
||||
/* 0x00: ID */
|
||||
/* 0x02: userdata size */
|
||||
/* 0x03: number of files */
|
||||
/* 0x04: sub-ID (used for different police voices in NFS games) */
|
||||
/* 0x08: alt number of files? */
|
||||
/* 0x09: offset mult */
|
||||
/* 0x0a: DAT size divided by offset mult */
|
||||
/* 0x0c: zero */
|
||||
/* 0x10: table start */
|
||||
|
||||
/* no nice way to validate these so we do what we can */
|
||||
if (read_32bitBE(0x0c, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* first offset is always zero */
|
||||
if (read_16bitBE(0x10, streamFile) != 0)
|
||||
goto fail;
|
||||
|
||||
/* must be accompanied by DAT file with SCHl sounds */
|
||||
datFile = open_streamfile_by_ext(streamFile, "dat");
|
||||
if (!datFile)
|
||||
goto fail;
|
||||
|
||||
if (read_32bitBE(0x00, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
userdata_size = read_8bit(0x02, streamFile);
|
||||
total_sounds = read_8bit(0x03, streamFile);
|
||||
offset_mult = (uint8_t)read_8bit(0x09, streamFile) * 0x0100 + 0x0100;
|
||||
|
||||
if (read_8bit(0x08, streamFile) > total_sounds)
|
||||
goto fail;
|
||||
|
||||
dat_size = get_streamfile_size(datFile);
|
||||
if ((uint16_t)read_16bitLE(0x0a, streamFile) * offset_mult != dat_size &&
|
||||
(uint16_t)read_16bitBE(0x0a, streamFile) * offset_mult != dat_size)
|
||||
goto fail;
|
||||
|
||||
if (target_stream == 0) target_stream = 1;
|
||||
if (target_stream < 0 || total_sounds == 0 || target_stream > total_sounds)
|
||||
goto fail;
|
||||
|
||||
/* offsets are always big endian */
|
||||
schl_offset = (uint16_t)read_16bitBE(0x10 + (0x02 + userdata_size) * (target_stream - 1), streamFile) * offset_mult;
|
||||
if (read_32bitBE(schl_offset, datFile) != EA_BLOCKID_HEADER)
|
||||
goto fail;
|
||||
|
||||
|
@ -626,6 +626,7 @@ VGMSTREAM * init_vgmstream_ea_schl_video(STREAMFILE *streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_hdr_dat_v2(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_map_mus(STREAMFILE * steeamFile);
|
||||
VGMSTREAM * init_vgmstream_ea_mpf_mus(STREAMFILE * steeamFile);
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
static size_t joe_find_padding(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave);
|
||||
|
||||
/* .JOE - from Asobo Studio games [Up (PS2), Wall-E (PS2)] */
|
||||
VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int channel_count, loop_flag, sample_rate;
|
||||
int32_t num_samples, loop_start = 0, loop_end = 0;
|
||||
size_t file_size, data_size, unknown1, unknown2, interleave;
|
||||
size_t file_size, data_size, unknown1, unknown2, interleave, padding_size;
|
||||
|
||||
|
||||
/* checks */
|
||||
@ -20,44 +22,43 @@ VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
|
||||
unknown2 = read_32bitLE(0x0c,streamFile);
|
||||
|
||||
/* detect version */
|
||||
if (data_size/2 == file_size - 0x10
|
||||
if (data_size / 2 == file_size - 0x10
|
||||
&& unknown1 == 0x0045039A && unknown2 == 0x00108920) { /* Super Farm (PS2) */
|
||||
data_size = data_size / 2;
|
||||
interleave = 0x4000;
|
||||
start_offset = 0x10;
|
||||
}
|
||||
else if (data_size/2 == file_size - 0x10
|
||||
} else if (data_size / 2 == file_size - 0x10
|
||||
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* Sitting Ducks (PS2) */
|
||||
data_size = data_size / 2;
|
||||
interleave = 0x8000;
|
||||
start_offset = 0x10;
|
||||
}
|
||||
else if (data_size == file_size - 0x10
|
||||
} else if (data_size == file_size - 0x10
|
||||
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* The Mummy: The Animated Series (PS2) */
|
||||
interleave = 0x8000;
|
||||
start_offset = 0x10;
|
||||
}
|
||||
else if (data_size == file_size - 0x4020) { /* CT Special Forces (PS2), and all games beyond */
|
||||
} else if (data_size == file_size - 0x4020) { /* CT Special Forces (PS2), and all games beyond */
|
||||
interleave = unknown1; /* always 0? */
|
||||
if (!interleave)
|
||||
interleave = 0x10;
|
||||
start_offset = 0x4020; /* header padding contains garbage */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
//start_offset = file_size - data_size; /* also ok */
|
||||
channel_count = 2;
|
||||
loop_flag = 0;
|
||||
sample_rate = read_32bitLE(0x00,streamFile);
|
||||
|
||||
/* the file's end is padded with either 0xcdcdcdcd or zeroes */
|
||||
padding_size = joe_find_padding(streamFile, start_offset, data_size, channel_count, interleave);
|
||||
if (padding_size == SIZE_MAX)
|
||||
goto fail;
|
||||
|
||||
data_size -= padding_size;
|
||||
num_samples = ps_bytes_to_samples(data_size, channel_count);
|
||||
|
||||
|
||||
loop_flag = ps_find_loop_offsets(streamFile, start_offset, data_size, channel_count, interleave,&loop_start, &loop_end);
|
||||
/* most songs simply repeat except a few jingles (PS-ADPCM flags are always set) */
|
||||
loop_flag = loop_flag && (num_samples > 20*sample_rate); /* in seconds */
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
@ -66,6 +67,7 @@ VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
|
||||
vgmstream->num_samples = num_samples;
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
vgmstream->stream_size = data_size;
|
||||
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
@ -80,3 +82,38 @@ fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t joe_find_padding(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave) {
|
||||
uint8_t flag;
|
||||
off_t min_offset, offset;
|
||||
size_t frame_size = 0x10;
|
||||
size_t padding_size = 0;
|
||||
size_t interleave_consumed = 0;
|
||||
|
||||
if (data_size == 0 || channels == 0 || (channels > 0 && interleave == 0))
|
||||
return SIZE_MAX;
|
||||
|
||||
offset = start_offset + data_size - interleave * (channels - 1);
|
||||
min_offset = start_offset;
|
||||
|
||||
while (offset > min_offset) {
|
||||
offset -= frame_size;
|
||||
flag = read_8bit(offset + 0x01, streamFile);
|
||||
if (flag == 0x03)
|
||||
break;
|
||||
|
||||
padding_size += frame_size * channels;
|
||||
|
||||
/* skip other channels */
|
||||
interleave_consumed += 0x10;
|
||||
if (interleave_consumed == interleave) {
|
||||
interleave_consumed = 0;
|
||||
offset -= interleave * (channels - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (padding_size >= data_size)
|
||||
return SIZE_MAX;
|
||||
|
||||
return padding_size;
|
||||
}
|
||||
|
@ -333,6 +333,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
|
||||
init_vgmstream_ea_bnk,
|
||||
init_vgmstream_ea_abk,
|
||||
init_vgmstream_ea_hdr_dat,
|
||||
init_vgmstream_ea_hdr_dat_v2,
|
||||
init_vgmstream_ea_map_mus,
|
||||
init_vgmstream_ea_mpf_mus,
|
||||
init_vgmstream_ea_schl_fixed,
|
||||
|
Loading…
Reference in New Issue
Block a user