Commit df3bea2e authored by James's avatar James
Browse files

Simplify audio backend, remove timing related options

parent 8dfed947
......@@ -7,16 +7,10 @@
#include <libretro.h>
#include "audio_core/libretro_sink.h"
#include "audio_types.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/settings.h"
namespace AudioCore {
// TODO: Should this be global? I think: yes.
std::list<std::vector<s16>> queue;
std::mutex queue_mutex;
LibRetroSink::LibRetroSink() {}
LibRetroSink::~LibRetroSink() {}
......@@ -30,70 +24,15 @@ std::vector<std::string> LibRetroSink::GetDeviceList() const {
}
void LibRetroSink::EnqueueSamples(const s16* samples, size_t sample_count) {
SubmitAudioFrames(samples, sample_count);
LibRetro::SubmitAudio(samples, sample_count);
}
size_t LibRetroSink::SamplesInQueue() const {
std::lock_guard<std::mutex> lock(queue_mutex);
return std::accumulate(queue.begin(), queue.end(), static_cast<size_t>(0),
[](size_t sum, const auto& buffer) {
// Division by two because each stereo sample is made of
// two s16.
return sum + buffer.size() / 2;
});
return 0;
}
void LibRetroSink::SetDevice(int device_id) {}
void LibRetroSink::SubmitAudioFrames(const int16_t* samples, size_t sample_count) {
std::lock_guard<std::mutex> lock(queue_mutex);
// audio_batch_cb(data, frames);
queue.emplace_back(samples, samples + sample_count * 2);
}
bool audio_state = false;
// TODO: Let LibRetroSink register itself for this, and clean up automatically internally
void audio_callback() {
if (!audio_state) {
return;
}
u8 buffer_backing[512];
size_t remaining_size =
static_cast<size_t>(512) / sizeof(s16); // Keep track of size in 16-bit increments.
size_t max_size = remaining_size;
u8* buffer = buffer_backing;
{
std::lock_guard<std::mutex> lock(queue_mutex);
while (remaining_size > 0 && !queue.empty()) {
if (queue.front().size() <= remaining_size) {
memcpy(buffer, queue.front().data(), queue.front().size() * sizeof(s16));
buffer += queue.front().size() * sizeof(s16);
remaining_size -= queue.front().size();
queue.pop_front();
} else {
memcpy(buffer, queue.front().data(), remaining_size * sizeof(s16));
buffer += remaining_size * sizeof(s16);
queue.front().erase(queue.front().begin(), queue.front().begin() + remaining_size);
remaining_size = 0;
}
}
}
if (remaining_size > 0) {
memset(buffer, 0, remaining_size * sizeof(s16));
}
LibRetro::SubmitAudio((const int16_t*)&buffer_backing, (max_size - remaining_size) / 2);
}
void audio_set_state(bool state) {
audio_state = state;
}
} // namespace AudioCore
void LibRetro::SubmitAudio(const int16_t* data, size_t frames) {
......
......@@ -32,11 +32,9 @@ public:
std::vector<std::string> GetDeviceList() const override;
void SetDevice(int device_id) override;
/// Function provided by Retroarch dynamically to submit audio frames.
void SubmitAudioFrames(const int16_t* data, size_t frames);
private:
std::vector<s16> samples;
};
void audio_callback();
......
......@@ -73,11 +73,6 @@ void LibRetro::OnConfigureEnvironment() {
{"citra_analog_function",
"Right analog function; C-Stick and Touchscreen Pointer|Touchscreen Pointer|C-Stick"},
{"citra_deadzone", "Emulated pointer deadzone (%); 15|20|25|30|35|0|5|10"},
{"citra_limit_framerate", "Enable frame limiter; enabled|disabled"},
{"citra_limit_framerate_target",
"Frame limiter target (% of full speed); "
"100|110|120|130|140|150|200|250|300|350|400|450|500|50|80|90"},
{"citra_audio_stretching", "Enable audio stretching; enabled|disabled"},
{"citra_use_virtual_sd", "Enable virtual SD card; enabled|disabled"},
{"citra_use_libretro_save_path", "Savegame location; LibRetro Default|Citra Default"},
{"citra_is_new_3ds", "3DS system model; Old 3DS|New 3DS"},
......@@ -129,6 +124,7 @@ void UpdateSettings(bool init) {
{0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start"},
{0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select"},
{0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Home"},
{0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Touch Screen Touch"},
{0, 0},
};
......@@ -139,6 +135,11 @@ void UpdateSettings(bool init) {
Settings::values.log_filter = "*:Info";
Settings::values.sink_id = "libretro";
// We don't need these, as this is the frontend's responsibility.
Settings::values.enable_audio_stretching = false;
Settings::values.use_frame_limit = false;
Settings::values.frame_limit = 100;
// For our other settings, import them from LibRetro.
Settings::values.use_cpu_jit =
LibRetro::FetchVariable("citra_use_cpu_jit", "enabled") == "enabled";
......@@ -146,12 +147,6 @@ void UpdateSettings(bool init) {
LibRetro::FetchVariable("citra_use_hw_renderer", "enabled") == "enabled";
Settings::values.use_shader_jit =
LibRetro::FetchVariable("citra_use_shader_jit", "enabled") == "enabled";
Settings::values.enable_audio_stretching =
LibRetro::FetchVariable("citra_audio_stretching", "enabled") == "enabled";
Settings::values.use_frame_limit =
LibRetro::FetchVariable("citra_limit_framerate", "enabled") == "enabled";
auto framerate_target = LibRetro::FetchVariable("citra_limit_framerate_target", "100");
Settings::values.frame_limit = static_cast<u16>(std::stoi(framerate_target));
Settings::values.use_virtual_sd =
LibRetro::FetchVariable("citra_use_virtual_sd", "enabled") == "enabled";
Settings::values.is_new_3ds =
......@@ -416,13 +411,6 @@ bool retro_load_game(const struct retro_game_info* info) {
return false;
}
struct retro_audio_callback audio_cb = {AudioCore::audio_callback, AudioCore::audio_set_state};
if (!LibRetro::SetAudioCallback(&audio_cb)) {
LOG_CRITICAL(Frontend, "Async audio is not supported.");
LibRetro::DisplayMessage("Async audio is not supported.");
return false;
}
emu_instance->emu_window = std::make_unique<EmuWindow_LibRetro>();
UpdateSettings(true);
......@@ -478,11 +466,6 @@ bool retro_load_game(const struct retro_game_info* info) {
}
void retro_unload_game() {
struct retro_audio_callback audio_cb = {nullptr, nullptr};
if (!LibRetro::SetAudioCallback(&audio_cb)) {
LOG_CRITICAL(Frontend, "Async audio could not be halted.");
}
LOG_DEBUG(Frontend, "Unloading game...");
Core::System::GetInstance().Shutdown();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment