From e1123e7f36723a8b888501c9a22a589297849ca2 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Sun, 15 Apr 2012 17:22:01 -0700 Subject: [PATCH] Add support for scaling mode parameter in Visualizer effect Add set/get methods to set how the Visualizer scales the captured data. Change-Id: Ia1da00fd5474dd3484b59caf7d1d0a812d0347de --- .../android/media/audiofx/Visualizer.java | 56 +++++++++++++++++++ .../audioeffect/android_media_Visualizer.cpp | 23 ++++++++ 2 files changed, 79 insertions(+) diff --git a/media/java/android/media/audiofx/Visualizer.java b/media/java/android/media/audiofx/Visualizer.java index 91d0addde5f85..47c0d57c50eed 100755 --- a/media/java/android/media/audiofx/Visualizer.java +++ b/media/java/android/media/audiofx/Visualizer.java @@ -81,6 +81,20 @@ public class Visualizer { */ public static final int STATE_ENABLED = 2; + // to keep in sync with system/media/audio_effects/include/audio_effects/effect_visualizer.h + /** + * @hide + * Defines a capture mode where amplification is applied based on the content of the captured + * data. This is the default Visualizer mode, and is suitable for music visualization. + */ + public static final int SCALING_MODE_NORMALIZED = 0; + /** + * @hide + * Defines a capture mode where the playback volume will affect (scale) the range of the + * captured data. A low playback volume will lead to low sample and fft values, and vice-versa. + */ + public static final int SCALING_MODE_AS_PLAYED = 1; + // to keep in sync with frameworks/base/media/jni/audioeffect/android_media_Visualizer.cpp private static final int NATIVE_EVENT_PCM_CAPTURE = 0; private static final int NATIVE_EVENT_FFT_CAPTURE = 1; @@ -301,6 +315,44 @@ public class Visualizer { } } + /** + * @hide + * Set the type of scaling applied on the captured visualization data. + * @param mode see {@link #SCALING_MODE_NORMALIZED} + * and {@link #SCALING_MODE_AS_PLAYED} + * @return {@link #SUCCESS} in case of success, + * {@link #ERROR_BAD_VALUE} in case of failure. + * @throws IllegalStateException + */ + public int setScalingMode(int mode) + throws IllegalStateException { + synchronized (mStateLock) { + if (mState == STATE_UNINITIALIZED) { + throw(new IllegalStateException("setScalingMode() called in wrong state: " + + mState)); + } + return native_setScalingMode(mode); + } + } + + /** + * @hide + * Returns the current scaling mode on the captured visualization data. + * @return the scaling mode, see {@link #SCALING_MODE_NORMALIZED} + * and {@link #SCALING_MODE_AS_PLAYED}. + * @throws IllegalStateException + */ + public int getScalingMode() + throws IllegalStateException { + synchronized (mStateLock) { + if (mState == STATE_UNINITIALIZED) { + throw(new IllegalStateException("getScalingMode() called in wrong state: " + + mState)); + } + return native_getScalingMode(); + } + } + /** * Returns the sampling rate of the captured audio. * @return the sampling rate in milliHertz. @@ -588,6 +640,10 @@ public class Visualizer { private native final int native_getCaptureSize(); + private native final int native_setScalingMode(int mode); + + private native final int native_getScalingMode(); + private native final int native_getSamplingRate(); private native final int native_getWaveForm(byte[] waveform); diff --git a/media/jni/audioeffect/android_media_Visualizer.cpp b/media/jni/audioeffect/android_media_Visualizer.cpp index f015afbaf2094..c2655c72b9984 100644 --- a/media/jni/audioeffect/android_media_Visualizer.cpp +++ b/media/jni/audioeffect/android_media_Visualizer.cpp @@ -490,6 +490,27 @@ android_media_visualizer_native_getCaptureSize(JNIEnv *env, jobject thiz) return lpVisualizer->getCaptureSize(); } +static jint +android_media_visualizer_native_setScalingMode(JNIEnv *env, jobject thiz, jint mode) +{ + Visualizer* lpVisualizer = getVisualizer(env, thiz); + if (lpVisualizer == NULL) { + return VISUALIZER_ERROR_NO_INIT; + } + + return translateError(lpVisualizer->setScalingMode(mode)); +} + +static jint +android_media_visualizer_native_getScalingMode(JNIEnv *env, jobject thiz) +{ + Visualizer* lpVisualizer = getVisualizer(env, thiz); + if (lpVisualizer == NULL) { + return -1; + } + return lpVisualizer->getScalingMode(); +} + static jint android_media_visualizer_native_getSamplingRate(JNIEnv *env, jobject thiz) { @@ -582,6 +603,8 @@ static JNINativeMethod gMethods[] = { {"getMaxCaptureRate", "()I", (void *)android_media_visualizer_native_getMaxCaptureRate}, {"native_setCaptureSize", "(I)I", (void *)android_media_visualizer_native_setCaptureSize}, {"native_getCaptureSize", "()I", (void *)android_media_visualizer_native_getCaptureSize}, + {"native_setScalingMode", "(I)I", (void *)android_media_visualizer_native_setScalingMode}, + {"native_getScalingMode", "()I", (void *)android_media_visualizer_native_getScalingMode}, {"native_getSamplingRate", "()I", (void *)android_media_visualizer_native_getSamplingRate}, {"native_getWaveForm", "([B)I", (void *)android_media_visualizer_native_getWaveForm}, {"native_getFft", "([B)I", (void *)android_media_visualizer_native_getFft},