From b67837c0ef6550fd4354b9cb8beed7c54c896839 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 9 Jan 2024 22:08:57 +0100 Subject: [PATCH] cellMusicDecode: fix random pop at the end of a stream Observed in SSX, which seems to ignore the readSize sometimes --- rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp b/rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp index 0ae0cd80b4..0880a5db3e 100644 --- a/rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp @@ -227,6 +227,12 @@ error_code cell_music_decode_read(vm::ptr buf, vm::ptr startTime, u64 std::memcpy(buf.get_ptr(), &dec.decoder.data[dec.read_pos], size_to_read); + if (size_to_read < reqSize) + { + // Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize. + std::memset(vm::static_ptr_cast(buf).get_ptr() + size_to_read, 0, reqSize - size_to_read); + } + dec.read_pos += size_to_read; s64 start_time_ms = 0;