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
This commit is contained in:
parent
88d3de4e85
commit
432f68ad29
14 changed files with 221 additions and 331 deletions
|
@ -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<Sink> {
|
||||
return std::make_unique<CubebSink>(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<Sink> {
|
||||
return std::make_unique<SDLSink>(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<Sink> {
|
||||
return std::make_unique<NullSink>(device_id);
|
||||
},
|
||||
[](bool capture) { return std::vector<std::string>{"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<std::string_view> GetSinkIDs() {
|
||||
std::vector<std::string_view> sink_ids(std::size(sink_details));
|
||||
std::vector<Settings::AudioEngine> GetSinkIDs() {
|
||||
std::vector<Settings::AudioEngine> 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<std::string_view> GetSinkIDs() {
|
|||
return sink_ids;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetDeviceListForSink(std::string_view sink_id, bool capture) {
|
||||
std::vector<std::string> GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture) {
|
||||
return GetOutputSinkDetails(sink_id).list_devices(capture);
|
||||
}
|
||||
|
||||
std::unique_ptr<Sink> CreateSinkFromID(std::string_view sink_id, std::string_view device_id) {
|
||||
std::unique_ptr<Sink> CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id) {
|
||||
return GetOutputSinkDetails(sink_id).factory(device_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Settings {
|
||||
enum class AudioEngine : u32;
|
||||
}
|
||||
namespace AudioCore {
|
||||
class AudioManager;
|
||||
|
||||
|
@ -19,7 +22,7 @@ class Sink;
|
|||
*
|
||||
* @return Vector of available sink names.
|
||||
*/
|
||||
std::vector<std::string_view> GetSinkIDs();
|
||||
std::vector<Settings::AudioEngine> GetSinkIDs();
|
||||
|
||||
/**
|
||||
* Gets the list of devices for a particular sink identified by the given ID.
|
||||
|
@ -28,7 +31,7 @@ std::vector<std::string_view> GetSinkIDs();
|
|||
* @param capture - Get capture (input) devices, or output devices?
|
||||
* @return Vector of device names.
|
||||
*/
|
||||
std::vector<std::string> GetDeviceListForSink(std::string_view sink_id, bool capture);
|
||||
std::vector<std::string> GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture);
|
||||
|
||||
/**
|
||||
* Creates an audio sink identified by the given device ID.
|
||||
|
@ -37,7 +40,7 @@ std::vector<std::string> 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<Sink> CreateSinkFromID(std::string_view sink_id, std::string_view device_id);
|
||||
std::unique_ptr<Sink> CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id);
|
||||
|
||||
} // namespace Sink
|
||||
} // namespace AudioCore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue