mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 13:20:14 +00:00
Initial Commit
Added Device logic to Sinks Started on UI for selecting devices
This commit is contained in:
parent
ffda82eea5
commit
bac2124fb9
@ -71,6 +71,13 @@ void SelectSink(std::string sink_id) {
|
||||
DSP::HLE::SetSink(iter->factory());
|
||||
}
|
||||
|
||||
void SelectDevice(std::string device_id){
|
||||
if (device_id == "") {
|
||||
LOG_ERROR(Audio, "AudioCore::SelectDevice given invalid device_id");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
CoreTiming::UnscheduleEvent(tick_event, 0);
|
||||
DSP::HLE::Shutdown();
|
||||
|
@ -23,6 +23,9 @@ void AddAddressSpace(Kernel::VMManager& vm_manager);
|
||||
/// Select the sink to use based on sink id.
|
||||
void SelectSink(std::string sink_id);
|
||||
|
||||
/// Select the device to use based on device id.
|
||||
void SelectDevice(std::string device_id);
|
||||
|
||||
/// Shutdown Audio Core
|
||||
void Shutdown();
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
|
||||
#include "audio_core/audio_core.h"
|
||||
#include "audio_core/sink.h"
|
||||
@ -24,6 +25,12 @@ public:
|
||||
size_t SamplesInQueue() const override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetDevice(int device_id) override {}
|
||||
|
||||
std::map<int, std::string>* GetDeviceMap() override {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace AudioCore
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "audio_core/audio_core.h"
|
||||
#include "audio_core/sdl2_sink.h"
|
||||
|
||||
#include "core/settings.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include <numeric>
|
||||
@ -45,11 +47,29 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
|
||||
SDL_AudioSpec obtained_audiospec;
|
||||
SDL_zero(obtained_audiospec);
|
||||
|
||||
int device_count = SDL_GetNumAudioDevices(0);
|
||||
device_map.clear();
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
device_map[i] = SDL_GetAudioDeviceName(i, 0);
|
||||
}
|
||||
|
||||
if (device_count < 1 ||
|
||||
Settings::values.audio_device_id == "auto" ||
|
||||
Settings::values.audio_device_id == "") {
|
||||
impl->audio_device_id = SDL_OpenAudioDevice(nullptr, false, &desired_audiospec, &obtained_audiospec, 0);
|
||||
if (impl->audio_device_id <= 0) {
|
||||
LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
impl->audio_device_id = SDL_OpenAudioDevice(device_map[device_id].c_str(), false, &desired_audiospec, &obtained_audiospec, 0);
|
||||
if (impl->audio_device_id <= 0) {
|
||||
LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
impl->sample_rate = obtained_audiospec.freq;
|
||||
|
||||
@ -99,6 +119,14 @@ size_t SDL2Sink::SamplesInQueue() const {
|
||||
return total_size;
|
||||
}
|
||||
|
||||
void SDL2Sink::SetDevice(int _device_id) {
|
||||
this->device_id = _device_id;
|
||||
}
|
||||
|
||||
std::map<int, std::string>* SDL2Sink::GetDeviceMap() {
|
||||
return &device_map;
|
||||
}
|
||||
|
||||
void SDL2Sink::Impl::Callback(void* impl_, u8* buffer, int buffer_size_in_bytes) {
|
||||
Impl* impl = reinterpret_cast<Impl*>(impl_);
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include "audio_core/sink.h"
|
||||
|
||||
@ -22,9 +23,16 @@ public:
|
||||
|
||||
size_t SamplesInQueue() const override;
|
||||
|
||||
std::map<int, std::string>* GetDeviceMap();
|
||||
void SetDevice(int _device_id);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
int device_id;
|
||||
std::map<int, std::string> device_map;
|
||||
};
|
||||
|
||||
extern const std::map<int, std::string> g_device_map;
|
||||
|
||||
} // namespace AudioCore
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
@ -29,6 +30,9 @@ public:
|
||||
|
||||
/// Samples enqueued that have not been played yet.
|
||||
virtual std::size_t SamplesInQueue() const = 0;
|
||||
|
||||
virtual void SetDevice(int device_id) = 0;
|
||||
virtual std::map<int, std::string>* GetDeviceMap() = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -21,6 +21,12 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) :
|
||||
ui->output_sink_combo_box->addItem(sink_detail.id);
|
||||
}
|
||||
|
||||
ui->audio_device_combo_box->clear();
|
||||
ui->audio_device_combo_box->addItem("auto");
|
||||
//for (const auto& device : AudioCore:) {
|
||||
// ui->audio_device_combo_box->addItem(device.second.c_str());
|
||||
//}
|
||||
|
||||
this->setConfiguration();
|
||||
}
|
||||
|
||||
@ -36,9 +42,20 @@ void ConfigureAudio::setConfiguration() {
|
||||
}
|
||||
}
|
||||
ui->output_sink_combo_box->setCurrentIndex(new_sink_index);
|
||||
|
||||
|
||||
int new_device_index = -1;
|
||||
for (int index = 0; index < ui->audio_device_combo_box->count(); index++) {
|
||||
if (ui->audio_device_combo_box->itemText(index).toStdString() == Settings::values.audio_device_id) {
|
||||
new_device_index = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui->audio_device_combo_box->setCurrentIndex(new_sink_index);
|
||||
}
|
||||
|
||||
void ConfigureAudio::applyConfiguration() {
|
||||
Settings::values.sink_id = ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()).toStdString();
|
||||
Settings::values.audio_device_id = ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()).toStdString();
|
||||
Settings::Apply();
|
||||
}
|
||||
|
@ -25,6 +25,21 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel">
|
||||
<property name="text">
|
||||
<string>Audio Device:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="audio_device_combo_box">
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -24,7 +24,7 @@ void Apply() {
|
||||
VideoCore::g_scaled_resolution_enabled = values.use_scaled_resolution;
|
||||
|
||||
AudioCore::SelectSink(values.sink_id);
|
||||
|
||||
AudioCore::SelectDevice(values.audio_device_id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <map>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
@ -81,6 +82,7 @@ struct Values {
|
||||
|
||||
// Audio
|
||||
std::string sink_id;
|
||||
std::string audio_device_id;
|
||||
|
||||
// Debugging
|
||||
bool use_gdbstub;
|
||||
|
Loading…
Reference in New Issue
Block a user