From d5adc74beb7b215054505c0f38954d7d4cb77686 Mon Sep 17 00:00:00 2001 From: RedTrainer97 Date: Fri, 24 Mar 2017 17:47:53 +0100 Subject: [PATCH] Merged commit --- src/audio_core/hle/dsp.cpp | 17 ++++++++++++++-- src/citra/config.cpp | 2 ++ src/citra/default_ini.h | 8 ++++++++ src/citra_qt/config.cpp | 4 ++++ src/citra_qt/configure_audio.cpp | 5 +++++ src/citra_qt/configure_audio.ui | 34 ++++++++++++++++++++++++++++++++ src/core/settings.h | 2 ++ 7 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp index 31421fdc6..a7c3ef150 100644 --- a/src/audio_core/hle/dsp.cpp +++ b/src/audio_core/hle/dsp.cpp @@ -10,6 +10,7 @@ #include "audio_core/hle/source.h" #include "audio_core/sink.h" #include "audio_core/time_stretch.h" +#include "core/settings.h" namespace DSP { namespace HLE { @@ -89,6 +90,17 @@ static bool perform_time_stretching = true; static std::unique_ptr sink; static AudioCore::TimeStretcher time_stretcher; +static StereoFrame16 ChangeVolume(const StereoFrame16& frame) { + StereoFrame16 new_frame = StereoFrame16(); + if (!Settings::values.mute) { + for (int i = 0; i < frame.size(); i++) { + new_frame[i][0] = frame[i][0] * Settings::values.volume; + new_frame[i][1] = frame[i][1] * Settings::values.volume; + } + } + return new_frame; +} + static void FlushResidualStretcherAudio() { time_stretcher.Flush(); while (true) { @@ -100,8 +112,9 @@ static void FlushResidualStretcherAudio() { } static void OutputCurrentFrame(const StereoFrame16& frame) { + StereoFrame16 new_frame = ChangeVolume(frame); if (perform_time_stretching) { - time_stretcher.AddSamples(&frame[0][0], frame.size()); + time_stretcher.AddSamples(&new_frame[0][0], frame.size()); std::vector stretched_samples = time_stretcher.Process(sink->SamplesInQueue()); sink->EnqueueSamples(stretched_samples.data(), stretched_samples.size() / 2); } else { @@ -112,7 +125,7 @@ static void OutputCurrentFrame(const StereoFrame16& frame) { return; } - sink->EnqueueSamples(&frame[0][0], frame.size()); + sink->EnqueueSamples(&new_frame[0][0], frame.size()); } } diff --git a/src/citra/config.cpp b/src/citra/config.cpp index ef1229912..80eb838d6 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -100,6 +100,8 @@ void Config::ReadValues() { Settings::values.enable_audio_stretching = sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true); Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); + Settings::values.volume = sdl2_config->GetReal("Audio", "volume", 1); + Settings::values.mute = sdl2_config->GetBoolean("Audio", "mute", false); // Data Storage Settings::values.use_virtual_sd = diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index af9f7aa2a..2d8c6c958 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -108,6 +108,14 @@ enable_audio_stretching = # auto (default): Auto-select output_device = +# Output volume. +# 1.0 (default): 100%, 0.0; mute +volume = + +# Disable audio output. +# 0 (default): false, 1: true +mute = + [Data Storage] # Whether to create a virtual SD card. # 1 (default): Yes, 0: No diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 6ccfa1577..3caf4df83 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -87,6 +87,8 @@ void Config::ReadValues() { qt_config->value("enable_audio_stretching", true).toBool(); Settings::values.audio_device_id = qt_config->value("output_device", "auto").toString().toStdString(); + Settings::values.volume = qt_config->value("volume", 1).toFloat(); + Settings::values.mute = qt_config->value("mute", 0).toBool(); qt_config->endGroup(); using namespace Service::CAM; @@ -213,6 +215,8 @@ void Config::SaveValues() { qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); qt_config->setValue("enable_audio_stretching", Settings::values.enable_audio_stretching); qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); + qt_config->setValue("volume", Settings::values.volume); + qt_config->setValue("mute", Settings::values.mute); qt_config->endGroup(); using namespace Service::CAM; diff --git a/src/citra_qt/configure_audio.cpp b/src/citra_qt/configure_audio.cpp index 3ddcf9232..bca3839d0 100644 --- a/src/citra_qt/configure_audio.cpp +++ b/src/citra_qt/configure_audio.cpp @@ -51,6 +51,8 @@ void ConfigureAudio::setConfiguration() { } } ui->audio_device_combo_box->setCurrentIndex(new_device_index); + ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum()); + ui->mute_check_box->setChecked(Settings::values.mute); } void ConfigureAudio::applyConfiguration() { @@ -61,6 +63,9 @@ void ConfigureAudio::applyConfiguration() { Settings::values.audio_device_id = ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) .toStdString(); + Settings::values.volume = (float)ui->volume_slider->value() / ui->volume_slider->maximum(); + Settings::values.mute = ui->mute_check_box->isChecked(); + Settings::Apply(); } diff --git a/src/citra_qt/configure_audio.ui b/src/citra_qt/configure_audio.ui index dd870eb61..58c2e84c3 100644 --- a/src/citra_qt/configure_audio.ui +++ b/src/citra_qt/configure_audio.ui @@ -46,10 +46,44 @@ + + + + + + + + + + Volume: + + + + + + + 1023 + + + 1 + + + 0 + + + Qt::Horizontal + + + + + Mute + + + diff --git a/src/core/settings.h b/src/core/settings.h index d1a9f0da8..d8eb58324 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -110,6 +110,8 @@ struct Values { std::string sink_id; bool enable_audio_stretching; std::string audio_device_id; + float volume; + bool mute; // Camera std::array camera_name;