Added in API level 9

Equalizer


open class Equalizer : AudioEffect
kotlin.Any
   ↳ 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 android.media.MediaPlayer#getAudioSessionId() for details on audio sessions.

See android.media.audiofx.AudioEffect class for more details on controlling audio effects.

Summary

Nested classes
abstract

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

open

The Settings class regroups all equalizer parameters.

Constants
static Int

Band frequency range.

static Int

Band level.

static Int

Band center frequency.

static Int

Current preset.

static Int

Band for a given frequency.

static Int

Request number of presets.

static Int

Request preset name.

static Int

Band level range.

static Int

Number of bands.

static Int

Maximum size for preset name

Inherited constants
Public constructors
Equalizer(priority: Int, audioSession: Int)

Class constructor.

Public methods
open Short
getBand(frequency: Int)

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

open IntArray!

Gets the frequency range of the given frequency band.

open Short

Gets the gain set for the given equalizer band.

open ShortArray!

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

open Int

Gets the center frequency of the given band.

open Short

Gets current preset.

open Short

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

open Short

Gets the total number of presets the equalizer supports.

open String!

Gets the preset name based on the index.

open Equalizer.Settings!

Gets the equalizer properties.

open Unit
setBandLevel(band: Short, level: Short)

Sets the given equalizer band to the given gain value.

open Unit

Registers an OnParameterChangeListener interface.

open Unit

Sets the equalizer properties.

open Unit
usePreset(preset: Short)

Sets the equalizer according to the given preset.

Inherited functions
Inherited properties

Constants

PARAM_BAND_FREQ_RANGE

Added in API level 9
static val PARAM_BAND_FREQ_RANGE: Int

Band frequency range. Parameter ID for android.media.audiofx.Equalizer.OnParameterChangeListener

Value: 4

PARAM_BAND_LEVEL

Added in API level 9
static val PARAM_BAND_LEVEL: Int

Band level. Parameter ID for OnParameterChangeListener

Value: 2

PARAM_CENTER_FREQ

Added in API level 9
static val PARAM_CENTER_FREQ: Int

Band center frequency. Parameter ID for OnParameterChangeListener

Value: 3

PARAM_CURRENT_PRESET

Added in API level 9
static val PARAM_CURRENT_PRESET: Int

Current preset. Parameter ID for OnParameterChangeListener

Value: 6

PARAM_GET_BAND

Added in API level 9
static val PARAM_GET_BAND: Int

Band for a given frequency. Parameter ID for OnParameterChangeListener

Value: 5

PARAM_GET_NUM_OF_PRESETS

Added in API level 9
static val PARAM_GET_NUM_OF_PRESETS: Int

Request number of presets. Parameter ID for OnParameterChangeListener

Value: 7

PARAM_GET_PRESET_NAME

Added in API level 9
static val PARAM_GET_PRESET_NAME: Int

Request preset name. Parameter ID for OnParameterChangeListener

Value: 8

PARAM_LEVEL_RANGE

Added in API level 9
static val PARAM_LEVEL_RANGE: Int

Band level range. Parameter ID for OnParameterChangeListener

Value: 1

PARAM_NUM_BANDS

Added in API level 9
static val PARAM_NUM_BANDS: Int

Number of bands. Parameter ID for OnParameterChangeListener

Value: 0

PARAM_STRING_SIZE_MAX

Added in API level 9
static val PARAM_STRING_SIZE_MAX: Int

Maximum size for preset name

Value: 32

Public constructors

Equalizer

Added in API level 9
Equalizer(
    priority: Int,
    audioSession: Int)

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.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
java.lang.RuntimeException

Public methods

getBand

Added in API level 9
open fun getBand(frequency: Int): Short

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.
Return
Short the frequency band that has most effect on the given frequency.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getBandFreqRange

Added in API level 9
open fun getBandFreqRange(band: Short): IntArray!

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).
Return
IntArray! 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.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getBandLevel

Added in API level 9
open fun getBandLevel(band: Short): Short

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).
Return
Short the gain in millibels of the given band.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getBandLevelRange

Added in API level 9
open fun getBandLevelRange(): ShortArray!

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

Return
ShortArray! 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.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getCenterFreq

Added in API level 9
open fun getCenterFreq(band: Short): Int

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).
Return
Int the center frequency in milliHertz
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getCurrentPreset

Added in API level 9
open fun getCurrentPreset(): Short

Gets current preset.

Return
Short the preset that is set at the moment.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getNumberOfBands

Added in API level 9
open fun getNumberOfBands(): Short

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

Return
Short the number of bands
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getNumberOfPresets

Added in API level 9
open fun getNumberOfPresets(): Short

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

Return
Short the number of presets the equalizer supports.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getPresetName

Added in API level 9
open fun getPresetName(preset: Short): String!

Gets the preset name based on the index.

Parameters
preset Short: index of the preset. The valid range is [0, number of presets-1].
Return
String! a string containing the name of the given preset.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

getProperties

Added in API level 9
open fun getProperties(): Equalizer.Settings!

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

Return
Equalizer.Settings! an Equalizer.Settings object containing all current parameters values
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

setBandLevel

Added in API level 9
open fun setBandLevel(
    band: Short,
    level: Short
): Unit

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.
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

setParameterListener

Added in API level 9
open fun setParameterListener(listener: Equalizer.OnParameterChangeListener!): Unit

Registers an OnParameterChangeListener interface.

Parameters
listener Equalizer.OnParameterChangeListener!: OnParameterChangeListener interface registered

setProperties

Added in API level 9
open fun setProperties(settings: Equalizer.Settings!): Unit

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
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

usePreset

Added in API level 9
open fun usePreset(preset: Short): Unit

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].
Exceptions
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException