mirror of
https://github.com/PabloMK7/citra.git
synced 2025-09-10 12:50:04 +00:00
misc: Improve defaults for macOS and handling of missing audio backends. (#7273)
* misc: Improve backend defaults for macOS. * audio_core: Improve handling of missing audio backends.
This commit is contained in:
parent
dccb8f6b17
commit
178e602589
11 changed files with 109 additions and 107 deletions
|
@ -21,7 +21,7 @@ void DspInterface::SetSink(AudioCore::SinkType sink_type, std::string_view audio
|
|||
// Dispose of the current sink first to avoid contention.
|
||||
sink.reset();
|
||||
|
||||
sink = CreateSinkFromID(sink_type, audio_device);
|
||||
sink = AudioCore::GetSinkDetails(sink_type).create_sink(audio_device);
|
||||
sink->SetCallback(
|
||||
[this](s16* buffer, std::size_t num_frames) { OutputCallback(buffer, num_frames); });
|
||||
time_stretcher.SetOutputSampleRate(sink->GetNativeSampleRate());
|
||||
|
|
|
@ -20,24 +20,10 @@
|
|||
|
||||
namespace AudioCore {
|
||||
namespace {
|
||||
struct InputDetails {
|
||||
using FactoryFn = std::unique_ptr<Input> (*)(std::string_view);
|
||||
using ListDevicesFn = std::vector<std::string> (*)();
|
||||
|
||||
/// Type of this input.
|
||||
InputType type;
|
||||
/// Name for this input.
|
||||
std::string_view name;
|
||||
/// A method to call to construct an instance of this type of input.
|
||||
FactoryFn factory;
|
||||
/// A method to call to list available devices.
|
||||
ListDevicesFn list_devices;
|
||||
};
|
||||
|
||||
// input_details is ordered in terms of desirability, with the best choice at the top.
|
||||
constexpr std::array input_details = {
|
||||
#ifdef HAVE_CUBEB
|
||||
InputDetails{InputType::Cubeb, "Real Device (Cubeb)",
|
||||
InputDetails{InputType::Cubeb, "Real Device (Cubeb)", true,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
||||
LOG_WARNING(Audio,
|
||||
|
@ -49,7 +35,7 @@ constexpr std::array input_details = {
|
|||
&ListCubebInputDevices},
|
||||
#endif
|
||||
#ifdef HAVE_OPENAL
|
||||
InputDetails{InputType::OpenAL, "Real Device (OpenAL)",
|
||||
InputDetails{InputType::OpenAL, "Real Device (OpenAL)", true,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
if (!Core::System::GetInstance().HasMicPermission()) {
|
||||
LOG_WARNING(Audio,
|
||||
|
@ -60,17 +46,22 @@ constexpr std::array input_details = {
|
|||
},
|
||||
&ListOpenALInputDevices},
|
||||
#endif
|
||||
InputDetails{InputType::Static, "Static Noise",
|
||||
InputDetails{InputType::Static, "Static Noise", false,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
return std::make_unique<StaticInput>();
|
||||
},
|
||||
[] { return std::vector<std::string>{"Static Noise"}; }},
|
||||
InputDetails{InputType::Null, "None",
|
||||
InputDetails{InputType::Null, "None", false,
|
||||
[](std::string_view device_id) -> std::unique_ptr<Input> {
|
||||
return std::make_unique<NullInput>();
|
||||
},
|
||||
[] { return std::vector<std::string>{"None"}; }},
|
||||
};
|
||||
} // Anonymous namespace
|
||||
|
||||
std::vector<InputDetails> ListInputs() {
|
||||
return {input_details.begin(), input_details.end()};
|
||||
}
|
||||
|
||||
const InputDetails& GetInputDetails(InputType input_type) {
|
||||
auto iter = std::find_if(
|
||||
|
@ -88,21 +79,5 @@ const InputDetails& GetInputDetails(InputType input_type) {
|
|||
|
||||
return *iter;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string_view GetInputName(InputType input_type) {
|
||||
if (input_type == InputType::Auto) {
|
||||
return "Auto";
|
||||
}
|
||||
return GetInputDetails(input_type).name;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetDeviceListForInput(InputType input_type) {
|
||||
return GetInputDetails(input_type).list_devices();
|
||||
}
|
||||
|
||||
std::unique_ptr<Input> CreateInputFromID(InputType input_type, std::string_view device_id) {
|
||||
return GetInputDetails(input_type).factory(device_id);
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
@ -20,17 +20,28 @@ enum class InputType : u32 {
|
|||
Static = 2,
|
||||
Cubeb = 3,
|
||||
OpenAL = 4,
|
||||
|
||||
NumInputTypes,
|
||||
};
|
||||
|
||||
/// Gets the name of a input type.
|
||||
std::string_view GetInputName(InputType input_type);
|
||||
struct InputDetails {
|
||||
using FactoryFn = std::unique_ptr<Input> (*)(std::string_view device_id);
|
||||
using ListDevicesFn = std::vector<std::string> (*)();
|
||||
|
||||
/// Gets the list of devices for a particular input identified by the given ID.
|
||||
std::vector<std::string> GetDeviceListForInput(InputType input_type);
|
||||
/// Type of this input.
|
||||
InputType type;
|
||||
/// Name for this input.
|
||||
std::string_view name;
|
||||
/// Whether the input is backed by real devices.
|
||||
bool real;
|
||||
/// A method to call to construct an instance of this type of input.
|
||||
FactoryFn create_input;
|
||||
/// A method to call to list available devices.
|
||||
ListDevicesFn list_devices;
|
||||
};
|
||||
|
||||
/// Creates an audio input identified by the given device ID.
|
||||
std::unique_ptr<Input> CreateInputFromID(InputType input_type, std::string_view device_id);
|
||||
/// Lists all available input types.
|
||||
std::vector<InputDetails> ListInputs();
|
||||
|
||||
/// Gets the details of an input type.
|
||||
const InputDetails& GetInputDetails(InputType input_type);
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
@ -21,20 +21,6 @@
|
|||
|
||||
namespace AudioCore {
|
||||
namespace {
|
||||
struct SinkDetails {
|
||||
using FactoryFn = std::unique_ptr<Sink> (*)(std::string_view);
|
||||
using ListDevicesFn = std::vector<std::string> (*)();
|
||||
|
||||
/// Type of this sink.
|
||||
SinkType type;
|
||||
/// Name for this sink.
|
||||
std::string_view name;
|
||||
/// A method to call to construct an instance of this type of sink.
|
||||
FactoryFn factory;
|
||||
/// A method to call to list available devices.
|
||||
ListDevicesFn list_devices;
|
||||
};
|
||||
|
||||
// sink_details is ordered in terms of desirability, with the best choice at the top.
|
||||
constexpr std::array sink_details = {
|
||||
#ifdef HAVE_CUBEB
|
||||
|
@ -64,6 +50,11 @@ constexpr std::array sink_details = {
|
|||
},
|
||||
[] { return std::vector<std::string>{"None"}; }},
|
||||
};
|
||||
} // Anonymous namespace
|
||||
|
||||
std::vector<SinkDetails> ListSinks() {
|
||||
return {sink_details.begin(), sink_details.end()};
|
||||
}
|
||||
|
||||
const SinkDetails& GetSinkDetails(SinkType sink_type) {
|
||||
auto iter = std::find_if(
|
||||
|
@ -81,21 +72,5 @@ const SinkDetails& GetSinkDetails(SinkType sink_type) {
|
|||
|
||||
return *iter;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string_view GetSinkName(SinkType sink_type) {
|
||||
if (sink_type == SinkType::Auto) {
|
||||
return "Auto";
|
||||
}
|
||||
return GetSinkDetails(sink_type).name;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetDeviceListForSink(SinkType sink_type) {
|
||||
return GetSinkDetails(sink_type).list_devices();
|
||||
}
|
||||
|
||||
std::unique_ptr<Sink> CreateSinkFromID(SinkType sink_type, std::string_view device_id) {
|
||||
return GetSinkDetails(sink_type).factory(device_id);
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
@ -20,17 +20,26 @@ enum class SinkType : u32 {
|
|||
Cubeb = 2,
|
||||
OpenAL = 3,
|
||||
SDL2 = 4,
|
||||
|
||||
NumSinkTypes,
|
||||
};
|
||||
|
||||
/// Gets the name of a sink type.
|
||||
std::string_view GetSinkName(SinkType sink_type);
|
||||
struct SinkDetails {
|
||||
using FactoryFn = std::unique_ptr<Sink> (*)(std::string_view);
|
||||
using ListDevicesFn = std::vector<std::string> (*)();
|
||||
|
||||
/// Gets the list of devices for a particular sink identified by the given ID.
|
||||
std::vector<std::string> GetDeviceListForSink(SinkType sink_type);
|
||||
/// Type of this sink.
|
||||
SinkType type;
|
||||
/// Name for this sink.
|
||||
std::string_view name;
|
||||
/// A method to call to construct an instance of this type of sink.
|
||||
FactoryFn create_sink;
|
||||
/// A method to call to list available devices.
|
||||
ListDevicesFn list_devices;
|
||||
};
|
||||
|
||||
/// Creates an audio sink identified by the given device ID.
|
||||
std::unique_ptr<Sink> CreateSinkFromID(SinkType sink_type, std::string_view device_id);
|
||||
/// Lists all available sink types.
|
||||
std::vector<SinkDetails> ListSinks();
|
||||
|
||||
/// Gets the details of an sink type.
|
||||
const SinkDetails& GetSinkDetails(SinkType input_type);
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue