Improve getremainFrame.

Fixed Musou Orochi 2 and so on.
This commit is contained in:
oioitff 2013-05-17 01:15:23 +08:00
parent 8cfde53734
commit 7bd3f389c7

View File

@ -165,25 +165,18 @@ struct Atrac {
u32 getDecodePosBySample(int sample) {
return (u32)(firstSampleoffset + sample / ATRAC_MAX_SAMPLES * atracBytesPerFrame );
}
int getRemainFrames() {
// many games request to add atrac data when remainFrames = 0
// However, some other games request to add atrac data
// when remainFrames = PSP_ATRAC_ALLDATA_IS_ON_MEMORY .
// Still need to find out how getRemainFrames() should work.
// games would like to add atrac data when it wants.
// Do not try to guess when it want to add data.
// Just return current remainFrames.
int remainFrame;
if (first.fileoffset >= first.filesize || currentSample >= endSample)
remainFrame = PSP_ATRAC_ALLDATA_IS_ON_MEMORY;
else if (decodePos > first.size) {
// There are not enough atrac data right now to play at a certain position.
// Must load more atrac data first
remainFrame = 0;
} else if (second.writableBytes <= 0) {
remainFrame = PSP_ATRAC_NONLOOP_STREAM_DATA_IS_ON_MEMORY ;
} else {
else {
// guess the remain frames.
// games would add atrac data when remainFrame = 0 or -1
remainFrame = (first.size - decodePos) / atracBytesPerFrame - 1;
remainFrame = ((int)first.size - (int)decodePos) / atracBytesPerFrame;
}
return remainFrame;
}
@ -897,6 +890,8 @@ int __AtracSetContext(Atrac *atrac, u32 buffer, u32 bufferSize)
// alloc audio frame
atrac->pFrame = avcodec_alloc_frame();
// reinit decodePos, because ffmpeg had changed it.
atrac->decodePos = 0;
#endif
return 0;