diff --git a/core/libs/prx/libSceVoice/CMakeLists.txt b/core/libs/prx/libSceVoice/CMakeLists.txt new file mode 100644 index 000000000000..e2cc5765c8b4 --- /dev/null +++ b/core/libs/prx/libSceVoice/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(libSceVoice SHARED EXCLUDE_FROM_ALL Export.cpp) +target_include_directories(libSceVoice PRIVATE ${LIBS_INCLUDE_DIR}) +configure_windows_unwind(libSceVoice) + +if(BUILD_TESTING) + add_test_executable(guest_voice_tests ${LIBS_INCLUDE_DIR}/tests/GuestVoice.cpp) + target_include_directories(guest_voice_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_voice_tests PRIVATE libSceVoice libc) + configure_windows_unwind(guest_voice_tests) + add_test(NAME guest_voice COMMAND guest_voice_tests) + if(WIN32) + set_tests_properties(guest_voice PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() +endif() diff --git a/core/libs/prx/libSceVoice/Export.cpp b/core/libs/prx/libSceVoice/Export.cpp index ba55f55dd251..16fb9faecb97 100644 --- a/core/libs/prx/libSceVoice/Export.cpp +++ b/core/libs/prx/libSceVoice/Export.cpp @@ -197,11 +197,12 @@ int APS5_VABI sceVoiceReadFromOPort(uint32_t output_port_id, void* data, uint32_ } int APS5_VABI sceVoiceWriteToIPort(uint32_t input_port_id, const void* data, uint32_t* size, int16_t frame_gaps) { - (void)input_port_id; - (void)data; - (void)size; (void)frame_gaps; - NotImplemented_nid_no_patch(__func__); + if (data == nullptr || size == nullptr) APS5_INVALID_ARG_EX; + auto& voice = State(); + std::lock_guard lock(voice.mutex); + const auto type = RequirePort(voice, input_port_id, __func__).type; + if (type != PortInPcm && type != PortInVoice) Fail(__func__, "port does not take written data"); return 0; } @@ -230,8 +231,10 @@ int APS5_VABI sceVoiceEnableChat(void) { return 0; } -int APS5_VABI sceVoiceResetPort(void) { - NotImplemented_nid_no_patch(__func__); +int APS5_VABI sceVoiceResetPort(uint32_t port_id) { + auto& voice = State(); + std::lock_guard lock(voice.mutex); + RequirePort(voice, port_id, __func__); return 0; } diff --git a/core/libs/tests/GuestVoice.cpp b/core/libs/tests/GuestVoice.cpp new file mode 100644 index 000000000000..47a314572a5f --- /dev/null +++ b/core/libs/tests/GuestVoice.cpp @@ -0,0 +1,109 @@ +#include "SceTypes.hpp" +#include +#include +#include +#include + +extern "C" { +int APS5_VABI sceVoiceInit(VoiceInitParam*, std::int32_t); +int APS5_VABI sceVoiceEnd_nid_postfix(void); +int APS5_VABI sceVoiceCreatePort(std::uint32_t*, const VoicePortParam*); +int APS5_VABI sceVoiceDeletePort(std::uint32_t); +int APS5_VABI sceVoiceConnectIPortToOPort(std::uint32_t, std::uint32_t); +int APS5_VABI sceVoiceDisconnectIPortFromOPort(std::uint32_t, std::uint32_t); +int APS5_VABI sceVoiceResetPort(std::uint32_t); +int APS5_VABI sceVoiceSetVolume(std::uint32_t, float); +int APS5_VABI sceVoiceGetVolume(std::uint32_t, float*); +int APS5_VABI sceVoiceSetMuteFlag(std::uint32_t, bool); +int APS5_VABI sceVoiceGetMuteFlag(std::uint32_t, bool*); +int APS5_VABI sceVoiceGetBitRate(std::uint32_t, std::uint32_t*); +int APS5_VABI sceVoiceGetPortInfo(std::uint32_t, VoicePortInfo*); +int APS5_VABI sceVoiceWriteToIPort(std::uint32_t, const void*, std::uint32_t*, std::int16_t); +int APS5_VABI sceVoiceReadFromOPort(std::uint32_t, void*, std::uint32_t*); +} + +namespace { + +constexpr std::int32_t portInPcm = 1; +constexpr std::int32_t portInVoice = 2; +constexpr std::int32_t portOutPcm = 3; +constexpr std::int32_t portStateReady = 1; +constexpr std::int32_t bitrate = 16000; + +void Require(bool value) { if (!value) std::abort(); } + +bool ResetThrows(std::uint32_t portId) { + try { + static_cast(sceVoiceResetPort(portId)); + } catch (const std::logic_error&) { + return true; + } + return false; +} + +VoicePortParam PortParam(std::int32_t type) { + VoicePortParam param{}; + param.port_type = type; + param.volume = 1.0f; + return param; +} + +} + +int main() { + Require(ResetThrows(0)); + VoiceInitParam initParam{}; + Require(sceVoiceInit(&initParam, 0x100) == 0); + Require(ResetThrows(0)); + + std::uint32_t input = 0xffffffffu; + std::uint32_t output = 0xffffffffu; + std::uint32_t encoded = 0xffffffffu; + VoicePortParam inputParam = PortParam(portInPcm); + inputParam.pcmaudio.buffer_size = 3200; + inputParam.pcmaudio.sample_rate = 16000; + Require(sceVoiceCreatePort(&input, &inputParam) == 0); + const VoicePortParam outputParam = PortParam(portOutPcm); + Require(sceVoiceCreatePort(&output, &outputParam) == 0); + VoicePortParam encodedParam = PortParam(portInVoice); + encodedParam.voice.bitrate = bitrate; + Require(sceVoiceCreatePort(&encoded, &encodedParam) == 0); + Require(sceVoiceConnectIPortToOPort(input, output) == 0); + Require(sceVoiceSetVolume(input, 0.25f) == 0); + Require(sceVoiceSetMuteFlag(input, true) == 0); + + std::int16_t samples[320]{}; + std::uint32_t size = sizeof(samples); + Require(sceVoiceWriteToIPort(input, samples, &size, 0) == 0); + Require(size == sizeof(samples)); + for (std::uint32_t port : {input, output, encoded}) Require(sceVoiceResetPort(port) == 0); + Require(sceVoiceResetPort(input) == 0); + + float volume = -1.0f; + Require(sceVoiceGetVolume(input, &volume) == 0); + Require(volume == 0.25f); + bool muted = false; + Require(sceVoiceGetMuteFlag(input, &muted) == 0); + Require(muted); + std::uint32_t readBitrate = 0; + Require(sceVoiceGetBitRate(encoded, &readBitrate) == 0); + Require(readBitrate == static_cast(bitrate)); + VoicePortInfo info{}; + Require(sceVoiceGetPortInfo(input, &info) == 0); + Require(info.port_type == portInPcm && info.state == portStateReady); + Require(sceVoiceGetPortInfo(output, &info) == 0); + Require(info.port_type == portOutPcm && info.state == portStateReady); + size = sizeof(samples); + Require(sceVoiceReadFromOPort(output, samples, &size) == 0); + Require(size == 0); + Require(sceVoiceDisconnectIPortFromOPort(input, output) == 0); + + Require(ResetThrows(input + output + encoded + 1)); + Require(sceVoiceDeletePort(encoded) == 0); + Require(ResetThrows(encoded)); + Require(sceVoiceResetPort(input) == 0); + Require(sceVoiceEnd_nid_postfix() == 0); + Require(ResetThrows(input)); + Require(ResetThrows(output)); + return 0; +} diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index c1247e46bc80..b6d296f0bd92 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -47,6 +47,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceFontGlyphDefineAttribute](../../core/libs/prx/libSceFont/src/Render.cpp) (libSceFont) checks the glyph and ignores the attribute and its value, whose meaning is unknown. PPSA01325 sets attribute 0x11 to 0 on a glyph from `sceFontGenerateCharGlyph` that it deletes unused, and draws the character with `sceFontRenderCharGlyphImageHorizontal` - [sceAudioInInit](../../core/libs/prx/libSceAudioIn/Export.cpp) (libSceAudioIn) - returns 0 without library-wide setup, as `sceAudioOutInit` does; each `sceAudioInOpen` opens its own SDL capture device - [sceRazorCpuPushMarker](../../core/libs/prx/libSceRazorCpu/Export.cpp) (libSceRazorCpu) - signature (label, color, flags) from [SharpProspero](https://github.com/SvenGDK/SharpProspero), the same as sceRazorCpuPushMarkerStatic's except that the label is copied; it does nothing without a capture and returns 0 +- [sceVoiceWriteToIPort](../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) accepts the data written to a PCM or voice input port and drops it: nothing reaches a host output, `sceVoiceReadFromOPort` never has data and `sceVoiceResetPort` has nothing to clear ### Unknown function info @@ -93,7 +94,7 @@ Throughout the project, every function at every stage either **does exactly what - [scePadOpen and scePadOpenExt](../../core/libs/prx/libScePad/Export.cpp) (libScePad) - special ports (type 2) return `DEVICE_NOT_CONNECTED` (0x80920007) because the host has no special controller, and `scePadGetHandle` has no handle for them; whether the console opens a handle and reports the device as disconnected later is unknown. scePadOpenExt handles only special ports. PPSA01317 passes a 16-byte param that names the device by vendor and product id (`b7 0e 04 0e ...` for 0x0eb7:0x0e04) and skips the user on any negative result. Other port types throw - [scePadVrControllerReadState](../../core/libs/prx/libScePad/Export.cpp) (libScePad, NID `iA-DdobUen8`) - the name hashes to the imported NID; the `(int handle, void* state)` signature follows [PS5VR](https://github.com/theghostonline/PS5VR/blob/0e408909ce7a39891a2e06eee3438d07a09e11e3/app/src/app_vr.c#L326-L369) (PPSA99177), which passes a PS VR2 Sense controller handle from `scePadOpen` type 3 or 4 and a 0x68-byte state it reads as buttons at 0, stick bytes at 4 and a connected byte at 0x40. The title calls it only after `sceHmd2Initialize` succeeds, which it does not here, so every call throws; the state layout is otherwise unknown - [scePadSetVibrationMode](../../core/libs/prx/libScePad/Export.cpp) (libScePad) - modes 0 to 3 are accepted and stored; the meaning of mode 3 is unknown (PPSA21480 calls it with 3 right after `scePadOpen` and aborts on failure; [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Pad/Pad.cs) names only 1 and 2). The stored mode has no other effect -- PPSA23566 imports declared without parameters, signatures unknown: [sceAudioOut2UserGetSupportedAttributes](../../core/libs/prx/libSceAudioOut/src/AudioOut2System.cpp), [sceConvertKeycodeGetCharacterFromKeyboardData](../../core/libs/prx/libSceConvertKeycode/Export.cpp), [sce::Json::MemAllocator::notifyError](../../core/libs/prx/libSceJson2/Export.cpp), [sceNetResolverAbort](../../core/libs/prx/libSceNet/Export.cpp), [sceNpCommerceDialogOpen2](../../core/libs/prx/libSceNpCommerce/Export.cpp), [sceNpEntitlementAccessGetPftFlag](../../core/libs/prx/libSceNpEntitlementAccess/Export.cpp), [sceProprietaryVoiceChatHelper{Initialize,Terminate,SetVoiceChatState,GetVoiceChatUsageState}](../../core/libs/prx/libSceProprietaryVoiceChatHelperPrx/Export.cpp), [sceVoice{GetResourceInfo,ResetPort,EnableChat,DisableChat}](../../core/libs/prx/libSceVoice/Export.cpp). Names from the shadPS4 aerolib NID list +- PPSA23566 imports declared without parameters, signatures unknown: [sceAudioOut2UserGetSupportedAttributes](../../core/libs/prx/libSceAudioOut/src/AudioOut2System.cpp), [sceConvertKeycodeGetCharacterFromKeyboardData](../../core/libs/prx/libSceConvertKeycode/Export.cpp), [sce::Json::MemAllocator::notifyError](../../core/libs/prx/libSceJson2/Export.cpp), [sceNetResolverAbort](../../core/libs/prx/libSceNet/Export.cpp), [sceNpCommerceDialogOpen2](../../core/libs/prx/libSceNpCommerce/Export.cpp), [sceNpEntitlementAccessGetPftFlag](../../core/libs/prx/libSceNpEntitlementAccess/Export.cpp), [sceProprietaryVoiceChatHelper{Initialize,Terminate,SetVoiceChatState,GetVoiceChatUsageState}](../../core/libs/prx/libSceProprietaryVoiceChatHelperPrx/Export.cpp), [sceVoice{GetResourceInfo,EnableChat,DisableChat}](../../core/libs/prx/libSceVoice/Export.cpp). Names from the shadPS4 aerolib NID list - PPSA28416 imports declared without parameters, signatures unknown: [sceAudioOut2EnableChat](../../core/libs/prx/libSceAudioOut/src/AudioOut2System.cpp), imported by its bundled `party-ps5-shipping.prx`. Name from the shadPS4 aerolib NID list - PPSA08427 imports declared without parameters, signatures unknown: [sceNpEntitlementAccessGetGameTrialsFlag](../../core/libs/prx/libSceNpEntitlementAccess/Export.cpp), imported by its bundled `pros.sdk.Prospero.prx` and not called before the main menu. Name from the aerolib NID list - PPSA06888 imports declared without parameters, signatures unknown: [sceRudpEnableInternalIOThread2, sceRudpGetOption, sceRudpGetRemoteInfo](../../core/libs/prx/libSceRudp/Export.cpp) (libSceRudp), imported by its bundled `Media/Plugins/SceRudp.prx` and not called during start-up. Names from the NID table of [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/rudp/rudp.cpp), which declares them without parameters too @@ -369,6 +370,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceAppContentGetAddcontDownloadProgress](../../core/libs/prx/libSceAppContent/Export.cpp) (libSceAppContent) - imported by PPSA08755, which fails to load without it; added without an implementation because its behavior is unverified. [SharpProspero](https://github.com/SvenGDK/SharpProspero) lists `(uint32_t serviceLabel, entitlementLabel, SceAppContentAddcontDownloadProgress*)`, but no PS5 reference gives the progress layout or the error codes - [_sceFiberGetThreadFramePointerAddress](../../core/libs/prx/libSceFiber/Export.cpp) (libSceFiber, NID `0dy4JtMUcMQ`) forwards to `sceFiberGetThreadFramePointerAddress`; that the argument list matches is inferred from the export without the underscore, as for the underscore Ult exports, not measured +- [sceVoiceResetPort](../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - `(uint32_t port_id)` from the PS4 prototype in [Orbital](https://github.com/AlexAltea/orbital/blob/master/tools/ida/db_types.json); the PS5 export `udAxvCePkUs` is in [ps5rs](https://github.com/claimore22/ps5rs/blob/0df6569edcb87972226ec02c71c49506e2375f66/data/stubs/by_library/libSceVoice.txt)'s list, and shadPS4 stubs it, as does [KytyPlus](https://github.com/Coder787-source/KytyPlus/blob/35de5d798b940d368fe29977a942404135c4e31a/src/libs/libVoice.cpp)'s port of shadPS4's voice library. The [vitasdk](https://github.com/vitasdk/vita-headers/blob/master/include/psp2/voice.h) description says only that it clears a port's buffered data and resets its processing state (an ACTIVE port becomes IDLE, the other states keep their internal state); that the volume, mute flag, bit rate and connections stay is inferred (vitasdk documents only `sceVoiceDeletePort` as removing connections, and RPCS3's `cellVoiceResetPort` validates the port and returns OK), not known. Here a port buffers nothing and is always `READY`, so the call only checks the library state and the port id (an uninitialized library or an unknown port throws, as for `sceVoiceDeletePort`) and leaves the port as it is. Not confirmed on a PS5 title (PPSA23566 imports it) ### Functional