diff --git a/src/audio_core/sdl_audio.cpp b/src/audio_core/sdl_audio.cpp index 63319ab1d..457f8802f 100644 --- a/src/audio_core/sdl_audio.cpp +++ b/src/audio_core/sdl_audio.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include "sdl_audio.h" namespace Audio { @@ -90,9 +91,13 @@ int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq, s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) { std::scoped_lock lock{m_mutex}; auto& port = portsOut[handle - 1]; - if (!port.isOpen || ptr == nullptr) + if (!port.isOpen) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } + if (ptr == nullptr) { return 0; - + } + // TODO mixing channels int result = SDL_PutAudioStreamData(port.stream, ptr, port.samples_num * port.sample_size * port.channels_num); // TODO find a correct value 8192 is estimated diff --git a/src/audio_core/sdl_audio.h b/src/audio_core/sdl_audio.h index f1eff066d..5c29835c3 100644 --- a/src/audio_core/sdl_audio.h +++ b/src/audio_core/sdl_audio.h @@ -34,7 +34,8 @@ private: SDL_AudioStream* stream = nullptr; }; std::mutex m_mutex; - std::array portsOut; // main support up to 8 ports + std::array portsOut; // main up to 8 ports , BGM 1 port , voice up to 4 ports , + // personal up to 4 ports , padspk up to 5 ports , aux 1 port }; } // namespace Audio \ No newline at end of file diff --git a/src/core/libraries/libsceaudioout.cpp b/src/core/libraries/libsceaudioout.cpp index 0a6144b49..0b64aef92 100644 --- a/src/core/libraries/libsceaudioout.cpp +++ b/src/core/libraries/libsceaudioout.cpp @@ -231,10 +231,30 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id, OrbisAudioOutPort port_type, s32 index, u32 length, u32 sample_rate, OrbisAudioOutParam param_type) { LOG_INFO(Lib_AudioOut, - "AudioOutOpen id = {} port_type = {} index = {} lengh t= {} sample_rate = {} " + "AudioOutOpen id = {} port_type = {} index = {} lenght= {} sample_rate = {} " "param_type = {}", user_id, GetAudioOutPort(port_type), index, length, sample_rate, GetAudioOutParam(param_type)); + if ((port_type < 0 || port_type > 4) && (port_type != 127)) { + LOG_ERROR(Lib_AudioOut, "Invalid port type"); + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE; + } + if (sample_rate != 48000) { + LOG_ERROR(Lib_AudioOut, "Invalid sample rate"); + return ORBIS_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ; + } + if (param_type < 0 || param_type > 7) { + LOG_ERROR(Lib_AudioOut, "Invalid format"); + return ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT; + } + if (length != 256 && length != 512 && length != 768 && length != 1024 && length != 1280 && + length != 1536 && length != 1792 && length != 2048) { + LOG_ERROR(Lib_AudioOut, "Invalid length"); + return ORBIS_AUDIO_OUT_ERROR_INVALID_SIZE; + } + if (index != 0) { + LOG_ERROR(Lib_AudioOut, "index is not valid !=0 {}", index); + } int result = audio->AudioOutOpen(port_type, length, sample_rate, param_type); if (result == -1) { LOG_ERROR(Lib_AudioOut, "Audio ports are full");