diff options
| author | JMC47 <JMC4789@gmail.com> | 2025-06-07 23:07:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-07 23:07:37 -0400 |
| commit | 24b0bf01d54cf15977e7e2f4d2b529bb8230b060 (patch) | |
| tree | bfbe0b3fb7fc0c0d31dbbc66621b9ea7f1ef654a /Source/Android/app/src | |
| parent | 19fbbf0dba32ad98fe791804cfd464ced91464f5 (diff) | |
| parent | f99d3dbd5ccd80bcd071cf49e689f6b6724df499 (diff) | |
Merge pull request #12836 from JosJuice/opensles-buffer-size
Android: Ask system for optimal audio buffer size and sample rate
Diffstat (limited to 'Source/Android/app/src')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AudioUtils.kt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AudioUtils.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AudioUtils.kt new file mode 100644 index 0000000000..68e3573fa5 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/AudioUtils.kt @@ -0,0 +1,28 @@ +package org.dolphinemu.dolphinemu.utils + +import android.content.Context +import android.media.AudioManager +import androidx.annotation.Keep +import org.dolphinemu.dolphinemu.DolphinApplication + +object AudioUtils { + @JvmStatic @Keep + fun getSampleRate(): Int = + getAudioServiceProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE, 48000) + + @JvmStatic @Keep + fun getFramesPerBuffer(): Int = + getAudioServiceProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER, 256) + + private fun getAudioServiceProperty(property: String, fallback: Int): Int { + return try { + val context = DolphinApplication.getAppContext() + val am = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + Integer.parseUnsignedInt(am.getProperty(property)) + } catch (e: NullPointerException) { + fallback + } catch (e: NumberFormatException) { + fallback + } + } +} |
