Merge "Add support for scaling mode parameter in Visualizer effect"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5cef554cc8
@@ -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);
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user