[audio_core] Revert EA3835 audio sink changes (#136)
Some checks failed
eden-license / license-header (pull_request) Failing after 32s
Some checks failed
eden-license / license-header (pull_request) Failing after 32s
Fixes diablo/totk audio stutters Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: #136
This commit is contained in:
parent
b2914247c3
commit
0b29fb7c8a
5 changed files with 114 additions and 9 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
@ -334,6 +337,48 @@ std::vector<std::string> ListCubebSinkDevices(bool capture) {
|
||||||
return device_list;
|
return device_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* REVERSION TO 3833 - function GetCubebLatency REINTRODUCED FROM 3833 - DIABLO 3 FIX */
|
||||||
|
u32 GetCubebLatency() {
|
||||||
|
cubeb* ctx;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
auto com_init_result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Init cubeb
|
||||||
|
if (cubeb_init(&ctx, "yuzu Latency Getter", nullptr) != CUBEB_OK) {
|
||||||
|
LOG_CRITICAL(Audio_Sink, "cubeb_init failed");
|
||||||
|
// Return a large latency so we choose SDL instead.
|
||||||
|
return 10000u;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (SUCCEEDED(com_init_result)) {
|
||||||
|
CoUninitialize();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Get min latency
|
||||||
|
cubeb_stream_params params{};
|
||||||
|
params.rate = TargetSampleRate;
|
||||||
|
params.channels = 2;
|
||||||
|
params.format = CUBEB_SAMPLE_S16LE;
|
||||||
|
params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||||
|
params.layout = CUBEB_LAYOUT_STEREO;
|
||||||
|
|
||||||
|
u32 latency{0};
|
||||||
|
const auto latency_error = cubeb_get_min_latency(ctx, ¶ms, &latency);
|
||||||
|
if (latency_error != CUBEB_OK) {
|
||||||
|
LOG_CRITICAL(Audio_Sink, "Error getting minimum latency, error: {}", latency_error);
|
||||||
|
latency = TargetSampleCount * 2;
|
||||||
|
}
|
||||||
|
latency = std::max(latency, TargetSampleCount * 2);
|
||||||
|
cubeb_destroy(ctx);
|
||||||
|
return latency;
|
||||||
|
}
|
||||||
|
|
||||||
|
// REVERTED back to 3833 - Below namespace section and function IsCubebSuitable() removed, reverting to GetCubebLatency() above. - DIABLO 3 FIX
|
||||||
|
/*
|
||||||
namespace {
|
namespace {
|
||||||
static long TmpDataCallback(cubeb_stream*, void*, const void*, void*, long) {
|
static long TmpDataCallback(cubeb_stream*, void*, const void*, void*, long) {
|
||||||
return TargetSampleCount;
|
return TargetSampleCount;
|
||||||
|
@ -400,5 +445,6 @@ bool IsCubebSuitable() {
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} // namespace AudioCore::Sink
|
} // namespace AudioCore::Sink
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
@ -96,12 +99,20 @@ private:
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> ListCubebSinkDevices(bool capture);
|
std::vector<std::string> ListCubebSinkDevices(bool capture);
|
||||||
|
|
||||||
|
// REVERSION - function GetCubebLatency() reintroduced from EA-3833 - DIABLO 3 FIX
|
||||||
|
/**
|
||||||
|
* Get the reported latency for this sink.
|
||||||
|
*
|
||||||
|
* @return Minimum latency for this sink.
|
||||||
|
*/
|
||||||
|
u32 GetCubebLatency();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this backend is suitable for use.
|
* Check if this backend is suitable for use.
|
||||||
* Checks if enabled, its latency, whether it opens successfully, etc.
|
* Checks if enabled, its latency, whether it opens successfully, etc.
|
||||||
*
|
*
|
||||||
* @return True is this backend is suitable, false otherwise.
|
* @return True is this backend is suitable, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool IsCubebSuitable();
|
// bool IsCubebSuitable(); // REVERTED BACK TO GetCubebLatency() FROM 3833
|
||||||
|
|
||||||
} // namespace AudioCore::Sink
|
} // namespace AudioCore::Sink
|
||||||
|
|
|
@ -234,6 +234,13 @@ std::vector<std::string> ListSDLSinkDevices(bool capture) {
|
||||||
return device_list;
|
return device_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* REVERSION to 3833 - function GetSDLLatency() REINTRODUCED FROM 3833 - DIABLO 3 FIX */
|
||||||
|
u32 GetSDLLatency() {
|
||||||
|
return TargetSampleCount * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// REVERTED back to 3833 - Below function IsSDLSuitable() removed, reverting to GetSDLLatency() above. - DIABLO 3 FIX
|
||||||
|
/*
|
||||||
bool IsSDLSuitable() {
|
bool IsSDLSuitable() {
|
||||||
#if !defined(HAVE_SDL2)
|
#if !defined(HAVE_SDL2)
|
||||||
return false;
|
return false;
|
||||||
|
@ -271,5 +278,6 @@ bool IsSDLSuitable() {
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} // namespace AudioCore::Sink
|
} // namespace AudioCore::Sink
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
@ -87,12 +90,20 @@ private:
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> ListSDLSinkDevices(bool capture);
|
std::vector<std::string> ListSDLSinkDevices(bool capture);
|
||||||
|
|
||||||
|
// REVERSION - function GetSDLLatency() reintroduced from EA-3833 - DIABLO 3 FIX
|
||||||
/**
|
/**
|
||||||
|
* Get the reported latency for this sink.
|
||||||
|
*
|
||||||
|
* @return Minimum latency for this sink.
|
||||||
|
*/
|
||||||
|
u32 GetSDLLatency();
|
||||||
|
|
||||||
|
/** REVERTED back to 3833 - Below function IsSDLSuitable() removed, reverting to GetSDLLatency() above. - DIABLO 3 FIX
|
||||||
* Check if this backend is suitable for use.
|
* Check if this backend is suitable for use.
|
||||||
* Checks if enabled, its latency, whether it opens successfully, etc.
|
* Checks if enabled, its latency, whether it opens successfully, etc.
|
||||||
*
|
*
|
||||||
* @return True is this backend is suitable, false otherwise.
|
* @return True is this backend is suitable, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool IsSDLSuitable();
|
//bool IsSDLSuitable(); // REVERTED for GetSDLLatency() from EA-3833
|
||||||
|
|
||||||
} // namespace AudioCore::Sink
|
} // namespace AudioCore::Sink
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
@ -25,7 +28,8 @@ namespace {
|
||||||
struct SinkDetails {
|
struct SinkDetails {
|
||||||
using FactoryFn = std::unique_ptr<Sink> (*)(std::string_view);
|
using FactoryFn = std::unique_ptr<Sink> (*)(std::string_view);
|
||||||
using ListDevicesFn = std::vector<std::string> (*)(bool);
|
using ListDevicesFn = std::vector<std::string> (*)(bool);
|
||||||
using SuitableFn = bool (*)();
|
using LatencyFn = u32 (*)(); // REINTRODUCED FROM 3833 - DIABLO 3 FIX
|
||||||
|
// using SuitableFn = bool (*)(); // REVERTED FOR ABOVE - DIABLO 3 FIX
|
||||||
|
|
||||||
/// Name for this sink.
|
/// Name for this sink.
|
||||||
Settings::AudioEngine id;
|
Settings::AudioEngine id;
|
||||||
|
@ -33,10 +37,18 @@ struct SinkDetails {
|
||||||
FactoryFn factory;
|
FactoryFn factory;
|
||||||
/// A method to call to list available devices.
|
/// A method to call to list available devices.
|
||||||
ListDevicesFn list_devices;
|
ListDevicesFn list_devices;
|
||||||
|
/// Method to get the latency of this backend - REINTRODUCED FROM 3833 - DIABLO 3 FIX
|
||||||
|
LatencyFn latency;
|
||||||
/// Check whether this backend is suitable to be used.
|
/// Check whether this backend is suitable to be used.
|
||||||
SuitableFn is_suitable;
|
/// SuitableFn is_suitable; // REVERTED FOR LatencyFn latency ABOVE - DIABLO 3 FIX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// NOTE TO PROBABLY FIX LATER FOR ANDROID - the return value "0u" for the first HAVE_OBOE
|
||||||
|
// section below was just copied from the null section so there's a somewhat valid value
|
||||||
|
// being returned, since the previous "true" value probably isn't compatible with the
|
||||||
|
// previous EA-3833 code. (HAVE_OBOE was introduced in a later release.) Eventually need
|
||||||
|
// to change "0u" for something else directly from the oboe_sink.cpp functions.
|
||||||
|
|
||||||
// sink_details is ordered in terms of desirability, with the best choice at the top.
|
// sink_details is ordered in terms of desirability, with the best choice at the top.
|
||||||
constexpr SinkDetails sink_details[] = {
|
constexpr SinkDetails sink_details[] = {
|
||||||
#ifdef HAVE_OBOE
|
#ifdef HAVE_OBOE
|
||||||
|
@ -46,7 +58,7 @@ constexpr SinkDetails sink_details[] = {
|
||||||
return std::make_unique<OboeSink>();
|
return std::make_unique<OboeSink>();
|
||||||
},
|
},
|
||||||
[](bool capture) { return std::vector<std::string>{"Default"}; },
|
[](bool capture) { return std::vector<std::string>{"Default"}; },
|
||||||
[]() { return true; },
|
[]() { return 0u; },
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CUBEB
|
#ifdef HAVE_CUBEB
|
||||||
|
@ -56,7 +68,7 @@ constexpr SinkDetails sink_details[] = {
|
||||||
return std::make_unique<CubebSink>(device_id);
|
return std::make_unique<CubebSink>(device_id);
|
||||||
},
|
},
|
||||||
&ListCubebSinkDevices,
|
&ListCubebSinkDevices,
|
||||||
&IsCubebSuitable,
|
&GetCubebLatency,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
|
@ -66,7 +78,7 @@ constexpr SinkDetails sink_details[] = {
|
||||||
return std::make_unique<SDLSink>(device_id);
|
return std::make_unique<SDLSink>(device_id);
|
||||||
},
|
},
|
||||||
&ListSDLSinkDevices,
|
&ListSDLSinkDevices,
|
||||||
&IsSDLSuitable,
|
&GetSDLLatency,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
SinkDetails{
|
SinkDetails{
|
||||||
|
@ -75,7 +87,7 @@ constexpr SinkDetails sink_details[] = {
|
||||||
return std::make_unique<NullSink>(device_id);
|
return std::make_unique<NullSink>(device_id);
|
||||||
},
|
},
|
||||||
[](bool capture) { return std::vector<std::string>{"null"}; },
|
[](bool capture) { return std::vector<std::string>{"null"}; },
|
||||||
[]() { return true; },
|
[]() { return 0u; },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,6 +100,8 @@ const SinkDetails& GetOutputSinkDetails(Settings::AudioEngine sink_id) {
|
||||||
auto iter = find_backend(sink_id);
|
auto iter = find_backend(sink_id);
|
||||||
|
|
||||||
if (sink_id == Settings::AudioEngine::Auto) {
|
if (sink_id == Settings::AudioEngine::Auto) {
|
||||||
|
// REVERTED TO 3833 BELOW - DIABLO 3 FIX
|
||||||
|
/*
|
||||||
// Auto-select a backend. Use the sink details ordering, preferring cubeb first, checking
|
// Auto-select a backend. Use the sink details ordering, preferring cubeb first, checking
|
||||||
// that the backend is available and suitable to use.
|
// that the backend is available and suitable to use.
|
||||||
for (auto& details : sink_details) {
|
for (auto& details : sink_details) {
|
||||||
|
@ -96,14 +110,29 @@ const SinkDetails& GetOutputSinkDetails(Settings::AudioEngine sink_id) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/ // END REVERTED CODE - DIABLO 3 FIX
|
||||||
|
|
||||||
|
// BEGIN REINTRODUCED FROM 3833 - REPLACED CODE BLOCK ABOVE - DIABLO 3 FIX
|
||||||
|
// Auto-select a backend. Prefer CubeB, but it may report a large minimum latency which
|
||||||
|
// causes audio issues, in that case go with SDL.
|
||||||
|
#if defined(HAVE_CUBEB) && defined(HAVE_SDL2)
|
||||||
|
iter = find_backend(Settings::AudioEngine::Cubeb);
|
||||||
|
if (iter->latency() > TargetSampleCount * 3) {
|
||||||
|
iter = find_backend(Settings::AudioEngine::Sdl2);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
iter = std::begin(sink_details);
|
||||||
|
#endif
|
||||||
|
// END REINTRODUCED SECTION FROM 3833 - DIABLO 3 FIX
|
||||||
LOG_INFO(Service_Audio, "Auto-selecting the {} backend",
|
LOG_INFO(Service_Audio, "Auto-selecting the {} backend",
|
||||||
Settings::CanonicalizeEnum(iter->id));
|
Settings::CanonicalizeEnum(iter->id));
|
||||||
|
/* BEGIN REMOVED - REVERTING BACK TO 3833, this didn't exist at all. - DIABLO 3 FIX
|
||||||
} else {
|
} else {
|
||||||
if (iter != std::end(sink_details) && !iter->is_suitable()) {
|
if (iter != std::end(sink_details) && !iter->is_suitable()) {
|
||||||
LOG_ERROR(Service_Audio, "Selected backend {} is not suitable, falling back to null",
|
LOG_ERROR(Service_Audio, "Selected backend {} is not suitable, falling back to null",
|
||||||
Settings::CanonicalizeEnum(iter->id));
|
Settings::CanonicalizeEnum(iter->id));
|
||||||
iter = find_backend(Settings::AudioEngine::Null);
|
iter = find_backend(Settings::AudioEngine::Null);
|
||||||
}
|
} */ // END REMOVED REVERT - DIABLO 3 FIX
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iter == std::end(sink_details)) {
|
if (iter == std::end(sink_details)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue