Equalizer


public class Equalizer
extends AudioEffect

java.lang.Object
   ↳ android.media.audiofx.AudioEffect
     ↳ android.media.audiofx.Equalizer


An Equalizer is used to alter the frequency response of a particular music source or of the main output mix.

An application creates an Equalizer object to instantiate and control an Equalizer engine in the audio framework. The application can either simply use predefined presets or have a more precise control of the gain in each frequency band controlled by the equalizer.

The methods, parameter types and units exposed by the Equalizer implementation are directly mapping those defined by the OpenSL ES 1.0.1 Specification (http://www.khronos.org/opensles/) for the SLEqualizerItf interface. Please refer to this specification for more details.

To attach the Equalizer to a particular AudioTrack or MediaPlayer, specify the audio session ID of this AudioTrack or MediaPlayer when constructing the Equalizer.

NOTE: attaching an Equalizer to the global audio output mix by use of session 0 is deprecated.

See MediaPlayer.getAudioSessionId() for details on audio sessions.

See AudioEffect class for more details on controlling audio effects.

Summary

Nested classes

interface Equalizer.OnParameterChangeListener

The OnParameterChangeListener interface defines a method called by the Equalizer when a parameter value has changed. 

class Equalizer.Settings

The Settings class regroups all equalizer parameters. 

Constants

int PARAM_BAND_FREQ_RANGE

Band frequency range.

int PARAM_BAND_LEVEL

Band level.

int PARAM_CENTER_FREQ

Band center frequency.

int PARAM_CURRENT_PRESET

Current preset.

int PARAM_GET_BAND

Band for a given frequency.

int PARAM_GET_NUM_OF_PRESETS

Request number of presets.

int PARAM_GET_PRESET_NAME

Request preset name.

int PARAM_LEVEL_RANGE

Band level range.

int PARAM_NUM_BANDS

Number of bands.

int PARAM_STRING_SIZE_MAX

Maximum size for preset name

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

String EFFECT_POST_PROCESSING

Effect connection mode is post processing.

String EFFECT_PRE_PROCESSING

Effect connection mode is pre processing.

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.

Inherited 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_DYNAMICS_PROCESSING

UUID for Dynamics Processing

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_HAPTIC_GENERATOR

UUID for Haptic Generator.

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 constructors

Equalizer(int priority, int audioSession)

Class constructor.

Public methods

short getBand(int frequency)

Gets the band that has the most effect on the given frequency.

int[] getBandFreqRange(short band)

Gets the frequency range of the given frequency band.

short getBandLevel(short band)

Gets the gain set for the given equalizer band.

short[] getBandLevelRange()

Gets the level range for use by setBandLevel(short, short).

int getCenterFreq(short band)

Gets the center frequency of the given band.

short getCurrentPreset()

Gets current preset.

short getNumberOfBands()

Gets the number of frequency bands supported by the Equalizer engine.

short getNumberOfPresets()

Gets the total number of presets the equalizer supports.

String getPresetName(short preset)

Gets the preset name based on the index.

Equalizer.Settings getProperties()

Gets the equalizer properties.

void setBandLevel(short band, short level)

Sets the given equalizer band to the given gain value.

void setParameterListener(Equalizer.OnParameterChangeListener listener)

Registers an OnParameterChangeListener interface.

void setProperties(Equalizer.Settings settings)

Sets the equalizer properties.

void usePreset(short preset)

Sets the equalizer according to the given preset.

Inherited methods

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

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.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

PARAM_BAND_FREQ_RANGE

Added in API level 9
public static final int PARAM_BAND_FREQ_RANGE

Band frequency range. Parameter ID for Equalizer.OnParameterChangeListener

Constant Value: 4 (0x00000004)

PARAM_BAND_LEVEL

Added in API level 9
public static final int PARAM_BAND_LEVEL

Band level. Parameter ID for OnParameterChangeListener

Constant Value: 2 (0x00000002)

PARAM_CENTER_FREQ

Added in API level 9
public static final int PARAM_CENTER_FREQ

Band center frequency. Parameter ID for OnParameterChangeListener

Constant Value: 3 (0x00000003)

PARAM_CURRENT_PRESET

Added in API level 9
public static final int PARAM_CURRENT_PRESET

Current preset. Parameter ID for OnParameterChangeListener

Constant Value: 6 (0x00000006)

PARAM_GET_BAND

Added in API level 9
public static final int PARAM_GET_BAND

Band for a given frequency. Parameter ID for OnParameterChangeListener

Constant Value: 5 (0x00000005)

PARAM_GET_NUM_OF_PRESETS

Added in API level 9
public static final int PARAM_GET_NUM_OF_PRESETS

Request number of presets. Parameter ID for OnParameterChangeListener

Constant Value: 7 (0x00000007)

PARAM_GET_PRESET_NAME

Added in API level 9
public static final int PARAM_GET_PRESET_NAME

Request preset name. Parameter ID for OnParameterChangeListener

Constant Value: 8 (0x00000008)

PARAM_LEVEL_RANGE

Added in API level 9
public static final int PARAM_LEVEL_RANGE

Band level range. Parameter ID for OnParameterChangeListener

Constant Value: 1 (0x00000001)

PARAM_NUM_BANDS

Added in API level 9
public static final int PARAM_NUM_BANDS

Number of bands. Parameter ID for OnParameterChangeListener

Constant Value: 0 (0x00000000)

PARAM_STRING_SIZE_MAX

Added in API level 9
public static final int PARAM_STRING_SIZE_MAX

Maximum size for preset name

Constant Value: 32 (0x00000020)

Public constructors

Equalizer

Added in API level 9
public Equalizer (int priority, 
                int audioSession)

Class constructor.

Parameters
priority int: the priority level requested by the application for controlling the Equalizer engine. As the same engine can be shared by several applications, this parameter indicates how much the requesting application needs control of effect parameters. The normal priority is 0, above normal is a positive number, below normal a negative number.

audioSession int: system wide unique audio session identifier. The Equalizer will be attached to the MediaPlayer or AudioTrack in the same audio session.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
java.lang.RuntimeException
IllegalArgumentException
IllegalStateException
RuntimeException
UnsupportedOperationException

Public methods

getBand

Added in API level 9
public short getBand (int frequency)

Gets the band that has the most effect on the given frequency.

Parameters
frequency int: frequency in milliHertz which is to be equalized via the returned band.

Returns
short the frequency band that has most effect on the given frequency.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getBandFreqRange

Added in API level 9
public int[] getBandFreqRange (short band)

Gets the frequency range of the given frequency band.

Parameters
band short: frequency band whose frequency range is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).

Returns
int[] the frequency range in millHertz in an array of integers. The first element is the lower limit of the range, the second element the upper limit.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getBandLevel

Added in API level 9
public short getBandLevel (short band)

Gets the gain set for the given equalizer band.

Parameters
band short: frequency band whose gain is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).

Returns
short the gain in millibels of the given band.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getBandLevelRange

Added in API level 9
public short[] getBandLevelRange ()

Gets the level range for use by setBandLevel(short, short). The level is expressed in milliBel.

Returns
short[] the band level range in an array of short integers. The first element is the lower limit of the range, the second element the upper limit.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getCenterFreq

Added in API level 9
public int getCenterFreq (short band)

Gets the center frequency of the given band.

Parameters
band short: frequency band whose center frequency is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).

Returns
int the center frequency in milliHertz

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getCurrentPreset

Added in API level 9
public short getCurrentPreset ()

Gets current preset.

Returns
short the preset that is set at the moment.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getNumberOfBands

Added in API level 9
public short getNumberOfBands ()

Gets the number of frequency bands supported by the Equalizer engine.

Returns
short the number of bands

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getNumberOfPresets

Added in API level 9
public short getNumberOfPresets ()

Gets the total number of presets the equalizer supports. The presets will have indices [0, number of presets-1].

Returns
short the number of presets the equalizer supports.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

getPresetName

Added in API level 9
public String getPresetName (short preset)

Gets the preset name based on the index.

Parameters
preset short: index of the preset. The valid range is [0, number of presets-1].

Returns
String a string containing the name of the given preset.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getProperties

Added in API level 9
public Equalizer.Settings getProperties ()

Gets the equalizer properties. This method is useful when a snapshot of current equalizer settings must be saved by the application.

Returns
Equalizer.Settings an Equalizer.Settings object containing all current parameters values

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

setBandLevel

Added in API level 9
public void setBandLevel (short band, 
                short level)

Sets the given equalizer band to the given gain value.

Parameters
band short: frequency band that will have the new gain. The numbering of the bands starts from 0 and ends at (number of bands - 1).

level short: new gain in millibels that will be set to the given band. getBandLevelRange() will define the maximum and minimum values.

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

See also:

setParameterListener

Added in API level 9
public void setParameterListener (Equalizer.OnParameterChangeListener listener)

Registers an OnParameterChangeListener interface.

Parameters
listener Equalizer.OnParameterChangeListener: OnParameterChangeListener interface registered

setProperties

Added in API level 9
public void setProperties (Equalizer.Settings settings)

Sets the equalizer properties. This method is useful when equalizer settings have to be applied from a previous backup.

Parameters
settings Equalizer.Settings: an Equalizer.Settings object containing the properties to apply

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException

usePreset

Added in API level 9
public void usePreset (short preset)

Sets the equalizer according to the given preset.

Parameters
preset short: new preset that will be taken into use. The valid range is [0, number of presets-1].

Throws
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
IllegalArgumentException
IllegalStateException
UnsupportedOperationException