Skip to content

Commit 4fac4d3

Browse files
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.
1 parent f0551b4 commit 4fac4d3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Core/HLE/sceAtrac.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ struct Atrac {
297297
}
298298

299299
// Make sure to do this late; it depends on things like atracBytesPerFrame.
300-
if (p.mode == p.MODE_READ && data_buf != nullptr) {
300+
if (p.mode == p.MODE_READ && bufferState != ATRAC_STATUS_NO_DATA) {
301301
__AtracSetContext(this);
302302
}
303303

@@ -425,6 +425,10 @@ struct Atrac {
425425
currentSample = sample;
426426
}
427427

428+
u8 *BufferStart() {
429+
return ignoreDataBuf ? Memory::GetPointer(first.addr) : data_buf;
430+
}
431+
428432
void SeekToSample(int sample) {
429433
// Discard any pending packet data.
430434
packet->size = 0;
@@ -449,7 +453,7 @@ struct Atrac {
449453
const u32 start = off - dataOff < backfill ? dataOff : off - backfill;
450454
for (u32 pos = start; pos < off; pos += atracBytesPerFrame) {
451455
av_init_packet(packet);
452-
packet->data = data_buf + pos;
456+
packet->data = BufferStart() + pos;
453457
packet->size = atracBytesPerFrame;
454458
packet->pos = pos;
455459

@@ -468,7 +472,7 @@ struct Atrac {
468472
#ifdef USE_FFMPEG
469473
av_init_packet(packet);
470474
#endif // USE_FFMPEG
471-
packet->data = data_buf + off;
475+
packet->data = BufferStart() + off;
472476
packet->size = std::min((u32)atracBytesPerFrame, first.size - off);
473477
packet->pos = off;
474478

@@ -488,7 +492,7 @@ struct Atrac {
488492
bufferPos = dataOff;
489493
}
490494

491-
packet->data = data_buf + bufferPos;
495+
packet->data = BufferStart() + bufferPos;
492496
packet->size = atracBytesPerFrame;
493497
packet->pos = bufferPos;
494498
bufferPos += atracBytesPerFrame;
@@ -1751,6 +1755,13 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 bufferSize) {
17511755
atrac->CleanStuff();
17521756
atrac->SetBufferState();
17531757

1758+
if (atrac->bufferState == ATRAC_STATUS_ALL_DATA_LOADED || atrac->bufferState == ATRAC_STATUS_HALFWAY_BUFFER) {
1759+
// This says, don't use the data_buf array, use the PSP RAM.
1760+
// This way, games can load data async into the buffer, and it still works.
1761+
// TODO: Support this always, even for streaming.
1762+
atrac->ignoreDataBuf = true;
1763+
}
1764+
17541765
if (atrac->codecType == PSP_MODE_AT_3) {
17551766
if (atrac->atracChannels == 1) {
17561767
WARN_LOG(ME, "This is an atrac3 mono audio");

0 commit comments

Comments
 (0)