diff --git a/CMakeLists.txt b/CMakeLists.txt index 6806cf42ac..15b730f326 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2276,6 +2276,8 @@ add_library(${CoreLibName} ${CoreLinkType} Core/HLE/sceMt19937.h Core/HLE/sceMd5.cpp Core/HLE/sceMd5.h + Core/HLE/sceAac.cpp + Core/HLE/sceAac.h Core/HLE/sceMp4.cpp Core/HLE/sceMp4.h Core/HLE/sceMp3.cpp diff --git a/Common/Math/math_util.h b/Common/Math/math_util.h index 033e48ba90..4f4d30c982 100644 --- a/Common/Math/math_util.h +++ b/Common/Math/math_util.h @@ -7,15 +7,6 @@ #include #include -typedef unsigned short float16; - -inline float Float16ToFloat(float16 ix) { - uint32_t extended = ix; - float x; - memcpy(&x, &extended, sizeof(float)); - return x; -} - inline bool isPowerOf2(int n) { return n == 1 || (n & (n - 1)) == 0; } @@ -36,6 +27,7 @@ inline uint32_t RoundUpToPowerOf2(uint32_t v, uint32_t power) { return (v + power - 1) & ~(power - 1); } +// TODO: this should just use a bitscan. inline uint32_t log2i(uint32_t val) { unsigned int ret = -1; while (val != 0) { diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 28c511ae96..c38fb0c628 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -572,6 +572,7 @@ + @@ -1191,6 +1192,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 2350b54200..9771b9d34d 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1339,6 +1339,9 @@ HLE\Libraries + + HLE\Libraries + @@ -2157,6 +2160,9 @@ HLE\Libraries + + HLE\Libraries + diff --git a/Core/HLE/HLETables.cpp b/Core/HLE/HLETables.cpp index 4d974c77f5..6412586658 100644 --- a/Core/HLE/HLETables.cpp +++ b/Core/HLE/HLETables.cpp @@ -49,6 +49,7 @@ #include "sceKernelTime.h" #include "sceMd5.h" #include "sceMp4.h" +#include "sceAac.h" #include "sceMp3.h" #include "sceNet.h" #include "sceNetAdhoc.h" @@ -275,6 +276,7 @@ void RegisterAllModules() { Register_sceGameUpdate(); Register_sceDeflt(); Register_sceMp4(); + Register_sceAac(); Register_scePauth(); Register_sceNp(); Register_sceNpCommerce2(); diff --git a/Core/HLE/sceAac.cpp b/Core/HLE/sceAac.cpp new file mode 100644 index 0000000000..2a93131c0c --- /dev/null +++ b/Core/HLE/sceAac.cpp @@ -0,0 +1,223 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "Core/HLE/sceAac.h" + +#include + +#include "Common/Serialize/SerializeFuncs.h" +#include "Common/Serialize/SerializeMap.h" +#include "Core/HLE/HLE.h" +#include "Core/HLE/FunctionWrappers.h" +#include "Core/Reporting.h" +#include "Core/HW/SimpleAudioDec.h" + +static std::map aacMap; + +static AuCtx *getAacCtx(u32 id) { + if (aacMap.find(id) == aacMap.end()) + return NULL; + return aacMap[id]; +} + +void __AACShutdown() { + for (auto it = aacMap.begin(), end = aacMap.end(); it != end; it++) { + delete it->second; + } + aacMap.clear(); +} + +void __AACDoState(PointerWrap &p) { + auto s = p.Section("sceAAC", 0, 1); + if (!s) + return; + + Do(p, aacMap); +} + +static u32 sceAacExit(u32 id) { + if (aacMap.find(id) != aacMap.end()) { + delete aacMap[id]; + aacMap.erase(id); + } else { + return hleLogError(Log::ME, -1, "bad aac ID"); + } + return hleLogInfo(Log::ME, 0); +} + +static u32 sceAacInit(u32 id) +{ + if (!Memory::IsValidAddress(id)) { + return hleLogError(Log::ME, ERROR_AAC_INVALID_ADDRESS, "AAC Invalid id address %08x", id); + } + + AuCtx *aac = new AuCtx(); + aac->startPos = Memory::Read_U64(id); // AUDIO stream start position. + aac->endPos = Memory::Read_U32(id + 8); // AUDIO stream end position. + aac->AuBuf = Memory::Read_U32(id + 16); // Input AAC data buffer. + aac->AuBufSize = Memory::Read_U32(id + 20); // Input AAC data buffer size. + aac->PCMBuf = Memory::Read_U32(id + 24); // Output PCM data buffer. + aac->PCMBufSize = Memory::Read_U32(id + 28); // Output PCM data buffer size. + aac->freq = Memory::Read_U32(id + 32); // Frequency. + if (aac->AuBuf == 0 || aac->PCMBuf == 0) { + ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID ADDRESS AuBuf %08x PCMBuf %08x", aac->AuBuf, aac->PCMBuf); + delete aac; + return hleNoLog(ERROR_AAC_INVALID_ADDRESS); + } + if (aac->startPos > aac->endPos) { + ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID startPos %lli endPos %lli", aac->startPos, aac->endPos); + delete aac; + return hleNoLog(ERROR_AAC_INVALID_PARAMETER); + } + if (aac->AuBufSize < 8192 || aac->PCMBufSize < 8192) { + ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID PARAMETER, bufferSize %i outputSize %i", aac->AuBufSize, aac->PCMBufSize); + delete aac; + return hleNoLog(ERROR_AAC_INVALID_PARAMETER); + } + if (aac->freq != 24000 && aac->freq != 32000 && aac->freq != 44100 && aac->freq != 48000) { + ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID freq %i", aac->freq); + delete aac; + return hleNoLog(ERROR_AAC_INVALID_PARAMETER); + } + + DEBUG_LOG(Log::ME, "startPos %llx endPos %llx AuBuf %08x AuBufSize %08x PCMbuf %08x PCMbufSize %08x freq %d", + aac->startPos, aac->endPos, aac->AuBuf, aac->AuBufSize, aac->PCMBuf, aac->PCMBufSize, aac->freq); + + aac->Channels = 2; + aac->MaxOutputSample = aac->PCMBufSize / 4; + aac->SetReadPos((int)aac->startPos); + + // create aac decoder + aac->decoder = CreateAudioDecoder(PSP_CODEC_AAC); + + // close the audio if id already exist. + if (aacMap.find(id) != aacMap.end()) { + delete aacMap[id]; + aacMap.erase(id); + } + aacMap[id] = aac; + + return hleNoLog(id); +} + +static u32 sceAacInitResource(u32 numberIds) { + // Do nothing here + INFO_LOG_REPORT(Log::ME, "sceAacInitResource(%i)", numberIds); + return hleNoLog(0); +} + +static u32 sceAacTermResource() { + return hleLogError(Log::ME, 0, "UNIMPL"); +} + +static u32 sceAacDecode(u32 id, u32 pcmAddr) { + // return the size of output pcm, <0 error + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->AuDecode(pcmAddr)); +} + +static u32 sceAacGetLoopNum(u32 id) { + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogInfo(Log::ME, ctx->LoopNum); +} + +static u32 sceAacSetLoopNum(u32 id, int loop) { + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + ctx->LoopNum = loop; + return hleLogInfo(Log::ME, 0); +} + +static int sceAacCheckStreamDataNeeded(u32 id) { + // return 1 to read more data stream, 0 don't read, <0 error + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->AuCheckStreamDataNeeded()); +} + +static u32 sceAacNotifyAddStreamData(u32 id, int size) { + // check how many bytes we have read from source file + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->AuNotifyAddStreamData(size)); +} + +static u32 sceAacGetInfoToAddStreamData(u32 id, u32 buff, u32 size, u32 srcPos) { + // read from stream position srcPos of size bytes into buff + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->AuGetInfoToAddStreamData(buff, size, srcPos)); +} + +static u32 sceAacGetMaxOutputSample(u32 id) { + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->MaxOutputSample); +} + +static u32 sceAacGetSumDecodedSample(u32 id) { + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogDebug(Log::ME, ctx->SumDecodedSamples); +} + +static u32 sceAacResetPlayPosition(u32 id) { + INFO_LOG(Log::ME, "sceAacResetPlayPosition(id %i)", id); + auto ctx = getAacCtx(id); + if (!ctx) { + return hleLogError(Log::ME, -1, "bad aac id"); + } + return hleLogInfo(Log::ME, ctx->AuResetPlayPosition()); +} + +const HLEFunction sceAac[] = { + {0XE0C89ACA, &WrapU_U, "sceAacInit", 'x', "x" }, + {0X33B8C009, &WrapU_U, "sceAacExit", 'x', "x" }, + {0X5CFFC57C, &WrapU_U, "sceAacInitResource", 'x', "x" }, + {0X23D35CAE, &WrapU_V, "sceAacTermResource", 'x', "" }, + {0X7E4CFEE4, &WrapU_UU, "sceAacDecode", 'x', "xx" }, + {0X523347D9, &WrapU_U, "sceAacGetLoopNum", 'x', "x" }, + {0XBBDD6403, &WrapU_UI, "sceAacSetLoopNum", 'x', "xi" }, + {0XD7C51541, &WrapI_U, "sceAacCheckStreamDataNeeded", 'i', "x" }, + {0XAC6DCBE3, &WrapU_UI, "sceAacNotifyAddStreamData", 'x', "xi" }, + {0X02098C69, &WrapU_UUUU, "sceAacGetInfoToAddStreamData", 'x', "xxxx" }, + {0X6DC7758A, &WrapU_U, "sceAacGetMaxOutputSample", 'x', "x" }, + {0X506BF66C, &WrapU_U, "sceAacGetSumDecodedSample", 'x', "x" }, + {0XD2DA2BBA, &WrapU_U, "sceAacResetPlayPosition", 'x', "x" }, +}; + +void Register_sceAac() { + RegisterModule("sceAac", ARRAY_SIZE(sceAac), sceAac); +} diff --git a/Core/HLE/sceAac.h b/Core/HLE/sceAac.h new file mode 100644 index 0000000000..6642ea045a --- /dev/null +++ b/Core/HLE/sceAac.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Common/Serialize/Serializer.h" + +enum { + ERROR_AAC_INVALID_ADDRESS = 0x80691002, + ERROR_AAC_INVALID_PARAMETER = 0x80691003, +}; +void __AACShutdown(); +void __AACDoState(PointerWrap &p); + +void Register_sceAac(); diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 1df61d0551..6185f39d03 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -88,6 +88,7 @@ #include "sceHeap.h" #include "sceDmac.h" #include "sceMp4.h" +#include "sceAac.h" #include "sceOpenPSID.h" #include "sceHttp.h" #include "Core/Util/PPGeDraw.h" diff --git a/Core/HLE/sceMp4.cpp b/Core/HLE/sceMp4.cpp index bd6cdf2f11..13cdb79f29 100644 --- a/Core/HLE/sceMp4.cpp +++ b/Core/HLE/sceMp4.cpp @@ -25,57 +25,25 @@ #include "Core/HLE/sceMp4.h" #include "Core/HW/SimpleAudioDec.h" -static std::map aacMap; - -static AuCtx *getAacCtx(u32 id) { - if (aacMap.find(id) == aacMap.end()) - return NULL; - return aacMap[id]; +static u32 sceMp4Init() { + return hleLogInfo(Log::ME, 0); } -void __AACShutdown() { - for (auto it = aacMap.begin(), end = aacMap.end(); it != end; it++) { - delete it->second; - } - aacMap.clear(); +static u32 sceMp4Finish() { + return hleLogError(Log::ME, 0); } -void __AACDoState(PointerWrap &p) { - auto s = p.Section("sceAAC", 0, 1); - if (!s) - return; - - Do(p, aacMap); -} - -static u32 sceMp4Init() -{ - INFO_LOG(Log::ME, "sceMp4Init()"); - return 0; -} - -static u32 sceMp4Finish() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4Finish()"); - return 0; -} - -static u32 sceMp4Create(u32 mp4, u32 callbacks, u32 readBufferAddr, u32 readBufferSize) -{ +static u32 sceMp4Create(u32 mp4, u32 callbacks, u32 readBufferAddr, u32 readBufferSize) { ERROR_LOG_REPORT(Log::ME, "UNIMPL sceMp4Create(mp4 %i,callbacks %08x,readBufferAddr %08x,readBufferSize %i)", mp4, callbacks, readBufferAddr, readBufferSize); return 0; } -static u32 sceMp4GetNumberOfSpecificTrack() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetNumberOfSpecificTrack()"); - return 1; +static u32 sceMp4GetNumberOfSpecificTrack() { + return hleLogError(Log::ME, 1, "UNIMPL"); } -static u32 sceMp4GetMovieInfo(u32 mp4, u32 unknown2) -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetMovieInfo(mp4 %i, unknown2 %08x)",mp4, unknown2); - return 0; +static u32 sceMp4GetMovieInfo(u32 mp4, u32 unknown2) { + return hleLogError(Log::ME, 0, "UNIMPL"); } static u32 sceMp4TrackSampleBufAvailableSize(u32 mp4, u32 trackAddr, u32 writableSamplesAddr, u32 writableBytesAddr) { @@ -86,327 +54,90 @@ static u32 sceMp4Delete(u32 mp4) { return hleLogError(Log::ME, 0, "unimplemented"); } -static u32 sceMp4AacDecodeInitResource(int unknown) -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4AacDecodeInitResource(%i)",unknown); - return 0; +static u32 sceMp4AacDecodeInitResource(int unknown) { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4InitAu(u32 mp4, u32 unknown2, u32 auAddr) -{ +static u32 sceMp4InitAu(u32 mp4, u32 unknown2, u32 auAddr) { // unknown2 = return value of sceMpegAvcResourceGetAvcEsBuf() - ERROR_LOG(Log::ME, "UNIMPL sceMp4InitAu(mp4 %i,unknown2 %08x,auAddr %08x)", mp4, unknown2, auAddr); - return 0; + return hleLogError(Log::ME, 0, "UNIMPL (mp4 %i,unknown2 %08x,auAddr %08x)", mp4, unknown2, auAddr); } static u32 sceMp4GetAvcAu(u32 mp4, u32 unknown2, u32 auAddr, u32 unknown4) { // unknown2 = return value of sceMpegAvcResourceGetAvcEsBuf() - ERROR_LOG(Log::ME, "UNIMPL sceMp4InitAu(mp4 %i,unknown2 %08x,auAddr %08x,unknown4 %08x)", mp4, unknown2, auAddr, unknown4); - return 0; + return hleLogError(Log::ME, 0, "UNIMPL (mp4 %i,unknown2 %08x,auAddr %08x,unknown4 %08x)", mp4, unknown2, auAddr, unknown4); } - -static u32 sceMp4GetAvcTrackInfoData() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetAvcTrackInfoData()"); - return 0; +static u32 sceMp4GetAvcTrackInfoData() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4TrackSampleBufConstruct(u32 mp4, u32 unknown2, u32 unknown3, u32 unknown4, u32 unknown5, u32 unknown6, u32 unknown7) -{ - // unknown4 == value returned by sceMp4_BCA9389C - ERROR_LOG(Log::ME, "UNIMPL sceMp4TrackSampleBufConstruct(mp4 %i,unknown2 %08x,unknown3 %08x, unknown4 %08x, unknown5 %08x, unknown6 %08x, unknown7 %08x)", mp4, unknown2, unknown3, unknown4, unknown5, unknown6, unknown7); - return 0; +static u32 sceMp4TrackSampleBufConstruct(u32 mp4, u32 unknown2, u32 unknown3, u32 unknown4, u32 unknown5, u32 unknown6, u32 unknown7) { + return hleLogError(Log::ME, 0, "UNIMPL"); } static u32 sceMp4TrackSampleBufQueryMemSize(u32 unknown1, u32 unknown2, u32 unknown3, u32 unknown4, u32 unknown5) { u32 value = std::max(unknown2 * unknown3, unknown4 << 1) + (unknown2 << 6) + unknown5 + 256; - ERROR_LOG(Log::ME, "sceMp4TrackSampleBufQueryMemSize return %i",value); - return value; + return hleLogWarning(Log::ME, value); } -static u32 sceMp4AacDecode(u32 mp4, u32 auAddr, u32 bufferAddr, u32 init, u32 frequency) -{ +static u32 sceMp4AacDecode(u32 mp4, u32 auAddr, u32 bufferAddr, u32 init, u32 frequency) { // Decode audio: // - init: 1 at first call, 0 afterwards // - frequency: 44100 - ERROR_LOG(Log::ME, "sceMp4AacDecode(mp4 %i,auAddr %08x,bufferAddr %08x,init %i,frequency %i ", mp4, auAddr, bufferAddr, init, frequency); - return 0; + return hleLogError(Log::ME, 0, "mp4 % i, auAddr % 08x, bufferAddr % 08x, init % i, frequency % i ", mp4, auAddr, bufferAddr, init, frequency); //This is hack //return -1; } -static u32 sceMp4GetAacAu(u32 mp4, u32 unknown2, u32 auAddr, u32 unknown4) -{ +static u32 sceMp4GetAacAu(u32 mp4, u32 unknown2, u32 auAddr, u32 unknown4) { // unknown4: pointer to a 40-bytes structure - ERROR_LOG(Log::ME, "sceMp4GetAacAu(mp4 %i,unknown2 %08x,auAddr %08x,unknown4 %i ", mp4, unknown2, auAddr, unknown4); - return 0; + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4GetSampleInfo() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetSampleInfo()"); - return 0; +static u32 sceMp4GetSampleInfo() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4GetSampleNumWithTimeStamp() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetSampleNumWithTimeStamp()"); - return 0; +static u32 sceMp4GetSampleNumWithTimeStamp() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4TrackSampleBufFlush() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4TrackSampleBufFlush()"); - return 0; +static u32 sceMp4TrackSampleBufFlush() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4AacDecodeInit(int unknown) -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4AacDecodeInit(%i)",unknown); - return 0; +static u32 sceMp4AacDecodeInit(int unknown) { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4GetAacTrackInfoData() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetAacTrackInfoData()"); - return 0; +static u32 sceMp4GetAacTrackInfoData() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4GetNumberOfMetaData() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4GetNumberOfMetaData()"); - return 0; +static u32 sceMp4GetNumberOfMetaData() { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4RegistTrack(u32 mp4, u32 unknown2, u32 unknown3, u32 callbacks, u32 unknown5) -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4RegistTrack(mp4 %i,unknown2 %i,unknown3 %i,callbacks %i unknown5 %i)",mp4,unknown2,unknown3,callbacks,unknown5); - return 0; +static u32 sceMp4RegistTrack(u32 mp4, u32 unknown2, u32 unknown3, u32 callbacks, u32 unknown5) { + return hleLogError(Log::ME, 0, "UNIMPL"); } -static u32 sceMp4SearchSyncSampleNum() -{ - ERROR_LOG(Log::ME, "UNIMPL sceMp4SearchSyncSampleNum()"); - return 0; -} - - -// sceAac module starts from here - -static u32 sceAacExit(u32 id) -{ - INFO_LOG(Log::ME, "sceAacExit(id %i)", id); - if (aacMap.find(id) != aacMap.end()) { - delete aacMap[id]; - aacMap.erase(id); - } - else{ - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - return 0; -} - -static u32 sceAacInit(u32 id) -{ - INFO_LOG(Log::ME, "UNIMPL sceAacInit(%08x)", id); - if (!Memory::IsValidAddress(id)){ - ERROR_LOG(Log::ME, "sceAacInit() AAC Invalid id address %08x", id); - return ERROR_AAC_INVALID_ADDRESS; - } - - AuCtx *aac = new AuCtx(); - aac->startPos = Memory::Read_U64(id); // AUDIO stream start position. - aac->endPos = Memory::Read_U32(id + 8); // AUDIO stream end position. - aac->AuBuf = Memory::Read_U32(id + 16); // Input AAC data buffer. - aac->AuBufSize = Memory::Read_U32(id + 20); // Input AAC data buffer size. - aac->PCMBuf = Memory::Read_U32(id + 24); // Output PCM data buffer. - aac->PCMBufSize = Memory::Read_U32(id + 28); // Output PCM data buffer size. - aac->freq = Memory::Read_U32(id + 32); // Frequency. - if (aac->AuBuf == 0 || aac->PCMBuf == 0) { - ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID ADDRESS AuBuf %08x PCMBuf %08x", aac->AuBuf, aac->PCMBuf); - delete aac; - return ERROR_AAC_INVALID_ADDRESS; - } - if (aac->startPos > aac->endPos) { - ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID startPos %lli endPos %lli", aac->startPos, aac->endPos); - delete aac; - return ERROR_AAC_INVALID_PARAMETER; - } - if (aac->AuBufSize < 8192 || aac->PCMBufSize < 8192) { - ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID PARAMETER, bufferSize %i outputSize %i", aac->AuBufSize, aac->PCMBufSize); - delete aac; - return ERROR_AAC_INVALID_PARAMETER; - } - if (aac->freq != 24000 && aac->freq != 32000 && aac->freq != 44100 && aac->freq != 48000) { - ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID freq %i", aac->freq); - delete aac; - return ERROR_AAC_INVALID_PARAMETER; - } - - DEBUG_LOG(Log::ME, "startPos %llx endPos %llx AuBuf %08x AuBufSize %08x PCMbuf %08x PCMbufSize %08x freq %d", - aac->startPos, aac->endPos, aac->AuBuf, aac->AuBufSize, aac->PCMBuf, aac->PCMBufSize, aac->freq); - - aac->Channels = 2; - aac->MaxOutputSample = aac->PCMBufSize / 4; - aac->SetReadPos((int)aac->startPos); - - // create aac decoder - aac->decoder = CreateAudioDecoder(PSP_CODEC_AAC); - - // close the audio if id already exist. - if (aacMap.find(id) != aacMap.end()) { - delete aacMap[id]; - aacMap.erase(id); - } - aacMap[id] = aac; - - return id; -} - -static u32 sceAacInitResource(u32 numberIds) -{ - // Do nothing here - INFO_LOG_REPORT(Log::ME, "sceAacInitResource(%i)", numberIds); - return 0; -} - -static u32 sceAacTermResource() -{ - ERROR_LOG(Log::ME, "UNIMPL sceAacTermResource()"); - return 0; -} - -static u32 sceAacDecode(u32 id, u32 pcmAddr) -{ - // return the size of output pcm, <0 error - DEBUG_LOG(Log::ME, "sceAacDecode(id %i, bufferAddress %08x)", id, pcmAddr); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->AuDecode(pcmAddr); -} - -static u32 sceAacGetLoopNum(u32 id) -{ - INFO_LOG(Log::ME, "sceAacGetLoopNum(id %i)", id); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - return ctx->LoopNum; -} - -static u32 sceAacSetLoopNum(u32 id, int loop) -{ - INFO_LOG(Log::ME, "sceAacSetLoopNum(id %i,loop %d)", id, loop); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - ctx->LoopNum = loop; - return 0; -} - -static int sceAacCheckStreamDataNeeded(u32 id) -{ - // return 1 to read more data stream, 0 don't read, <0 error - DEBUG_LOG(Log::ME, "sceAacCheckStreamDataNeeded(%i)", id); - - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->AuCheckStreamDataNeeded(); -} - -static u32 sceAacNotifyAddStreamData(u32 id, int size) -{ - // check how many bytes we have read from source file - DEBUG_LOG(Log::ME, "sceAacNotifyAddStreamData(%i, %08x)", id, size); - - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->AuNotifyAddStreamData(size); -} - -static u32 sceAacGetInfoToAddStreamData(u32 id, u32 buff, u32 size, u32 srcPos) -{ - // read from stream position srcPos of size bytes into buff - DEBUG_LOG(Log::ME, "sceAacGetInfoToAddStreamData(%08X, %08X, %08X, %08X)", id, buff, size, srcPos); - - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac handle %08x", __FUNCTION__, id); - return -1; - } - - return ctx->AuGetInfoToAddStreamData(buff, size, srcPos); -} - -static u32 sceAacGetMaxOutputSample(u32 id) -{ - DEBUG_LOG(Log::ME, "sceAacGetMaxOutputSample(id %i)", id); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->MaxOutputSample; -} - -static u32 sceAacGetSumDecodedSample(u32 id) -{ - DEBUG_LOG(Log::ME, "sceAacGetSumDecodedSample(id %i)", id); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->SumDecodedSamples; -} - -static u32 sceAacResetPlayPosition(u32 id) -{ - INFO_LOG(Log::ME, "sceAacResetPlayPosition(id %i)", id); - auto ctx = getAacCtx(id); - if (!ctx) { - ERROR_LOG(Log::ME, "%s: bad aac id %08x", __FUNCTION__, id); - return -1; - } - - return ctx->AuResetPlayPosition(); +static u32 sceMp4SearchSyncSampleNum() { + return hleLogError(Log::ME, 0, "UNIMPL"); } static u32 mp4msv_3C2183C7(u32 unknown1, u32 unknown2) { - ERROR_LOG(Log::ME, "UNIMPL mp4msv_3C2183C7(%d, %x)", unknown1, unknown2); - return 0; + return hleLogError(Log::ME, 0, "UNIMPL"); } static u32 mp4msv_9CA13D1A(u32 unknown1, u32 unknown2) { - ERROR_LOG(Log::ME, "UNIMPL mp4msv_9CA13D1A(%d, %x)", unknown1, unknown2); - return 0; + return hleLogError(Log::ME, 0, "UNIMPL"); } -const HLEFunction sceMp4[] = -{ +const HLEFunction sceMp4[] = { {0X68651CBC, &WrapU_V, "sceMp4Init", 'x', "" }, {0X9042B257, &WrapU_V, "sceMp4Finish", 'x', "" }, {0XB1221EE7, &WrapU_UUUU, "sceMp4Create", 'x', "xxxx" }, @@ -448,36 +179,15 @@ const HLEFunction sceMp4[] = {0X9CA13D1A, nullptr, "mp4msv_9CA13D1A", '?', "" }, }; -// 395 -const HLEFunction sceAac[] = { - {0XE0C89ACA, &WrapU_U, "sceAacInit", 'x', "x" }, - {0X33B8C009, &WrapU_U, "sceAacExit", 'x', "x" }, - {0X5CFFC57C, &WrapU_U, "sceAacInitResource", 'x', "x" }, - {0X23D35CAE, &WrapU_V, "sceAacTermResource", 'x', "" }, - {0X7E4CFEE4, &WrapU_UU, "sceAacDecode", 'x', "xx" }, - {0X523347D9, &WrapU_U, "sceAacGetLoopNum", 'x', "x" }, - {0XBBDD6403, &WrapU_UI, "sceAacSetLoopNum", 'x', "xi" }, - {0XD7C51541, &WrapI_U, "sceAacCheckStreamDataNeeded", 'i', "x" }, - {0XAC6DCBE3, &WrapU_UI, "sceAacNotifyAddStreamData", 'x', "xi" }, - {0X02098C69, &WrapU_UUUU, "sceAacGetInfoToAddStreamData", 'x', "xxxx" }, - {0X6DC7758A, &WrapU_U, "sceAacGetMaxOutputSample", 'x', "x" }, - {0X506BF66C, &WrapU_U, "sceAacGetSumDecodedSample", 'x', "x" }, - {0XD2DA2BBA, &WrapU_U, "sceAacResetPlayPosition", 'x', "x" }, -}; - const HLEFunction mp4msv[] = { {0x3C2183C7, &WrapU_UU, "mp4msv_3C2183C7", 'x', "xx" }, {0x9CA13D1A, &WrapU_UU, "mp4msv_9CA13D1A", 'x', "xx" }, - }; -void Register_sceMp4() -{ +void Register_sceMp4() { RegisterModule("sceMp4", ARRAY_SIZE(sceMp4), sceMp4); - RegisterModule("sceAac", ARRAY_SIZE(sceAac), sceAac); } -void Register_mp4msv() -{ +void Register_mp4msv() { RegisterModule("mp4msv", ARRAY_SIZE(mp4msv), mp4msv); } diff --git a/Core/HLE/sceMp4.h b/Core/HLE/sceMp4.h index 9df50ed96f..ee43ac89d4 100644 --- a/Core/HLE/sceMp4.h +++ b/Core/HLE/sceMp4.h @@ -17,12 +17,5 @@ #pragma once -enum { - ERROR_AAC_INVALID_ADDRESS = 0x80691002, - ERROR_AAC_INVALID_PARAMETER = 0x80691003, -}; - void Register_sceMp4(); -void __AACShutdown(); -void __AACDoState(PointerWrap &p); void Register_mp4msv(); diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj index fdaf2089e6..197d4dbe3a 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj +++ b/UWP/CoreUWP/CoreUWP.vcxproj @@ -231,6 +231,7 @@ + @@ -491,6 +492,7 @@ + diff --git a/UWP/CoreUWP/CoreUWP.vcxproj.filters b/UWP/CoreUWP/CoreUWP.vcxproj.filters index d5252caeda..645ab2e4f6 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj.filters +++ b/UWP/CoreUWP/CoreUWP.vcxproj.filters @@ -450,6 +450,9 @@ HLE + + HLE + HLE @@ -1540,6 +1543,9 @@ HLE + + HLE + HLE diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 0a0d520179..95b758d9a0 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -705,6 +705,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Core/HLE/sceMpeg.cpp \ $(SRC)/Core/HLE/sceMd5.cpp \ $(SRC)/Core/HLE/sceMp4.cpp \ + $(SRC)/Core/HLE/sceAac.cpp \ $(SRC)/Core/HLE/sceMp3.cpp \ $(SRC)/Core/HLE/sceNet.cpp \ $(SRC)/Core/HLE/sceNet_lib.cpp \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 77f9ac045d..32f7f08d35 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -751,6 +751,7 @@ SOURCES_CXX += \ $(COREDIR)/HLE/sceP3da.cpp \ $(COREDIR)/HLE/sceMt19937.cpp \ $(COREDIR)/HLE/sceMd5.cpp \ + $(COREDIR)/HLE/sceAac.cpp \ $(COREDIR)/HLE/sceMp4.cpp \ $(COREDIR)/HLE/sceMp3.cpp \ $(COREDIR)/HLE/sceParseHttp.cpp \