@@ -81,6 +81,20 @@ public class Visualizer {
8181 */
8282 public static final int STATE_ENABLED = 2 ;
8383
84+ // to keep in sync with system/media/audio_effects/include/audio_effects/effect_visualizer.h
85+ /**
86+ * @hide
87+ * Defines a capture mode where amplification is applied based on the content of the captured
88+ * data. This is the default Visualizer mode, and is suitable for music visualization.
89+ */
90+ public static final int SCALING_MODE_NORMALIZED = 0 ;
91+ /**
92+ * @hide
93+ * Defines a capture mode where the playback volume will affect (scale) the range of the
94+ * captured data. A low playback volume will lead to low sample and fft values, and vice-versa.
95+ */
96+ public static final int SCALING_MODE_AS_PLAYED = 1 ;
97+
8498 // to keep in sync with frameworks/base/media/jni/audioeffect/android_media_Visualizer.cpp
8599 private static final int NATIVE_EVENT_PCM_CAPTURE = 0 ;
86100 private static final int NATIVE_EVENT_FFT_CAPTURE = 1 ;
@@ -301,6 +315,44 @@ public int getCaptureSize()
301315 }
302316 }
303317
318+ /**
319+ * @hide
320+ * Set the type of scaling applied on the captured visualization data.
321+ * @param mode see {@link #SCALING_MODE_NORMALIZED}
322+ * and {@link #SCALING_MODE_AS_PLAYED}
323+ * @return {@link #SUCCESS} in case of success,
324+ * {@link #ERROR_BAD_VALUE} in case of failure.
325+ * @throws IllegalStateException
326+ */
327+ public int setScalingMode (int mode )
328+ throws IllegalStateException {
329+ synchronized (mStateLock ) {
330+ if (mState == STATE_UNINITIALIZED ) {
331+ throw (new IllegalStateException ("setScalingMode() called in wrong state: "
332+ + mState ));
333+ }
334+ return native_setScalingMode (mode );
335+ }
336+ }
337+
338+ /**
339+ * @hide
340+ * Returns the current scaling mode on the captured visualization data.
341+ * @return the scaling mode, see {@link #SCALING_MODE_NORMALIZED}
342+ * and {@link #SCALING_MODE_AS_PLAYED}.
343+ * @throws IllegalStateException
344+ */
345+ public int getScalingMode ()
346+ throws IllegalStateException {
347+ synchronized (mStateLock ) {
348+ if (mState == STATE_UNINITIALIZED ) {
349+ throw (new IllegalStateException ("getScalingMode() called in wrong state: "
350+ + mState ));
351+ }
352+ return native_getScalingMode ();
353+ }
354+ }
355+
304356 /**
305357 * Returns the sampling rate of the captured audio.
306358 * @return the sampling rate in milliHertz.
@@ -588,6 +640,10 @@ private native final int native_setup(Object audioeffect_this,
588640
589641 private native final int native_getCaptureSize ();
590642
643+ private native final int native_setScalingMode (int mode );
644+
645+ private native final int native_getScalingMode ();
646+
591647 private native final int native_getSamplingRate ();
592648
593649 private native final int native_getWaveForm (byte [] waveform );
0 commit comments