mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-10 05:38:49 +00:00
Ds4 Speaker Audio Rebase Fix (#3607)
* Logic update, no QT ui * Fixing errors * Gui boxes * fixes * prevent device list refreshing too fast when game not running * Removed duplicate Socket declarations in kernel/file_system.cpp and fs.h * Fixed clang-format and micDevice errors * Ran clang-format and fixed rebase compiler issues * Settings dialog fix * Addressed squidbus' concerns * Update config.cpp to adhere to clang-format * Removed a space causing clang-format to complain * Addressed squidbus' concerns and added fallbacks Concerns: - Changed dev_name construct to remove unnecessary cast - Added an invalid AudioDeviceID macro to replace magic number --------- Co-authored-by: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com>
This commit is contained in:
@@ -208,7 +208,7 @@ int PS4_SYSV_ABI sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* sta
|
||||
state->channel = port.format_info.num_channels > 2 ? 2 : port.format_info.num_channels;
|
||||
break;
|
||||
case OrbisAudioOutPort::Personal:
|
||||
case OrbisAudioOutPort::Padspk:
|
||||
case OrbisAudioOutPort::PadSpk:
|
||||
state->output = 4;
|
||||
state->channel = 1;
|
||||
break;
|
||||
@@ -328,7 +328,7 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id,
|
||||
LOG_ERROR(Lib_AudioOut, "Audio out not initialized");
|
||||
return ORBIS_AUDIO_OUT_ERROR_NOT_INIT;
|
||||
}
|
||||
if ((port_type < OrbisAudioOutPort::Main || port_type > OrbisAudioOutPort::Padspk) &&
|
||||
if ((port_type < OrbisAudioOutPort::Main || port_type > OrbisAudioOutPort::PadSpk) &&
|
||||
(port_type != OrbisAudioOutPort::Audio3d && port_type != OrbisAudioOutPort::Aux)) {
|
||||
LOG_ERROR(Lib_AudioOut, "Invalid port type");
|
||||
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE;
|
||||
|
||||
@@ -25,7 +25,7 @@ enum class OrbisAudioOutPort {
|
||||
Bgm = 1,
|
||||
Voice = 2,
|
||||
Personal = 3,
|
||||
Padspk = 4,
|
||||
PadSpk = 4,
|
||||
Audio3d = 126,
|
||||
Aux = 127,
|
||||
};
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <SDL3/SDL_audio.h>
|
||||
#include <SDL3/SDL_hints.h>
|
||||
#include <common/config.h>
|
||||
|
||||
#include "common/config.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/audio/audioout.h"
|
||||
#include "core/libraries/audio/audioout_backend.h"
|
||||
|
||||
#define SDL_INVALID_AUDIODEVICEID 0 // Defined in SDL_audio.h but not made a macro
|
||||
namespace Libraries::AudioOut {
|
||||
|
||||
class SDLPortBackend : public PortBackend {
|
||||
@@ -21,8 +23,42 @@ public:
|
||||
.channels = port.format_info.num_channels,
|
||||
.freq = static_cast<int>(port.sample_rate),
|
||||
};
|
||||
stream =
|
||||
SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &fmt, nullptr, nullptr);
|
||||
|
||||
// Determine port type
|
||||
std::string port_name = port.type == OrbisAudioOutPort::PadSpk
|
||||
? Config::getPadSpkOutputDevice()
|
||||
: Config::getMainOutputDevice();
|
||||
SDL_AudioDeviceID dev_id = SDL_INVALID_AUDIODEVICEID;
|
||||
if (port_name == "None") {
|
||||
stream = nullptr;
|
||||
return;
|
||||
} else if (port_name == "Default Device") {
|
||||
dev_id = SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
|
||||
} else {
|
||||
try {
|
||||
SDL_AudioDeviceID* dev_array = SDL_GetAudioPlaybackDevices(nullptr);
|
||||
for (; dev_array != 0;) {
|
||||
std::string dev_name(SDL_GetAudioDeviceName(*dev_array));
|
||||
if (dev_name == port_name) {
|
||||
dev_id = *dev_array;
|
||||
break;
|
||||
} else {
|
||||
dev_array++;
|
||||
}
|
||||
}
|
||||
if (dev_id == SDL_INVALID_AUDIODEVICEID) {
|
||||
LOG_WARNING(Lib_AudioOut, "Audio device not found: {}", port_name);
|
||||
dev_id = SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR(Lib_AudioOut, "Invalid audio output device: {}", port_name);
|
||||
stream = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Open the audio stream
|
||||
stream = SDL_OpenAudioDeviceStream(dev_id, &fmt, nullptr, nullptr);
|
||||
if (stream == nullptr) {
|
||||
LOG_ERROR(Lib_AudioOut, "Failed to create SDL audio stream: {}", SDL_GetError());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user