diff --git a/Core/HLE/AtracCtx.h b/Core/HLE/AtracCtx.h index 8e0123bee4..ba25ccf127 100644 --- a/Core/HLE/AtracCtx.h +++ b/Core/HLE/AtracCtx.h @@ -162,25 +162,22 @@ struct Atrac { int RemainingFrames() const; - int atracID_ = -1; - u8 *dataBuf_ = nullptr; + // Offset of the first sample in the input buffer + int dataOff_ = 0; // Indicates that the dataBuf_ array should not be used. bool ignoreDataBuf_ = false; - u32 decodePos_ = 0; + int atracID_ = -1; u16 channels_ = 0; u16 outputChannels_ = 2; int currentSample_ = 0; int endSample_ = 0; int firstSampleOffset_ = 0; - // Offset of the first sample in the input buffer - int dataOff_ = 0; std::vector loopinfo_; - int loopStartSample_ = -1; int loopEndSample_ = -1; int loopNum_ = 0; @@ -255,7 +252,7 @@ private: u32 bufferMaxSize_ = 0; int jointStereo_ = 0; - // Used by low-level decoding and to track streaming. + // Used to track streaming. u32 bufferPos_ = 0; u32 bufferValidBytes_ = 0; u32 bufferHeaderSize_ = 0; diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 1d395eba85..410490237d 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -291,6 +291,7 @@ static u32 sceAtracGetBufferInfoForResetting(int atracID, int sample, u32 buffer } else if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->second_.size == 0) { return hleReportError(ME, ATRAC_ERROR_SECOND_BUFFER_NEEDED, "no second buffer"); } else if ((u32)sample + atrac->firstSampleOffset_ > (u32)atrac->endSample_ + atrac->firstSampleOffset_) { + // NOTE: Above we have to add firstSampleOffset to both sides - we seem to rely on wraparound. return hleLogWarning(ME, ATRAC_ERROR_BAD_SAMPLE, "invalid sample position"); } else { atrac->GetResetBufferInfo(bufferInfo, sample); @@ -544,6 +545,7 @@ static u32 sceAtracResetPlayPosition(int atracID, int sample, int bytesWrittenFi if (atrac->BufferState() == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER && atrac->second_.size == 0) { return hleReportError(ME, ATRAC_ERROR_SECOND_BUFFER_NEEDED, "no second buffer"); } else if ((u32)sample + atrac->firstSampleOffset_ > (u32)atrac->endSample_ + atrac->firstSampleOffset_) { + // NOTE: Above we have to add firstSampleOffset to both sides - we seem to rely on wraparound. return hleLogWarning(ME, ATRAC_ERROR_BAD_SAMPLE, "invalid sample position"); }