2022-07-17 00:48:45 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2022-09-14 09:32:14 +02:00
|
|
|
#include <array>
|
|
|
|
#include <span>
|
|
|
|
|
2022-07-17 00:48:45 +02:00
|
|
|
#include "audio_core/audio_core.h"
|
|
|
|
#include "audio_core/common/feature_support.h"
|
|
|
|
#include "audio_core/renderer/audio_device.h"
|
|
|
|
#include "audio_core/sink/sink.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
|
2023-08-31 16:09:15 +02:00
|
|
|
namespace AudioCore::Renderer {
|
2022-07-17 00:48:45 +02:00
|
|
|
|
2022-09-14 09:32:14 +02:00
|
|
|
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"},
|
|
|
|
};
|
|
|
|
|
2022-07-17 00:48:45 +02:00
|
|
|
AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id_,
|
|
|
|
const u32 revision)
|
|
|
|
: output_sink{system.AudioCore().GetOutputSink()},
|
|
|
|
applet_resource_user_id{applet_resource_user_id_}, user_revision{revision} {}
|
|
|
|
|
|
|
|
u32 AudioDevice::ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer,
|
2022-09-15 15:06:14 +02:00
|
|
|
const size_t max_count) const {
|
2022-09-14 09:32:14 +02:00
|
|
|
std::span<const AudioDeviceName> names{};
|
2022-07-17 00:48:45 +02:00
|
|
|
|
|
|
|
if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) {
|
|
|
|
names = usb_device_names;
|
|
|
|
} else {
|
|
|
|
names = device_names;
|
|
|
|
}
|
|
|
|
|
2022-09-15 15:06:14 +02:00
|
|
|
const u32 out_count{static_cast<u32>(std::min(max_count, names.size()))};
|
2022-07-17 00:48:45 +02:00
|
|
|
for (u32 i = 0; i < out_count; i++) {
|
|
|
|
out_buffer.push_back(names[i]);
|
|
|
|
}
|
|
|
|
return out_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 AudioDevice::ListAudioOutputDeviceName(std::vector<AudioDeviceName>& out_buffer,
|
2022-09-15 15:06:14 +02:00
|
|
|
const size_t max_count) const {
|
|
|
|
const u32 out_count{static_cast<u32>(std::min(max_count, output_device_names.size()))};
|
2022-07-17 00:48:45 +02:00
|
|
|
|
|
|
|
for (u32 i = 0; i < out_count; i++) {
|
|
|
|
out_buffer.push_back(output_device_names[i]);
|
|
|
|
}
|
|
|
|
return out_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDevice::SetDeviceVolumes(const f32 volume) {
|
|
|
|
output_sink.SetDeviceVolume(volume);
|
|
|
|
}
|
|
|
|
|
2022-09-15 15:06:14 +02:00
|
|
|
f32 AudioDevice::GetDeviceVolume([[maybe_unused]] std::string_view name) const {
|
2022-07-17 00:48:45 +02:00
|
|
|
return output_sink.GetDeviceVolume();
|
|
|
|
}
|
|
|
|
|
2023-08-31 16:09:15 +02:00
|
|
|
} // namespace AudioCore::Renderer
|