From 6fe5fe07a4e786bcdd271653dcd4f176cf6186d4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Jan 2016 11:12:35 -0800 Subject: [PATCH 1/3] Atrac: Revert broken seeking fix. This wasn't the right solution to getting the right packets. --- Core/HLE/sceAtrac.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index c0645d462d..8d2dc085a9 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -292,7 +292,7 @@ struct Atrac { } u32 getFileOffsetBySample(int sample) const { - int offsetSample = sample + firstSampleoffset + firstOffsetExtra(); + int offsetSample = sample + firstSampleoffset; int frameOffset = offsetSample / (int)samplesPerFrame(); return (u32)(dataOff + atracBytesPerFrame + frameOffset * atracBytesPerFrame); } @@ -312,7 +312,7 @@ struct Atrac { } // Since the first frame is shorter by this offset, add to round up at this offset. - const int remainingBytes = first.fileoffset - getFileOffsetBySample(currentSample - samplesPerFrame()); + const int remainingBytes = first.fileoffset - getFileOffsetBySample(currentSample - samplesPerFrame() + firstOffsetExtra()); return remainingBytes / atracBytesPerFrame; } @@ -1154,7 +1154,7 @@ static void AtracGetResetBufferInfo(Atrac *atrac, AtracResetBufferInfo *bufferIn // This is because we're filling the buffer start to finish, not streaming. bufferInfo->first.writePosPtr = atrac->first.addr + atrac->first.size; bufferInfo->first.writableBytes = atrac->first.filesize - atrac->first.size; - int minWriteBytes = atrac->getFileOffsetBySample(sample - atrac->firstOffsetExtra()) - atrac->first.size; + int minWriteBytes = atrac->getFileOffsetBySample(sample) - atrac->first.size; if (minWriteBytes > 0) { bufferInfo->first.minWriteBytes = minWriteBytes; } else { @@ -1165,7 +1165,7 @@ static void AtracGetResetBufferInfo(Atrac *atrac, AtracResetBufferInfo *bufferIn atrac->first.writableBytes = bufferInfo->first.writableBytes; } else { // This is without the sample offset. The file offset also includes the previous batch of samples? - int sampleFileOffset = atrac->getFileOffsetBySample(sample - atrac->firstSampleoffset - atrac->samplesPerFrame() - atrac->firstOffsetExtra()); + int sampleFileOffset = atrac->getFileOffsetBySample(sample - atrac->firstSampleoffset - atrac->samplesPerFrame()); // Update the writable bytes. When streaming, this is just the number of bytes until the end. const u32 bufSizeAligned = (atrac->atracBufSize / atrac->atracBytesPerFrame) * atrac->atracBytesPerFrame; From 85ff5eb68aceb1856056bfaac4905f15d35885cd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Jan 2016 11:13:09 -0800 Subject: [PATCH 2/3] Atrac: Adjust reads a bit earlier when skipping. The frames we initially get may not start at 0, depending on how many frames we're skipping. Of course... --- Core/HLE/sceAtrac.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 8d2dc085a9..c28e770cf2 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -408,7 +408,12 @@ struct Atrac { // Prefill the decode buffer with packets before the first sample offset. avcodec_flush_buffers(pCodecCtx); - const u32 off = getFileOffsetBySample(sample); + int adjust = 0; + if (sample == 0) { + int offsetSamples = firstSampleoffset + firstOffsetExtra(); + adjust = -(offsetSamples % samplesPerFrame()); + } + const u32 off = getFileOffsetBySample(sample + adjust); const u32 backfill = atracBytesPerFrame * 2; const u32 start = off - dataOff < backfill ? dataOff : off - backfill; for (u32 pos = start; pos < off; pos += atracBytesPerFrame) { @@ -426,8 +431,8 @@ struct Atrac { currentSample = sample; } - bool FillPacket() { - u32 off = getFileOffsetBySample(currentSample); + bool FillPacket(int adjust = 0) { + u32 off = getFileOffsetBySample(currentSample + adjust); if (off < first.size) { #ifdef USE_FFMPEG av_init_packet(packet); @@ -1004,7 +1009,7 @@ u32 _AtracDecodeData(int atracID, u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u3 atrac->SeekToSample(atrac->currentSample); AtracDecodeResult res = ATDECODE_FEEDME; - while (atrac->FillPacket()) { + while (atrac->FillPacket(-skipSamples)) { res = atrac->DecodePacket(); if (res == ATDECODE_FAILED) { *SamplesNum = 0; From 96d5e105494f3faef02037a5868b1b6c1bc98aba Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Jan 2016 11:13:48 -0800 Subject: [PATCH 3/3] Atrac: Seek ahead only one frame at end. If it had a partial ending frame, it should go ahead one frame, not one frame plus the partial ending. --- Core/HLE/sceAtrac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index c28e770cf2..ffefe8a73d 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -1098,7 +1098,7 @@ u32 _AtracDecodeData(int atracID, u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u3 // Still move forward, so we know that we've read everything. // This seems to be reflected in the context as well. - atrac->currentSample += atrac->samplesPerFrame(); + atrac->currentSample += atrac->samplesPerFrame() - numSamples; } *finish = finishFlag;