Skip to content

Commit

Permalink
Android: Add audio volume setting
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Nov 24, 2019
1 parent 4305a9a commit 9a3ad65
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,23 @@ private void addGeneralSettings(ArrayList<SettingsItem> sl)
Setting overclock = null;
Setting speedLimit = null;
Setting audioStretch = null;
Setting audioVolume = null;
Setting overrideRegionSettings = null;
Setting autoDiscChange = null;
Setting analytics = null;
Setting enableSaveState;
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);
overclockEnable = coreSection.getSetting(SettingsFile.KEY_OVERCLOCK_ENABLE);
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);
Expand Down Expand Up @@ -275,6 +278,8 @@ else if (defaultCpuCore == 4) // AArch64
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
15 changes: 12 additions & 3 deletions Source/Core/AudioCommon/OpenSLESStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Refer to the license.txt file included.

#ifdef ANDROID
#include <assert.h>
#include <cassert>
#include <cmath>

#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
Expand All @@ -12,6 +13,7 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"

// engine interfaces
static SLObjectItf engineObject;
Expand All @@ -22,7 +24,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
Expand All @@ -37,6 +38,13 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
assert(bq == bqPlayerBufferQueue);
assert(nullptr == context);

const auto& config = SConfig::GetInstance();
const SLmillibel attenuation =
config.m_Volume <= 0 ? SL_MILLIBEL_MIN :
static_cast<SLmillibel>(2000 * std::log10(config.m_Volume / 100.0f));
(*bqPlayerVolume)->SetVolumeLevel(bqPlayerVolume, attenuation);
(*bqPlayerVolume)->SetMute(bqPlayerVolume, static_cast<SLboolean>(config.m_IsMuted));

// Render to the fresh buffer
g_mixer->Mix(reinterpret_cast<short*>(buffer[curBuffer]), BUFFER_SIZE_IN_SAMPLES);
SLresult result =
Expand Down Expand Up @@ -94,6 +102,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);
Expand All @@ -118,7 +128,6 @@ OpenSLESStream::~OpenSLESStream()
bqPlayerObject = nullptr;
bqPlayerPlay = nullptr;
bqPlayerBufferQueue = nullptr;
bqPlayerMuteSolo = nullptr;
bqPlayerVolume = nullptr;
}

Expand Down

0 comments on commit 9a3ad65

Please sign in to comment.