audio: Replace APIs with low level APIs

This commit is contained in:
Hajime Hoshi 2016-05-31 22:04:14 +09:00
parent 84bf1ddf5c
commit 3ce8122557

View File

@ -45,10 +45,6 @@ static char* initAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
(*env)->GetStaticIntField( (*env)->GetStaticIntField(
env, android_media_AudioTrack, env, android_media_AudioTrack,
(*env)->GetStaticFieldID(env, android_media_AudioTrack, "MODE_STREAM", "I")); (*env)->GetStaticFieldID(env, android_media_AudioTrack, "MODE_STREAM", "I"));
const jint android_media_AudioTrack_WRITE_BLOCKING =
(*env)->GetStaticIntField(
env, android_media_AudioTrack,
(*env)->GetStaticFieldID(env, android_media_AudioTrack, "WRITE_BLOCKING", "I"));
const jint android_media_AudioFormat_CHANNEL_OUT_MONO = const jint android_media_AudioFormat_CHANNEL_OUT_MONO =
(*env)->GetStaticIntField( (*env)->GetStaticIntField(
env, android_media_AudioFormat, env, android_media_AudioFormat,
@ -115,8 +111,8 @@ static char* initAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
writtenBytes = writtenBytes =
(*env)->CallIntMethod( (*env)->CallIntMethod(
env, *audioTrack, env, *audioTrack,
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BIII)I"), (*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BII)I"),
arr, 0, length, android_media_AudioTrack_WRITE_BLOCKING); arr, 0, length);
} while (writtenBytes != 0); } while (writtenBytes != 0);
// TODO: Check if writtenBytes < 0 // TODO: Check if writtenBytes < 0
@ -134,10 +130,6 @@ 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_BLOCKING =
(*env)->GetStaticIntField(
env, android_media_AudioTrack,
(*env)->GetStaticFieldID(env, android_media_AudioTrack, "WRITE_BLOCKING", "I"));
jbyteArray arrInBytes; jbyteArray arrInBytes;
jshortArray arrInShorts; jshortArray arrInShorts;
@ -158,15 +150,15 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
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", "([BII)I"),
arrInBytes, 0, length, android_media_AudioTrack_WRITE_BLOCKING); arrInBytes, 0, length);
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", "([SII)I"),
arrInShorts, 0, length, android_media_AudioTrack_WRITE_BLOCKING); arrInShorts, 0, length);
break; break;
} }