diff options
| author | JosJuice <josjuice@gmail.com> | 2019-11-24 21:34:50 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2019-11-26 21:10:27 +0100 |
| commit | cf8208ace91a3cf389c214cf3d03c377133d968a (patch) | |
| tree | 34827d138aa6cdde54d0cb2173cc09cd426761d4 /Source/Core/AudioCommon/OpenSLESStream.cpp | |
| parent | 4305a9ac57a4bee1e0be0c54b9df2cda385b114a (diff) | |
Android: Add audio volume setting
Diffstat (limited to 'Source/Core/AudioCommon/OpenSLESStream.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/OpenSLESStream.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
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 <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 |
