Skip to content

Commit

Permalink
Add extra frames if we run out of atrac data.
Browse files Browse the repository at this point in the history
We could probably insert frames instead for GHA phase shifting, but this
will solve other bugs too, I think.
  • Loading branch information
unknownbrackets committed Sep 23, 2014
1 parent 145b44f commit db6ad2f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Core/HLE/sceAtrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ u32 _AtracDecodeData(int atracID, u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u3
atrac->SeekToSample(atrac->currentSample == 0 ? 0 : atrac->currentSample + offsetSamples);
AVPacket packet;
av_init_packet(&packet);
int got_frame, avret;
int got_frame = 0, avret;
while (av_read_frame(atrac->pFormatCtx, &packet) >= 0) {
if (packet.stream_index != atrac->audio_stream_index) {
av_free_packet(&packet);
Expand Down Expand Up @@ -713,6 +713,15 @@ u32 _AtracDecodeData(int atracID, u8 *outbuf, u32 outbufPtr, u32 *SamplesNum, u3
break;
}
}

if (!got_frame && atrac->currentSample < atrac->endSample) {
// Never got a frame. We may have dropped a GHA frame or otherwise have a bug.
// For now, let's try to provide an extra "frame" if possible so games don't infinite loop.
numSamples = std::min((u32)atrac->endSample - (u32)atrac->currentSample, atracSamplesPerFrame);
u32 outBytes = numSamples * atrac->atracOutputChannels * sizeof(s16);
memset(outbuf, 0, outBytes);
CBreakPoints::ExecMemCheck(outbufPtr, true, outBytes, currentMIPS->pc);
}
}
#endif // USE_FFMPEG

Expand Down

0 comments on commit db6ad2f

Please sign in to comment.