aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-01-26 18:23:29 -0800
committerChris Robinson <[email protected]>2017-01-26 18:23:29 -0800
commit67ffdf7a78ae3e48b1fbdd866ad7c2add7e5b6fd (patch)
tree95cc68c9f83f3f23b6671dcadf342a82a902eead /Alc
parent3ba03c5a29bcebb1866f36555957c3c293a99962 (diff)
Try to use the system sample rate with Android
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/opensl.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/Alc/backends/opensl.c b/Alc/backends/opensl.c
index 0796c49a..32f6fa7d 100644
--- a/Alc/backends/opensl.c
+++ b/Alc/backends/opensl.c
@@ -22,9 +22,11 @@
#include "config.h"
#include <stdlib.h>
+#include <jni.h>
#include "alMain.h"
#include "alu.h"
+#include "compat.h"
#include "threads.h"
#include <SLES/OpenSLES.h>
@@ -231,16 +233,64 @@ static ALCboolean opensl_reset_playback(ALCdevice *Device)
SLDataFormat_PCM format_pcm;
SLDataSource audioSrc;
SLDataSink audioSnk;
+ ALuint sampleRate;
SLInterfaceID id;
- SLboolean req;
SLresult result;
+ SLboolean req;
+ if((Device->Flags&DEVICE_FREQUENCY_REQUEST))
+ sampleRate = Device->Frequency;
+ else
+ {
+ JNIEnv *env = Android_GetJNIEnv();
+
+ /* Get necessary stuff for using java.lang.Integer,
+ * android.content.Context, and android.media.AudioManager.
+ */
+ jclass int_cls = JCALL(env,FindClass)("java/lang/Integer");
+ jmethodID int_parseint = JCALL(env,GetStaticMethodID)(int_cls,
+ "parseInt", "(Ljava/lang/String;)I"
+ );
+
+ jclass ctx_cls = (*env)->FindClass(env, "android/content/Context");
+ jfieldID ctx_audsvc = (*env)->GetStaticFieldID(env, ctx_cls,
+ "AUDIO_SERVICE", "Ljava/lang/String;"
+ );
+ jmethodID ctx_getSysSvc = (*env)->GetMethodID(env, ctx_cls,
+ "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"
+ );
+
+ jclass audmgr_cls = JCALL(env,FindClass)("android/media/AudioManager");
+ jfieldID audmgr_prop_out_srate = JCALL(env,GetStaticFieldID)(audmgr_cls,
+ "PROPERTY_OUTPUT_SAMPLE_RATE", "Ljava/lang/String;"
+ );
+ jmethodID audmgr_getproperty = JCALL(env,GetMethodID)(audmgr_cls,
+ "getProperty", "(Ljava/lang/String;)Ljava/lang/Object;"
+ );
+
+ /* Now make the calls. */
+ //AudioManager audMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
+ jobject audMgr = JCALL(env,CallStaticObjectMethod)(ctx_cls, ctx_getSysSvc,
+ JCALL(env,GetStaticObjectField)(ctx_cls, ctx_audsvc)
+ );
+
+ //String srateStr = audMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
+ jstring srateStr = JCALL(env,CallObjectMethod)(audMgr, audmgr_getproperty,
+ JCALL(env,GetStaticObjectField)(audmgr_cls, audmgr_prop_out_srate)
+ );
+
+ //int sampleRate = Integer.parseInt(srateStr);
+ sampleRate = JCALL(env,CallStaticIntMethod)(int_cls, int_parseint, srateStr);
+
+ if(!sampleRate) sampleRate = Device->Frequency;
+ else sampleRate = maxu(sampleRate, MIN_OUTPUT_RATE);
+ }
- Device->UpdateSize = (ALuint64)Device->UpdateSize * 44100 / Device->Frequency;
- Device->UpdateSize = Device->UpdateSize * Device->NumUpdates / 2;
- Device->NumUpdates = 2;
-
- Device->Frequency = 44100;
+ if(sampleRate != Device->Frequency)
+ {
+ Device->NumUpdates = Device->NumUpdates * sampleRate / Device->Frequency;
+ Device->Frequency = sampleRate;
+ }
Device->FmtChans = DevFmtStereo;
Device->FmtType = DevFmtShort;