public class Equalizer
extends AudioEffect
java.lang.Object | ||
↳ | android.media.audiofx.AudioEffect | |
↳ | android.media.audiofx.Equalizer |
均衡器用于改变特定音乐源或主输出混合的频率响应。
应用程序创建一个Equalizer对象来实例化和控制音频框架中的均衡器引擎。 应用程序可以简单地使用预定义的预设或者对由均衡器控制的每个频带中的增益进行更精确的控制。
由Equalizer实现公开的方法,参数类型和单元直接映射由SLEqualizerItf接口的OpenSL ES 1.0.1规范(http://www.khronos.org/opensles/)定义的那些方法,参数类型和单元。 有关更多详细信息,请参阅此规范。
要将均衡器附加到特定的AudioTrack或MediaPlayer,请在构建均衡器时指定此AudioTrack或MediaPlayer的音频会话ID。
注:不建议使用会话0将全球音频输出混合连接到均衡器。
有关音频会话的详细信息,请参阅 getAudioSessionId()
。
有关控制音频效果的更多详细信息,请参见 AudioEffect
类。
Nested classes |
|
---|---|
interface |
Equalizer.OnParameterChangeListener OnParameterChangeListener接口定义了当参数值发生变化时由均衡器调用的方法。 |
class |
Equalizer.Settings Settings类重新组合所有均衡器参数。 |
Constants |
|
---|---|
int |
PARAM_BAND_FREQ_RANGE 波段频率范围。 |
int |
PARAM_BAND_LEVEL 乐队级别。 |
int |
PARAM_CENTER_FREQ 频带中心频率。 |
int |
PARAM_CURRENT_PRESET 当前预设。 |
int |
PARAM_GET_BAND 给定频率的频带。 |
int |
PARAM_GET_NUM_OF_PRESETS 请求预设数量。 |
int |
PARAM_GET_PRESET_NAME 请求预设名称。 |
int |
PARAM_LEVEL_RANGE 乐队等级范围。 |
int |
PARAM_NUM_BANDS 带数。 |
int |
PARAM_STRING_SIZE_MAX 预设名称的最大大小 |
Inherited constants |
---|
From class android.media.audiofx.AudioEffect
|
Inherited fields |
---|
From class android.media.audiofx.AudioEffect
|
Public constructors |
|
---|---|
Equalizer(int priority, int audioSession) 类构造函数。 |
Public methods |
|
---|---|
short |
getBand(int frequency) 获得对给定频率影响最大的频段。 |
int[] |
getBandFreqRange(short band) 获取给定频段的频率范围。 |
short |
getBandLevel(short band) 获取给定均衡器频段的增益集。 |
short[] |
getBandLevelRange() 获取 |
int |
getCenterFreq(short band) 获取给定乐队的中心频率。 |
short |
getCurrentPreset() 获取当前预设。 |
short |
getNumberOfBands() 获取均衡器引擎支持的频段数量。 |
short |
getNumberOfPresets() 获取均衡器支持的预设总数。 |
String |
getPresetName(short preset) 根据索引获取预设名称。 |
Equalizer.Settings |
getProperties() 获取均衡器属性。 |
void |
setBandLevel(short band, short level) 将给定的均衡器频段设置为给定的增益值。 |
void |
setParameterListener(Equalizer.OnParameterChangeListener listener) 注册OnParameterChangeListener接口。 |
void |
setProperties(Equalizer.Settings settings) 设置均衡器属性。 |
void |
usePreset(short preset) 根据给定的预设设置均衡器。 |
Inherited methods |
|
---|---|
From class android.media.audiofx.AudioEffect
|
|
From class java.lang.Object
|
int PARAM_BAND_FREQ_RANGE
波段频率范围。 参数ID为Equalizer.OnParameterChangeListener
常量值:4(0x00000004)
int PARAM_BAND_LEVEL
乐队级别。 OnParameterChangeListener的参数ID
常量值:2(0x00000002)
int PARAM_CENTER_FREQ
频带中心频率。 OnParameterChangeListener的参数ID
常量值:3(0x00000003)
int PARAM_CURRENT_PRESET
当前预设。 OnParameterChangeListener的参数ID
常数值:6(0x00000006)
int PARAM_GET_BAND
给定频率的频带。 OnParameterChangeListener的参数ID
常量值:5(0x00000005)
int PARAM_GET_NUM_OF_PRESETS
请求预设数量。 OnParameterChangeListener的参数ID
常量值:7(0x00000007)
int PARAM_GET_PRESET_NAME
请求预设名称。 OnParameterChangeListener的参数ID
常量值:8(0x00000008)
int PARAM_LEVEL_RANGE
乐队等级范围。 OnParameterChangeListener的参数ID
常数值:1(0x00000001)
int PARAM_NUM_BANDS
带数。 OnParameterChangeListener的参数ID
常量值:0(0x00000000)
Equalizer (int priority, int audioSession)
类构造函数。
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 |
RuntimeException |
|
IllegalStateException |
|
IllegalArgumentException |
|
UnsupportedOperationException |
short getBand (int 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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
int[] getBandFreqRange (short 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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
short getBandLevel (short 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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
short[] getBandLevelRange ()
获取setBandLevel(short, short)
使用的等级范围。 该级别以毫巴表示。
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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
int getCenterFreq (short 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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
short getCurrentPreset ()
获取当前预设。
Returns | |
---|---|
short |
the preset that is set at the moment. |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
short getNumberOfBands ()
获取均衡器引擎支持的频段数量。
Returns | |
---|---|
short |
the number of bands |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
short getNumberOfPresets ()
获取均衡器支持的预设总数。 预设将具有索引[0,预设数量-1]。
Returns | |
---|---|
short |
the number of presets the equalizer supports. |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
String getPresetName (short preset)
根据索引获取预设名称。
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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
Equalizer.Settings getProperties ()
获取均衡器属性。 当应用程序必须保存当前均衡器设置的快照时,此方法非常有用。
Returns | |
---|---|
Equalizer.Settings |
an Equalizer.Settings object containing all current parameters values |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
void setBandLevel (short band, short level)
将给定的均衡器频段设置为给定的增益值。
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 | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
|
UnsupportedOperationException |
IllegalStateException |
|
IllegalArgumentException |
|
UnsupportedOperationException |
也可以看看:
void setParameterListener (Equalizer.OnParameterChangeListener listener)
注册OnParameterChangeListener接口。
Parameters | |
---|---|
listener |
Equalizer.OnParameterChangeListener : OnParameterChangeListener interface registered |
void setProperties (Equalizer.Settings settings)
设置均衡器属性。 当必须从先前的备份应用均衡器设置时,此方法非常有用。
Parameters | |
---|---|
settings |
Equalizer.Settings : an Equalizer.Settings object containing the properties to apply |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
UnsupportedOperationException |
|
IllegalStateException |
|
IllegalArgumentException |
void usePreset (short preset)
根据给定的预设设置均衡器。
Parameters | |
---|---|
preset |
short : new preset that will be taken into use. The valid range is [0, number of presets-1]. |
Throws | |
---|---|
|
IllegalStateException |
|
IllegalArgumentException |
|
UnsupportedOperationException |
IllegalStateException |
|
IllegalArgumentException |
|
UnsupportedOperationException |
也可以看看: