More GetTrack removal

This commit is contained in:
Henrik Rydgård 2025-03-16 11:06:52 +01:00
parent 3f71260671
commit fd9564166b
5 changed files with 49 additions and 23 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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;

View file

@ -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;
};

View file

@ -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");