From 463fc3c792dfbcbe2d5704a1751668b87ebfa02e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 25 Jan 2021 23:51:55 -0800 Subject: [PATCH] Mp3: Allow decode without pcm pointer. Just like other audio decoding, you're allowed to skip audio. Also prevents a crash if the mp3 is not yet inited. --- Core/HLE/sceMp3.cpp | 14 ++++++++------ Core/HW/SimpleAudioDec.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Core/HLE/sceMp3.cpp b/Core/HLE/sceMp3.cpp index 0f4fb8a4b0..3c48549776 100644 --- a/Core/HLE/sceMp3.cpp +++ b/Core/HLE/sceMp3.cpp @@ -159,19 +159,21 @@ void __Mp3DoState(PointerWrap &p) { } static int sceMp3Decode(u32 mp3, u32 outPcmPtr) { - DEBUG_LOG(ME, "sceMp3Decode(%08x,%08x)", mp3, outPcmPtr); - AuCtx *ctx = getMp3Ctx(mp3); if (!ctx) { - ERROR_LOG(ME, "%s: bad mp3 handle %08x", __FUNCTION__, mp3); - return -1; + if (mp3 >= MP3_MAX_HANDLES) + return hleLogError(ME, ERROR_MP3_INVALID_HANDLE, "invalid handle"); + return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "unreserved handle"); + } else if (ctx->Version < 0 || ctx->AuBuf == 0) { + return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "not yet init"); } int pcmBytes = ctx->AuDecode(outPcmPtr); if (pcmBytes > 0) { // decode data successfully, delay thread - return hleDelayResult(pcmBytes, "mp3 decode", mp3DecodeDelay); + return hleDelayResult(hleLogSuccessI(ME, pcmBytes), "mp3 decode", mp3DecodeDelay); } + // Should already have logged. return pcmBytes; } @@ -719,7 +721,7 @@ const HLEFunction sceMp3[] = { {0X8AB81558, &WrapU_V, "sceMp3StartEntry", 'x', "" }, {0X8F450998, &WrapI_U, "sceMp3GetSamplingRate", 'i', "x" }, {0XA703FE0F, &WrapI_UUUU, "sceMp3GetInfoToAddStreamData", 'i', "xppp" }, - {0XD021C0FB, &WrapI_UU, "sceMp3Decode", 'i', "xx" }, + {0XD021C0FB, &WrapI_UU, "sceMp3Decode", 'i', "xp" }, {0XD0A56296, &WrapI_U, "sceMp3CheckStreamDataNeeded", 'i', "x" }, {0XD8F54A51, &WrapI_U, "sceMp3GetLoopNum", 'i', "x" }, {0XF5478233, &WrapI_U, "sceMp3ReleaseMp3Handle", 'i', "x" }, diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 10159d7daa..2e9ac873d4 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -327,9 +327,8 @@ size_t AuCtx::FindNextMp3Sync() { // return output pcm size, <0 error u32 AuCtx::AuDecode(u32 pcmAddr) { - if (!Memory::IsValidAddress(pcmAddr)){ - ERROR_LOG(ME, "%s: output bufferAddress %08x is invalctx", __FUNCTION__, pcmAddr); - return -1; + if (!Memory::GetPointer(PCMBuf)) { + return hleLogError(ME, -1, "ctx output bufferAddress %08x is invalid", PCMBuf); } auto outbuf = Memory::GetPointer(PCMBuf); @@ -376,7 +375,8 @@ u32 AuCtx::AuDecode(u32 pcmAddr) { memset(outbuf + outpcmbufsize, 0, PCMBufSize - outpcmbufsize); } - Memory::Write_U32(PCMBuf, pcmAddr); + if (pcmAddr) + Memory::Write_U32(PCMBuf, pcmAddr); return outpcmbufsize; }