Update AA3Analyze

This commit is contained in:
Henrik Rydgård 2025-03-04 13:39:07 +01:00
parent 70543c0363
commit d88487e7fd
3 changed files with 25 additions and 32 deletions

View file

@ -471,39 +471,30 @@ int AnalyzeAtracTrack(u32 addr, u32 size, Track *track) {
return 0;
}
int Atrac::AnalyzeAA3(u32 addr, u32 size, u32 fileSize) {
first_.addr = addr;
first_.size = size;
first_._filesize_dontuse = fileSize;
AnalyzeReset();
return AnalyzeAA3Track(addr, size, fileSize, &track_);
}
int AnalyzeAA3Track(u32 addr, u32 size, u32 fileSize, Track *track) {
if (size < 10) {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_SIZE_TOO_SMALL, "buffer too small");
return SCE_ERROR_ATRAC_AA3_SIZE_TOO_SMALL;
}
// TODO: Make sure this validation is correct, more testing.
const u8 *buffer = Memory::GetPointer(addr);
if (buffer[0] != 'e' || buffer[1] != 'a' || buffer[2] != '3') {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_INVALID_DATA, "invalid ea3 magic bytes");
return SCE_ERROR_ATRAC_AA3_INVALID_DATA;
}
// It starts with an id3 header (replaced with ea3.) This is the size.
u32 tagSize = buffer[9] | (buffer[8] << 7) | (buffer[7] << 14) | (buffer[6] << 21);
if (size < tagSize + 36) {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_SIZE_TOO_SMALL, "truncated before id3 end");
return SCE_ERROR_ATRAC_AA3_SIZE_TOO_SMALL;
}
// EA3 header starts at id3 header (10) + tagSize.
buffer = Memory::GetPointer(addr + 10 + tagSize);
if (buffer[0] != 'E' || buffer[1] != 'A' || buffer[2] != '3') {
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_INVALID_DATA, "invalid EA3 magic bytes");
ERROR_LOG(Log::ME, "AnalyzeAA3Track: Invalid EA3 magic bytes");
return SCE_ERROR_ATRAC_AA3_INVALID_DATA;
}
track->fileSize = fileSize;
// Based on FFmpeg's code.
@ -527,9 +518,11 @@ int AnalyzeAA3Track(u32 addr, u32 size, u32 fileSize, Track *track) {
case 3:
case 4:
case 5:
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_INVALID_DATA, "unsupported codec type %d", buffer[32]);
ERROR_LOG(Log::ME, "AnalyzeAA3Track: unsupported codec type %d", buffer[32]);
return SCE_ERROR_ATRAC_AA3_INVALID_DATA;
default:
return hleReportError(Log::ME, SCE_ERROR_ATRAC_AA3_INVALID_DATA, "invalid codec type %d", buffer[32]);
ERROR_LOG(Log::ME, "AnalyzeAA3Track: invalid codec type %d", buffer[32]);
return SCE_ERROR_ATRAC_AA3_INVALID_DATA;
}
track->dataByteOffset = 10 + tagSize + 96;
@ -541,6 +534,16 @@ int AnalyzeAA3Track(u32 addr, u32 size, u32 fileSize, Track *track) {
return 0;
}
int Atrac::AnalyzeAA3(u32 addr, u32 size, u32 fileSize) {
first_.addr = addr;
first_.size = size;
first_._filesize_dontuse = fileSize;
AnalyzeReset();
return AnalyzeAA3Track(addr, size, fileSize, &track_);
}
void Atrac::CalculateStreamInfo(u32 *outReadOffset) {
u32 readOffset = first_.fileoffset;
if (bufferState_ == ATRAC_STATUS_ALL_DATA_LOADED) {

View file

@ -79,19 +79,11 @@ void Atrac2::WriteContextToPSPMem() {
}
int Atrac2::Analyze(u32 addr, u32 size) {
int retval = AnalyzeAtracTrack(addr, size, &track_);
if (retval < 0) {
return retval;
}
return 0;
return AnalyzeAtracTrack(addr, size, &track_);
}
int Atrac2::AnalyzeAA3(u32 addr, u32 size, u32 filesize) {
int retval = AnalyzeAA3Track(addr, size, filesize, &track_);
if (retval < 0) {
return retval;
}
return 0;
int Atrac2::AnalyzeAA3(u32 addr, u32 size, u32 filesize) {
return AnalyzeAA3Track(addr, size, filesize, &track_);
}
int Atrac2::RemainingFrames() const {

View file

@ -849,9 +849,8 @@ static int sceAtracSetAA3DataAndGetID(u32 buffer, u32 bufferSize, u32 fileSize,
AtracBase *atrac = allocAtrac();
int ret = atrac->AnalyzeAA3(buffer, bufferSize, fileSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
int atracID = createAtrac(atrac);
if (atracID < 0) {
@ -973,9 +972,8 @@ static int sceAtracSetAA3HalfwayBufferAndGetID(u32 buffer, u32 readSize, u32 buf
AtracBase *atrac = allocAtrac();
int ret = atrac->AnalyzeAA3(buffer, readSize, fileSize);
if (ret < 0) {
// Already logged.
delete atrac;
return ret;
return hleLogError(Log::ME, ret);
}
int atracID = createAtrac(atrac);
if (atracID < 0) {