From ee2739f996410d912670724d9ee6323316634dea Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 31 Oct 2021 20:12:57 +0100 Subject: [PATCH] Improve FSB4 MPEG full loops [Deadpool (PS3)] --- src/coding/mpeg_custom_utils.c | 6 ++++-- src/coding/mpeg_decoder.c | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/coding/mpeg_custom_utils.c b/src/coding/mpeg_custom_utils.c index f3cb4508..4a91fa66 100644 --- a/src/coding/mpeg_custom_utils.c +++ b/src/coding/mpeg_custom_utils.c @@ -87,8 +87,10 @@ int mpeg_custom_setup_init_default(STREAMFILE* sf, off_t start_offset, mpeg_code //case MPEG_P3D: data->skip_samples = info.frame_samples; break; /* matches Radical ADPCM (PC) output */ /* FSBs (with FMOD DLLs) don't seem to need it. Particularly a few games (all from Wayforward?) - * contain audible garbage at the beginning, but it's actually there in-game too */ - //case MPEG_FSB: data->skip_samples = 0; break; + * contain audible garbage at the beginning, but it's actually there in-game too. + * Games doing full loops also must not have delay (reuses mpeg state on loop) */ + case MPEG_FSB: + data->skip_samples = 0; break; case MPEG_XVAG: /* set in header and needed for gapless looping */ data->skip_samples = data->config.skip_samples; break; diff --git a/src/coding/mpeg_decoder.c b/src/coding/mpeg_decoder.c index d73ae220..f083a0ff 100644 --- a/src/coding/mpeg_decoder.c +++ b/src/coding/mpeg_decoder.c @@ -481,6 +481,8 @@ decode_fail: /* UTILS */ /*********/ +static void flush_mpeg(mpeg_codec_data* data, int is_loop); + void free_mpeg(mpeg_codec_data* data) { if (!data) return; @@ -513,7 +515,7 @@ void free_mpeg(mpeg_codec_data* data) { void reset_mpeg(mpeg_codec_data* data) { if (!data) return; - flush_mpeg(data); + flush_mpeg(data, 0); #if 0 /* flush_mpeg properly resets mpg123 with mpg123_open_feed, and @@ -550,7 +552,7 @@ void seek_mpeg(VGMSTREAM* vgmstream, int32_t num_sample) { else { int i; - flush_mpeg(data); + flush_mpeg(data, 1); /* restart from 0 and manually discard samples, since we don't really know the correct offset */ for (i = 0; i < data->streams_size; i++) { @@ -566,7 +568,7 @@ void seek_mpeg(VGMSTREAM* vgmstream, int32_t num_sample) { } /* resets mpg123 decoder and its internals without seeking, useful when a new MPEG substream starts */ -void flush_mpeg(mpeg_codec_data* data) { +static void flush_mpeg(mpeg_codec_data* data, int is_loop) { if (!data) return; @@ -578,7 +580,10 @@ void flush_mpeg(mpeg_codec_data* data) { int i; /* re-start from 0 */ for (i=0; i < data->streams_size; i++) { - mpg123_open_feed(data->streams[i]->m); + /* On loop FSB retains MDCT state so it mixes with next/loop frame (confirmed with recordings). + * This only matters on full loops and if there is no encoder delay (since loops use discard right now) */ + if (is_loop && data->custom && !(data->type == MPEG_FSB)) + mpg123_open_feed(data->streams[i]->m); data->streams[i]->bytes_in_buffer = 0; data->streams[i]->buffer_full = 0; data->streams[i]->buffer_used = 0;