Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions core/libs/prx/libSceVoice/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ constexpr std::int32_t PortOutDevice = 5;
constexpr std::int32_t PortStateReady = 1;
constexpr std::uint32_t VoiceFrameMs = 20;
constexpr std::int32_t PortAttrVoiceActivity = 1001;
constexpr int VoiceErrorNotInitialized = static_cast<int>(0x804E0801u);
constexpr int VoiceErrorAlreadyInitialized = static_cast<int>(0x804E0802u);

struct Port {
std::int32_t type;
Expand Down Expand Up @@ -66,7 +68,7 @@ int APS5_VABI sceVoiceInit(VoiceInitParam* param, int32_t version) {
if (param == nullptr) APS5_INVALID_ARG_EX;
auto& voice = State();
std::lock_guard lock(voice.mutex);
if (voice.initialized) Fail(__func__, "already initialized");
if (voice.initialized) return VoiceErrorAlreadyInitialized;
voice.initialized = true;
return 0;
}
Expand All @@ -77,10 +79,10 @@ int APS5_VABI sceVoiceSetThreadsParams(void* params) {
}

int APS5_VABI sceVoiceStart(const VoiceStartParam* param) {
if (param == nullptr) APS5_INVALID_ARG_EX;
auto& voice = State();
std::lock_guard lock(voice.mutex);
if (!voice.initialized) Fail(__func__, "library not initialized");
if (!voice.initialized) return VoiceErrorNotInitialized;
if (param == nullptr) APS5_INVALID_ARG_EX;
voice.started = true;
return 0;
}
Expand All @@ -106,11 +108,11 @@ int APS5_VABI sceVoiceEnd_nid_postfix(void) {
}

int APS5_VABI sceVoiceCreatePort(uint32_t* port_id, const VoicePortParam* param) {
if (port_id == nullptr || param == nullptr) APS5_INVALID_ARG_EX;
if (param->port_type < PortInDevice || param->port_type > PortOutDevice) Fail(__func__, "unknown port type " + std::to_string(param->port_type));
auto& voice = State();
std::lock_guard lock(voice.mutex);
if (!voice.initialized) Fail(__func__, "library not initialized");
if (!voice.initialized) return VoiceErrorNotInitialized;
if (port_id == nullptr || param == nullptr) APS5_INVALID_ARG_EX;
if (param->port_type < PortInDevice || param->port_type > PortOutDevice) Fail(__func__, "unknown port type " + std::to_string(param->port_type));
const bool voicePort = param->port_type == PortInVoice || param->port_type == PortOutVoice;
const auto id = voice.nextId++;
voice.ports.emplace(id, Port{param->port_type, param->volume, voicePort ? static_cast<std::uint32_t>(param->voice.bitrate) : 0u});
Expand Down Expand Up @@ -171,9 +173,10 @@ int APS5_VABI sceVoiceGetVolume(uint32_t port_id, float* volume) {
}

int APS5_VABI sceVoiceGetPortInfo(uint32_t port_id, VoicePortInfo* info) {
if (info == nullptr) APS5_INVALID_ARG_EX;
auto& voice = State();
std::lock_guard lock(voice.mutex);
if (!voice.initialized) return VoiceErrorNotInitialized;
if (info == nullptr) APS5_INVALID_ARG_EX;
const auto& port = RequirePort(voice, port_id, __func__);
*info = VoicePortInfo{};
info->port_type = port.type;
Expand Down
28 changes: 28 additions & 0 deletions core/libs/tests/GuestVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <stdexcept>

extern "C" {
Expand All @@ -27,6 +28,9 @@ int APS5_VABI sceVoiceDisableChat(void);

namespace {

constexpr int NotInitialized = static_cast<int>(0x804E0801u);
constexpr int AlreadyInitialized = static_cast<int>(0x804E0802u);

void Require(bool value) { if (!value) std::abort(); }

template <typename TFunction>
Expand All @@ -35,6 +39,27 @@ void RequireThrows(TFunction function) {
std::abort();
}

void TestNotInitialized() {
Require(sceVoiceStart(nullptr) == NotInitialized);
VoiceStartParam start{};
Require(sceVoiceStart(&start) == NotInitialized);
Require(sceVoiceCreatePort(nullptr, nullptr) == NotInitialized);
VoicePortParam badType{};
badType.port_type = 99;
std::uint32_t id = 0xA5A5A5A5u;
Require(sceVoiceCreatePort(&id, &badType) == NotInitialized);
VoicePortParam param{};
param.port_type = 3;
Require(sceVoiceCreatePort(&id, &param) == NotInitialized);
Require(id == 0xA5A5A5A5u);
Require(sceVoiceGetPortInfo(0, nullptr) == NotInitialized);
VoicePortInfo info{};
std::memset(&info, 0xA5, sizeof(info));
VoicePortInfo sentinel = info;
Require(sceVoiceGetPortInfo(0, &info) == NotInitialized);
Require(std::memcmp(&info, &sentinel, sizeof(info)) == 0);
}

std::uint32_t CreatePort(std::int32_t type, float volume) {
VoicePortParam param{};
param.port_type = type;
Expand All @@ -48,6 +73,7 @@ std::uint32_t CreatePort(std::int32_t type, float volume) {
} // namespace

int main() {
TestNotInitialized();
RequireThrows([] { sceVoiceResetPort(0); });
RequireThrows([] { sceVoicePausePort(0); });
RequireThrows([] { sceVoiceResumePort(0); });
Expand All @@ -57,6 +83,7 @@ int main() {
VoiceInitParam init{};
VoiceStartParam start{};
Require(sceVoiceInit(&init, 0) == 0);
Require(sceVoiceInit(&init, 0) == AlreadyInitialized);
Require(sceVoiceStart(&start) == 0);
RequireThrows([] { sceVoiceGetResourceInfo(nullptr); });
VoiceResourceInfo resourceInfo{};
Expand Down Expand Up @@ -106,6 +133,7 @@ int main() {
RequireThrows([&] { sceVoicePausePort(input); });
Require(sceVoiceResetPort(output) == 0);
Require(sceVoiceEnd_nid_postfix() == 0);
TestNotInitialized();
RequireThrows([&] { sceVoiceResetPort(output); });
RequireThrows([&] { sceVoiceResumePort(output); });
RequireThrows([] { VoiceResourceInfo info{}; sceVoiceGetResourceInfo(&info); });
Expand Down
1 change: 1 addition & 0 deletions docs/dev/debt/libSceVoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
- [sceVoiceResetPort](../../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - the `(uint32_t portId)` signature is the PS Vita one in [VitaSDK](https://github.com/vitasdk/vita-headers/blob/ae5808f3105c42fa3373ba4ab64ab54e2e3ca848/include/psp2/voice.h#L503-L514) and the PS3 `cellVoiceResetPort` in [RPCS3](https://github.com/RPCS3/rpcs3/blob/be69c054eeac57e2e671697a463473d37fe5a7b2/rpcs3/Emu/Cell/Modules/cellVoice.cpp#L493-L510); that the PS5 library takes the same argument is assumed. A reset clears a port's buffered data, and ports here buffer nothing (`sceVoiceReadFromOPort` returns 0 bytes and `sceVoiceWriteToIPort` throws), so it only checks that the library is initialized and the port exists, as RPCS3 does, and keeps the port's connections, volume and mute flag. An uninitialized library or an unknown port throws like the other port calls; the console's error codes are not measured. PPSA23566 imports it
- [sceVoiceGetResourceInfo](../../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - the `(VoiceResourceInfo* info)` signature and port limits (7 voice inputs, 7 voice outputs, 1 device input, 1 device output, 64 total ports) are the PS Vita ones in [VitaSDK](https://github.com/vitasdk/vita-headers/blob/ae5808f3105c42fa3373ba4ab64ab54e2e3ca848/include/psp2/voice.h#L150-L157); that the PS5 library uses the same layout and limits is assumed. An uninitialized library or a null output pointer throws like the other Voice calls; console limits and error codes are not measured. PPSA23566 imports it
- [sceVoiceEnableChat, sceVoiceDisableChat](../../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) take no arguments and return 0, following [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Audio/AudioOut2.cs#L460-L464) and the `sceAudioOut2EnableChat` model. The host mixes no chat audio, so the calls only record whether chat audio is enabled and fail when the library is not initialized. Console error codes and chat session requirements are unverified. PPSA23566 imports them
- [sceVoiceInit, sceVoiceStart, sceVoiceCreatePort, sceVoiceGetPortInfo](../../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - a second `sceVoiceInit` returns 0x804E0802, and Start, CreatePort and GetPortInfo return 0x804E0801 before checking any argument while the library is not initialized, as [prosper](https://github.com/mattias800/prosper/blob/ed42e499888d5a86792c3e1b2df3aebd8ca1a681/prosper/src/hle/audio/hle_audio.cpp#L4697-L4713) reads them from the shipped module. The other port and lifecycle calls still throw when the library is not initialized, since prosper gives no module address for them. Whether `sceVoiceInit` checks a null param before its state is unknown, so a null param still throws first, and that `sceVoiceEnd` returns the library to the not-initialized state is assumed. Closes when: the other entry points are read from the module or measured on a PS5
- [sceVoicePausePort, sceVoiceResumePort](../../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - not measured on a PS5: the `(uint32_t portId)` signature follows [VitaSDK](https://github.com/vitasdk/vita-headers/blob/ae5808f3105c42fa3373ba4ab64ab54e2e3ca848/include/psp2/voice.h#L516-L538) and the PS3 calls in [RPCS3](https://github.com/RPCS3/rpcs3/blob/be69c054eeac57e2e671697a463473d37fe5a7b2/rpcs3/Emu/Cell/Modules/cellVoice.cpp#L443-L529), and the console's error codes and its result for pausing a paused port or resuming a running one are unknown (0 here, as in RPCS3). Both only check that the library is initialized and the port exists: VitaSDK documents that a paused port keeps its data and reported state, and nothing here processes port data. PPSA24191 imports them
Loading