Merge pull request #8493 from JosJuice/android-audio-volume

Android: Add audio volume setting
This commit is contained in:
Anthony 2019-11-27 15:36:54 -08:00 committed by GitHub
commit 34a1df1c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 6 deletions

View File

@ -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));

View File

@ -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));

View File

@ -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";

View File

@ -153,6 +153,7 @@
<string name="analytics">Enable usage statistics reporting</string>
<string name="analytics_desc">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.</string>
<string name="gametdb_thanks">Thanks to GameTDB.com for providing GameCube and Wii covers!</string>
<string name="audio_volume">Audio Volume</string>
<!-- Interface Preference Fragment -->
<string name="interface_submenu">Interface</string>

View File

@ -3,15 +3,18 @@
// Refer to the license.txt file included.
#ifdef ANDROID
#include <assert.h>
#include "AudioCommon/OpenSLESStream.h"
#include <cassert>
#include <cmath>
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#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<SLmillibel>(2000 * std::log10(volume / 100.0f));
(*bqPlayerVolume)->SetVolumeLevel(bqPlayerVolume, attenuation);
}
#endif

View File

@ -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: