From 894df45850ed6910997f1ad26dc0deab3ca207c0 Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 23 Apr 2020 17:42:57 +0200 Subject: [PATCH] Fix interleave bug in mono --- src/meta/wwise.c | 9 +++++++-- src/vgmstream.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/meta/wwise.c b/src/meta/wwise.c index f7ea4fb0..983e922e 100644 --- a/src/meta/wwise.c +++ b/src/meta/wwise.c @@ -435,7 +435,6 @@ VGMSTREAM * init_vgmstream_wwise(STREAMFILE* sf) { case DSP: { /* Wii/3DS/WiiU */ off_t wiih_offset; size_t wiih_size; - int i; //if (ww.fmt_size != 0x28 && ww.fmt_size != ?) goto fail; /* old, new */ if (ww.bits_per_sample != 4) goto fail; @@ -711,10 +710,16 @@ static int is_dsp_full_interleave(STREAMFILE* sf, wwise_header* ww, off_t coef_o if (ww->truncated) return 0; + if (ww->channels == 1) + return 0; + if (check_extensions(sf,"bnk")) return 1; - if (ww->channels == 2 && ww->data_size <= 0x30000) { + if (ww->data_size > 0x30000) + return 0; + + { uint16_t head_ps2 = read_u16be(coef_offset + 1 * 0x2e + 0x22, sf); /* ch2's initial predictor */ uint16_t init_ps2 = read_u8(ww->data_offset + 0x08, sf); /* at normal interleave */ uint16_t half_ps2 = read_u8(ww->data_offset + ww->data_size / 2, sf); /* at full interleave */ diff --git a/src/vgmstream.c b/src/vgmstream.c index 8e236b5f..325ff591 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -2890,6 +2890,25 @@ int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t s vgmstream->frame_size = vgmstream->interleave_block_size; } + /* big interleaved values for non-interleaved data may result in incorrect behavior, + * quick fix for now since layouts are finicky, with 'interleave' left for meta info + * (certain layouts+codecs combos results in funny output too, should rework the whole thing) */ + if (vgmstream->layout_type == layout_interleave + && vgmstream->channels == 1 + && vgmstream->interleave_block_size > 0) { + /* main codecs that use arbitrary interleaves but could happen for others too */ + switch(vgmstream->coding_type) { + case coding_NGC_DSP: + case coding_NGC_DSP_subint: + case coding_PSX: + case coding_PSX_badflags: + vgmstream->interleave_block_size = 0; + break; + default: + break; + } + } + /* if interleave is big enough keep a buffer per channel */ if (vgmstream->interleave_block_size * vgmstream->channels >= STREAMFILE_DEFAULT_BUFFER_SIZE) { use_streamfile_per_channel = 1;