From 01076d2a4fad86438c9acfec25154c11af54985f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 17 Mar 2025 14:00:08 +0100 Subject: [PATCH] InitLowLevel parameter cleanup --- Core/HLE/AtracCtx.cpp | 8 ++++---- Core/HLE/AtracCtx.h | 4 ++-- Core/HLE/AtracCtx2.cpp | 8 ++++---- Core/HLE/AtracCtx2.h | 2 +- Core/HLE/sceAtrac.cpp | 4 +++- Core/HLE/sceAtrac.h | 6 ++++++ Core/HLE/sceUtility.cpp | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Core/HLE/AtracCtx.cpp b/Core/HLE/AtracCtx.cpp index c3a9bf44ae..d4198f4548 100644 --- a/Core/HLE/AtracCtx.cpp +++ b/Core/HLE/AtracCtx.cpp @@ -1197,13 +1197,13 @@ int Atrac::ResetPlayPosition(int sample, int bytesWrittenFirstBuf, int bytesWrit return 0; } -void Atrac::InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) { +void Atrac::InitLowLevel(const Atrac3LowLevelParams ¶ms, bool jointStereo, int codecType) { track_ = Track(); track_.codecType = codecType; track_.endSample = 0; - track_.channels = Memory::Read_U32(paramsAddr); - outputChannels_ = Memory::Read_U32(paramsAddr + 4); - bufferMaxSize_ = Memory::Read_U32(paramsAddr + 8); + track_.channels = params.encodedChannels; + outputChannels_ = params.outputChannels; + bufferMaxSize_ = params.bytesPerFrame; track_.bytesPerFrame = bufferMaxSize_; first_.writableBytes = track_.bytesPerFrame; ResetData(); diff --git a/Core/HLE/AtracCtx.h b/Core/HLE/AtracCtx.h index 36075e031a..c40e2f7f67 100644 --- a/Core/HLE/AtracCtx.h +++ b/Core/HLE/AtracCtx.h @@ -225,7 +225,7 @@ public: virtual u32 DecodeData(u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u32 *finish, int *remains) = 0; virtual int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) = 0; virtual u32 GetNextSamples() = 0; - virtual void InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) = 0; + virtual void InitLowLevel(const Atrac3LowLevelParams ¶ms, bool jointStereo, int codecType) = 0; virtual int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const = 0; @@ -317,7 +317,7 @@ public: int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) override; // Returns how many samples the next DecodeData will write. u32 GetNextSamples() override; - void InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) override; + void InitLowLevel(const Atrac3LowLevelParams ¶ms, bool jointStereo, int codecType) override; int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const override; diff --git a/Core/HLE/AtracCtx2.cpp b/Core/HLE/AtracCtx2.cpp index 2736d7efce..206efe00eb 100644 --- a/Core/HLE/AtracCtx2.cpp +++ b/Core/HLE/AtracCtx2.cpp @@ -966,12 +966,12 @@ int Atrac2::Bitrate() const { return bitrate; } -void Atrac2::InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) { +void Atrac2::InitLowLevel(const Atrac3LowLevelParams ¶ms, bool jointStereo, int codecType) { SceAtracIdInfo &info = context_->info; info.codec = codecType; - info.numChan = Memory::ReadUnchecked_U32(paramsAddr); - outputChannels_ = Memory::ReadUnchecked_U32(paramsAddr + 4); - info.sampleSize = Memory::ReadUnchecked_U32(paramsAddr + 8); + info.numChan = params.encodedChannels; + outputChannels_ = params.outputChannels; + info.sampleSize = params.bytesPerFrame; info.dataOff = 0; info.decodePos = 0; info.state = ATRAC_STATUS_LOW_LEVEL; diff --git a/Core/HLE/AtracCtx2.h b/Core/HLE/AtracCtx2.h index be85932723..e59c0a8dc7 100644 --- a/Core/HLE/AtracCtx2.h +++ b/Core/HLE/AtracCtx2.h @@ -43,7 +43,7 @@ public: int DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) override; u32 GetNextSamples() override; - void InitLowLevel(u32 paramsAddr, bool jointStereo, int codecType) override; + void InitLowLevel(const Atrac3LowLevelParams ¶ms, bool jointStereo, int codecType) override; int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const override; diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 8af5266185..1ad8555a88 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -974,6 +974,8 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) { return hleReportError(Log::ME, 0, "invalid pointers"); } + auto params = PSPPointer::Create(paramsAddr); + int codecType = atracContextTypes[atracID]; bool jointStereo = false; @@ -992,7 +994,7 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) { } } - atrac->InitLowLevel(paramsAddr, jointStereo, codecType); + atrac->InitLowLevel(*params, jointStereo, codecType); const char *codecName = atrac->CodecType() == PSP_MODE_AT_3 ? "atrac3" : "atrac3+"; const char *channelName = atrac->Channels() == 1 ? "mono" : "stereo"; diff --git a/Core/HLE/sceAtrac.h b/Core/HLE/sceAtrac.h index 6f75114d98..c776826b6b 100644 --- a/Core/HLE/sceAtrac.h +++ b/Core/HLE/sceAtrac.h @@ -119,6 +119,12 @@ struct SceAtracContext { SceAtracIdInfo info; }; +struct Atrac3LowLevelParams { + int encodedChannels; + int outputChannels; + int bytesPerFrame; +}; + constexpr int PSP_MAX_ATRAC_IDS = 6; class AtracBase; diff --git a/Core/HLE/sceUtility.cpp b/Core/HLE/sceUtility.cpp index 4327bf5562..e5d19b5a4d 100644 --- a/Core/HLE/sceUtility.cpp +++ b/Core/HLE/sceUtility.cpp @@ -117,7 +117,7 @@ static const ModuleLoadInfo moduleLoadInfo[] = { ModuleLoadInfo(0x2ff, 0x00000000, "unk_0x2ff"), ModuleLoadInfo(0x300, 0x00000000, "av_avcodec", &NotifyLoadStatusAvcodec), // AudioCodec ModuleLoadInfo(0x301, 0x00000000, "av_sascore"), - // TODO: We should put the Atrac contexts inside the allocated bss space. Also, current actual full size (including text, on latest fw) seems to be 0x45C0. + // The size varies a bit per version, from about 0x3C00 to 0x4500 bytes. We could make a lookup table... ModuleLoadInfo(0x302, 0x00004000, "av_atrac3plus", atrac3PlusModuleDeps, &NotifyLoadStatusAtrac), ModuleLoadInfo(0x303, 0x0000c000, "av_mpegbase", mpegBaseModuleDeps), ModuleLoadInfo(0x304, 0x00004000, "av_mp3"),