Update Atrac->Analyze

This commit is contained in:
Henrik Rydgård 2025-03-04 13:50:45 +01:00
parent d88487e7fd
commit 1678c141ba
2 changed files with 22 additions and 29 deletions

View file

@ -249,23 +249,24 @@ int Atrac::Analyze(u32 addr, u32 size) {
// 72 is about the size of the minimum required data to even be valid.
if (size < 72) {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_SIZE_TOO_SMALL, "buffer too small");
return SCE_ERROR_ATRAC_SIZE_TOO_SMALL;
}
// TODO: Check the range (addr, size) instead.
if (!Memory::IsValidAddress(addr)) {
return hleReportWarning(Log::ME, SCE_KERNEL_ERROR_ILLEGAL_ADDRESS, "invalid buffer address");
return SCE_KERNEL_ERROR_ILLEGAL_ADDRESS;
}
// TODO: Validate stuff.
if (Memory::ReadUnchecked_U32(addr) != RIFF_CHUNK_MAGIC) {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_UNKNOWN_FORMAT, "invalid RIFF header");
ERROR_LOG(Log::ME, "Couldn't find RIFF header");
return SCE_ERROR_ATRAC_UNKNOWN_FORMAT;
}
int retval = AnalyzeAtracTrack(addr, size, &track_);
first_._filesize_dontuse = track_.fileSize;
track_.DebugLog();
return hleLogDebugOrError(Log::ME, retval);
return retval;
}
int AnalyzeAtracTrack(u32 addr, u32 size, Track *track) {

View file

@ -579,8 +579,7 @@ static u32 sceAtracSetHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u32 b
int ret = atrac->Analyze(buffer, readSize);
if (ret < 0) {
// Already logged.
return ret;
return hleLogError(Log::ME, ret);
}
return _AtracSetData(atracID, buffer, readSize, bufferSize, 2, false);
@ -604,8 +603,7 @@ static u32 sceAtracSetData(int atracID, u32 buffer, u32 bufferSize) {
int ret = atrac->Analyze(buffer, bufferSize);
if (ret < 0) {
// Already logged.
return ret;
return hleLogError(Log::ME, ret);
}
if (atrac->GetTrack().codecType != atracContextTypes[atracID]) {
@ -627,9 +625,8 @@ static int sceAtracSetDataAndGetID(u32 buffer, int bufferSize) {
AtracBase *atrac = allocAtrac();
int ret = atrac->Analyze(buffer, bufferSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
int atracID = createAtrac(atrac);
if (atracID < 0) {
@ -647,9 +644,8 @@ static int sceAtracSetHalfwayBufferAndGetID(u32 buffer, u32 readSize, u32 buffer
AtracBase *atrac = allocAtrac();
int ret = atrac->Analyze(buffer, readSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
int atracID = createAtrac(atrac);
if (atracID < 0) {
@ -686,8 +682,7 @@ static u32 sceAtracSetLoopNum(int atracID, int loopNum) {
static int sceAtracReinit(int at3Count, int at3plusCount) {
for (int i = 0; i < PSP_NUM_ATRAC_IDS; ++i) {
if (atracContexts[i] != nullptr) {
ERROR_LOG_REPORT(Log::ME, "sceAtracReinit(%d, %d): cannot reinit while IDs in use", at3Count, at3plusCount);
return SCE_KERNEL_ERROR_BUSY;
return hleReportError(Log::ME, SCE_KERNEL_ERROR_BUSY, "cannot reinit while IDs in use");
}
}
@ -765,8 +760,7 @@ static int sceAtracSetMOutHalfwayBuffer(int atracID, u32 buffer, u32 readSize, u
int ret = atrac->Analyze(buffer, readSize);
if (ret < 0) {
// Already logged.
return ret;
return hleLogError(Log::ME, ret);
}
if (atrac->GetTrack().channels != 1) {
// It seems it still sets the data.
@ -787,8 +781,7 @@ static u32 sceAtracSetMOutData(int atracID, u32 buffer, u32 bufferSize) {
int ret = atrac->Analyze(buffer, bufferSize);
if (ret < 0) {
// Already logged.
return ret;
return hleLogError(Log::ME, ret);
}
if (atrac->GetTrack().channels != 1) {
// It seems it still sets the data.
@ -804,9 +797,8 @@ static int sceAtracSetMOutDataAndGetID(u32 buffer, u32 bufferSize) {
AtracBase *atrac = allocAtrac();
int ret = atrac->Analyze(buffer, bufferSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
if (atrac->GetTrack().channels != 1) {
delete atrac;
@ -828,9 +820,8 @@ static int sceAtracSetMOutHalfwayBufferAndGetID(u32 buffer, u32 readSize, u32 bu
AtracBase *atrac = allocAtrac();
int ret = atrac->Analyze(buffer, readSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
if (atrac->GetTrack().channels != 1) {
delete atrac;
@ -864,9 +855,9 @@ static int sceAtracSetAA3DataAndGetID(u32 buffer, u32 bufferSize, u32 fileSize,
static u32 _sceAtracGetContextAddress(int atracID) {
AtracBase *atrac = getAtrac(atracID);
if (!atrac) {
ERROR_LOG(Log::ME, "_sceAtracGetContextAddress(%i): bad atrac id", atracID);
return 0;
return hleLogError(Log::ME, 0, "bad atrac id");
}
if (!atrac->context_.IsValid()) {
// allocate a new context_
u32 contextSize = sizeof(SceAtracContext);
@ -875,11 +866,12 @@ static u32 _sceAtracGetContextAddress(int atracID) {
if (atrac->context_.IsValid())
Memory::Memset(atrac->context_.ptr, 0, contextSize, "AtracContextClear");
WARN_LOG(Log::ME, "%08x=_sceAtracGetContextAddress(%i): allocated new context", atrac->context_.ptr, atracID);
}
else
} else {
WARN_LOG(Log::ME, "%08x=_sceAtracGetContextAddress(%i)", atrac->context_.ptr, atracID);
}
atrac->WriteContextToPSPMem();
return atrac->context_.ptr;
return hleLogDebug(Log::ME, atrac->context_.ptr);
}
struct At3HeaderMap {
@ -989,14 +981,14 @@ static int sceAtracSetAA3HalfwayBufferAndGetID(u32 buffer, u32 readSize, u32 buf
u32 AtracSasAddStreamData(int atracID, u32 bufPtr, u32 bytesToAdd) {
AtracBase *atrac = getAtrac(atracID);
if (!atrac)
return 0;
return hleLogWarning(Log::ME, 0, "bad atrac ID");
return atrac->AddStreamDataSas(bufPtr, bytesToAdd);
}
u32 AtracSasDecodeData(int atracID, u8* outbuf, u32 outbufPtr, u32 *SamplesNum, u32* finish, int *remains) {
AtracBase *atrac = getAtrac(atracID);
if (!atrac)
return 0;
return hleLogWarning(Log::ME, 0, "bad atrac ID");
return atrac->DecodeData(outbuf, outbufPtr, SamplesNum, finish, remains);
}