Skip to content

Commit

Permalink
Revert "sceNetAccept sleep and SDLAudio::AudioOutOutput latency and c…
Browse files Browse the repository at this point in the history
…pu improvements (shadps4-emu#507)"

This reverts commit d66d129.
  • Loading branch information
georgemoralis authored and baggins183 committed Sep 12, 2024
1 parent 2d7fe48 commit f2dcbc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
33 changes: 10 additions & 23 deletions src/audio_core/sdl_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq,
port.stream =
SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &fmt, NULL, NULL);
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(port.stream));
return id + 1; // Handle range 1..n keeps 0 reserved
return id + 1;
}
}

Expand All @@ -93,35 +93,22 @@ int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq,

s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
std::shared_lock lock{m_mutex};
if (handle < 1 || handle > portsOut.size()) {
// Handle is outside range 1..n
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT;
}
auto& port = portsOut[handle - 1];
if (!port.isOpen) {
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT;
}

// Allow call with null - this acts as "wait for buffer ready"
if (ptr != nullptr) {
// TODO mixing channels
int result = SDL_PutAudioStreamData(
port.stream, ptr, port.samples_num * port.sample_size * port.channels_num);
if (result != 0) {
// There's various possible failures, just assume some buffer is full
return ORBIS_AUDIO_OUT_ERROR_PORT_FULL;
}
if (ptr == nullptr) {
return 0;
}

auto bytesPerSecond = 48000 * port.sample_size * port.channels_num;
const int TARGET_LATENCY_MS = 20; // Arbitrary, but slightly more than one 60fps frame
auto sizeTarget = (bytesPerSecond * TARGET_LATENCY_MS) / 1000;

while (SDL_GetAudioStreamAvailable(port.stream) > sizeTarget) {
SDL_Delay(1); // Sleep behaviour is platform-dependent; 1ms may be up to 17ms
// 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
while (SDL_GetAudioStreamAvailable(port.stream) > 65536) {
SDL_Delay(0);
}

return ORBIS_OK;
return result;
}

bool SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) {
Expand Down
5 changes: 1 addition & 4 deletions src/core/libraries/network/net.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <thread>

#ifdef WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Ws2tcpip.h>
Expand Down Expand Up @@ -61,8 +59,7 @@ int PS4_SYSV_ABI sce_net_in6addr_nodelocal_allnodes() {
}

OrbisNetId PS4_SYSV_ABI sceNetAccept(OrbisNetId s, OrbisNetSockaddr* addr, u32* paddrlen) {
LOG_ERROR(Lib_Net, "(STUBBED) called [sleeping]");
std::this_thread::sleep_for(std::chrono::seconds(5));
LOG_ERROR(Lib_Net, "(STUBBED) called");
return ORBIS_OK;
}

Expand Down

0 comments on commit f2dcbc1

Please sign in to comment.