Просмотр исходного кода

Pass sample rate and frames/buffer to opensl_latency.cpp to be used with Oboe later.

Miku AuahDark 5 лет назад
Родитель
Сommit
b96fd660f9

+ 2 - 6
love/src/jni/openal-soft/Android.mk

@@ -120,7 +120,8 @@ LOCAL_SRC_FILES := \
     alc/uhjfilter.cpp \
     alc/uiddefs.cpp \
     alc/voice.cpp \
-    alc/mixer/mixer_c.cpp
+    alc/mixer/mixer_c.cpp \
+	opensl_latency.cpp
 
 #
 # Conditionals source files
@@ -159,11 +160,6 @@ LOCAL_SRC_FILES += \
     alc/backends/opensl.cpp \
     alc/backends/wave.cpp
 
-#
-# OpenSL latency setting workaround
-#
-LOCAL_SRC_FILES += opensl_latency.cpp
-
 #
 # Libraries related
 #

+ 30 - 1
love/src/main/java/org/love2d/android/GameActivity.java

@@ -66,9 +66,11 @@ public class GameActivity extends SDLActivity {
     public int safeAreaBottom = 0;
     public int safeAreaRight = 0;
 
+    private static native void nativeSetDefaultStreamValues(int sampleRate, int framesPerBurst);
+
     @Override
     protected String[] getLibraries() {
-        return new String[]{
+        return new String[] {
             "c++_shared",
             "mpg123",
             "openal",
@@ -117,6 +119,9 @@ public class GameActivity extends SDLActivity {
         super.onCreate(savedInstanceState);
         getWindowManager().getDefaultDisplay().getMetrics(metrics);
 
+        // Set low-latency audio values
+        nativeSetDefaultStreamValues(getAudioFreq(), getAudioSMP());
+
         if (android.os.Build.VERSION.SDK_INT >= 28) {
             getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
             shortEdgesMode = false;
@@ -534,4 +539,28 @@ public class GameActivity extends SDLActivity {
 
         return false;
     }
+
+    public int getAudioSMP() {
+        int smp = 256;
+
+        if (android.os.Build.VERSION.SDK_INT >= 17) {
+            AudioManager a = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+            int b = Integer.parseInt(a.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
+            return b > 0 ? b : smp;
+        }
+
+        return smp;
+    }
+
+    public int getAudioFreq() {
+        int freq = 44100;
+
+        if (android.os.Build.VERSION.SDK_INT >= 17) {
+            AudioManager a = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+            int b = Integer.parseInt(a.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));
+            return b > 0 ? b : freq;
+        }
+
+        return freq;
+    }
 }