Fields Summary |
---|
private static final String | TAG |
public static final UUID | EFFECT_TYPE_ENV_REVERBUUID for environmental reverberation effect |
public static final UUID | EFFECT_TYPE_PRESET_REVERBUUID for preset reverberation effect |
public static final UUID | EFFECT_TYPE_EQUALIZERUUID for equalizer effect |
public static final UUID | EFFECT_TYPE_BASS_BOOSTUUID for bass boost effect |
public static final UUID | EFFECT_TYPE_VIRTUALIZERUUID for virtualizer effect |
public static final UUID | EFFECT_TYPE_AGCUUID for Automatic Gain Control (AGC) |
public static final UUID | EFFECT_TYPE_AECUUID for Acoustic Echo Canceler (AEC) |
public static final UUID | EFFECT_TYPE_NSUUID for Noise Suppressor (NS) |
public static final UUID | EFFECT_TYPE_LOUDNESS_ENHANCERUUID for Loudness Enhancer |
public static final UUID | EFFECT_TYPE_NULLNull effect UUID. Used when the UUID for effect type of |
public static final int | STATE_UNINITIALIZEDState of an AudioEffect object that was not successfully initialized upon
creation |
public static final int | STATE_INITIALIZEDState of an AudioEffect object that is ready to be used. |
public static final int | NATIVE_EVENT_CONTROL_STATUSEvent id for engine control ownership change notification. |
public static final int | NATIVE_EVENT_ENABLED_STATUSEvent id for engine state change notification. |
public static final int | NATIVE_EVENT_PARAMETER_CHANGEDEvent id for engine parameter change notification. |
public static final int | SUCCESSSuccessful operation. |
public static final int | ERRORUnspecified error. |
public static final int | ALREADY_EXISTSInternal operation status. Not returned by any method. |
public static final int | ERROR_NO_INITOperation failed due to bad object initialization. |
public static final int | ERROR_BAD_VALUEOperation failed due to bad parameter value. |
public static final int | ERROR_INVALID_OPERATIONOperation failed because it was requested in wrong state. |
public static final int | ERROR_NO_MEMORYOperation failed due to lack of memory. |
public static final int | ERROR_DEAD_OBJECTOperation failed due to dead remote object. |
public static final String | EFFECT_INSERTEffect connection mode is insert. Specifying an audio session ID when creating the effect
will insert this effect after all players in the same audio session. |
public static final String | EFFECT_AUXILIARYEffect connection mode is auxiliary.
Auxiliary effects must be created on session 0 (global output mix). In order for a
MediaPlayer or AudioTrack to be fed into this effect, they must be explicitely attached to
this effect and a send level must be specified.
Use the effect ID returned by {@link #getId()} to designate this particular effect when
attaching it to the MediaPlayer or AudioTrack. |
public static final String | EFFECT_PRE_PROCESSINGEffect connection mode is pre processing.
The audio pre processing effects are attached to an audio input (AudioRecord). |
private int | mStateIndicates the state of the AudioEffect instance |
private final Object | mStateLockLock to synchronize access to mState |
private int | mIdSystem wide unique effect ID |
private long | mNativeAudioEffect |
private long | mJniData |
private Descriptor | mDescriptorEffect descriptor |
private OnEnableStatusChangeListener | mEnableStatusChangeListenerListener for effect engine state change notifications. |
private OnControlStatusChangeListener | mControlChangeStatusListenerListener for effect engine control ownership change notifications. |
private OnParameterChangeListener | mParameterChangeListenerListener for effect engine control ownership change notifications. |
public final Object | mListenerLockLock to protect listeners updates against event notifications |
public NativeEventHandler | mNativeEventHandlerHandler for events coming from the native code |
public static final String | ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANELIntent to launch an audio effect control panel UI.
The goal of this intent is to enable separate implementations of music/media player
applications and audio effect control application or services.
This will allow platform vendors to offer more advanced control options for standard effects
or control for platform specific effects.
The intent carries a number of extras used by the player application to communicate
necessary pieces of information to the control panel application.
The calling application must use the
{@link android.app.Activity#startActivityForResult(Intent, int)} method to launch the
control panel so that its package name is indicated and used by the control panel
application to keep track of changes for this particular application.
The {@link #EXTRA_AUDIO_SESSION} extra will indicate an audio session to which the
audio effects should be applied. If no audio session is specified, either one of the
follownig will happen:
- If an audio session was previously opened by the calling application with
{@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intent, the effect changes will
be applied to that session.
- If no audio session is opened, the changes will be stored in the package specific
storage area and applied whenever a new audio session is opened by this application.
The {@link #EXTRA_CONTENT_TYPE} extra will help the control panel application
customize both the UI layout and the default audio effect settings if none are already
stored for the calling application. |
public static final String | ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSIONIntent to signal to the effect control application or service that a new audio session
is opened and requires audio effects to be applied.
This is different from {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} in that no
UI should be displayed in this case. Music player applications can broadcast this intent
before starting playback to make sure that any audio effect settings previously selected
by the user are applied.
The effect control application receiving this intent will look for previously stored
settings for the calling application, create all required audio effects and apply the
effect settings to the specified audio session.
The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the
audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory.
If no stored settings are found for the calling application, default settings for the
content type indicated by {@link #EXTRA_CONTENT_TYPE} will be applied. The default settings
for a given content type are platform specific. |
public static final String | ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSIONIntent to signal to the effect control application or service that an audio session
is closed and that effects should not be applied anymore.
The effect control application receiving this intent will delete all effects on
this session and store current settings in package specific storage.
The calling package name is indicated by the {@link #EXTRA_PACKAGE_NAME} extra and the
audio session ID by the {@link #EXTRA_AUDIO_SESSION} extra. Both extras are mandatory.
It is good practice for applications to broadcast this intent when music playback stops
and/or when exiting to free system resources consumed by audio effect engines. |
public static final String | EXTRA_AUDIO_SESSIONContains the ID of the audio session the effects should be applied to.
This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL},
{@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and
{@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents.
The extra value is of type int and is the audio session ID. |
public static final String | EXTRA_PACKAGE_NAMEContains the package name of the calling application.
This extra is for use with {@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} and
{@link #ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION} intents.
The extra value is a string containing the full package name. |
public static final String | EXTRA_CONTENT_TYPEIndicates which type of content is played by the application.
This extra is for use with {@link #ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL} and
{@link #ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION} intents.
This information is used by the effect control application to customize UI and select
appropriate default effect settings. The content type is one of the following:
- {@link #CONTENT_TYPE_MUSIC}
- {@link #CONTENT_TYPE_MOVIE}
- {@link #CONTENT_TYPE_GAME}
- {@link #CONTENT_TYPE_VOICE}
If omitted, the content type defaults to {@link #CONTENT_TYPE_MUSIC}. |
public static final int | CONTENT_TYPE_MUSICValue for {@link #EXTRA_CONTENT_TYPE} when the type of content played is music |
public static final int | CONTENT_TYPE_MOVIEValue for {@link #EXTRA_CONTENT_TYPE} when the type of content played is video or movie |
public static final int | CONTENT_TYPE_GAMEValue for {@link #EXTRA_CONTENT_TYPE} when the type of content played is game audio |
public static final int | CONTENT_TYPE_VOICEValue for {@link #EXTRA_CONTENT_TYPE} when the type of content played is voice audio |
Methods Summary |
---|
public static int | byteArrayToInt(byte[] valueBuf)
return byteArrayToInt(valueBuf, 0);
|
public static int | byteArrayToInt(byte[] valueBuf, int offset)
ByteBuffer converter = ByteBuffer.wrap(valueBuf);
converter.order(ByteOrder.nativeOrder());
return converter.getInt(offset);
|
public static short | byteArrayToShort(byte[] valueBuf)
return byteArrayToShort(valueBuf, 0);
|
public static short | byteArrayToShort(byte[] valueBuf, int offset)
ByteBuffer converter = ByteBuffer.wrap(valueBuf);
converter.order(ByteOrder.nativeOrder());
return converter.getShort(offset);
|
public void | checkState(java.lang.String methodName)
synchronized (mStateLock) {
if (mState != STATE_INITIALIZED) {
throw (new IllegalStateException(methodName
+ " called on uninitialized AudioEffect."));
}
}
|
public void | checkStatus(int status)
if (isError(status)) {
switch (status) {
case AudioEffect.ERROR_BAD_VALUE:
throw (new IllegalArgumentException(
"AudioEffect: bad parameter value"));
case AudioEffect.ERROR_INVALID_OPERATION:
throw (new UnsupportedOperationException(
"AudioEffect: invalid parameter operation"));
default:
throw (new RuntimeException("AudioEffect: set/get parameter error"));
}
}
|
public int | command(int cmdCode, byte[] command, byte[] reply)Send a command to the effect engine. This method is intended to send
proprietary commands to a particular effect implementation.
In case of success, returns the number of meaningful bytes in reply array.
In case of failure, the returned value is negative and implementation specific.
checkState("command()");
return native_command(cmdCode, command.length, command, reply.length, reply);
|
public static byte[] | concatArrays(byte[] arrays)
int len = 0;
for (byte[] a : arrays) {
len += a.length;
}
byte[] b = new byte[len];
int offs = 0;
for (byte[] a : arrays) {
System.arraycopy(a, 0, b, offs, a.length);
offs += a.length;
}
return b;
|
private void | createNativeEventHandler()
Looper looper;
if ((looper = Looper.myLooper()) != null) {
mNativeEventHandler = new NativeEventHandler(this, looper);
} else if ((looper = Looper.getMainLooper()) != null) {
mNativeEventHandler = new NativeEventHandler(this, looper);
} else {
mNativeEventHandler = null;
}
|
protected void | finalize()
native_finalize();
|
public android.media.audiofx.AudioEffect$Descriptor | getDescriptor()Get the effect descriptor.
checkState("getDescriptor()");
return mDescriptor;
|
public boolean | getEnabled()Returns effect enabled state
checkState("getEnabled()");
return native_getEnabled();
|
public int | getId()Returns effect unique identifier. This system wide unique identifier can
be used to attach this effect to a MediaPlayer or an AudioTrack when the
effect is an auxiliary effect (Reverb)
checkState("getId()");
return mId;
|
public int | getParameter(byte[] param, byte[] value)Get effect parameter. The getParameter method is provided in several
forms addressing most common parameter formats. This form is the most
generic one where the parameter and its value are both specified as an
array of bytes. The parameter and value type and length are therefore
totally free.
checkState("getParameter()");
return native_getParameter(param.length, param, value.length, value);
|
public int | getParameter(int param, byte[] value)Get effect parameter. The parameter is an integer and the value is an
array of bytes.
byte[] p = intToByteArray(param);
return getParameter(p, value);
|
public int | getParameter(int param, int[] value)Get effect parameter. The parameter is an integer and the value is an
array of 1 or 2 integers
if (value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param);
byte[] v = new byte[value.length * 4];
int status = getParameter(p, v);
if (status == 4 || status == 8) {
value[0] = byteArrayToInt(v);
if (status == 8) {
value[1] = byteArrayToInt(v, 4);
}
status /= 4;
} else {
status = ERROR;
}
return status;
|
public int | getParameter(int param, short[] value)Get effect parameter. The parameter is an integer and the value is an
array of 1 or 2 short integers
if (value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param);
byte[] v = new byte[value.length * 2];
int status = getParameter(p, v);
if (status == 2 || status == 4) {
value[0] = byteArrayToShort(v);
if (status == 4) {
value[1] = byteArrayToShort(v, 2);
}
status /= 2;
} else {
status = ERROR;
}
return status;
|
public int | getParameter(int[] param, int[] value)Get effect parameter. The parameter is an array of 1 or 2 integers and
the value is also an array of 1 or 2 integers
if (param.length > 2 || value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
byte[] v = new byte[value.length * 4];
int status = getParameter(p, v);
if (status == 4 || status == 8) {
value[0] = byteArrayToInt(v);
if (status == 8) {
value[1] = byteArrayToInt(v, 4);
}
status /= 4;
} else {
status = ERROR;
}
return status;
|
public int | getParameter(int[] param, short[] value)Get effect parameter. The parameter is an array of 1 or 2 integers and
the value is an array of 1 or 2 short integers
if (param.length > 2 || value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
byte[] v = new byte[value.length * 2];
int status = getParameter(p, v);
if (status == 2 || status == 4) {
value[0] = byteArrayToShort(v);
if (status == 4) {
value[1] = byteArrayToShort(v, 2);
}
status /= 2;
} else {
status = ERROR;
}
return status;
|
public int | getParameter(int[] param, byte[] value)Get effect parameter. The parameter is an array of 1 or 2 integers and
the value is an array of bytes
if (param.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
return getParameter(p, value);
|
public boolean | hasControl()Checks if this AudioEffect object is controlling the effect engine.
checkState("hasControl()");
return native_hasControl();
|
public static byte[] | intToByteArray(int value)
ByteBuffer converter = ByteBuffer.allocate(4);
converter.order(ByteOrder.nativeOrder());
converter.putInt(value);
return converter.array();
|
public static boolean | isEffectTypeAvailable(java.util.UUID type)Checks if the device implements the specified effect type.
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
if (desc == null) {
return false;
}
for (int i = 0; i < desc.length; i++) {
if (desc[i].type.equals(type)) {
return true;
}
}
return false;
|
public static boolean | isError(int status)
return (status < 0);
|
private final native int | native_command(int cmdCode, int cmdSize, byte[] cmdData, int repSize, byte[] repData)
|
private final native void | native_finalize()
|
private final native boolean | native_getEnabled()
|
private final native int | native_getParameter(int psize, byte[] param, int vsize, byte[] value)
|
private final native boolean | native_hasControl()
|
private static final native void | native_init()
|
private static native java.lang.Object[] | native_query_effects()
|
private static native java.lang.Object[] | native_query_pre_processing(int audioSession)
|
private final native void | native_release()
|
private final native int | native_setEnabled(boolean enabled)
|
private final native int | native_setParameter(int psize, byte[] param, int vsize, byte[] value)
|
private final native int | native_setup(java.lang.Object audioeffect_this, java.lang.String type, java.lang.String uuid, int priority, int audioSession, int[] id, java.lang.Object[] desc)
|
private static void | postEventFromNative(java.lang.Object effect_ref, int what, int arg1, int arg2, java.lang.Object obj)
AudioEffect effect = (AudioEffect) ((WeakReference) effect_ref).get();
if (effect == null) {
return;
}
if (effect.mNativeEventHandler != null) {
Message m = effect.mNativeEventHandler.obtainMessage(what, arg1,
arg2, obj);
effect.mNativeEventHandler.sendMessage(m);
}
|
public static android.media.audiofx.AudioEffect$Descriptor[] | queryEffects()Query all effects available on the platform. Returns an array of
{@link android.media.audiofx.AudioEffect.Descriptor} objects
return (Descriptor[]) native_query_effects();
|
public static android.media.audiofx.AudioEffect$Descriptor[] | queryPreProcessings(int audioSession)Query all audio pre-processing effects applied to the AudioRecord with the supplied
audio session ID. Returns an array of {@link android.media.audiofx.AudioEffect.Descriptor}
objects.
return (Descriptor[]) native_query_pre_processing(audioSession);
|
public void | release()Releases the native AudioEffect resources. It is a good practice to
release the effect engine when not in use as control can be returned to
other applications or the native resources released.
synchronized (mStateLock) {
native_release();
mState = STATE_UNINITIALIZED;
}
|
public void | setControlStatusListener(android.media.audiofx.AudioEffect$OnControlStatusChangeListener listener)Sets the listener AudioEffect notifies when the effect engine control is
taken or returned.
synchronized (mListenerLock) {
mControlChangeStatusListener = listener;
}
if ((listener != null) && (mNativeEventHandler == null)) {
createNativeEventHandler();
}
|
public void | setEnableStatusListener(android.media.audiofx.AudioEffect$OnEnableStatusChangeListener listener)Sets the listener AudioEffect notifies when the effect engine is enabled
or disabled.
synchronized (mListenerLock) {
mEnableStatusChangeListener = listener;
}
if ((listener != null) && (mNativeEventHandler == null)) {
createNativeEventHandler();
}
|
public int | setEnabled(boolean enabled)Enable or disable the effect.
Creating an audio effect does not automatically apply this effect on the audio source. It
creates the resources necessary to process this effect but the audio signal is still bypassed
through the effect engine. Calling this method will make that the effect is actually applied
or not to the audio content being played in the corresponding audio session.
checkState("setEnabled()");
return native_setEnabled(enabled);
|
public int | setParameter(int param, int value)Set effect parameter. The parameter and its value are integers.
byte[] p = intToByteArray(param);
byte[] v = intToByteArray(value);
return setParameter(p, v);
|
public int | setParameter(int param, short value)Set effect parameter. The parameter is an integer and the value is a
short integer.
byte[] p = intToByteArray(param);
byte[] v = shortToByteArray(value);
return setParameter(p, v);
|
public int | setParameter(int param, byte[] value)Set effect parameter. The parameter is an integer and the value is an
array of bytes.
byte[] p = intToByteArray(param);
return setParameter(p, value);
|
public int | setParameter(int[] param, int[] value)Set effect parameter. The parameter is an array of 1 or 2 integers and
the value is also an array of 1 or 2 integers
if (param.length > 2 || value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
byte[] v = intToByteArray(value[0]);
if (value.length > 1) {
byte[] v2 = intToByteArray(value[1]);
v = concatArrays(v, v2);
}
return setParameter(p, v);
|
public int | setParameter(int[] param, short[] value)Set effect parameter. The parameter is an array of 1 or 2 integers and
the value is an array of 1 or 2 short integers
if (param.length > 2 || value.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
byte[] v = shortToByteArray(value[0]);
if (value.length > 1) {
byte[] v2 = shortToByteArray(value[1]);
v = concatArrays(v, v2);
}
return setParameter(p, v);
|
public int | setParameter(int[] param, byte[] value)Set effect parameter. The parameter is an array of 1 or 2 integers and
the value is an array of bytes
if (param.length > 2) {
return ERROR_BAD_VALUE;
}
byte[] p = intToByteArray(param[0]);
if (param.length > 1) {
byte[] p2 = intToByteArray(param[1]);
p = concatArrays(p, p2);
}
return setParameter(p, value);
|
public int | setParameter(byte[] param, byte[] value)Set effect parameter. The setParameter method is provided in several
forms addressing most common parameter formats. This form is the most
generic one where the parameter and its value are both specified as an
array of bytes. The parameter and value type and length are therefore
totally free. For standard effect defined by OpenSL ES, the parameter
format and values must match the definitions in the corresponding OpenSL
ES interface.
checkState("setParameter()");
return native_setParameter(param.length, param, value.length, value);
|
public void | setParameterListener(android.media.audiofx.AudioEffect$OnParameterChangeListener listener)Sets the listener AudioEffect notifies when a parameter is changed.
synchronized (mListenerLock) {
mParameterChangeListener = listener;
}
if ((listener != null) && (mNativeEventHandler == null)) {
createNativeEventHandler();
}
|
public static byte[] | shortToByteArray(short value)
ByteBuffer converter = ByteBuffer.allocate(2);
converter.order(ByteOrder.nativeOrder());
short sValue = (short) value;
converter.putShort(sValue);
return converter.array();
|