mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08: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 =
|
const jclass android_media_AudioTrack =
|
||||||
(*env)->FindClass(env, "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)->GetStaticIntField(
|
||||||
env, android_media_AudioTrack,
|
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;
|
jbyteArray arrInBytes;
|
||||||
jshortArray arrInShorts;
|
jshortArray arrInShorts;
|
||||||
@ -151,26 +151,23 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
|
|||||||
(*env)->SetShortArrayRegion(env, arrInShorts, 0, length, data);
|
(*env)->SetShortArrayRegion(env, arrInShorts, 0, length, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < length;) {
|
jint result;
|
||||||
jint result = 0;
|
switch (bytesPerSample) {
|
||||||
switch (bytesPerSample) {
|
case 1:
|
||||||
case 1:
|
result =
|
||||||
result =
|
(*env)->CallIntMethod(
|
||||||
(*env)->CallIntMethod(
|
env, audioTrack,
|
||||||
env, audioTrack,
|
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BIII)I"),
|
||||||
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BIII)I"),
|
arrInBytes, 0, length, android_media_AudioTrack_WRITE_BLOCKING);
|
||||||
arrInBytes, i, length - i, android_media_AudioTrack_WRITE_NON_BLOCKING);
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 2:
|
result =
|
||||||
result =
|
(*env)->CallIntMethod(
|
||||||
(*env)->CallIntMethod(
|
env, audioTrack,
|
||||||
env, audioTrack,
|
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([SIII)I"),
|
||||||
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([SIII)I"),
|
arrInShorts, 0, length, android_media_AudioTrack_WRITE_BLOCKING);
|
||||||
arrInShorts, i, length - i, android_media_AudioTrack_WRITE_NON_BLOCKING);
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
i += result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check the result.
|
// TODO: Check the result.
|
||||||
|
Loading…
Reference in New Issue
Block a user