summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/jni/android_media_AudioTrack.cpp19
-rw-r--r--media/java/android/media/AudioFormat.java4
2 files changed, 14 insertions, 9 deletions
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));
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 82e8d77..8990fe5 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -54,8 +54,8 @@ public class AudioFormat {
/** Default audio channel mask */
public static final int CHANNEL_OUT_DEFAULT = 1;
- // Channel mask definitions must be kept in sync with native values
- // in /system/core/include/system/audio.h
+ // Channel mask definitions below are translated to the native values defined in
+ // in /system/core/include/system/audio.h in the JNI code of AudioTrack
public static final int CHANNEL_OUT_FRONT_LEFT = 0x4;
public static final int CHANNEL_OUT_FRONT_RIGHT = 0x8;
public static final int CHANNEL_OUT_FRONT_CENTER = 0x10;