diff --git a/CMakeLists.txt b/CMakeLists.txt index 185205221..1c0932b5c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -378,6 +378,24 @@ set(SYSTEM_LIBS src/core/libraries/system/commondialog.cpp src/core/libraries/ngs2/ngs2_error.h src/core/libraries/ngs2/ngs2_impl.cpp src/core/libraries/ngs2/ngs2_impl.h + src/core/libraries/ngs2/ngs2_custom.cpp + src/core/libraries/ngs2/ngs2_custom.h + src/core/libraries/ngs2/ngs2_reverb.cpp + src/core/libraries/ngs2/ngs2_reverb.h + src/core/libraries/ngs2/ngs2_geom.cpp + src/core/libraries/ngs2/ngs2_geom.h + src/core/libraries/ngs2/ngs2_pan.cpp + src/core/libraries/ngs2/ngs2_pan.h + src/core/libraries/ngs2/ngs2_report.cpp + src/core/libraries/ngs2/ngs2_report.h + src/core/libraries/ngs2/ngs2_eq.cpp + src/core/libraries/ngs2/ngs2_eq.h + src/core/libraries/ngs2/ngs2_mastering.cpp + src/core/libraries/ngs2/ngs2_mastering.h + src/core/libraries/ngs2/ngs2_sampler.cpp + src/core/libraries/ngs2/ngs2_sampler.h + src/core/libraries/ngs2/ngs2_submixer.cpp + src/core/libraries/ngs2/ngs2_submixer.h src/core/libraries/ajm/ajm_error.h src/core/libraries/audio3d/audio3d.cpp src/core/libraries/audio3d/audio3d.h diff --git a/src/core/libraries/ngs2/ngs2.cpp b/src/core/libraries/ngs2/ngs2.cpp index 7eb663413..0b42e2471 100644 --- a/src/core/libraries/ngs2/ngs2.cpp +++ b/src/core/libraries/ngs2/ngs2.cpp @@ -5,21 +5,480 @@ #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/ngs2/ngs2.h" +#include "core/libraries/ngs2/ngs2_custom.h" #include "core/libraries/ngs2/ngs2_error.h" +#include "core/libraries/ngs2/ngs2_geom.h" #include "core/libraries/ngs2/ngs2_impl.h" +#include "core/libraries/ngs2/ngs2_pan.h" +#include "core/libraries/ngs2/ngs2_report.h" namespace Libraries::Ngs2 { -int PS4_SYSV_ABI sceNgs2CalcWaveformBlock() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); +// Ngs2 + +s32 PS4_SYSV_ABI sceNgs2CalcWaveformBlock(const OrbisNgs2WaveformFormat* format, u32 samplePos, + u32 numSamples, OrbisNgs2WaveformBlock* outBlock) { + LOG_INFO(Lib_Ngs2, "samplePos = {}, numSamples = {}", samplePos, numSamples); return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2CustomRackGetModuleInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); +s32 PS4_SYSV_ABI sceNgs2GetWaveformFrameInfo(const OrbisNgs2WaveformFormat* format, + u32* outFrameSize, u32* outNumFrameSamples, + u32* outUnitsPerFrame, u32* outNumDelaySamples) { + LOG_INFO(Lib_Ngs2, "called"); return ORBIS_OK; } +s32 PS4_SYSV_ABI sceNgs2ParseWaveformData(const void* data, size_t dataSize, + OrbisNgs2WaveformInfo* outInfo) { + LOG_INFO(Lib_Ngs2, "dataSize = {}", dataSize); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2ParseWaveformFile(const char* path, u64 offset, + OrbisNgs2WaveformInfo* outInfo) { + LOG_INFO(Lib_Ngs2, "path = {}, offset = {}", path, offset); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2ParseWaveformUser(OrbisNgs2ParseReadHandler handler, uintptr_t userData, + OrbisNgs2WaveformInfo* outInfo) { + LOG_INFO(Lib_Ngs2, "userData = {}", userData); + if (!handler) { + LOG_ERROR(Lib_Ngs2, "handler is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackCreate(OrbisNgs2Handle systemHandle, u32 rackId, + const OrbisNgs2RackOption* option, + const OrbisNgs2ContextBufferInfo* bufferInfo, + OrbisNgs2Handle* outHandle) { + LOG_INFO(Lib_Ngs2, "rackId = {}", rackId); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackCreateWithAllocator(OrbisNgs2Handle systemHandle, u32 rackId, + const OrbisNgs2RackOption* option, + const OrbisNgs2BufferAllocator* allocator, + OrbisNgs2Handle* outHandle) { + LOG_INFO(Lib_Ngs2, "rackId = {}", rackId); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackDestroy(OrbisNgs2Handle rackHandle, + OrbisNgs2ContextBufferInfo* outBufferInfo) { + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackGetInfo(OrbisNgs2Handle rackHandle, OrbisNgs2RackInfo* outInfo, + size_t infoSize) { + LOG_INFO(Lib_Ngs2, "infoSize = {}", infoSize); + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackGetUserData(OrbisNgs2Handle rackHandle, uintptr_t* outUserData) { + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackGetVoiceHandle(OrbisNgs2Handle rackHandle, u32 voiceIndex, + OrbisNgs2Handle* outHandle) { + LOG_INFO(Lib_Ngs2, "voiceIndex = {}", voiceIndex); + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackLock(OrbisNgs2Handle rackHandle) { + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackQueryBufferSize(u32 rackId, const OrbisNgs2RackOption* option, + OrbisNgs2ContextBufferInfo* outBufferInfo) { + LOG_INFO(Lib_Ngs2, "rackId = {}", rackId); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackSetUserData(OrbisNgs2Handle rackHandle, uintptr_t userData) { + LOG_INFO(Lib_Ngs2, "userData = {}", userData); + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2RackUnlock(OrbisNgs2Handle rackHandle) { + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemCreate(const OrbisNgs2SystemOption* option, + const OrbisNgs2ContextBufferInfo* bufferInfo, + OrbisNgs2Handle* outHandle) { + s32 result; + OrbisNgs2ContextBufferInfo localInfo; + if (!bufferInfo || !outHandle) { + if (!bufferInfo) { + result = ORBIS_NGS2_ERROR_INVALID_BUFFER_INFO; + LOG_ERROR(Lib_Ngs2, "Invalid system buffer info {}", (void*)bufferInfo); + } else { + result = ORBIS_NGS2_ERROR_INVALID_OUT_ADDRESS; + LOG_ERROR(Lib_Ngs2, "Invalid system handle address {}", (void*)outHandle); + } + + // TODO: Report errors? + } else { + // Make bufferInfo copy + localInfo.hostBuffer = bufferInfo->hostBuffer; + localInfo.hostBufferSize = bufferInfo->hostBufferSize; + for (int i = 0; i < 5; i++) { + localInfo.reserved[i] = bufferInfo->reserved[i]; + } + localInfo.userData = bufferInfo->userData; + + result = SystemSetup(option, &localInfo, 0, outHandle); + } + + // TODO: API reporting? + + LOG_INFO(Lib_Ngs2, "called"); + return result; +} + +s32 PS4_SYSV_ABI sceNgs2SystemCreateWithAllocator(const OrbisNgs2SystemOption* option, + const OrbisNgs2BufferAllocator* allocator, + OrbisNgs2Handle* outHandle) { + s32 result; + if (allocator && allocator->allocHandler != 0) { + OrbisNgs2BufferAllocHandler hostAlloc = allocator->allocHandler; + if (outHandle) { + OrbisNgs2BufferFreeHandler hostFree = allocator->freeHandler; + OrbisNgs2ContextBufferInfo* bufferInfo = 0; + result = SystemSetup(option, bufferInfo, 0, 0); + if (result >= 0) { + uintptr_t sysUserData = allocator->userData; + result = hostAlloc(bufferInfo); + if (result >= 0) { + OrbisNgs2Handle* handleCopy = outHandle; + result = SystemSetup(option, bufferInfo, hostFree, handleCopy); + if (result < 0) { + if (hostFree) { + hostFree(bufferInfo); + } + } + } + } + } else { + result = ORBIS_NGS2_ERROR_INVALID_OUT_ADDRESS; + LOG_ERROR(Lib_Ngs2, "Invalid system handle address {}", (void*)outHandle); + } + } else { + result = ORBIS_NGS2_ERROR_INVALID_BUFFER_ALLOCATOR; + LOG_ERROR(Lib_Ngs2, "Invalid system buffer allocator {}", (void*)allocator); + } + LOG_INFO(Lib_Ngs2, "called"); + return result; +} + +s32 PS4_SYSV_ABI sceNgs2SystemDestroy(OrbisNgs2Handle systemHandle, + OrbisNgs2ContextBufferInfo* outBufferInfo) { + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemEnumHandles(OrbisNgs2Handle* aOutHandle, u32 maxHandles) { + LOG_INFO(Lib_Ngs2, "maxHandles = {}", maxHandles); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemEnumRackHandles(OrbisNgs2Handle systemHandle, + OrbisNgs2Handle* aOutHandle, u32 maxHandles) { + LOG_INFO(Lib_Ngs2, "maxHandles = {}", maxHandles); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemGetInfo(OrbisNgs2Handle rackHandle, OrbisNgs2SystemInfo* outInfo, + size_t infoSize) { + LOG_INFO(Lib_Ngs2, "infoSize = {}", infoSize); + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemGetUserData(OrbisNgs2Handle systemHandle, uintptr_t* outUserData) { + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemLock(OrbisNgs2Handle systemHandle) { + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemQueryBufferSize(const OrbisNgs2SystemOption* option, + OrbisNgs2ContextBufferInfo* outBufferInfo) { + s32 result; + if (outBufferInfo) { + result = SystemSetup(option, outBufferInfo, 0, 0); + LOG_INFO(Lib_Ngs2, "called"); + } else { + result = ORBIS_NGS2_ERROR_INVALID_OUT_ADDRESS; + LOG_ERROR(Lib_Ngs2, "Invalid system buffer info {}", (void*)outBufferInfo); + } + + return result; +} + +s32 PS4_SYSV_ABI sceNgs2SystemRender(OrbisNgs2Handle systemHandle, + const OrbisNgs2RenderBufferInfo* aBufferInfo, + u32 numBufferInfo) { + LOG_INFO(Lib_Ngs2, "numBufferInfo = {}", numBufferInfo); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +static s32 PS4_SYSV_ABI sceNgs2SystemResetOption(OrbisNgs2SystemOption* outOption) { + static const OrbisNgs2SystemOption option = { + sizeof(OrbisNgs2SystemOption), "", 0, 512, 256, 48000, {0}}; + + if (!outOption) { + LOG_ERROR(Lib_Ngs2, "Invalid system option address {}", (void*)outOption); + return ORBIS_NGS2_ERROR_INVALID_OPTION_ADDRESS; + } + *outOption = option; + + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemSetGrainSamples(OrbisNgs2Handle systemHandle, u32 numSamples) { + LOG_INFO(Lib_Ngs2, "numSamples = {}", numSamples); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemSetSampleRate(OrbisNgs2Handle systemHandle, u32 sampleRate) { + LOG_INFO(Lib_Ngs2, "sampleRate = {}", sampleRate); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemSetUserData(OrbisNgs2Handle systemHandle, uintptr_t userData) { + LOG_INFO(Lib_Ngs2, "userData = {}", userData); + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2SystemUnlock(OrbisNgs2Handle systemHandle) { + if (!systemHandle) { + LOG_ERROR(Lib_Ngs2, "systemHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceControl(OrbisNgs2Handle voiceHandle, + const OrbisNgs2VoiceParamHeader* paramList) { + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceGetMatrixInfo(OrbisNgs2Handle voiceHandle, u32 matrixId, + OrbisNgs2VoiceMatrixInfo* outInfo, size_t outInfoSize) { + LOG_INFO(Lib_Ngs2, "matrixId = {}, outInfoSize = {}", matrixId, outInfoSize); + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceGetOwner(OrbisNgs2Handle voiceHandle, OrbisNgs2Handle* outRackHandle, + u32* outVoiceId) { + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceGetPortInfo(OrbisNgs2Handle voiceHandle, u32 port, + OrbisNgs2VoicePortInfo* outInfo, size_t outInfoSize) { + LOG_INFO(Lib_Ngs2, "port = {}, outInfoSize = {}", port, outInfoSize); + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceGetState(OrbisNgs2Handle voiceHandle, OrbisNgs2VoiceState* outState, + size_t stateSize) { + LOG_INFO(Lib_Ngs2, "stateSize = {}", stateSize); + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2VoiceGetStateFlags(OrbisNgs2Handle voiceHandle, u32* outStateFlags) { + if (!voiceHandle) { + LOG_ERROR(Lib_Ngs2, "voiceHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +// Ngs2Custom + +s32 PS4_SYSV_ABI sceNgs2CustomRackGetModuleInfo(OrbisNgs2Handle rackHandle, u32 moduleIndex, + OrbisNgs2CustomModuleInfo* outInfo, + size_t infoSize) { + LOG_INFO(Lib_Ngs2, "moduleIndex = {}, infoSize = {}", moduleIndex, infoSize); + if (!rackHandle) { + LOG_ERROR(Lib_Ngs2, "rackHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; + } + return ORBIS_OK; +} + +// Ngs2Geom + +s32 PS4_SYSV_ABI sceNgs2GeomResetListenerParam(OrbisNgs2GeomListenerParam* outListenerParam) { + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2GeomResetSourceParam(OrbisNgs2GeomSourceParam* outSourceParam) { + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2GeomCalcListener(const OrbisNgs2GeomListenerParam* param, + OrbisNgs2GeomListenerWork* outWork, u32 flags) { + LOG_INFO(Lib_Ngs2, "flags = {}", flags); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2GeomApply(const OrbisNgs2GeomListenerWork* listener, + const OrbisNgs2GeomSourceParam* source, + OrbisNgs2GeomAttribute* outAttrib, u32 flags) { + LOG_INFO(Lib_Ngs2, "flags = {}", flags); + return ORBIS_OK; +} + +// Ngs2Pan + +s32 PS4_SYSV_ABI sceNgs2PanInit(OrbisNgs2PanWork* work, const float* aSpeakerAngle, float unitAngle, + u32 numSpeakers) { + LOG_INFO(Lib_Ngs2, "aSpeakerAngle = {}, unitAngle = {}, numSpeakers = {}", *aSpeakerAngle, + unitAngle, numSpeakers); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2PanGetVolumeMatrix(OrbisNgs2PanWork* work, const OrbisNgs2PanParam* aParam, + u32 numParams, u32 matrixFormat, + float* outVolumeMatrix) { + LOG_INFO(Lib_Ngs2, "numParams = {}, matrixFormat = {}", numParams, matrixFormat); + return ORBIS_OK; +} + +// Ngs2Report + +s32 PS4_SYSV_ABI sceNgs2ReportRegisterHandler(u32 reportType, OrbisNgs2ReportHandler handler, + uintptr_t userData, OrbisNgs2Handle* outHandle) { + LOG_INFO(Lib_Ngs2, "reportType = {}, userData = {}", reportType, userData); + if (!handler) { + LOG_ERROR(Lib_Ngs2, "handler is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_REPORT_HANDLE; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceNgs2ReportUnregisterHandler(OrbisNgs2Handle reportHandle) { + if (!reportHandle) { + LOG_ERROR(Lib_Ngs2, "reportHandle is nullptr"); + return ORBIS_NGS2_ERROR_INVALID_REPORT_HANDLE; + } + LOG_INFO(Lib_Ngs2, "called"); + return ORBIS_OK; +} + +// Unknown + int PS4_SYSV_ABI sceNgs2FftInit() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; @@ -35,31 +494,6 @@ int PS4_SYSV_ABI sceNgs2FftQuerySize() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2GeomApply() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2GeomCalcListener() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2GeomResetListenerParam() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2GeomResetSourceParam() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2GetWaveformFrameInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2JobSchedulerResetOption() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; @@ -80,71 +514,6 @@ int PS4_SYSV_ABI sceNgs2ModuleQueueEnumItems() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2PanGetVolumeMatrix() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2PanInit() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2ParseWaveformData() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2ParseWaveformFile() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2ParseWaveformUser() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackCreate() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackCreateWithAllocator() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackDestroy() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackGetInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackGetUserData() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackGetVoiceHandle() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackLock() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackQueryBufferSize() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2RackQueryInfo() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; @@ -155,116 +524,21 @@ int PS4_SYSV_ABI sceNgs2RackRunCommands() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2RackSetUserData() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2RackUnlock() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2ReportRegisterHandler() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2ReportUnregisterHandler() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemCreate() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemCreateWithAllocator() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemDestroy() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemEnumHandles() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemEnumRackHandles() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemGetInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemGetUserData() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemLock() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemQueryBufferSize() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2SystemQueryInfo() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2SystemRender() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemResetOption() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2SystemRunCommands() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2SystemSetGrainSamples() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2SystemSetLoudThreshold() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2SystemSetSampleRate() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemSetUserData() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2SystemUnlock() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2StreamCreate() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; @@ -300,36 +574,6 @@ int PS4_SYSV_ABI sceNgs2StreamRunCommands() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNgs2VoiceControl() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2VoiceGetMatrixInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2VoiceGetOwner() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2VoiceGetPortInfo() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2VoiceGetState() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - -int PS4_SYSV_ABI sceNgs2VoiceGetStateFlags() { - LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); - return ORBIS_OK; -} - int PS4_SYSV_ABI sceNgs2VoiceQueryInfo() { LOG_ERROR(Lib_Ngs2, "(STUBBED) called"); return ORBIS_OK; diff --git a/src/core/libraries/ngs2/ngs2.h b/src/core/libraries/ngs2/ngs2.h index a5f1f52a6..a34bf21d4 100644 --- a/src/core/libraries/ngs2/ngs2.h +++ b/src/core/libraries/ngs2/ngs2.h @@ -3,7 +3,11 @@ #pragma once +#include "core/libraries/ngs2/ngs2_impl.h" + #include +#include +#include #include "common/types.h" namespace Core::Loader { @@ -12,60 +16,253 @@ class SymbolsResolver; namespace Libraries::Ngs2 { -class Ngs2; +typedef s32 (*OrbisNgs2ParseReadHandler)(uintptr_t userData, u32 offset, void* data, size_t size); -using SceNgs2Handle = Ngs2*; - -enum class SceNgs2HandleType : u32 { - System = 0, +enum class OrbisNgs2HandleType : u32 { + Invalid = 0, + System = 1, + Rack = 2, + Voice = 3, + VoiceControl = 6 }; -struct Ngs2Handle { - void* selfPointer; - void* dataPointer; - std::atomic* atomicPtr; - u32 handleType; - u32 flags_unk; +static const int ORBIS_NGS2_MAX_VOICE_CHANNELS = 8; +static const int ORBIS_NGS2_WAVEFORM_INFO_MAX_BLOCKS = 4; +static const int ORBIS_NGS2_MAX_MATRIX_LEVELS = + (ORBIS_NGS2_MAX_VOICE_CHANNELS * ORBIS_NGS2_MAX_VOICE_CHANNELS); - u32 uid; - u16 maxGrainSamples; - u16 minGrainSamples; - u16 currentGrainSamples; - u16 numGrainSamples; - u16 unknown2; +struct OrbisNgs2WaveformFormat { + u32 waveformType; + u32 numChannels; u32 sampleRate; - u32 unknown3; - - void* flushMutex; - u32 flushMutexInitialized; - void* processMutex; - u32 processMutexInitialized; - - // Linked list pointers for system list - Ngs2Handle* prev; - Ngs2Handle* next; + u32 configData; + u32 frameOffset; + u32 frameMargin; }; -struct SystemOptions { - char padding[6]; - s32 maxGrainSamples; - s32 numGrainSamples; - s32 sampleRate; +struct OrbisNgs2WaveformBlock { + u32 dataOffset; + u32 dataSize; + u32 numRepeats; + u32 numSkipSamples; + u32 numSamples; + u32 reserved; + uintptr_t userData; }; -struct SystemState { - // TODO +struct OrbisNgs2WaveformInfo { + OrbisNgs2WaveformFormat format; + + u32 dataOffset; + u32 dataSize; + + u32 loopBeginPosition; + u32 loopEndPosition; + u32 numSamples; + + u32 audioUnitSize; + u32 numAudioUnitSamples; + u32 numAudioUnitPerFrame; + + u32 audioFrameSize; + u32 numAudioFrameSamples; + + u32 numDelaySamples; + + u32 numBlocks; + OrbisNgs2WaveformBlock aBlock[ORBIS_NGS2_WAVEFORM_INFO_MAX_BLOCKS]; }; -struct StackBuffer { - void** top; - void* base; - void* curr; - size_t usedSize; - size_t totalSize; - size_t alignment; - char isVerifyEnabled; - char padding[7]; +struct OrbisNgs2EnvelopePoint { + u32 curve; + u32 duration; + float height; +}; + +struct OrbisNgs2UserFxProcessContext { + float** aChannelData; + uintptr_t userData0; + uintptr_t userData1; + uintptr_t userData2; + u32 flags; + u32 numChannels; + u32 numGrainSamples; + u32 sampleRate; +}; + +typedef s32 (*OrbisNgs2UserFxProcessHandler)(OrbisNgs2UserFxProcessContext* context); + +struct OrbisNgs2UserFx2SetupContext { + void* common; + void* param; + void* work; + uintptr_t userData; + u32 maxVoices; + u32 voiceIndex; + u64 reserved[4]; +}; + +typedef s32 (*OrbisNgs2UserFx2SetupHandler)(OrbisNgs2UserFx2SetupContext* context); + +struct OrbisNgs2UserFx2CleanupContext { + void* common; + void* param; + void* work; + uintptr_t userData; + u32 maxVoices; + u32 voiceIndex; + u64 reserved[4]; +}; + +typedef s32 (*OrbisNgs2UserFx2CleanupHandler)(OrbisNgs2UserFx2CleanupContext* context); + +struct OrbisNgs2UserFx2ControlContext { + const void* data; + size_t dataSize; + void* common; + void* param; + uintptr_t userData; + u64 reserved[4]; +}; + +typedef s32 (*OrbisNgs2UserFx2ControlHandler)(OrbisNgs2UserFx2ControlContext* context); + +struct OrbisNgs2UserFx2ProcessContext { + float** aChannelData; + void* common; + const void* param; + void* work; + void* state; + uintptr_t userData; + u32 flags; + u32 numInputChannels; + u32 numOutputChannels; + u32 numGrainSamples; + u32 sampleRate; + u32 reserved; + u64 reserved2[4]; +}; + +typedef s32 (*OrbisNgs2UserFx2ProcessHandler)(OrbisNgs2UserFx2ProcessContext* context); + +struct OrbisNgs2BufferAllocator { + OrbisNgs2BufferAllocHandler allocHandler; + OrbisNgs2BufferFreeHandler freeHandler; + uintptr_t userData; +}; + +struct OrbisNgs2RenderBufferInfo { + void* buffer; + size_t bufferSize; + u32 waveformType; + u32 numChannels; +}; + +struct OrbisNgs2RackOption { + size_t size; + char name[ORBIS_NGS2_RACK_NAME_LENGTH]; + + u32 flags; + u32 maxGrainSamples; + u32 maxVoices; + u32 maxInputDelayBlocks; + u32 maxMatrices; + u32 maxPorts; + u32 aReserved[20]; +}; + +struct OrbisNgs2VoiceParamHeader { + u16 size; + s16 next; + u32 id; +}; + +struct OrbisNgs2VoiceMatrixLevelsParam { + OrbisNgs2VoiceParamHeader header; + + u32 matrixId; + u32 numLevels; + const float* aLevel; +}; + +struct OrbisNgs2VoicePortMatrixParam { + OrbisNgs2VoiceParamHeader header; + + u32 port; + s32 matrixId; +}; + +struct OrbisNgs2VoicePortVolumeParam { + OrbisNgs2VoiceParamHeader header; + + u32 port; + float level; +}; + +struct OrbisNgs2VoicePortDelayParam { + OrbisNgs2VoiceParamHeader header; + + u32 port; + u32 numSamples; +}; + +struct OrbisNgs2VoicePatchParam { + OrbisNgs2VoiceParamHeader header; + + u32 port; + u32 destInputId; + OrbisNgs2Handle destHandle; +}; + +struct OrbisNgs2VoiceEventParam { + OrbisNgs2VoiceParamHeader header; + + u32 eventId; +}; + +struct OrbisNgs2VoiceCallbackInfo { + uintptr_t callbackData; + OrbisNgs2Handle voiceHandle; + u32 flag; + u32 reserved; + union { + struct { + uintptr_t userData; + const void* data; + u32 dataSize; + u32 repeatedCount; + u32 attributeFlags; + u32 reserved2; + } waveformBlock; + } param; +}; + +typedef void (*OrbisNgs2VoiceCallbackHandler)(const OrbisNgs2VoiceCallbackInfo* info); + +struct OrbisNgs2VoiceCallbackParam { + OrbisNgs2VoiceParamHeader header; + OrbisNgs2VoiceCallbackHandler callbackHandler; + + uintptr_t callbackData; + u32 flags; + u32 reserved; +}; + +struct OrbisNgs2VoicePortInfo { + s32 matrixId; + float volume; + u32 numDelaySamples; + u32 destInputId; + OrbisNgs2Handle destHandle; +}; + +struct OrbisNgs2VoiceMatrixInfo { + u32 numLevels; + float aLevel[ORBIS_NGS2_MAX_MATRIX_LEVELS]; +}; + +struct OrbisNgs2VoiceState { + u32 stateFlags; }; void RegisterlibSceNgs2(Core::Loader::SymbolsResolver* sym); diff --git a/src/core/libraries/ngs2/ngs2_custom.cpp b/src/core/libraries/ngs2/ngs2_custom.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_custom.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_custom.h b/src/core/libraries/ngs2/ngs2_custom.h new file mode 100644 index 000000000..0c45a5d81 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_custom.h @@ -0,0 +1,444 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" +#include "ngs2_reverb.h" + +namespace Libraries::Ngs2 { + +class Ngs2Custom; + +static const int ORBIS_NGS2_CUSTOM_MAX_MODULES = 24; +static const int ORBIS_NGS2_CUSTOM_MAX_PORTS = 16; +static const int ORBIS_NGS2_CUSTOM_DELAY_MAX_TAPS = 8; + +struct OrbisNgs2CustomModuleOption { + u32 size; +}; + +struct OrbisNgs2CustomEnvelopeModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + u32 maxPoints; + u32 reserved; +}; + +struct OrbisNgs2CustomReverbModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + u32 reverbSize; + u32 reserved; +}; + +struct OrbisNgs2CustomChorusModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + u32 maxPhases; + u32 reserved; +} OrbisNgs2CustomChorusModuleOption; + +struct OrbisNgs2CustomPeakMeterModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + u32 numBlocks; + u32 reserved; +}; + +struct OrbisNgs2CustomDelayModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + u32 type; + u32 maxTaps; + float maxLength; + u32 reserved; +}; + +struct OrbisNgs2CustomPitchShiftModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + u32 quality; +}; + +struct OrbisNgs2CustomUserFx2ModuleOption { + OrbisNgs2CustomModuleOption customModuleOption; + + OrbisNgs2UserFx2SetupHandler setupHandler; + OrbisNgs2UserFx2CleanupHandler cleanupHandler; + OrbisNgs2UserFx2ControlHandler controlHandler; + OrbisNgs2UserFx2ProcessHandler processHandler; + + size_t commonSize; + size_t paramSize; + size_t workSize; + uintptr_t userData; +}; + +struct OrbisNgs2CustomRackModuleInfo { + const OrbisNgs2CustomModuleOption* option; + + u32 moduleId; + u32 sourceBufferId; + u32 extraBufferId; + u32 destBufferId; + u32 stateOffset; + u32 stateSize; + u32 reserved; + u32 reserved2; +}; + +struct OrbisNgs2CustomRackPortInfo { + u32 sourceBufferId; + u32 reserved; +}; + +struct OrbisNgs2CustomRackOption { + OrbisNgs2RackOption rackOption; + u32 stateSize; + u32 numBuffers; + u32 numModules; + u32 reserved; + OrbisNgs2CustomRackModuleInfo aModule[ORBIS_NGS2_CUSTOM_MAX_MODULES]; + OrbisNgs2CustomRackPortInfo aPort[ORBIS_NGS2_CUSTOM_MAX_PORTS]; +}; + +struct OrbisNgs2CustomSamplerRackOption { + OrbisNgs2CustomRackOption customRackOption; + + u32 maxChannelWorks; + u32 maxWaveformBlocks; + u32 maxAtrac9Decoders; + u32 maxAtrac9ChannelWorks; + u32 maxAjmAtrac9Decoders; + u32 maxCodecCaches; +}; + +struct OrbisNgs2CustomSubmixerRackOption { + OrbisNgs2CustomRackOption customRackOption; + + u32 maxChannels; + u32 maxInputs; +}; + +struct OrbisNgs2CustomMasteringRackOption { + OrbisNgs2CustomRackOption customRackOption; + + u32 maxChannels; + u32 maxInputs; +}; + +struct OrbisNgs2CustomSamplerVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + OrbisNgs2WaveformFormat format; + u32 flags; + u32 reserved; +}; + +struct OrbisNgs2CustomSamplerVoiceWaveformBlocksParam { + OrbisNgs2VoiceParamHeader header; + const void* data; + u32 flags; + u32 numBlocks; + const OrbisNgs2WaveformBlock* aBlock; +}; + +struct OrbisNgs2CustomSamplerVoiceWaveformAddressParam { + OrbisNgs2VoiceParamHeader header; + const void* from; + const void* to; +}; + +struct OrbisNgs2CustomSamplerVoiceWaveformFrameOffsetParam { + OrbisNgs2VoiceParamHeader header; + u32 frameOffset; + u32 reserved; +}; + +struct OrbisNgs2CustomSamplerVoiceExitLoopParam { + OrbisNgs2VoiceParamHeader header; +}; + +struct OrbisNgs2CustomSamplerVoicePitchParam { + OrbisNgs2VoiceParamHeader header; + float ratio; + u32 reserved; +}; + +struct OrbisNgs2CustomSamplerVoiceState { + OrbisNgs2VoiceState voiceState; + char padding[32]; + const void* waveformData; + u64 numDecodedSamples; + u64 decodedDataSize; + u64 userData; + u32 reserved; + u32 reserved2; +}; + +struct OrbisNgs2CustomSubmixerVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + u32 numInputChannels; + u32 numOutputChannels; + u32 flags; + u32 reserved; +}; + +struct OrbisNgs2CustomSubmixerVoiceState { + OrbisNgs2VoiceState voiceState; // Voice state + u32 reserved; + u32 reserved2; +}; + +struct OrbisNgs2CustomMasteringVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + u32 numInputChannels; + u32 flags; +}; + +struct OrbisNgs2CustomMasteringVoiceOutputParam { + OrbisNgs2VoiceParamHeader header; + u32 outputId; + u32 reserved; +}; + +struct OrbisNgs2CustomMasteringVoiceState { + OrbisNgs2VoiceState voiceState; + u32 reserved; + u32 reserved2; +}; + +struct OrbisNgs2CustomVoiceEnvelopeParam { + OrbisNgs2VoiceParamHeader header; + u32 numForwardPoints; + u32 numReleasePoints; + const OrbisNgs2EnvelopePoint* aPoint; +}; + +struct OrbisNgs2CustomVoiceDistortionParam { + OrbisNgs2VoiceParamHeader header; + u32 flags; + float a; + float b; + float clip; + float gate; + float wetLevel; + float dryLevel; + u32 reserved; +}; + +struct OrbisNgs2CustomVoiceCompressorParam { + OrbisNgs2VoiceParamHeader header; + u32 flags; + float threshold; + float ratio; + float knee; + float attackTime; + float releaseTime; + float level; + u32 reserved; +}; + +struct OrbisNgs2CustomVoiceFilterParam { + OrbisNgs2VoiceParamHeader header; + u32 type; + u32 channelMask; + union { + struct { + float i0; + float i1; + float i2; + float o1; + float o2; + } direct; + struct { + float fc; + float q; + float level; + u32 reserved; + u32 reserved2; + } fcq; + } param; + u32 reserved3; +}; + +struct OrbisNgs2CustomVoiceLfeFilterParam { + OrbisNgs2VoiceParamHeader header; + u32 enableFlag; + u32 fc; +}; + +struct OrbisNgs2CustomVoiceGainParam { + OrbisNgs2VoiceParamHeader header; + float aLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS]; +}; + +struct OrbisNgs2CustomVoiceMixerParam { + OrbisNgs2VoiceParamHeader header; + float aSourceLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS]; + float aDestLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS]; +}; + +struct OrbisNgs2CustomVoiceChannelMixerParam { + OrbisNgs2VoiceParamHeader header; + float aLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS][ORBIS_NGS2_MAX_VOICE_CHANNELS]; +}; + +struct OrbisNgs2CustomVoiceUserFxParam { + OrbisNgs2VoiceParamHeader header; + OrbisNgs2UserFxProcessHandler handler; + + uintptr_t userData0; + uintptr_t userData1; + uintptr_t userData2; +}; + +struct OrbisNgs2CustomVoiceUserFx2Param { + OrbisNgs2VoiceParamHeader header; + const void* data; + size_t dataSize; +}; + +struct OrbisNgs2CustomVoiceOutputParam { + OrbisNgs2VoiceParamHeader header; + u32 outputId; + u32 reserved; +}; + +struct OrbisNgs2CustomVoicePeakMeterParam { + OrbisNgs2VoiceParamHeader header; + u32 enableFlag; + u32 reserved; +} OrbisNgs2CustomVoicePeakMeterParam; + +struct OrbisNgs2CustomVoiceReverbParam { + OrbisNgs2VoiceParamHeader header; + OrbisNgs2ReverbI3DL2Param i3dl2; +}; + +struct OrbisNgs2CustomVoiceChorusParam { + OrbisNgs2VoiceParamHeader header; + u32 flags; + u32 numPhases; + u32 channelMask; + float inputLevel; + float delayTime; + float modulationRatio; + float modulationDepth; + float feedbackLevel; + float wetLevel; + float dryLevel; +}; + +struct OrbisNgs2DelayTapInfo { + float tapLevel; + float delayTime; +}; + +struct OrbisNgs2CustomVoiceDelayParam { + OrbisNgs2VoiceParamHeader header; + float dryLevel; + float wetLevel; + float inputLevel; + float feedbackLevel; + float lowpassFc; + u32 numTaps; + OrbisNgs2DelayTapInfo aTap[ORBIS_NGS2_CUSTOM_DELAY_MAX_TAPS]; + float aInputMixLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS]; + u32 channelMask; + u32 flags; +}; + +struct OrbisNgs2CustomVoiceNoiseGateParam { + OrbisNgs2VoiceParamHeader header; + u32 flags; + float threshold; + float attackTime; + float releaseTime; +}; + +struct OrbisNgs2CustomVoicePitchShiftParam { + OrbisNgs2VoiceParamHeader header; + s32 cent; +}; + +struct OrbisNgs2CustomEnvelopeModuleState { + float height; + u32 reserved; +}; + +struct OrbisNgs2CustomCompressorModuleState { + float peakHeight; + float compressorHeight; +}; + +struct OrbisNgs2CustomPeakMeterModuleState { + float peak; + float aChannelPeak[ORBIS_NGS2_MAX_VOICE_CHANNELS]; + u32 reserved; +}; + +struct OrbisNgs2CustomNoiseGateModuleState { + float gateHeight; +}; + +struct OrbisNgs2CustomRackInfo { + OrbisNgs2RackInfo rackInfo; + u32 stateSize; + u32 numBuffers; + u32 numModules; + u32 reserved; + OrbisNgs2CustomRackModuleInfo aModule[ORBIS_NGS2_CUSTOM_MAX_MODULES]; + OrbisNgs2CustomRackPortInfo aPort[ORBIS_NGS2_CUSTOM_MAX_PORTS]; +}; + +struct OrbisNgs2CustomSamplerRackInfo { + OrbisNgs2CustomRackInfo customRackInfo; + + u32 maxChannelWorks; + u32 maxWaveformBlocks; + u32 maxAtrac9Decoders; + u32 maxAtrac9ChannelWorks; + u32 maxAjmAtrac9Decoders; + u32 maxCodecCaches; +}; + +struct OrbisNgs2CustomSubmixerRackInfo { + OrbisNgs2CustomRackInfo customRackInfo; + + u32 maxChannels; + u32 maxInputs; +}; + +struct OrbisNgs2CustomMasteringRackInfo { + OrbisNgs2CustomRackInfo customRackInfo; + + u32 maxChannels; + u32 maxInputs; +}; + +struct OrbisNgs2CustomModuleInfo { + u32 moduleId; + u32 sourceBufferId; + u32 extraBufferId; + u32 destBufferId; + u32 stateOffset; + u32 stateSize; + u32 reserved; + u32 reserved2; +}; + +struct OrbisNgs2CustomEnvelopeModuleInfo { + OrbisNgs2CustomModuleInfo moduleInfo; + + u32 maxPoints; + u32 reserved; +}; + +struct OrbisNgs2CustomReverbModuleInfo { + OrbisNgs2CustomModuleInfo moduleInfo; + + u32 reverbSize; + u32 reserved; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_eq.cpp b/src/core/libraries/ngs2/ngs2_eq.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_eq.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_eq.h b/src/core/libraries/ngs2/ngs2_eq.h new file mode 100644 index 000000000..99688f24e --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_eq.h @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Eq; + +struct OrbisNgs2EqVoiceSetupParam { + u32 numChannels; +}; + +struct OrbisNgs2EqVoiceFilterParam { + u32 type; + u32 channelMask; + union { + struct { + float i0; + float i1; + float i2; + float o1; + float o2; + } direct; + struct { + float fc; + float q; + float level; + u32 reserved; + u32 reserved2; + } fcq; + } param; +}; + +struct OrbisNgs2EqVoiceState { + u32 stateFlags; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_geom.cpp b/src/core/libraries/ngs2/ngs2_geom.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_geom.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_geom.h b/src/core/libraries/ngs2/ngs2_geom.h new file mode 100644 index 000000000..93af99d8d --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_geom.h @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Geom; + +struct OrbisNgs2GeomVector { + float x; + float y; + float z; +}; + +struct OrbisNgs2GeomCone { + float innerLevel; + float innerAngle; + float outerLevel; + float outerAngle; +}; + +struct OrbisNgs2GeomRolloff { + u32 model; + float maxDistance; + float rolloffFactor; + float referenceDistance; +}; + +struct OrbisNgs2GeomListenerParam { + OrbisNgs2GeomVector position; + OrbisNgs2GeomVector orientFront; + OrbisNgs2GeomVector orientUp; + OrbisNgs2GeomVector velocity; + float soundSpeed; + u32 reserved[2]; +}; + +struct OrbisNgs2GeomListenerWork { + float matrix[4][4]; + OrbisNgs2GeomVector velocity; + float soundSpeed; + u32 coordinate; + u32 reserved[3]; +}; + +struct OrbisNgs2GeomSourceParam { + OrbisNgs2GeomVector position; + OrbisNgs2GeomVector velocity; + OrbisNgs2GeomVector direction; + OrbisNgs2GeomCone cone; + OrbisNgs2GeomRolloff rolloff; + float dopplerFactor; + float fbwLevel; + float lfeLevel; + float maxLevel; + float minLevel; + float radius; + u32 numSpeakers; + u32 matrixFormat; + u32 reserved[2]; +}; + +struct OrbisNgs2GeomA3dAttribute { + OrbisNgs2GeomVector position; + float volume; + u32 reserved[4]; +}; + +struct OrbisNgs2GeomAttribute { + float pitchRatio; + float aLevel[ORBIS_NGS2_MAX_VOICE_CHANNELS * ORBIS_NGS2_MAX_VOICE_CHANNELS]; + + OrbisNgs2GeomA3dAttribute a3dAttrib; + u32 reserved[4]; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_impl.cpp b/src/core/libraries/ngs2/ngs2_impl.cpp index b358a05f7..1248f76d7 100644 --- a/src/core/libraries/ngs2/ngs2_impl.cpp +++ b/src/core/libraries/ngs2/ngs2_impl.cpp @@ -12,153 +12,171 @@ using namespace Libraries::Kernel; namespace Libraries::Ngs2 { -s32 Ngs2::ReportInvalid(Ngs2Handle* handle, u32 handle_type) const { - uintptr_t hAddress = reinterpret_cast(handle); - switch (handle_type) { +s32 HandleReportInvalid(OrbisNgs2Handle handle, u32 handleType) { + switch (handleType) { case 1: - LOG_ERROR(Lib_Ngs2, "Invalid system handle {}", hAddress); + LOG_ERROR(Lib_Ngs2, "Invalid system handle {}", handle); return ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE; case 2: - LOG_ERROR(Lib_Ngs2, "Invalid rack handle {}", hAddress); + LOG_ERROR(Lib_Ngs2, "Invalid rack handle {}", handle); return ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE; case 4: - LOG_ERROR(Lib_Ngs2, "Invalid voice handle {}", hAddress); + LOG_ERROR(Lib_Ngs2, "Invalid voice handle {}", handle); return ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE; case 8: - LOG_ERROR(Lib_Ngs2, "Invalid report handle {}", hAddress); + LOG_ERROR(Lib_Ngs2, "Invalid report handle {}", handle); return ORBIS_NGS2_ERROR_INVALID_REPORT_HANDLE; default: - LOG_ERROR(Lib_Ngs2, "Invalid handle {}", hAddress); + LOG_ERROR(Lib_Ngs2, "Invalid handle {}", handle); return ORBIS_NGS2_ERROR_INVALID_HANDLE; } } -s32 Ngs2::HandleSetup(Ngs2Handle* handle, void* data, std::atomic* atomic, u32 type, - u32 flags) { - handle->dataPointer = data; - handle->atomicPtr = atomic; - handle->handleType = type; - handle->flags_unk = flags; - return ORBIS_OK; +void* MemoryClear(void* buffer, size_t size) { + return memset(buffer, 0, size); } -s32 Ngs2::HandleCleanup(Ngs2Handle* handle, u32 hType, void* dataOut) { - if (handle && handle->selfPointer == handle) { - std::atomic* tmp_atomic = handle->atomicPtr; - if (tmp_atomic && handle->handleType == hType) { - while (tmp_atomic->load() != 0) { - u32 expected = 1; - if (tmp_atomic->compare_exchange_strong(expected, 0)) { - if (dataOut) { - dataOut = handle->dataPointer; - } - // sceNgs2MemoryClear(handle, 32); - return ORBIS_OK; - } - tmp_atomic = handle->atomicPtr; - } - } - } - return this->ReportInvalid(handle, hType); -} - -s32 Ngs2::HandleEnter(Ngs2Handle* handle, u32 hType, Ngs2Handle* handleOut) { - if (!handle) { - return this->ReportInvalid(handle, 0); - } - - if (handle->selfPointer != handle || !handle->atomicPtr || !handle->dataPointer || - (~hType & handle->handleType)) { - return this->ReportInvalid(handle, handle->handleType); - } - - std::atomic* atomic = handle->atomicPtr; - while (true) { - u32 i = atomic->load(); - if (i == 0) { - return this->ReportInvalid(handle, handle->handleType); - } - if (atomic->compare_exchange_strong(i, i + 1)) { - break; - } - } - - if (handleOut) { - handleOut = handle; +s32 StackBufferClose(StackBuffer* stackBuffer, size_t* outTotalSize) { + if (outTotalSize) { + *outTotalSize = stackBuffer->usedSize + stackBuffer->alignment; } return ORBIS_OK; } -s32 Ngs2::HandleLeave(Ngs2Handle* handle) { - std::atomic* tmp_atomic; - u32 i; - do { - tmp_atomic = handle->atomicPtr; - i = tmp_atomic->load(); - } while (!tmp_atomic->compare_exchange_strong(i, i - 1)); - return ORBIS_OK; -} +s32 StackBufferOpen(StackBuffer* stackBuffer, void* bufferStart, size_t bufferSize, + void** outBuffer, u8 flags) { + stackBuffer->top = outBuffer; + stackBuffer->base = bufferStart; + stackBuffer->size = (size_t)bufferStart; + stackBuffer->currentOffset = (size_t)bufferStart; + stackBuffer->usedSize = 0; + stackBuffer->totalSize = bufferSize; + stackBuffer->alignment = 8; // this is a fixed value + stackBuffer->flags = flags; -s32 Ngs2::StackBufferOpen(StackBuffer* buf, void* base_addr, size_t size, void** stackTop, - bool verify) { - buf->top = stackTop; - buf->base = base_addr; - buf->curr = base_addr; - buf->usedSize = 0; - buf->totalSize = size; - buf->alignment = 8; - buf->isVerifyEnabled = verify; - - if (stackTop) { - *stackTop = nullptr; + if (outBuffer != NULL) { + *outBuffer = NULL; } return ORBIS_OK; } -s32 Ngs2::StackBufferClose(StackBuffer* buf, size_t* usedSize) { - if (usedSize) { - *usedSize = buf->usedSize + buf->alignment; +s32 SystemCleanup(OrbisNgs2Handle systemHandle, OrbisNgs2ContextBufferInfo* outInfo) { + if (!systemHandle) { + return ORBIS_NGS2_ERROR_INVALID_HANDLE; } + // TODO + return ORBIS_OK; } -s32 Ngs2::SystemSetupCore(StackBuffer* buf, SystemOptions* options, Ngs2Handle** sysOut) { +s32 SystemSetupCore(StackBuffer* stackBuffer, const OrbisNgs2SystemOption* option, + SystemInternal* outSystem) { u32 maxGrainSamples = 512; u32 numGrainSamples = 256; u32 sampleRate = 48000; - if (options) { - maxGrainSamples = options->maxGrainSamples; - numGrainSamples = options->numGrainSamples; - sampleRate = options->sampleRate; + if (option) { + sampleRate = option->sampleRate; + maxGrainSamples = option->maxGrainSamples; + numGrainSamples = option->numGrainSamples; } - // Validate maxGrainSamples - if (maxGrainSamples < 64 || maxGrainSamples > 1024 || (maxGrainSamples & 0x3F) != 0) { + if (maxGrainSamples < 64 || maxGrainSamples > 1024 || (maxGrainSamples & 63) != 0) { LOG_ERROR(Lib_Ngs2, "Invalid system option (maxGrainSamples={},x64)", maxGrainSamples); return ORBIS_NGS2_ERROR_INVALID_MAX_GRAIN_SAMPLES; } - // Validate numGrainSamples - if (numGrainSamples < 64 || numGrainSamples > 1024 || (numGrainSamples & 0x3F) != 0) { + if (numGrainSamples < 64 || numGrainSamples > 1024 || (numGrainSamples & 63) != 0) { LOG_ERROR(Lib_Ngs2, "Invalid system option (numGrainSamples={},x64)", numGrainSamples); return ORBIS_NGS2_ERROR_INVALID_NUM_GRAIN_SAMPLES; } - // Validate sampleRate if (sampleRate != 11025 && sampleRate != 12000 && sampleRate != 22050 && sampleRate != 24000 && - sampleRate != 44100 && sampleRate != 48000 && sampleRate != 88200 && sampleRate != 96000) { + sampleRate != 44100 && sampleRate != 48000 && sampleRate != 88200 && sampleRate != 96000 && + sampleRate != 176400 && sampleRate != 192000) { LOG_ERROR(Lib_Ngs2, "Invalid system option(sampleRate={}:44.1/48kHz series)", sampleRate); return ORBIS_NGS2_ERROR_INVALID_SAMPLE_RATE; } - int result = ORBIS_OK; + return ORBIS_OK; +} +s32 SystemSetup(const OrbisNgs2SystemOption* option, OrbisNgs2ContextBufferInfo* hostBufferInfo, + OrbisNgs2BufferFreeHandler hostFree, OrbisNgs2Handle* outHandle) { + u8 optionFlags = 0; + StackBuffer stackBuffer; + SystemInternal setupResult; + void* systemList = NULL; + size_t requiredBufferSize = 0; + u32 result = ORBIS_NGS2_ERROR_INVALID_BUFFER_SIZE; + + if (option) { + if (option->size != 64) { + LOG_ERROR(Lib_Ngs2, "Invalid system option size ({})", option->size); + return ORBIS_NGS2_ERROR_INVALID_OPTION_SIZE; + } + optionFlags = option->flags >> 31; + } + + // Init + StackBufferOpen(&stackBuffer, NULL, 0, NULL, optionFlags); + result = SystemSetupCore(&stackBuffer, option, 0); + + if (result < 0) { + return result; + } + + StackBufferClose(&stackBuffer, &requiredBufferSize); + + // outHandle unprovided + if (!outHandle) { + hostBufferInfo->hostBuffer = NULL; + hostBufferInfo->hostBufferSize = requiredBufferSize; + MemoryClear(&hostBufferInfo->reserved, sizeof(hostBufferInfo->reserved)); + return ORBIS_OK; + } + + if (!hostBufferInfo->hostBuffer) { + LOG_ERROR(Lib_Ngs2, "Invalid system buffer address ({})", hostBufferInfo->hostBuffer); + return ORBIS_NGS2_ERROR_INVALID_BUFFER_ADDRESS; + } + + if (hostBufferInfo->hostBufferSize < requiredBufferSize) { + LOG_ERROR(Lib_Ngs2, "Invalid system buffer size ({}<{}[byte])", + hostBufferInfo->hostBufferSize, requiredBufferSize); + return ORBIS_NGS2_ERROR_INVALID_BUFFER_SIZE; + } + + // Setup + StackBufferOpen(&stackBuffer, hostBufferInfo->hostBuffer, hostBufferInfo->hostBufferSize, + &systemList, optionFlags); + result = SystemSetupCore(&stackBuffer, option, &setupResult); + + if (result < 0) { + return result; + } + + StackBufferClose(&stackBuffer, &requiredBufferSize); + + // Copy buffer results + setupResult.bufferInfo = *hostBufferInfo; + setupResult.hostFree = hostFree; // TODO + // setupResult.systemList = systemList; - return result; // Success + OrbisNgs2Handle systemHandle = setupResult.systemHandle; + if (hostBufferInfo->hostBufferSize >= requiredBufferSize) { + *outHandle = systemHandle; + return ORBIS_OK; + } + + SystemCleanup(systemHandle, 0); + + LOG_ERROR(Lib_Ngs2, "Invalid system buffer size ({}<{}[byte])", hostBufferInfo->hostBufferSize, + requiredBufferSize); + return ORBIS_NGS2_ERROR_INVALID_BUFFER_SIZE; } } // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_impl.h b/src/core/libraries/ngs2/ngs2_impl.h index fea87c51c..7be0f89cc 100644 --- a/src/core/libraries/ngs2/ngs2_impl.h +++ b/src/core/libraries/ngs2/ngs2_impl.h @@ -3,23 +3,176 @@ #pragma once -#include "ngs2.h" +#include "core/libraries/kernel/threads/pthread.h" namespace Libraries::Ngs2 { -class Ngs2 { -public: - s32 ReportInvalid(Ngs2Handle* handle, u32 handle_type) const; - s32 HandleSetup(Ngs2Handle* handle, void* data, std::atomic* atomic, u32 type, u32 flags); - s32 HandleCleanup(Ngs2Handle* handle, u32 hType, void* dataOut); - s32 HandleEnter(Ngs2Handle* handle, u32 hType, Ngs2Handle* handleOut); - s32 HandleLeave(Ngs2Handle* handle); - s32 StackBufferOpen(StackBuffer* buf, void* base_addr, size_t size, void** stackTop, - bool verify); - s32 StackBufferClose(StackBuffer* buf, size_t* usedSize); - s32 SystemSetupCore(StackBuffer* buf, SystemOptions* options, Ngs2Handle** sysOut); +static const int ORBIS_NGS2_SYSTEM_NAME_LENGTH = 16; +static const int ORBIS_NGS2_RACK_NAME_LENGTH = 16; -private: +typedef uintptr_t OrbisNgs2Handle; + +struct OrbisNgs2ContextBufferInfo { + void* hostBuffer; + size_t hostBufferSize; + uintptr_t reserved[5]; + uintptr_t userData; }; +struct OrbisNgs2SystemOption { + size_t size; + char name[ORBIS_NGS2_SYSTEM_NAME_LENGTH]; + + u32 flags; + u32 maxGrainSamples; + u32 numGrainSamples; + u32 sampleRate; + u32 aReserved[6]; +}; + +typedef s32 (*OrbisNgs2BufferAllocHandler)(OrbisNgs2ContextBufferInfo* ioBufferInfo); +typedef s32 (*OrbisNgs2BufferFreeHandler)(OrbisNgs2ContextBufferInfo* ioBufferInfo); + +struct OrbisNgs2SystemInfo { + char name[ORBIS_NGS2_SYSTEM_NAME_LENGTH]; // 0 + + OrbisNgs2Handle systemHandle; // 16 + OrbisNgs2ContextBufferInfo bufferInfo; // 24 + + u32 uid; // 88 + u32 minGrainSamples; // 92 + u32 maxGrainSamples; // 96 + + u32 stateFlags; // 100 + u32 rackCount; // 104 + float lastRenderRatio; // 108 + s64 lastRenderTick; // 112 + s64 renderCount; // 120 + u32 sampleRate; // 128 + u32 numGrainSamples; // 132 +}; + +struct OrbisNgs2RackInfo { + char name[ORBIS_NGS2_RACK_NAME_LENGTH]; // 0 + + OrbisNgs2Handle rackHandle; // 16 + OrbisNgs2ContextBufferInfo bufferInfo; // 24 + + OrbisNgs2Handle ownerSystemHandle; // 88 + + u32 type; // 96 + u32 rackId; // 100 + u32 uid; // 104 + u32 minGrainSamples; // 108 + u32 maxGrainSamples; // 112 + u32 maxVoices; // 116 + u32 maxChannelWorks; // 120 + u32 maxInputs; // 124 + u32 maxMatrices; // 128 + u32 maxPorts; // 132 + + u32 stateFlags; // 136 + float lastProcessRatio; // 140 + u64 lastProcessTick; // 144 + u64 renderCount; // 152 + u32 activeVoiceCount; // 160 + u32 activeChannelWorkCount; // 164 +}; + +struct StackBuffer { + void** top; + void* base; + size_t size; + size_t currentOffset; + size_t usedSize; + size_t totalSize; + size_t alignment; + u8 flags; + char padding[7]; +}; + +struct SystemInternal { + // setup init + char name[ORBIS_NGS2_SYSTEM_NAME_LENGTH]; // 0 + OrbisNgs2ContextBufferInfo bufferInfo; // 16 + OrbisNgs2BufferFreeHandler hostFree; // 80 + OrbisNgs2Handle systemHandle; // 88 + void* unknown1; // 96 + void* unknown2; // 104 + OrbisNgs2Handle rackHandle; // 112 + uintptr_t* userData; // 120 + SystemInternal* systemList; // 128 + StackBuffer* stackBuffer; // 136 + OrbisNgs2SystemInfo ownerSystemInfo; // 144 + + struct rackList { + void* prev; + void* next; + void* unknown; + }; + + rackList rackListPreset; // 152 + rackList rackListNormal; // 176 + rackList rackListMaster; // 200 + + void* unknown3; // 208 + void* systemListPrev; // 216 + void* unknown4; // 224 + void* systemListNext; // 232 + void* rackFunction; // 240 + + Kernel::PthreadMutex processLock; // 248 + u32 hasProcessMutex; // 256 + u32 unknown5; // 260 + Kernel::PthreadMutex flushLock; // 264 + u32 hasFlushMutex; // 272 + u32 unknown6; // 276 + + // info + u64 lastRenderTick; // 280 + u64 renderCount; // 288 + u32 isActive; // 296 + std::atomic lockCount; // 300 + u32 uid; // 304 + u32 systemType; // 308 + + struct { + u8 isBufferValid : 1; + u8 isRendering : 1; + u8 isSorted : 1; + u8 isFlushReady : 1; + } flags; // 312 + + u16 currentMaxGrainSamples; // 316 + u16 minGrainSamples; // 318 + u16 maxGrainSamples; // 320 + u16 numGrainSamples; // 322 + u32 currentNumGrainSamples; // 324 + u32 sampleRate; // 328 + u32 currentSampleRate; // 332 + u32 rackCount; // 336 + float lastRenderRatio; // 340 + float cpuLoad; // 344 +}; + +struct HandleInternal { + HandleInternal* selfPtr; // 0 + SystemInternal* systemData; // 8 + std::atomic refCount; // 16 + u32 handleType; // 24 + u32 handleID; // 28 +}; + +s32 StackBufferClose(StackBuffer* stackBuffer, size_t* outTotalSize); +s32 StackBufferOpen(StackBuffer* stackBuffer, void* buffer, size_t bufferSize, void** outBuffer, + u8 flags); +s32 SystemSetupCore(StackBuffer* stackBuffer, const OrbisNgs2SystemOption* option, + SystemInternal* outSystem); + +s32 HandleReportInvalid(OrbisNgs2Handle handle, u32 handleType); +void* MemoryClear(void* buffer, size_t size); +s32 SystemCleanup(OrbisNgs2Handle systemHandle, OrbisNgs2ContextBufferInfo* outInfo); +s32 SystemSetup(const OrbisNgs2SystemOption* option, OrbisNgs2ContextBufferInfo* hostBufferInfo, + OrbisNgs2BufferFreeHandler hostFree, OrbisNgs2Handle* outHandle); + } // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_mastering.cpp b/src/core/libraries/ngs2/ngs2_mastering.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_mastering.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_mastering.h b/src/core/libraries/ngs2/ngs2_mastering.h new file mode 100644 index 000000000..e0ba478c3 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_mastering.h @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Mastering; + +struct OrbisNgs2MasteringRackOption { + OrbisNgs2RackOption rackOption; + u32 maxChannels; + u32 numPeakMeterBlocks; +}; + +struct OrbisNgs2MasteringVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + + u32 numInputChannels; + u32 flags; +}; + +struct OrbisNgs2MasteringVoiceMatrixParam { + OrbisNgs2VoiceParamHeader header; + + u32 type; + u32 numLevels; + const float* aLevel; +}; + +struct OrbisNgs2MasteringVoiceLfeParam { + OrbisNgs2VoiceParamHeader header; + + u32 enableFlag; + u32 fc; +}; + +struct OrbisNgs2MasteringVoiceLimiterParam { + OrbisNgs2VoiceParamHeader header; + + u32 enableFlag; + float threshold; +}; + +struct OrbisNgs2MasteringVoiceGainParam { + OrbisNgs2VoiceParamHeader header; + + float fbwLevel; + float lfeLevel; +}; + +struct OrbisNgs2MasteringVoiceOutputParam { + OrbisNgs2VoiceParamHeader header; + + u32 outputId; + u32 reserved; +}; + +struct OrbisNgs2MasteringVoicePeakMeterParam { + OrbisNgs2VoiceParamHeader header; + u32 enableFlag; + u32 reserved; +}; + +struct OrbisNgs2MasteringVoiceState { + OrbisNgs2VoiceState voiceState; + float limiterPeakLevel; + float limiterPressLevel; + float aInputPeakHeight[ORBIS_NGS2_MAX_VOICE_CHANNELS]; + float aOutputPeakHeight[ORBIS_NGS2_MAX_VOICE_CHANNELS]; +}; + +struct OrbisNgs2MasteringRackInfo { + OrbisNgs2RackInfo rackInfo; + u32 maxChannels; + u32 reserved; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_pan.cpp b/src/core/libraries/ngs2/ngs2_pan.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_pan.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_pan.h b/src/core/libraries/ngs2/ngs2_pan.h new file mode 100644 index 000000000..d39ec67cd --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_pan.h @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Pan; + +struct OrbisNgs2PanParam { + float angle; + float distance; + float fbwLevel; + float lfeLevel; +}; + +struct OrbisNgs2PanWork { + float aSpeakerAngle[ORBIS_NGS2_MAX_VOICE_CHANNELS]; + float unitAngle; + u32 numSpeakers; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_report.cpp b/src/core/libraries/ngs2/ngs2_report.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_report.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_report.h b/src/core/libraries/ngs2/ngs2_report.h new file mode 100644 index 000000000..88f6d1df0 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_report.h @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +#include // va_list + +namespace Libraries::Ngs2 { + +class Ngs2Report; + +struct OrbisNgs2ReportDataHeader { + size_t size; + OrbisNgs2Handle handle; + u32 type; + s32 result; +}; + +typedef void (*OrbisNgs2ReportHandler)(const OrbisNgs2ReportDataHeader* data, uintptr_t userData); + +struct OrbisNgs2ReportMessageData { + OrbisNgs2ReportDataHeader header; + const char* message; +}; + +struct OrbisNgs2ReportApiData { + OrbisNgs2ReportDataHeader header; + const char* functionName; + const char* format; + va_list argument; +}; + +struct OrbisNgs2ReportControlData { + OrbisNgs2ReportDataHeader header; + const OrbisNgs2VoiceParamHeader* param; +}; + +struct OrbisNgs2ReportOutputData { + OrbisNgs2ReportDataHeader header; + const OrbisNgs2RenderBufferInfo* bufferInfo; + + u32 bufferIndex; + u32 sampleRate; + u32 numGrainSamples; + u32 reserved; +}; + +struct OrbisNgs2ReportCpuLoadData { + OrbisNgs2ReportDataHeader header; + float totalRatio; + float flushRatio; + float processRatio; + float feedbackRatio; +}; + +struct OrbisNgs2ReportRenderStateData { + OrbisNgs2ReportDataHeader header; + u32 state; + u32 reserved; +}; + +struct OrbisNgs2ReportVoiceWaveformData { + OrbisNgs2ReportDataHeader header; + u32 location; + u32 waveformType; + u32 numChannels; + u32 sampleRate; + u32 numGrainSamples; + u32 reserved; + void* const* aData; +}; + +s32 PS4_SYSV_ABI sceNgs2ReportRegisterHandler(u32 reportType, OrbisNgs2ReportHandler handler, + uintptr_t userData, OrbisNgs2Handle* outHandle); + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_reverb.cpp b/src/core/libraries/ngs2/ngs2_reverb.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_reverb.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_reverb.h b/src/core/libraries/ngs2/ngs2_reverb.h new file mode 100644 index 000000000..715d7480a --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_reverb.h @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Reverb; + +struct OrbisNgs2ReverbRackOption { + OrbisNgs2RackOption rackOption; + u32 maxChannels; + u32 reverbSize; +}; + +struct OrbisNgs2ReverbI3DL2Param { + float wet; + float dry; + s32 room; + s32 roomHF; + u32 reflectionPattern; + float decayTime; + float decayHFRatio; + s32 reflections; + float reflectionsDelay; + s32 reverb; + float reverbDelay; + float diffusion; + float density; + float HFReference; + u32 reserve[8]; +}; + +struct OrbisNgs2ReverbVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + + u32 numInputChannels; + u32 numOutputChannels; + u32 flags; + u32 reserved; +}; + +struct OrbisNgs2ReverbVoiceI3DL2Param { + OrbisNgs2VoiceParamHeader header; + + OrbisNgs2ReverbI3DL2Param i3dl2; +}; + +struct OrbisNgs2ReverbVoiceState { + OrbisNgs2VoiceState voiceState; +}; + +struct OrbisNgs2ReverbRackInfo { + OrbisNgs2RackInfo rackInfo; + u32 maxChannels; + u32 reverbSize; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_sampler.cpp b/src/core/libraries/ngs2/ngs2_sampler.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_sampler.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_sampler.h b/src/core/libraries/ngs2/ngs2_sampler.h new file mode 100644 index 000000000..0842b9cb2 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_sampler.h @@ -0,0 +1,162 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Sampler; + +struct OrbisNgs2SamplerRackOption { + OrbisNgs2RackOption rackOption; + u32 maxChannelWorks; + u32 maxCodecCaches; + u32 maxWaveformBlocks; + u32 maxEnvelopePoints; + u32 maxFilters; + u32 maxAtrac9Decoders; + u32 maxAtrac9ChannelWorks; + u32 maxAjmAtrac9Decoders; + u32 numPeakMeterBlocks; +}; + +struct OrbisNgs2SamplerVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + + OrbisNgs2WaveformFormat format; + u32 flags; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceWaveformBlocksParam { + OrbisNgs2VoiceParamHeader header; + + const void* data; + u32 flags; + u32 numBlocks; + const OrbisNgs2WaveformBlock* aBlock; + // Blocks +}; + +struct OrbisNgs2SamplerVoiceWaveformAddressParam { + OrbisNgs2VoiceParamHeader header; + + const void* from; + const void* to; +}; + +struct OrbisNgs2SamplerVoiceWaveformFrameOffsetParam { + OrbisNgs2VoiceParamHeader header; + + u32 frameOffset; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceExitLoopParam { + OrbisNgs2VoiceParamHeader header; +}; + +struct OrbisNgs2SamplerVoicePitchParam { + OrbisNgs2VoiceParamHeader header; + + float ratio; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceEnvelopeParam { + OrbisNgs2VoiceParamHeader header; + + u32 numForwardPoints; + u32 numReleasePoints; + const OrbisNgs2EnvelopePoint* aPoint; +}; + +struct OrbisNgs2SamplerVoiceDistortionParam { + OrbisNgs2VoiceParamHeader header; + + u32 flags; + float a; + float b; + float clip; + float gate; + float wetLevel; + float dryLevel; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceUserFxParam { + OrbisNgs2VoiceParamHeader header; + + OrbisNgs2UserFxProcessHandler handler; + + uintptr_t userData0; + uintptr_t userData1; + uintptr_t userData2; +}; + +struct OrbisNgs2SamplerVoicePeakMeterParam { + OrbisNgs2VoiceParamHeader header; + + u32 enableFlag; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceFilterParam { + OrbisNgs2VoiceParamHeader header; + + u32 index; + u32 location; + u32 type; + u32 channelMask; + union { + struct { + float i0; + float i1; + float i2; + float o1; + float o2; + } direct; + struct { + float fc; + float q; + float level; + u32 reserved; + u32 reserved2; + } fcq; + } param; + u32 reserved3; +}; + +struct OrbisNgs2SamplerVoiceNumFilters { + OrbisNgs2VoiceParamHeader header; + + u32 numFilters; + u32 reserved; +}; + +struct OrbisNgs2SamplerVoiceState { + OrbisNgs2VoiceState voiceState; + float envelopeHeight; + float peakHeight; + u32 reserved; + u64 numDecodedSamples; + u64 decodedDataSize; + u64 userData; + const void* waveformData; +}; + +struct OrbisNgs2SamplerRackInfo { + OrbisNgs2RackInfo rackInfo; + u32 maxChannelWorks; + u32 maxCodecCaches; + u32 maxWaveformBlocks; + u32 maxEnvelopePoints; + u32 maxFilters; + u32 maxAtrac9Decoders; + u32 maxAtrac9ChannelWorks; + u32 maxAjmAtrac9Decoders; +}; + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_submixer.cpp b/src/core/libraries/ngs2/ngs2_submixer.cpp new file mode 100644 index 000000000..8c82e4e49 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_submixer.cpp @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ngs2_error.h" +#include "ngs2_impl.h" + +#include "common/logging/log.h" +#include "core/libraries/error_codes.h" + +using namespace Libraries::Kernel; + +namespace Libraries::Ngs2 {} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2_submixer.h b/src/core/libraries/ngs2/ngs2_submixer.h new file mode 100644 index 000000000..df2d8a835 --- /dev/null +++ b/src/core/libraries/ngs2/ngs2_submixer.h @@ -0,0 +1,126 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "ngs2.h" + +namespace Libraries::Ngs2 { + +class Ngs2Submixer; + +struct OrbisNgs2SubmixerRackOption { + OrbisNgs2RackOption rackOption; + u32 maxChannels; + u32 maxEnvelopePoints; + u32 maxFilters; + u32 maxInputs; + u32 numPeakMeterBlocks; +}; + +struct OrbisNgs2SubmixerVoiceSetupParam { + OrbisNgs2VoiceParamHeader header; + u32 numIoChannels; + u32 flags; +}; + +struct OrbisNgs2SubmixerVoiceEnvelopeParam { + OrbisNgs2VoiceParamHeader header; + + u32 numForwardPoints; + u32 numReleasePoints; + const OrbisNgs2EnvelopePoint* aPoint; +}; + +struct OrbisNgs2SubmixerVoiceCompressorParam { + OrbisNgs2VoiceParamHeader header; + + u32 flags; + float threshold; + float ratio; + float knee; + float attackTime; + float releaseTime; + float level; + u32 reserved; +}; + +struct OrbisNgs2SubmixerVoiceDistortionParam { + OrbisNgs2VoiceParamHeader header; + + u32 flags; + float a; + float b; + float clip; + float gate; + float wetLevel; + float dryLevel; + u32 reserved; +}; + +struct OrbisNgs2SubmixerVoiceUserFxParam { + OrbisNgs2VoiceParamHeader header; + + OrbisNgs2UserFxProcessHandler handler; + + uintptr_t userData0; + uintptr_t userData1; + uintptr_t userData2; +}; + +struct OrbisNgs2SubmixerVoicePeakMeterParam { + OrbisNgs2VoiceParamHeader header; + + u32 enableFlag; + u32 reserved; +}; + +struct OrbisNgs2SubmixerVoiceFilterParam { + OrbisNgs2VoiceParamHeader header; + + u32 index; + u32 location; + u32 type; + u32 channelMask; + union { + struct { + float i0; + float i1; + float i2; + float o1; + float o2; + } direct; + struct { + float fc; + float q; + float level; + u32 reserved; + u32 reserved2; + } fcq; + } param; + u32 reserved3; +}; + +struct OrbisNgs2SubmixerVoiceNumFilters { + OrbisNgs2VoiceParamHeader header; + + u32 numFilters; + u32 reserved; +}; + +struct OrbisNgs2SubmixerVoiceState { + OrbisNgs2VoiceState voiceState; + float envelopeHeight; + float peakHeight; + float compressorHeight; +}; + +struct OrbisNgs2SubmixerRackInfo { + OrbisNgs2RackInfo rackInfo; + u32 maxChannels; + u32 maxEnvelopePoints; + u32 maxFilters; + u32 maxInputs; +}; + +} // namespace Libraries::Ngs2