(Android) Detects buffer size properly now on Android 4.2 and up -

bases requested latency on this. Old fallback applies for non-4.2
This commit is contained in:
twinaphex 2013-08-24 05:10:14 +02:00
parent 67f4f1b3ed
commit d13542f12b
2 changed files with 28 additions and 2 deletions

View File

@ -163,6 +163,18 @@ public class MainMenuActivity extends PreferenceActivity {
return Integer.parseInt(manager
.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));
}
@TargetApi(17)
public static int getLowLatencyBufferSize() {
AudioManager manager = (AudioManager) MainMenuActivity.getInstance()
.getApplicationContext()
.getSystemService(Context.AUDIO_SERVICE);
int buffersize = Integer.parseInt(manager
.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
Log.i(TAG, "Queried ideal buffer size: " + buffersize);
return buffersize;
}
public static int getOptimalSamplingRate() {
int ret;
@ -251,8 +263,20 @@ public class MainMenuActivity extends PreferenceActivity {
prefs.getBoolean("audio_rate_control", true));
config.setInt("audio_out_rate",
MainMenuActivity.getOptimalSamplingRate());
config.setInt("audio_latency",
prefs.getBoolean("audio_high_latency", false) ? 160 : 64);
int buffersize = 0;
if (android.os.Build.VERSION.SDK_INT >= 17) {
buffersize = getLowLatencyBufferSize();
if (config.getBoolean("audio_high_latency") == false) {
config.setInt("audio_latency", buffersize / 32);
}
}
else {
config.setInt("audio_latency",
prefs.getBoolean("audio_high_latency", false) ? 160 : 64);
}
config.setBoolean("audio_enable",
prefs.getBoolean("audio_enable", true));
config.setBoolean("video_smooth",

View File

@ -115,6 +115,8 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency)
if (!sl)
goto error;
RARCH_LOG("[SLES ] : Requested audio latency: %dms...", latency);
GOTO_IF_FAIL(slCreateEngine(&sl->engine_object, 0, NULL, 0, NULL, NULL));
GOTO_IF_FAIL(SLObjectItf_Realize(sl->engine_object, SL_BOOLEAN_FALSE));
GOTO_IF_FAIL(SLObjectItf_GetInterface(sl->engine_object, SL_IID_ENGINE, &sl->engine));