Skip to content

Commit

Permalink
Atrac: Keep track of the set second buffer.
Browse files Browse the repository at this point in the history
Not actually used yet, but this way our context/etc. can be right.
  • Loading branch information
unknownbrackets committed Jan 12, 2016
1 parent 40bd31f commit a317b10
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Core/HLE/sceAtrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct Atrac {
}

void DoState(PointerWrap &p) {
auto s = p.Section("Atrac", 1, 7);
auto s = p.Section("Atrac", 1, 8);
if (!s)
return;

Expand Down Expand Up @@ -301,6 +301,12 @@ struct Atrac {
ignoreDataBuf = false;
}

if (s < 8 && bufferState == ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER) {
// We didn't actually allow the second buffer to be set this far back.
// Pretend it's a regular loop, we'll just try our best.
bufferState = ATRAC_STATUS_STREAMED_LOOP_FROM_END;
}

// Make sure to do this late; it depends on things like atracBytesPerFrame.
if (p.mode == p.MODE_READ && bufferState != ATRAC_STATUS_NO_DATA) {
__AtracSetContext(this);
Expand Down Expand Up @@ -1852,15 +1858,27 @@ static u32 sceAtracSetHalfwayBuffer(int atracID, u32 halfBuffer, u32 readSize, u

static u32 sceAtracSetSecondBuffer(int atracID, u32 secondBuffer, u32 secondBufferSize) {
Atrac *atrac = getAtrac(atracID);
if (!atrac) {
ERROR_LOG(ME, "sceAtracSetSecondBuffer(%i, %08x, %8x): bad atrac ID", atracID, secondBuffer, secondBufferSize);
return ATRAC_ERROR_BAD_ATRACID;
} else if (!atrac->data_buf) {
ERROR_LOG(ME, "sceAtracSetSecondBuffer(%i, %08x, %8x): no data", atracID, secondBuffer, secondBufferSize);
return ATRAC_ERROR_NO_DATA;
u32 err = AtracValidateManaged(atrac);
if (err != 0) {
// Already logged.
return err;
}

u32 secondFileOffset = atrac->getFileOffsetBySample(atrac->loopEndSample - atrac->firstSampleoffset);
u32 desiredSize = atrac->first.filesize - secondFileOffset;

// 3 seems to be the number of frames required to handle a loop.
if (secondBufferSize < desiredSize && secondBufferSize < (u32)atrac->atracBytesPerFrame * 3) {
return hleReportError(ME, ATRAC_ERROR_SIZE_TOO_SMALL, "too small");
}
if (atrac->bufferState != ATRAC_STATUS_STREAMED_LOOP_WITH_TRAILER) {
return hleReportError(ME, ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED, "not needed");
}

ERROR_LOG_REPORT(ME, "UNIMPL sceAtracSetSecondBuffer(%i, %08x, %8x)", atracID, secondBuffer, secondBufferSize);
atrac->second.addr = secondBuffer;
atrac->second.size = secondBufferSize;
atrac->second.fileoffset = secondFileOffset;

return 0;
}

Expand Down

0 comments on commit a317b10

Please sign in to comment.