mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Refactoring for mobiles (reduce calls)
This commit is contained in:
parent
857bc1ed51
commit
ebac6cbb81
@ -134,10 +134,10 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
|
||||
|
||||
const jclass android_media_AudioTrack =
|
||||
(*env)->FindClass(env, "android/media/AudioTrack");
|
||||
const jint android_media_AudioTrack_WRITE_NON_BLOCKING =
|
||||
const jint android_media_AudioTrack_WRITE_BLOCKING =
|
||||
(*env)->GetStaticIntField(
|
||||
env, android_media_AudioTrack,
|
||||
(*env)->GetStaticFieldID(env, android_media_AudioTrack, "WRITE_NON_BLOCKING", "I"));
|
||||
(*env)->GetStaticFieldID(env, android_media_AudioTrack, "WRITE_BLOCKING", "I"));
|
||||
|
||||
jbyteArray arrInBytes;
|
||||
jshortArray arrInShorts;
|
||||
@ -151,27 +151,24 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
|
||||
(*env)->SetShortArrayRegion(env, arrInShorts, 0, length, data);
|
||||
break;
|
||||
}
|
||||
int i = 0;
|
||||
for (i = 0; i < length;) {
|
||||
jint result = 0;
|
||||
|
||||
jint result;
|
||||
switch (bytesPerSample) {
|
||||
case 1:
|
||||
result =
|
||||
(*env)->CallIntMethod(
|
||||
env, audioTrack,
|
||||
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BIII)I"),
|
||||
arrInBytes, i, length - i, android_media_AudioTrack_WRITE_NON_BLOCKING);
|
||||
arrInBytes, 0, length, android_media_AudioTrack_WRITE_BLOCKING);
|
||||
break;
|
||||
case 2:
|
||||
result =
|
||||
(*env)->CallIntMethod(
|
||||
env, audioTrack,
|
||||
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([SIII)I"),
|
||||
arrInShorts, i, length - i, android_media_AudioTrack_WRITE_NON_BLOCKING);
|
||||
arrInShorts, 0, length, android_media_AudioTrack_WRITE_BLOCKING);
|
||||
break;
|
||||
}
|
||||
i += result;
|
||||
}
|
||||
|
||||
// TODO: Check the result.
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user