Skip to content

Commit 5cef554

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Add support for scaling mode parameter in Visualizer effect"
2 parents 9afbfb5 + e1123e7 commit 5cef554

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

media/java/android/media/audiofx/Visualizer.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

media/jni/audioeffect/android_media_Visualizer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,27 @@ android_media_visualizer_native_getCaptureSize(JNIEnv *env, jobject thiz)
490490
return lpVisualizer->getCaptureSize();
491491
}
492492

493+
static jint
494+
android_media_visualizer_native_setScalingMode(JNIEnv *env, jobject thiz, jint mode)
495+
{
496+
Visualizer* lpVisualizer = getVisualizer(env, thiz);
497+
if (lpVisualizer == NULL) {
498+
return VISUALIZER_ERROR_NO_INIT;
499+
}
500+
501+
return translateError(lpVisualizer->setScalingMode(mode));
502+
}
503+
504+
static jint
505+
android_media_visualizer_native_getScalingMode(JNIEnv *env, jobject thiz)
506+
{
507+
Visualizer* lpVisualizer = getVisualizer(env, thiz);
508+
if (lpVisualizer == NULL) {
509+
return -1;
510+
}
511+
return lpVisualizer->getScalingMode();
512+
}
513+
493514
static jint
494515
android_media_visualizer_native_getSamplingRate(JNIEnv *env, jobject thiz)
495516
{
@@ -582,6 +603,8 @@ static JNINativeMethod gMethods[] = {
582603
{"getMaxCaptureRate", "()I", (void *)android_media_visualizer_native_getMaxCaptureRate},
583604
{"native_setCaptureSize", "(I)I", (void *)android_media_visualizer_native_setCaptureSize},
584605
{"native_getCaptureSize", "()I", (void *)android_media_visualizer_native_getCaptureSize},
606+
{"native_setScalingMode", "(I)I", (void *)android_media_visualizer_native_setScalingMode},
607+
{"native_getScalingMode", "()I", (void *)android_media_visualizer_native_getScalingMode},
585608
{"native_getSamplingRate", "()I", (void *)android_media_visualizer_native_getSamplingRate},
586609
{"native_getWaveForm", "([B)I", (void *)android_media_visualizer_native_getWaveForm},
587610
{"native_getFft", "([B)I", (void *)android_media_visualizer_native_getFft},

0 commit comments

Comments
 (0)