From 4fac4d364eee6a4d5586e2db2fd657f4d6a33bf9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 1 Jan 2016 23:53:01 -0800 Subject: [PATCH] Atrac: Read non-streamed data from PSP RAM. This should fix games that don't actually read into the RAM right away, which is probably "incorrect" but works on the PSP, should should work in PPSSPP. --- Core/HLE/sceAtrac.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 22a1d12b3a..578559c887 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -297,7 +297,7 @@ struct Atrac { } // Make sure to do this late; it depends on things like atracBytesPerFrame. - if (p.mode == p.MODE_READ && data_buf != nullptr) { + if (p.mode == p.MODE_READ && bufferState != ATRAC_STATUS_NO_DATA) { __AtracSetContext(this); } @@ -425,6 +425,10 @@ struct Atrac { currentSample = sample; } + u8 *BufferStart() { + return ignoreDataBuf ? Memory::GetPointer(first.addr) : data_buf; + } + void SeekToSample(int sample) { // Discard any pending packet data. packet->size = 0; @@ -449,7 +453,7 @@ struct Atrac { const u32 start = off - dataOff < backfill ? dataOff : off - backfill; for (u32 pos = start; pos < off; pos += atracBytesPerFrame) { av_init_packet(packet); - packet->data = data_buf + pos; + packet->data = BufferStart() + pos; packet->size = atracBytesPerFrame; packet->pos = pos; @@ -468,7 +472,7 @@ struct Atrac { #ifdef USE_FFMPEG av_init_packet(packet); #endif // USE_FFMPEG - packet->data = data_buf + off; + packet->data = BufferStart() + off; packet->size = std::min((u32)atracBytesPerFrame, first.size - off); packet->pos = off; @@ -488,7 +492,7 @@ struct Atrac { bufferPos = dataOff; } - packet->data = data_buf + bufferPos; + packet->data = BufferStart() + bufferPos; packet->size = atracBytesPerFrame; packet->pos = bufferPos; bufferPos += atracBytesPerFrame; @@ -1751,6 +1755,13 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 bufferSize) { atrac->CleanStuff(); atrac->SetBufferState(); + if (atrac->bufferState == ATRAC_STATUS_ALL_DATA_LOADED || atrac->bufferState == ATRAC_STATUS_HALFWAY_BUFFER) { + // This says, don't use the data_buf array, use the PSP RAM. + // This way, games can load data async into the buffer, and it still works. + // TODO: Support this always, even for streaming. + atrac->ignoreDataBuf = true; + } + if (atrac->codecType == PSP_MODE_AT_3) { if (atrac->atracChannels == 1) { WARN_LOG(ME, "This is an atrac3 mono audio");