1
0
Fork 0
forked from suyu/suyu

audio_device: Make AudioDeviceName constructor constexpr

These are used as read-only arrays, so we can make the data read-only
and available at compile-time.

Now constructing an AudioDevice no longer needs to initialize some
tables
This commit is contained in:
Lioncash 2022-09-14 03:32:14 -04:00
parent 1be456db83
commit 1c7dae966d
5 changed files with 30 additions and 17 deletions

View file

@ -82,7 +82,7 @@ u32 Manager::GetDeviceNames(std::vector<AudioRenderer::AudioDevice::AudioDeviceN
auto input_devices{Sink::GetDeviceListForSink(Settings::values.sink_id.GetValue(), true)}; auto input_devices{Sink::GetDeviceListForSink(Settings::values.sink_id.GetValue(), true)};
if (input_devices.size() > 1) { if (input_devices.size() > 1) {
names.push_back(AudioRenderer::AudioDevice::AudioDeviceName("Uac")); names.emplace_back("Uac");
return 1; return 1;
} }
return 0; return 0;

View file

@ -74,7 +74,7 @@ void Manager::BufferReleaseAndRegister() {
u32 Manager::GetAudioOutDeviceNames( u32 Manager::GetAudioOutDeviceNames(
std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names) const { std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names) const {
names.push_back({"DeviceOut"}); names.emplace_back("DeviceOut");
return 1; return 1;
} }

View file

@ -1,6 +1,9 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <array>
#include <span>
#include "audio_core/audio_core.h" #include "audio_core/audio_core.h"
#include "audio_core/common/feature_support.h" #include "audio_core/common/feature_support.h"
#include "audio_core/renderer/audio_device.h" #include "audio_core/renderer/audio_device.h"
@ -9,6 +12,25 @@
namespace AudioCore::AudioRenderer { namespace AudioCore::AudioRenderer {
constexpr std::array usb_device_names{
AudioDevice::AudioDeviceName{"AudioStereoJackOutput"},
AudioDevice::AudioDeviceName{"AudioBuiltInSpeakerOutput"},
AudioDevice::AudioDeviceName{"AudioTvOutput"},
AudioDevice::AudioDeviceName{"AudioUsbDeviceOutput"},
};
constexpr std::array device_names{
AudioDevice::AudioDeviceName{"AudioStereoJackOutput"},
AudioDevice::AudioDeviceName{"AudioBuiltInSpeakerOutput"},
AudioDevice::AudioDeviceName{"AudioTvOutput"},
};
constexpr std::array output_device_names{
AudioDevice::AudioDeviceName{"AudioBuiltInSpeakerOutput"},
AudioDevice::AudioDeviceName{"AudioTvOutput"},
AudioDevice::AudioDeviceName{"AudioExternalOutput"},
};
AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id_, AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id_,
const u32 revision) const u32 revision)
: output_sink{system.AudioCore().GetOutputSink()}, : output_sink{system.AudioCore().GetOutputSink()},
@ -16,7 +38,7 @@ AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id
u32 AudioDevice::ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer, u32 AudioDevice::ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer,
const size_t max_count) { const size_t max_count) {
std::span<AudioDeviceName> names{}; std::span<const AudioDeviceName> names{};
if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) { if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) {
names = usb_device_names; names = usb_device_names;

View file

@ -3,7 +3,7 @@
#pragma once #pragma once
#include <span> #include <string_view>
#include "audio_core/audio_render_manager.h" #include "audio_core/audio_render_manager.h"
@ -23,21 +23,13 @@ namespace AudioRenderer {
class AudioDevice { class AudioDevice {
public: public:
struct AudioDeviceName { struct AudioDeviceName {
std::array<char, 0x100> name; std::array<char, 0x100> name{};
AudioDeviceName(const char* name_) { constexpr AudioDeviceName(std::string_view name_) {
std::strncpy(name.data(), name_, name.size()); name_.copy(name.data(), name.size() - 1);
} }
}; };
std::array<AudioDeviceName, 4> usb_device_names{"AudioStereoJackOutput",
"AudioBuiltInSpeakerOutput", "AudioTvOutput",
"AudioUsbDeviceOutput"};
std::array<AudioDeviceName, 3> device_names{"AudioStereoJackOutput",
"AudioBuiltInSpeakerOutput", "AudioTvOutput"};
std::array<AudioDeviceName, 3> output_device_names{"AudioBuiltInSpeakerOutput", "AudioTvOutput",
"AudioExternalOutput"};
explicit AudioDevice(Core::System& system, u64 applet_resource_user_id, u32 revision); explicit AudioDevice(Core::System& system, u64 applet_resource_user_id, u32 revision);
/** /**

View file

@ -246,9 +246,8 @@ void AudOutU::ListAudioOuts(Kernel::HLERequestContext& ctx) {
const auto write_count = const auto write_count =
static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName)); static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName));
std::vector<AudioDevice::AudioDeviceName> device_names{}; std::vector<AudioDevice::AudioDeviceName> device_names{};
std::string print_names{};
if (write_count > 0) { if (write_count > 0) {
device_names.push_back(AudioDevice::AudioDeviceName("DeviceOut")); device_names.emplace_back("DeviceOut");
LOG_DEBUG(Service_Audio, "called. \nName=DeviceOut"); LOG_DEBUG(Service_Audio, "called. \nName=DeviceOut");
} else { } else {
LOG_DEBUG(Service_Audio, "called. Empty buffer passed in."); LOG_DEBUG(Service_Audio, "called. Empty buffer passed in.");