@@ -297,7 +297,7 @@ struct Atrac {
297
297
}
298
298
299
299
// 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 ) {
301
301
__AtracSetContext (this );
302
302
}
303
303
@@ -425,6 +425,10 @@ struct Atrac {
425
425
currentSample = sample;
426
426
}
427
427
428
+ u8 *BufferStart () {
429
+ return ignoreDataBuf ? Memory::GetPointer (first.addr ) : data_buf;
430
+ }
431
+
428
432
void SeekToSample (int sample) {
429
433
// Discard any pending packet data.
430
434
packet->size = 0 ;
@@ -449,7 +453,7 @@ struct Atrac {
449
453
const u32 start = off - dataOff < backfill ? dataOff : off - backfill;
450
454
for (u32 pos = start; pos < off; pos += atracBytesPerFrame) {
451
455
av_init_packet (packet);
452
- packet->data = data_buf + pos;
456
+ packet->data = BufferStart () + pos;
453
457
packet->size = atracBytesPerFrame;
454
458
packet->pos = pos;
455
459
@@ -468,7 +472,7 @@ struct Atrac {
468
472
#ifdef USE_FFMPEG
469
473
av_init_packet (packet);
470
474
#endif // USE_FFMPEG
471
- packet->data = data_buf + off;
475
+ packet->data = BufferStart () + off;
472
476
packet->size = std::min ((u32 )atracBytesPerFrame, first.size - off);
473
477
packet->pos = off;
474
478
@@ -488,7 +492,7 @@ struct Atrac {
488
492
bufferPos = dataOff;
489
493
}
490
494
491
- packet->data = data_buf + bufferPos;
495
+ packet->data = BufferStart () + bufferPos;
492
496
packet->size = atracBytesPerFrame;
493
497
packet->pos = bufferPos;
494
498
bufferPos += atracBytesPerFrame;
@@ -1751,6 +1755,13 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 bufferSize) {
1751
1755
atrac->CleanStuff ();
1752
1756
atrac->SetBufferState ();
1753
1757
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
+
1754
1765
if (atrac->codecType == PSP_MODE_AT_3) {
1755
1766
if (atrac->atracChannels == 1 ) {
1756
1767
WARN_LOG (ME, " This is an atrac3 mono audio" );
0 commit comments