Merge branch 'master' of https://github.com/kode54/vgmstream into mix-etc

This commit is contained in:
bnnm 2019-03-23 22:49:19 +01:00
commit da4b31c0d3
3 changed files with 78 additions and 41 deletions

View File

@ -314,7 +314,7 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
uint32_t i, num_sounds, type_desc;
uint16_t num_metas, meta_type;
off_t table_offset, types_offset, entry_offset, metas_offset, data_offset, snr_offset, sns_offset;
STREAMFILE *sbsFile = NULL, *streamData = NULL;
STREAMFILE *sbsFile = NULL;
VGMSTREAM *vgmstream = NULL;
int target_stream = streamFile->stream_index;
@ -359,13 +359,30 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
}
}
if (snr_offset == 0xFFFFFFFF)
if (snr_offset == 0xFFFFFFFF && sns_offset == 0xFFFFFFFF)
goto fail;
if (sns_offset == 0xFFFFFFFF) {
if (snr_offset == 0xFFFFFFFF) {
/* SPS file */
sbsFile = open_streamfile_by_ext(streamFile, "sbs");
if (!sbsFile)
goto fail;
if (read_32bitBE(0x00, sbsFile) != 0x53424B53) /* "SBKS" */
goto fail;
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);
if (!vgmstream)
goto fail;
} else if (sns_offset == 0xFFFFFFFF) {
/* RAM asset */
streamData = streamFile;
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);
if (!vgmstream)
goto fail;
} else {
/* streamed asset */
sbsFile = open_streamfile_by_ext(streamFile, "sbs");
@ -375,12 +392,10 @@ VGMSTREAM * init_vgmstream_ea_sbr(STREAMFILE *streamFile) {
if (read_32bitBE(0x00, sbsFile) != 0x53424B53) /* "SBKS" */
goto fail;
streamData = sbsFile;
}
vgmstream = init_vgmstream_eaaudiocore_header(streamFile, streamData, snr_offset, sns_offset, meta_EA_SNR_SNS);
vgmstream = init_vgmstream_eaaudiocore_header(streamFile, sbsFile, snr_offset, sns_offset, meta_EA_SNR_SNS);
if (!vgmstream)
goto fail;
}
vgmstream->num_streams = num_sounds;
close_streamfile(sbsFile);

View File

@ -377,7 +377,7 @@ VGMSTREAM * init_vgmstream_ea_abk(STREAMFILE *streamFile) {
if (!bnk_offset)
goto fail;
bnk_target_stream = read_32bit(target_entry_offset + 0x04, streamFile) + 1;
bnk_target_stream = read_32bit(target_entry_offset + 0x04, streamFile);
vgmstream = parse_bnk_header(streamFile, bnk_offset, bnk_target_stream, 1);
if (!vgmstream)
goto fail;
@ -873,7 +873,7 @@ static VGMSTREAM * parse_bnk_header(STREAMFILE *streamFile, off_t offset, int ta
goto fail;
entry_offset = offset + table_offset + 0x04 * target_stream;
header_offset = entry_offset + read_32bit(offset + entry_offset, streamFile);
header_offset = entry_offset + read_32bit(entry_offset, streamFile);
} else {
/* some of these are dummies with zero offset, skip them when opening standalone BNK */
for (i = 0; i < num_sounds; i++) {

View File

@ -4,10 +4,10 @@
VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
int loop_flag, channel_count;
int8_t version;
int8_t version, num_layers, codec_id;
int32_t loop_length, coef_start_offset, coef_spacing;
off_t start_offset;
int8_t channelMultiplier;
size_t data_size, skip = 0;
if (!check_extensions(streamFile, "kns,ktss"))
goto fail;
@ -15,6 +15,33 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
if (read_32bitBE(0, streamFile) != 0x4B545353) /* "KTSS" */
goto fail;
codec_id = read_8bit(0x20, streamFile);
loop_length = read_32bitLE(0x38, streamFile);
loop_flag = loop_length > 0;
// A layered stream/track model seems to be used in Hyrule Warriors (Switch).
// It's also present in other Koei Tecmo KNS but the channel count was always
// explicitly defined in the 0x29 byte and the number of layers was set to 1.
// Here, 10 channel files are set up with 2 channels in 5 layers.
// Super hacky on KT's part and ours to implement but it works.
num_layers = read_8bit(0x28, streamFile);
channel_count = read_8bit(0x29, streamFile) * num_layers;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = read_32bitLE(0x30, streamFile);
vgmstream->sample_rate = read_32bitLE(0x2c, streamFile);
vgmstream->loop_start_sample = read_32bitLE(0x34, streamFile);
vgmstream->loop_end_sample = vgmstream->loop_start_sample + loop_length;
vgmstream->meta_type = meta_KTSS;
start_offset = read_32bitLE(0x24, streamFile) + 0x20;
switch (codec_id) {
case 0x2: /* DSP ADPCM - Hyrule Warriors, Fire Emblem Warriors, and other Koei Tecmo games */
/* check type details */
version = read_8bit(0x22, streamFile);
if (version == 1) {
@ -28,36 +55,31 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
else
goto fail;
loop_length = read_32bitLE(0x38, streamFile);
loop_flag = loop_length > 0;
// For unknown reasons, a channel multiplier is necessary in Hyrule Warriors (Switch)
// It seems to be present in other Koei Tecmo KNS but the channel count was always
// explicitly defined in the 0x29 byte. Here, 10 channel files have '2' in 0x29*
// and '5' in 0x28 whereas previous titles usually contained '1'
// This is super meh on KT's part but whatever
channelMultiplier = read_8bit(0x28, streamFile);
channel_count = read_8bit(0x29, streamFile) * channelMultiplier;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = read_32bitLE(0x30, streamFile);
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x2c, streamFile);
vgmstream->loop_start_sample = read_32bitLE(0x34, streamFile);
vgmstream->loop_end_sample = vgmstream->loop_start_sample + loop_length;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_KTSS;
vgmstream->interleave_block_size = 0x8;
dsp_read_coefs_le(vgmstream, streamFile, coef_start_offset, coef_spacing);
start_offset = read_32bitLE(0x24, streamFile) + 0x20;
break;
#ifdef VGM_USE_FFMPEG
case 0x9: /* Opus - Dead or Alive Xtreme 3: Scarlet */
data_size = read_32bitLE(0x44, streamFile);
{
vgmstream->codec_data = init_ffmpeg_switch_opus(streamFile, start_offset, data_size, vgmstream->channels, skip, vgmstream->sample_rate);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
if (vgmstream->num_samples == 0) {
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, streamFile) - skip;
}
}
break;
default:
goto fail;
#endif
}
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;