From 432f68ad29df7a368ba375d75d667c954e9c80b9 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 May 2023 17:54:22 -0400 Subject: configure_audio: Implement ui generation Needs a considerable amount of management specific to some of the comoboboxes due to the audio engine configuration. general: Partial audio config implmentation configure_audio: Implement ui generation Needs a considerable amount of management specific to some of the comoboboxes due to the audio engine configuration. general: Partial audio config implmentation settings: Make audio settings as enums --- src/audio_core/sink/sink_details.cpp | 33 +++++++++++++++++---------------- src/audio_core/sink/sink_details.h | 9 ++++++--- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src/audio_core/sink') diff --git a/src/audio_core/sink/sink_details.cpp b/src/audio_core/sink/sink_details.cpp index 39ea6d91b..751e97bfc 100644 --- a/src/audio_core/sink/sink_details.cpp +++ b/src/audio_core/sink/sink_details.cpp @@ -15,6 +15,7 @@ #endif #include "audio_core/sink/null_sink.h" #include "common/logging/log.h" +#include "common/settings_enums.h" namespace AudioCore::Sink { namespace { @@ -24,7 +25,7 @@ struct SinkDetails { using LatencyFn = u32 (*)(); /// Name for this sink. - std::string_view id; + Settings::AudioEngine id; /// A method to call to construct an instance of this type of sink. FactoryFn factory; /// A method to call to list available devices. @@ -37,7 +38,7 @@ struct SinkDetails { constexpr SinkDetails sink_details[] = { #ifdef HAVE_CUBEB SinkDetails{ - "cubeb", + Settings::AudioEngine::Cubeb, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, @@ -47,7 +48,7 @@ constexpr SinkDetails sink_details[] = { #endif #ifdef HAVE_SDL2 SinkDetails{ - "sdl2", + Settings::AudioEngine::Sdl2, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, @@ -55,46 +56,46 @@ constexpr SinkDetails sink_details[] = { &GetSDLLatency, }, #endif - SinkDetails{"null", + SinkDetails{Settings::AudioEngine::Null, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, [](bool capture) { return std::vector{"null"}; }, []() { return 0u; }}, }; -const SinkDetails& GetOutputSinkDetails(std::string_view sink_id) { - const auto find_backend{[](std::string_view id) { +const SinkDetails& GetOutputSinkDetails(Settings::AudioEngine sink_id) { + const auto find_backend{[](Settings::AudioEngine id) { return std::find_if(std::begin(sink_details), std::end(sink_details), [&id](const auto& sink_detail) { return sink_detail.id == id; }); }}; auto iter = find_backend(sink_id); - if (sink_id == "auto") { + if (sink_id == Settings::AudioEngine::Auto) { // 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("cubeb"); + iter = find_backend(Settings::AudioEngine::Cubeb); if (iter->latency() > TargetSampleCount * 3) { - iter = find_backend("sdl2"); + iter = find_backend(Settings::AudioEngine::Sdl2); } #else iter = std::begin(sink_details); #endif - LOG_INFO(Service_Audio, "Auto-selecting the {} backend", iter->id); + LOG_INFO(Service_Audio, "Auto-selecting the {} backend", Settings::TranslateEnum(iter->id)); } if (iter == std::end(sink_details)) { - LOG_ERROR(Audio, "Invalid sink_id {}", sink_id); - iter = find_backend("null"); + LOG_ERROR(Audio, "Invalid sink_id {}", Settings::TranslateEnum(sink_id)); + iter = find_backend(Settings::AudioEngine::Null); } return *iter; } } // Anonymous namespace -std::vector GetSinkIDs() { - std::vector sink_ids(std::size(sink_details)); +std::vector GetSinkIDs() { + std::vector sink_ids(std::size(sink_details)); std::transform(std::begin(sink_details), std::end(sink_details), std::begin(sink_ids), [](const auto& sink) { return sink.id; }); @@ -102,11 +103,11 @@ std::vector GetSinkIDs() { return sink_ids; } -std::vector GetDeviceListForSink(std::string_view sink_id, bool capture) { +std::vector GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture) { return GetOutputSinkDetails(sink_id).list_devices(capture); } -std::unique_ptr CreateSinkFromID(std::string_view sink_id, std::string_view device_id) { +std::unique_ptr CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id) { return GetOutputSinkDetails(sink_id).factory(device_id); } diff --git a/src/audio_core/sink/sink_details.h b/src/audio_core/sink/sink_details.h index e75932898..44403db71 100644 --- a/src/audio_core/sink/sink_details.h +++ b/src/audio_core/sink/sink_details.h @@ -7,6 +7,9 @@ #include #include +namespace Settings { +enum class AudioEngine : u32; +} namespace AudioCore { class AudioManager; @@ -19,7 +22,7 @@ class Sink; * * @return Vector of available sink names. */ -std::vector GetSinkIDs(); +std::vector GetSinkIDs(); /** * Gets the list of devices for a particular sink identified by the given ID. @@ -28,7 +31,7 @@ std::vector GetSinkIDs(); * @param capture - Get capture (input) devices, or output devices? * @return Vector of device names. */ -std::vector GetDeviceListForSink(std::string_view sink_id, bool capture); +std::vector GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture); /** * Creates an audio sink identified by the given device ID. @@ -37,7 +40,7 @@ std::vector GetDeviceListForSink(std::string_view sink_id, bool cap * @param device_id - Name of the device to create. * @return Pointer to the created sink. */ -std::unique_ptr CreateSinkFromID(std::string_view sink_id, std::string_view device_id); +std::unique_ptr CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id); } // namespace Sink } // namespace AudioCore -- cgit v1.2.3