From d9ae1c573e37e245c7f4f0480a8fa925e57bd49d Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Mon, 25 Jul 2011 12:58:14 -0700 Subject: Fix bug 4319552 Java to native channel mask translation When creating a new AudioTrack instance, translate from a Java channel mask as defined in android.media.AudioFormat to one as defined in audio.h which matches industry-standard channel mask definitions. Change-Id: I7eeece8ec2a437977c31f6e82590f9591158144b --- core/jni/android_media_AudioTrack.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'core/jni') diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index bd70dad..2929056 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -167,11 +167,11 @@ static void audioCallback(int event, void* user, void *info) { // ---------------------------------------------------------------------------- static int android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this, - jint streamType, jint sampleRateInHertz, jint channels, + jint streamType, jint sampleRateInHertz, jint javaChannelMask, jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession) { - LOGV("sampleRate=%d, audioFormat(from Java)=%d, channels=%x, buffSize=%d", - sampleRateInHertz, audioFormat, channels, buffSizeInBytes); + LOGV("sampleRate=%d, audioFormat(from Java)=%d, channel mask=%x, buffSize=%d", + sampleRateInHertz, audioFormat, javaChannelMask, buffSizeInBytes); int afSampleRate; int afFrameCount; @@ -184,11 +184,16 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM; } - if (!audio_is_output_channel(channels)) { + // Java channel masks don't map directly to the native definition, but it's a simple shift + // to skip the two deprecated channel configurations "default" and "mono". + uint32_t nativeChannelMask = ((uint32_t)javaChannelMask) >> 2; + + if (!audio_is_output_channel(nativeChannelMask)) { LOGE("Error creating AudioTrack: invalid channel mask."); return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK; } - int nbChannels = popcount(channels); + + int nbChannels = popcount(nativeChannelMask); // check the stream type audio_stream_type_t atStreamType; @@ -285,7 +290,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th atStreamType,// stream type sampleRateInHertz, format,// word length, PCM - channels, + nativeChannelMask, frameCount, 0,// flags audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user) @@ -306,7 +311,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th atStreamType,// stream type sampleRateInHertz, format,// word length, PCM - channels, + nativeChannelMask, frameCount, 0,// flags audioCallback, &(lpJniStorage->mCallbackData),//callback, callback data (user)); -- cgit v1.1