From be6710ea4a30a9a224a28313d55472aaf0d5dcbd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 24 Apr 2019 14:13:46 -0700 Subject: [PATCH] Mp3: Fix errors for a bunch of init getters. --- Core/HLE/sceMp3.cpp | 60 +++++++++++++++++++++++++------------- Core/HW/SimpleAudioDec.cpp | 5 ---- Core/HW/SimpleAudioDec.h | 10 +++---- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Core/HLE/sceMp3.cpp b/Core/HLE/sceMp3.cpp index 10d8afaf60..a1f09e77e9 100644 --- a/Core/HLE/sceMp3.cpp +++ b/Core/HLE/sceMp3.cpp @@ -29,6 +29,7 @@ static const u32 ERROR_MP3_INVALID_HANDLE = 0x80671001; static const u32 ERROR_MP3_UNRESERVED_HANDLE = 0x80671102; +static const u32 ERROR_MP3_NOT_YET_INIT_HANDLE = 0x80671103; static const u32 ERROR_MP3_NO_RESOURCE_AVAIL = 0x80671201; static const u32 ERROR_MP3_BAD_ADDR = 0x80671002; static const u32 ERROR_MP3_BAD_SIZE = 0x80671003; @@ -239,7 +240,6 @@ static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) { Au->PCMBufSize = 0; } - Au->Channels = 2; Au->SumDecodedSamples = 0; Au->MaxOutputSample = Au->PCMBufSize / 4; Au->LoopNum = -1; @@ -487,39 +487,48 @@ static int sceMp3SetLoopNum(u32 mp3, int loop) { } static int sceMp3GetMp3ChannelNum(u32 mp3) { - INFO_LOG(ME, "sceMp3GetMp3ChannelNum(%08X)", mp3); - 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) { + return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "not yet init"); + } else if (ctx->AuBuf == 0) { + return hleLogWarning(ME, 0, "no channel available for low level"); } - return ctx->AuGetChannelNum(); + return hleLogSuccessI(ME, ctx->AuGetChannelNum()); } static int sceMp3GetBitRate(u32 mp3) { - INFO_LOG(ME, "sceMp3GetBitRate(%08X)", mp3); - 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) { + return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "not yet init"); + } else if (ctx->AuBuf == 0) { + return hleLogWarning(ME, 0, "no bitrate available for low level"); } - return ctx->AuGetBitRate(); + return hleLogSuccessI(ME, ctx->AuGetBitRate()); } static int sceMp3GetSamplingRate(u32 mp3) { - INFO_LOG(ME, "sceMp3GetSamplingRate(%08X)", mp3); - 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) { + return hleLogError(ME, ERROR_MP3_NOT_YET_INIT_HANDLE, "not yet init"); + } else if (ctx->AuBuf == 0) { + return hleLogWarning(ME, 0, "no sample rate available for low level"); } - return ctx->AuGetSamplingRate(); + return hleLogSuccessI(ME, ctx->AuGetSamplingRate()); } static int sceMp3GetInfoToAddStreamData(u32 mp3, u32 dstPtr, u32 towritePtr, u32 srcposPtr) { @@ -583,14 +592,20 @@ static u32 sceMp3GetFrameNum(u32 mp3) { } static u32 sceMp3GetMPEGVersion(u32 mp3) { - INFO_LOG(ME, "sceMp3GetMPEGVersion(%08x)", mp3); 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_UNRESERVED_HANDLE, "unreserved handle"); + } else if (ctx->Version < 0) { + // Seems to be the wrong error code. + return hleLogError(ME, ERROR_MP3_UNRESERVED_HANDLE, "not yet init"); + } else if (ctx->AuBuf == 0) { + return hleLogWarning(ME, 0, "no MPEG version available for low level"); } - return ctx->AuGetVersion(); + // Tests have not revealed how to expose more than "3" here as a result. + return hleReportDebug(ME, ctx->AuGetVersion()); } static u32 sceMp3ResetPlayPositionByFrame(u32 mp3, int position) { @@ -617,8 +632,11 @@ static u32 sceMp3LowLevelInit(u32 mp3, u32 unk) { delete mp3Map[mp3]; mp3Map.erase(mp3); } - mp3Map[mp3] = ctx; + + // Indicate that we've run low level init by setting version to 1. + ctx->Version = 1; + return 0; } diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index b8062ca56e..3a55ec71fa 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -298,11 +298,6 @@ AuCtx::AuCtx() { PCMBuf = 0; PCMBufSize = 2048; AuBufAvailable = 0; - SamplingRate = 44100; - freq = SamplingRate; - BitRate = 0; - Channels = 2; - Version = 0; SumDecodedSamples = 0; MaxOutputSample = 0; askedReadSize = 0; diff --git a/Core/HW/SimpleAudioDec.h b/Core/HW/SimpleAudioDec.h index c41707c3a5..1894da0838 100644 --- a/Core/HW/SimpleAudioDec.h +++ b/Core/HW/SimpleAudioDec.h @@ -129,11 +129,11 @@ public: u32 AuBufSize; u32 PCMBuf; u32 PCMBufSize; - int freq; - int BitRate; - int SamplingRate; - int Channels; - int Version; + int freq = -1; + int BitRate = 0; + int SamplingRate = -1; + int Channels = 0; + int Version = -1; // State variables. These should be relatively easy to move into private. u32 SumDecodedSamples;