diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index caabe6d04b..ec153ba706 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -91,6 +91,7 @@ struct InputBuffer { struct Atrac; int __AtracSetContext(Atrac *atrac); +void _AtracGenarateContext(Atrac *atrac, SceAtracId *context); struct AtracLoopInfo { int cuePointID; @@ -178,9 +179,6 @@ struct Atrac { p.Do(loopEndSample); p.Do(loopNum); - // Is NULL okay for this? - if (p.mode == p.MODE_READ) - decoder_context = 0; p.Do(atracContext); p.DoMarker("Atrac"); @@ -465,6 +463,24 @@ u32 sceAtracGetAtracID(int codecType) return atracID; } +u32 _AtracAddStreamData(int atracID, u8 *buf, u32 bytesToAdd) { + Atrac *atrac = getAtrac(atracID); + if (!atrac) + return 0; + int addbytes = std::min(bytesToAdd, atrac->first.filesize - atrac->first.fileoffset); + memcpy(atrac->data_buf + atrac->first.fileoffset, buf, addbytes); + atrac->first.size += bytesToAdd; + if (atrac->first.size > atrac->first.filesize) + atrac->first.size = atrac->first.filesize; + atrac->first.fileoffset = atrac->first.size; + atrac->first.writableBytes = 0; + if (atrac->atracContext.Valid()) { + // refresh atracContext + _AtracGenarateContext(atrac, atrac->atracContext); + } + return 0; +} + // PSP allow games to add stream data to a temp buf, the buf size is given by "atracBufSize "here. // "first.offset" means how many bytes the temp buf has been written, // and "first.writableBytes" means how many bytes the temp buf is allowed to write @@ -611,6 +627,10 @@ u32 _AtracDecodeData(int atracID, u8* outbuf, u32 *SamplesNum, u32* finish, int *finish = finishFlag; *remains = atrac->getRemainFrames(); } + if (atrac->atracContext.Valid()) { + // refresh atracContext + _AtracGenarateContext(atrac, atrac->atracContext); + } // TODO: Can probably remove this after we validate no wrong ids? } else { memset(outbuf, 0, ATRAC3_MAX_SAMPLES * sizeof(s16) * atrac->atracOutputChannels); @@ -1276,11 +1296,13 @@ int _AtracGetIDByContext(u32 contextAddr) { void _AtracGenarateContext(Atrac *atrac, SceAtracId *context) { context->info.buffer = atrac->first.addr; context->info.bufferByte = atrac->atracBufSize; + context->info.secondBuffer = atrac->second.addr; + context->info.secondBufferByte = atrac->second.size; context->info.codec = atrac->codeType; context->info.loopNum = atrac->loopNum; context->info.loopStart = atrac->loopStartSample > 0 ? atrac->loopStartSample : 0; context->info.loopEnd = atrac->loopEndSample > 0 ? atrac->loopEndSample : 0; - if (atrac->first.size >= atrac->first.fileoffset) { + if (atrac->first.size >= atrac->first.filesize) { // state 2, all data loaded context->info.state = 2; } else if (atrac->loopinfoNum == 0) { @@ -1297,6 +1319,7 @@ void _AtracGenarateContext(Atrac *atrac, SceAtracId *context) { context->info.endSample = atrac->endSample; context->info.dataEnd = atrac->first.filesize; context->info.curOff = atrac->first.size; + context->info.decodePos = atrac->getDecodePosBySample(atrac->currentSample); context->info.streamDataByte = atrac->first.size - atrac->firstSampleoffset; u8* buf = (u8*)context; diff --git a/Core/HLE/sceAtrac.h b/Core/HLE/sceAtrac.h index 71e2b801d9..1775100c64 100644 --- a/Core/HLE/sceAtrac.h +++ b/Core/HLE/sceAtrac.h @@ -66,5 +66,6 @@ typedef struct // provide some decoder interface +u32 _AtracAddStreamData(int atracID, u8 *buf, u32 bytesToAdd); u32 _AtracDecodeData(int atracID, u8* outbuf, u32 *SamplesNum, u32* finish, int *remains); int _AtracGetIDByContext(u32 contextAddr); \ No newline at end of file