Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

AudioEffect

extends Object
java.lang.Object
   ↳ android.media.audiofx.AudioEffect
Known Direct Subclasses

Class Overview

AudioEffect is the base class for controlling audio effects provided by the android audio framework.

Applications should not use the AudioEffect class directly but one of its derived classes to control specific effects:

To apply the audio effect to a specific AudioTrack or MediaPlayer instance, the application must specify the audio session ID of that instance when creating the AudioEffect. (see getAudioSessionId() for details on audio sessions).

NOTE: attaching insert effects (equalizer, bass boost, virtualizer) to the global audio output mix by use of session 0 is deprecated.

Creating an AudioEffect object will create the corresponding effect engine in the audio framework if no instance of the same effect type exists in the specified audio session. If one exists, this instance will be used.

The application creating the AudioEffect object (or a derived class) will either receive control of the effect engine or not depending on the priority parameter. If priority is higher than the priority used by the current effect engine owner, the control will be transfered to the new object. Otherwise control will remain with the previous object. In this case, the new application will be notified of changes in effect engine state or control ownership by the appropiate listener.

Summary

Nested Classes
class AudioEffect.Descriptor The effect descriptor contains information on a particular effect implemented in the audio framework:
  • type: UUID identifying the effect type. 
interface AudioEffect.OnControlStatusChangeListener The OnControlStatusChangeListener interface defines a method called by the AudioEffect when a the control of the effect engine is gained or lost by the application  
interface AudioEffect.OnEnableStatusChangeListener The OnEnableStatusChangeListener interface defines a method called by the AudioEffect when a the enabled state of the effect engine was changed by the controlling application. 
Constants
String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION Intent to signal to the effect control application or service that an audio session is closed and that effects should not be applied anymore.
String ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL Intent to launch an audio effect control panel UI.
String ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION Intent to signal to the effect control application or service that a new audio session is opened and requires audio effects to be applied.
int ALREADY_EXISTS Internal operation status.
int CONTENT_TYPE_GAME Value for EXTRA_CONTENT_TYPE when the type of content played is game audio
int CONTENT_TYPE_MOVIE Value for EXTRA_CONTENT_TYPE when the type of content played is video or movie
int CONTENT_TYPE_MUSIC Value for EXTRA_CONTENT_TYPE when the type of content played is music
int CONTENT_TYPE_VOICE Value for EXTRA_CONTENT_TYPE when the type of content played is voice audio
String EFFECT_AUXILIARY Effect connection mode is auxiliary.
String EFFECT_INSERT Effect connection mode is insert.
int ERROR Unspecified error.
int ERROR_BAD_VALUE Operation failed due to bad parameter value.
int ERROR_DEAD_OBJECT Operation failed due to dead remote object.
int ERROR_INVALID_OPERATION Operation failed because it was requested in wrong state.
int ERROR_NO_INIT Operation failed due to bad object initialization.
int ERROR_NO_MEMORY Operation failed due to lack of memory.
String EXTRA_AUDIO_SESSION Contains the ID of the audio session the effects should be applied to.
String EXTRA_CONTENT_TYPE Indicates which type of content is played by the application.
String EXTRA_PACKAGE_NAME Contains the package name of the calling application.
int SUCCESS Successful operation.
Fields
public static final UUID EFFECT_TYPE_AEC UUID for Acoustic Echo Canceler (AEC)
public static final UUID EFFECT_TYPE_AGC UUID for Automatic Gain Control (AGC)
public static final UUID EFFECT_TYPE_BASS_BOOST UUID for bass boost effect
public static final UUID EFFECT_TYPE_ENV_REVERB UUID for environmental reverberation effect
public static final UUID EFFECT_TYPE_EQUALIZER UUID for equalizer effect
public static final UUID EFFECT_TYPE_LOUDNESS_ENHANCER UUID for Loudness Enhancer
public static final UUID EFFECT_TYPE_NS UUID for Noise Suppressor (NS)
public static final UUID EFFECT_TYPE_PRESET_REVERB UUID for preset reverberation effect
public static final UUID EFFECT_TYPE_VIRTUALIZER UUID for virtualizer effect
Public Methods
AudioEffect.Descriptor getDescriptor ()
Get the effect descriptor.
boolean getEnabled ()
Returns effect enabled state
int getId ()
Returns effect unique identifier.
boolean hasControl ()
Checks if this AudioEffect object is controlling the effect engine.
static Descriptor[] queryEffects ()
Query all effects available on the platform.
void release ()
Releases the native AudioEffect resources.
void setControlStatusListener ( AudioEffect.OnControlStatusChangeListener listener)
Sets the listener AudioEffect notifies when the effect engine control is taken or returned.
void setEnableStatusListener ( AudioEffect.OnEnableStatusChangeListener listener)
Sets the listener AudioEffect notifies when the effect engine is enabled or disabled.
int setEnabled (boolean enabled)
Enable or disable the effect.
Protected Methods
void finalize ()
Invoked when the garbage collector has detected that this instance is no longer reachable.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION

Added in API level 9

Intent 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 EXTRA_PACKAGE_NAME extra and the audio session ID by the 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.

Constant Value: "android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION"

public static final String ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL

Added in API level 9

Intent 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 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 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 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 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.

Constant Value: "android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL"

public static final String ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION

Added in API level 9

Intent 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 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 EXTRA_PACKAGE_NAME extra and the audio session ID by the 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 EXTRA_CONTENT_TYPE will be applied. The default settings for a given content type are platform specific.

Constant Value: "android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION"

public static final int ALREADY_EXISTS

Added in API level 9

Internal operation status. Not returned by any method.

Constant Value: -2 (0xfffffffe)

public static final int CONTENT_TYPE_GAME

Added in API level 9

Value for EXTRA_CONTENT_TYPE when the type of content played is game audio

Constant Value: 2 (0x00000002)

public static final int CONTENT_TYPE_MOVIE

Added in API level 9

Value for EXTRA_CONTENT_TYPE when the type of content played is video or movie

Constant Value: 1 (0x00000001)

public static final int CONTENT_TYPE_MUSIC

Added in API level 9

Value for EXTRA_CONTENT_TYPE when the type of content played is music

Constant Value: 0 (0x00000000)

public static final int CONTENT_TYPE_VOICE

Added in API level 9

Value for EXTRA_CONTENT_TYPE when the type of content played is voice audio

Constant Value: 3 (0x00000003)

public static final String EFFECT_AUXILIARY

Added in API level 9

Effect 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 getId() to designate this particular effect when attaching it to the MediaPlayer or AudioTrack.

Constant Value: "Auxiliary"

public static final String EFFECT_INSERT

Added in API level 9

Effect 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.

Constant Value: "Insert"

public static final int ERROR

Added in API level 9

Unspecified error.

Constant Value: -1 (0xffffffff)

public static final int ERROR_BAD_VALUE

Added in API level 9

Operation failed due to bad parameter value.

Constant Value: -4 (0xfffffffc)

public static final int ERROR_DEAD_OBJECT

Added in API level 9

Operation failed due to dead remote object.

Constant Value: -7 (0xfffffff9)

public static final int ERROR_INVALID_OPERATION

Added in API level 9

Operation failed because it was requested in wrong state.

Constant Value: -5 (0xfffffffb)

public static final int ERROR_NO_INIT

Added in API level 9

Operation failed due to bad object initialization.

Constant Value: -3 (0xfffffffd)

public static final int ERROR_NO_MEMORY

Added in API level 9

Operation failed due to lack of memory.

Constant Value: -6 (0xfffffffa)

public static final String EXTRA_AUDIO_SESSION

Added in API level 9

Contains the ID of the audio session the effects should be applied to.

This extra is for use with ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL , ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION and ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION intents.

The extra value is of type int and is the audio session ID.

Constant Value: "android.media.extra.AUDIO_SESSION"

public static final String EXTRA_CONTENT_TYPE

Added in API level 9

Indicates which type of content is played by the application.

This extra is for use with ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL and 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:

If omitted, the content type defaults to CONTENT_TYPE_MUSIC .

Constant Value: "android.media.extra.CONTENT_TYPE"

public static final String EXTRA_PACKAGE_NAME

Added in API level 9

Contains the package name of the calling application.

This extra is for use with ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION and ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION intents.

The extra value is a string containing the full package name.

Constant Value: "android.media.extra.PACKAGE_NAME"

public static final int SUCCESS

Added in API level 9

Successful operation.

Constant Value: 0 (0x00000000)

Fields

public static final UUID EFFECT_TYPE_AEC

UUID for Acoustic Echo Canceler (AEC)

public static final UUID EFFECT_TYPE_AGC

UUID for Automatic Gain Control (AGC)

public static final UUID EFFECT_TYPE_BASS_BOOST

UUID for bass boost effect

public static final UUID EFFECT_TYPE_ENV_REVERB

UUID for environmental reverberation effect

public static final UUID EFFECT_TYPE_EQUALIZER

UUID for equalizer effect

public static final UUID EFFECT_TYPE_LOUDNESS_ENHANCER

UUID for Loudness Enhancer

public static final UUID EFFECT_TYPE_NS

UUID for Noise Suppressor (NS)

public static final UUID EFFECT_TYPE_PRESET_REVERB

UUID for preset reverberation effect

public static final UUID EFFECT_TYPE_VIRTUALIZER

UUID for virtualizer effect

Public Methods

public AudioEffect.Descriptor getDescriptor ()

Added in API level 9

Get the effect descriptor.

public boolean getEnabled ()

Added in API level 9

Returns effect enabled state

Returns
  • true if the effect is enabled, false otherwise.

public int getId ()

Added in API level 9

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)

Returns
  • the effect identifier.

public boolean hasControl ()

Added in API level 9

Checks if this AudioEffect object is controlling the effect engine.

Returns
  • true if this instance has control of effect engine, false otherwise.

public static Descriptor[] queryEffects ()

Added in API level 9

Query all effects available on the platform. Returns an array of AudioEffect.Descriptor objects

public void release ()

Added in API level 9

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.

public void setControlStatusListener ( AudioEffect.OnControlStatusChangeListener listener)

Added in API level 9

Sets the listener AudioEffect notifies when the effect engine control is taken or returned.

public void setEnableStatusListener ( AudioEffect.OnEnableStatusChangeListener listener)

Added in API level 9

Sets the listener AudioEffect notifies when the effect engine is enabled or disabled.

public int setEnabled (boolean enabled)

Added in API level 9

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.

Parameters
enabled the requested enable state
Returns

Protected Methods

protected void finalize ()

Added in API level 9

Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable ), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.