From cf8208ace91a3cf389c214cf3d03c377133d968a Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 24 Nov 2019 21:34:50 +0100 Subject: [PATCH] Android: Add audio volume setting --- .../features/settings/model/Settings.java | 5 +++-- .../settings/ui/SettingsFragmentPresenter.java | 5 +++++ .../features/settings/utils/SettingsFile.java | 1 + .../app/src/main/res/values/strings.xml | 1 + Source/Core/AudioCommon/OpenSLESStream.cpp | 18 ++++++++++++++---- Source/Core/AudioCommon/OpenSLESStream.h | 1 + 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java index d3cb2b6c66..ce3e82aa9d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/Settings.java @@ -17,6 +17,7 @@ public class Settings { public static final String SECTION_INI_CORE = "Core"; public static final String SECTION_INI_INTERFACE = "Interface"; + public static final String SECTION_INI_DSP = "DSP"; public static final String SECTION_GFX_SETTINGS = "Settings"; public static final String SECTION_GFX_ENHANCEMENTS = "Enhancements"; @@ -41,8 +42,8 @@ public class Settings static { configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN, - Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_BINDINGS, - SECTION_ANALYTICS, SECTION_DEBUG)); + Arrays.asList(SECTION_INI_CORE, SECTION_INI_INTERFACE, SECTION_INI_DSP, + SECTION_BINDINGS, SECTION_ANALYTICS, SECTION_DEBUG)); configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX, Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS, SECTION_STEREOSCOPY)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 83817cae95..271d556a4b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -220,6 +220,7 @@ public final class SettingsFragmentPresenter Setting overclock = null; Setting speedLimit = null; Setting audioStretch = null; + Setting audioVolume = null; Setting overrideRegionSettings = null; Setting autoDiscChange = null; Setting analytics = null; @@ -227,6 +228,7 @@ public final class SettingsFragmentPresenter Setting lockToLandscape; SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE); + SettingSection dspSection = mSettings.getSection(Settings.SECTION_INI_DSP); SettingSection analyticsSection = mSettings.getSection(Settings.SECTION_ANALYTICS); cpuCore = coreSection.getSetting(SettingsFile.KEY_CPU_CORE); dualCore = coreSection.getSetting(SettingsFile.KEY_DUAL_CORE); @@ -234,6 +236,7 @@ public final class SettingsFragmentPresenter overclock = coreSection.getSetting(SettingsFile.KEY_OVERCLOCK_PERCENT); speedLimit = coreSection.getSetting(SettingsFile.KEY_SPEED_LIMIT); audioStretch = coreSection.getSetting(SettingsFile.KEY_AUDIO_STRETCH); + audioVolume = dspSection.getSetting(SettingsFile.KEY_AUDIO_VOLUME); overrideRegionSettings = coreSection.getSetting(SettingsFile.KEY_OVERRIDE_REGION_SETTINGS); autoDiscChange = coreSection.getSetting(SettingsFile.KEY_AUTO_DISC_CHANGE); analytics = analyticsSection.getSetting(SettingsFile.KEY_ANALYTICS_ENABLED); @@ -275,6 +278,8 @@ public final class SettingsFragmentPresenter R.string.speed_limit, 0, 200, "%", 100, speedLimit)); sl.add(new CheckBoxSetting(SettingsFile.KEY_AUDIO_STRETCH, Settings.SECTION_INI_CORE, R.string.audio_stretch, R.string.audio_stretch_description, false, audioStretch)); + sl.add(new SliderSetting(SettingsFile.KEY_AUDIO_VOLUME, Settings.SECTION_INI_DSP, + R.string.audio_volume, 0, 100, "%", 100, audioVolume)); sl.add(new CheckBoxSetting(SettingsFile.KEY_OVERRIDE_REGION_SETTINGS, Settings.SECTION_INI_CORE, R.string.override_region_settings, 0, false, overrideRegionSettings)); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index 7c24bac42d..6f7bf15be8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -47,6 +47,7 @@ public final class SettingsFile public static final String KEY_SPEED_LIMIT = "EmulationSpeed"; public static final String KEY_VIDEO_BACKEND = "GFXBackend"; public static final String KEY_AUDIO_STRETCH = "AudioStretch"; + public static final String KEY_AUDIO_VOLUME = "Volume"; public static final String KEY_AUTO_DISC_CHANGE = "AutoDiscChange"; public static final String KEY_GAME_CUBE_LANGUAGE = "SelectedLanguage"; public static final String KEY_OVERRIDE_REGION_SETTINGS = "OverrideRegionSettings"; diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 2ecbb07df7..e2cea34579 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -153,6 +153,7 @@ Enable usage statistics reporting If authorized, Dolphin can collect data on its performance, feature usage, and configuration, as well as data on your system\'s hardware and operating system.\n\nNo private data is ever collected. This data helps us understand how people and emulated games use Dolphin and prioritize our efforts. It also helps us identify rare configurations that are causing bugs, performance and stability issues. This authorization can be revoked at any time through Dolphin\'s settings. Thanks to GameTDB.com for providing GameCube and Wii covers! + Audio Volume Interface diff --git a/Source/Core/AudioCommon/OpenSLESStream.cpp b/Source/Core/AudioCommon/OpenSLESStream.cpp index 6e1d210407..08bd2899d5 100644 --- a/Source/Core/AudioCommon/OpenSLESStream.cpp +++ b/Source/Core/AudioCommon/OpenSLESStream.cpp @@ -3,15 +3,18 @@ // Refer to the license.txt file included. #ifdef ANDROID -#include +#include "AudioCommon/OpenSLESStream.h" + +#include +#include #include #include -#include "AudioCommon/OpenSLESStream.h" #include "Common/Assert.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" +#include "Core/ConfigManager.h" // engine interfaces static SLObjectItf engineObject; @@ -22,7 +25,6 @@ static SLObjectItf outputMixObject; static SLObjectItf bqPlayerObject = nullptr; static SLPlayItf bqPlayerPlay; static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; -static SLMuteSoloItf bqPlayerMuteSolo; static SLVolumeItf bqPlayerVolume; static Mixer* g_mixer; #define BUFFER_SIZE 512 @@ -94,6 +96,8 @@ bool OpenSLESStream::Init() result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE, &bqPlayerBufferQueue); assert(SL_RESULT_SUCCESS == result); + result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume); + assert(SL_RESULT_SUCCESS == result); result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, nullptr); assert(SL_RESULT_SUCCESS == result); result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); @@ -118,7 +122,6 @@ OpenSLESStream::~OpenSLESStream() bqPlayerObject = nullptr; bqPlayerPlay = nullptr; bqPlayerBufferQueue = nullptr; - bqPlayerMuteSolo = nullptr; bqPlayerVolume = nullptr; } @@ -135,4 +138,11 @@ OpenSLESStream::~OpenSLESStream() engineEngine = nullptr; } } + +void OpenSLESStream::SetVolume(int volume) +{ + const SLmillibel attenuation = + volume <= 0 ? SL_MILLIBEL_MIN : static_cast(2000 * std::log10(volume / 100.0f)); + (*bqPlayerVolume)->SetVolumeLevel(bqPlayerVolume, attenuation); +} #endif diff --git a/Source/Core/AudioCommon/OpenSLESStream.h b/Source/Core/AudioCommon/OpenSLESStream.h index 237501c54c..8a76781dbf 100644 --- a/Source/Core/AudioCommon/OpenSLESStream.h +++ b/Source/Core/AudioCommon/OpenSLESStream.h @@ -16,6 +16,7 @@ public: ~OpenSLESStream() override; bool Init() override; bool SetRunning(bool running) override { return running; } + void SetVolume(int volume) override; static bool isValid() { return true; } private: