From fd9564166bece3ea7a7eaf60fac17e64c8d03fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 16 Mar 2025 11:06:52 +0100 Subject: [PATCH] More GetTrack removal --- Core/HLE/AtracCtx.cpp | 2 +- Core/HLE/AtracCtx.h | 36 +++++++++++++++++++++++------------- Core/HLE/AtracCtx2.cpp | 8 ++++++++ Core/HLE/AtracCtx2.h | 6 ++++++ Core/HLE/sceAtrac.cpp | 20 +++++++++++--------- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Core/HLE/AtracCtx.cpp b/Core/HLE/AtracCtx.cpp index 462b5c6700..c6cccacabb 100644 --- a/Core/HLE/AtracCtx.cpp +++ b/Core/HLE/AtracCtx.cpp @@ -547,7 +547,7 @@ int Atrac::AnalyzeAA3(u32 addr, u32 size, u32 fileSize) { return AnalyzeAA3Track(addr, size, fileSize, &track_); } -int AtracBase::GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) { +int Atrac::GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const { *endSample = GetTrack().endSample; *loopStartSample = GetTrack().loopStartSample == -1 ? -1 : GetTrack().loopStartSample - GetTrack().FirstSampleOffsetFull(); *loopEndSample = GetTrack().loopEndSample == -1 ? -1 : GetTrack().loopEndSample - GetTrack().FirstSampleOffsetFull(); diff --git a/Core/HLE/AtracCtx.h b/Core/HLE/AtracCtx.h index 6818367847..99d3eed7c9 100644 --- a/Core/HLE/AtracCtx.h +++ b/Core/HLE/AtracCtx.h @@ -141,12 +141,13 @@ struct Track { return codecType == PSP_MODE_AT_3_PLUS ? ATRAC3PLUS_MAX_SAMPLES : ATRAC3_MAX_SAMPLES; } - void UpdateBitrate() { - bitrate = (bytesPerFrame * 352800) / 1000; + int Bitrate() const { + int bitrate = (bytesPerFrame * 352800) / 1000; if (codecType == PSP_MODE_AT_3_PLUS) bitrate = ((bitrate >> 11) + 8) & 0xFFFFFFF0; else bitrate = (bitrate + 511) >> 10; + return bitrate; } // This appears to be buggy, should probably include FirstOffsetExtra? @@ -186,17 +187,10 @@ public: const Track &GetTrack() const { return track_; } - // This should be rare. - Track &GetTrackMut() { - return track_; - } int Channels() const { return track_.channels; } - int SamplesPerFrame() const { - return track_.SamplesPerFrame(); - } int GetOutputChannels() const { return outputChannels_; @@ -215,9 +209,7 @@ public: return bufferState_; } - int LoopNum() const { - return loopNum_; - } + virtual int LoopNum() const = 0; virtual int LoopStatus() const = 0; u32 CodecType() const { return track_.codecType; @@ -231,6 +223,8 @@ public: virtual int CurrentSample() const = 0; virtual int RemainingFrames() const = 0; virtual u32 SecondBufferSize() const = 0; + virtual int Bitrate() const = 0; + virtual int SamplesPerFrame() const = 0; virtual int Analyze(u32 addr, u32 size) = 0; virtual int AnalyzeAA3(u32 addr, u32 size, u32 filesize) = 0; @@ -253,7 +247,7 @@ public: virtual u32 GetNextSamples() = 0; virtual void InitLowLevel(u32 paramsAddr, bool jointStereo) = 0; - int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample); + virtual int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const = 0; protected: Track track_{}; @@ -295,12 +289,26 @@ public: u32 SecondBufferSize() const override { return second_.size; } + int LoopNum() const override { + return loopNum_; + } int LoopStatus() const override { if (track_.loopinfo.size() > 0) return 1; else return 0; } + int Bitrate() const override { + return track_.Bitrate(); + } + int SamplesPerFrame() const override { + return track_.SamplesPerFrame(); + } + + // This should be rare. + Track &GetTrackMut() { + return track_; + } // Ask where in memory new data should be written. void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) override; @@ -317,6 +325,8 @@ public: u32 GetNextSamples() override; void InitLowLevel(u32 paramsAddr, bool jointStereo) override; + int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const override; + protected: void AnalyzeReset(); diff --git a/Core/HLE/AtracCtx2.cpp b/Core/HLE/AtracCtx2.cpp index aa60e2c7be..76ee437225 100644 --- a/Core/HLE/AtracCtx2.cpp +++ b/Core/HLE/AtracCtx2.cpp @@ -35,6 +35,10 @@ // * Half Minute Hero (bufsize 65536) // * Flatout (tricky! needs investigation) +Atrac2::Atrac2(int codecType) { + track_.codecType = codecType; +} + void Atrac2::DoState(PointerWrap &p) { _assert_msg_(false, "Savestates not yet support with new Atrac implementation.\n\nTurn it off in Developer settings.\n\n"); } @@ -114,6 +118,10 @@ int Atrac2::GetResetBufferInfo(AtracResetBufferInfo *bufferInfo, int sample) { return 0; } +int Atrac2::GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const { + return 0; +} + int Atrac2::SetData(u32 buffer, u32 readSize, u32 bufferSize, int outputChannels) { if (readSize == bufferSize) { bufferState_ = ATRAC_STATUS_ALL_DATA_LOADED; diff --git a/Core/HLE/AtracCtx2.h b/Core/HLE/AtracCtx2.h index 12fe48714d..fd24006390 100644 --- a/Core/HLE/AtracCtx2.h +++ b/Core/HLE/AtracCtx2.h @@ -7,6 +7,7 @@ class Atrac2 : public AtracBase { public: + Atrac2(int codecType); void DoState(PointerWrap &p) override; void WriteContextToPSPMem() override; @@ -16,6 +17,9 @@ public: int CurrentSample() const override { return currentSample_; } int RemainingFrames() const override; int LoopStatus() const override { return 0; } + int Bitrate() const override { return 0; } + int LoopNum() const override { return 0; } + int SamplesPerFrame() const override { return 0; } void GetStreamDataInfo(u32 *writePtr, u32 *writableBytes, u32 *readOffset) override; int AddStreamData(u32 bytesToAdd) override; @@ -31,6 +35,8 @@ public: u32 GetNextSamples() override; void InitLowLevel(u32 paramsAddr, bool jointStereo) override; + int GetSoundSample(int *endSample, int *loopStartSample, int *loopEndSample) const override; + private: int currentSample_ = 0; }; diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 66b80c6e80..e54e37524e 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -157,11 +157,15 @@ void __AtracDoState(PointerWrap &p) { } } -static AtracBase *allocAtrac(bool forceOld = false) { - if (g_Config.bUseExperimentalAtrac && !forceOld) { - return new Atrac2(); +static AtracBase *allocAtrac(int codecType = 0) { + if (g_Config.bUseExperimentalAtrac) { + return new Atrac2(codecType); } else { - return new Atrac(); + Atrac *atrac = new Atrac(); + if (codecType) { + atrac->GetTrackMut().codecType = codecType; + } + return atrac; } } @@ -205,8 +209,7 @@ static u32 sceAtracGetAtracID(int codecType) { return hleReportError(Log::ME, SCE_ERROR_ATRAC_INVALID_CODECTYPE, "invalid codecType"); } - AtracBase *atrac = allocAtrac(); - atrac->GetTrackMut().codecType = codecType; + AtracBase *atrac = allocAtrac(codecType); int atracID = createAtrac(atrac); if (atracID < 0) { delete atrac; @@ -325,10 +328,9 @@ static u32 sceAtracGetBitrate(int atracID, u32 outBitrateAddr) { return hleLogError(Log::ME, err); } - atrac->GetTrackMut().UpdateBitrate(); - + int bitrate = atrac->Bitrate(); if (Memory::IsValidAddress(outBitrateAddr)) { - Memory::WriteUnchecked_U32(atrac->GetTrack().bitrate, outBitrateAddr); + Memory::WriteUnchecked_U32(atrac->Bitrate(), outBitrateAddr); return hleLogDebug(Log::ME, 0); } else { return hleLogError(Log::ME, 0, "invalid address");