Equalizer - Android SDK | Android Developers Android中文文档@工具屋(toolib)
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. If the audio session ID 0 is specified, the Equalizer applies to the main audio output mix.

Creating an Equalizer on the output mix (audio session 0) requires permission MODIFY_AUDIO_SETTINGS

See getAudioSessionId() for details on audio sessions.

See AudioEffect class for more details on controlling audio effects.

摘要

嵌套类
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. 
常量
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
[展开]
继承的常量
来自 class android.media.audiofx.AudioEffect
公有构造函数
Equalizer(int priority, int audioSession)
Class constructor.
公有方法
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.
[展开]
继承的方法
来自 class android.media.audiofx.AudioEffect
来自 class java.lang.Object

常量

public static final int PARAM_BAND_FREQ_RANGE

引入自:API 级别9

Band frequency range. Parameter ID for Equalizer.OnParameterChangeListener

常量值: 4 (0x00000004)

public static final int PARAM_BAND_LEVEL

引入自:API 级别9

Band level. Parameter ID for OnParameterChangeListener

常量值: 2 (0x00000002)

public static final int PARAM_CENTER_FREQ

引入自:API 级别9

Band center frequency. Parameter ID for OnParameterChangeListener

常量值: 3 (0x00000003)

public static final int PARAM_CURRENT_PRESET

引入自:API 级别9

Current preset. Parameter ID for OnParameterChangeListener

常量值: 6 (0x00000006)

public static final int PARAM_GET_BAND

引入自:API 级别9

Band for a given frequency. Parameter ID for OnParameterChangeListener

常量值: 5 (0x00000005)

public static final int PARAM_GET_NUM_OF_PRESETS

引入自:API 级别9

Request number of presets. Parameter ID for OnParameterChangeListener

常量值: 7 (0x00000007)

public static final int PARAM_GET_PRESET_NAME

引入自:API 级别9

Request preset name. Parameter ID for OnParameterChangeListener

常量值: 8 (0x00000008)

public static final int PARAM_LEVEL_RANGE

引入自:API 级别9

Band level range. Parameter ID for OnParameterChangeListener

常量值: 1 (0x00000001)

public static final int PARAM_NUM_BANDS

引入自:API 级别9

Number of bands. Parameter ID for OnParameterChangeListener

常量值: 0 (0x00000000)

public static final int PARAM_STRING_SIZE_MAX

引入自:API 级别9

Maximum size for preset name

常量值: 32 (0x00000020)

公有构造函数

public Equalizer (int priority, int audioSession)

引入自:API 级别9

Class constructor.

参数
priority 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 system wide unique audio session identifier. If audioSession is not 0, the Equalizer will be attached to the MediaPlayer or AudioTrack in the same audio session. Otherwise, the Equalizer will apply to the output mix.
抛出
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException
RuntimeException
IllegalStateException
IllegalArgumentException
UnsupportedOperationException

公有方法

public short getBand (int frequency)

引入自:API 级别9

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

参数
frequency frequency in milliHertz which is to be equalized via the returned band.
返回值
  • the frequency band that has most effect on the given frequency.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public int[] getBandFreqRange (short band)

引入自:API 级别9

Gets the frequency range of the given frequency band.

参数
band frequency band whose frequency range is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).
返回值
  • 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.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public short getBandLevel (short band)

引入自:API 级别9

Gets the gain set for the given equalizer band.

参数
band frequency band whose gain is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).
返回值
  • the gain in millibels of the given band.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public short[] getBandLevelRange ()

引入自:API 级别9

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

返回值
  • 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.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public int getCenterFreq (short band)

引入自:API 级别9

Gets the center frequency of the given band.

参数
band frequency band whose center frequency is requested. The numbering of the bands starts from 0 and ends at (number of bands - 1).
返回值
  • the center frequency in milliHertz
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public short getCurrentPreset ()

引入自:API 级别9

Gets current preset.

返回值
  • the preset that is set at the moment.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public short getNumberOfBands ()

引入自:API 级别9

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

返回值
  • the number of bands
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public short getNumberOfPresets ()

引入自:API 级别9

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

返回值
  • the number of presets the equalizer supports.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public String getPresetName (short preset)

引入自:API 级别9

Gets the preset name based on the index.

参数
preset index of the preset. The valid range is [0, number of presets-1].
返回值
  • a string containing the name of the given preset.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException

public Equalizer.Settings getProperties ()

引入自:API 级别9

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

返回值
  • an Equalizer.Settings object containing all current parameters values
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public void setBandLevel (short band, short level)

引入自:API 级别9

Sets the given equalizer band to the given gain value.

参数
band frequency band that will have the new gain. The numbering of the bands starts from 0 and ends at (number of bands - 1).
level new gain in millibels that will be set to the given band. getBandLevelRange() will define the maximum and minimum values.
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException
UnsupportedOperationException

public void setParameterListener (Equalizer.OnParameterChangeListener listener)

引入自:API 级别9

Registers an OnParameterChangeListener interface.

参数
listener OnParameterChangeListener interface registered

public void setProperties (Equalizer.Settings settings)

引入自:API 级别9

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

参数
settings an Equalizer.Settings object containing the properties to apply
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

public void usePreset (short preset)

引入自:API 级别9

Sets the equalizer according to the given preset.

参数
preset new preset that will be taken into use. The valid range is [0, number of presets-1].
抛出
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
分享到
新浪微博