Most visited

Recently visited

Added in API level 9

Virtualizer

public class Virtualizer
extends AudioEffect

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


音频虚拟器是音频通道空间化的通用名称。 这种效果的确切行为取决于音频输入通道的数量以及设备音频输出通道的类型和数量。 例如,在立体声输入和立体声耳机输出的情况下,打开此效果时会使用立体声加宽效果。

应用程序创建一个Virtualizer对象来实例化和控制音频框架中的虚拟器引擎。

Virtualizer实现公开的方法,参数类型和单位直接映射到SLVirtualizerItf接口的OpenSL ES 1.0.1规范(http://www.khronos.org/opensles/)定义的方法,参数类型和单位。 有关更多详细信息,请参阅此规范。

要将Virtualizer附加到特定的AudioTrack或MediaPlayer,请在构建Virtualizer时指定此AudioTrack或MediaPlayer的音频会话ID。

注:不建议使用会话0将Virtualizer附加到全局音频输出组合。

有关音频会话的详细信息,请参阅 getAudioSessionId()

有关控制音频效果的更多详细信息,请参见 AudioEffect类。

Summary

Nested classes

interface Virtualizer.OnParameterChangeListener

OnParameterChangeListener接口定义了当参数值发生变化时由Virtualizer调用的方法。

class Virtualizer.Settings

Settings类重新组合所有虚拟器参数。

Constants

int PARAM_STRENGTH

虚拟器效果强度。

int PARAM_STRENGTH_SUPPORTED

虚拟引擎支持强度参数。

int VIRTUALIZATION_MODE_AUTO

用于指示虚拟器效果的虚拟化模式必须停止强制处理到 forceVirtualizationMode(int)的特定模式。

int VIRTUALIZATION_MODE_BINAURAL

通常通过耳机使用的虚拟化模式。

int VIRTUALIZATION_MODE_OFF

指示虚拟化处理的虚拟化模式不活动。

int VIRTUALIZATION_MODE_TRANSAURAL

通常用于扬声器的虚拟化模式。

Inherited constants

From class android.media.audiofx.AudioEffect

Inherited fields

From class android.media.audiofx.AudioEffect

Public constructors

Virtualizer(int priority, int audioSession)

类构造函数。

Public methods

boolean canVirtualize(int inputChannelMask, int virtualizationMode)

检查此虚拟器是否支持通道掩码和虚拟化模式的组合。

boolean forceVirtualizationMode(int virtualizationMode)

强制虚拟器效果使用给定的处理模式。

Virtualizer.Settings getProperties()

获取虚拟器属性。

short getRoundedStrength()

获取当前效果的强度。

boolean getSpeakerAngles(int inputChannelMask, int virtualizationMode, int[] angles)

查询通道掩码和虚拟化模式组合的虚拟扬声器角度(方位角和仰角)。

boolean getStrengthSupported()

指示是否支持设置强度。

int getVirtualizationMode()

返回正在使用的虚拟化模式(如果有的话)。

void setParameterListener(Virtualizer.OnParameterChangeListener listener)

注册OnParameterChangeListener接口。

void setProperties(Virtualizer.Settings settings)

设置虚拟器属性。

void setStrength(short strength)

设置虚拟器效果的强度。

Inherited methods

From class android.media.audiofx.AudioEffect
From class java.lang.Object

Constants

PARAM_STRENGTH

Added in API level 9
int PARAM_STRENGTH

虚拟器效果强度。 参数ID为Virtualizer.OnParameterChangeListener

常数值:1(0x00000001)

PARAM_STRENGTH_SUPPORTED

Added in API level 9
int PARAM_STRENGTH_SUPPORTED

虚拟引擎支持强度参数。 getParameter()的参数ID。

常量值:0(0x00000000)

VIRTUALIZATION_MODE_AUTO

Added in API level 21
int VIRTUALIZATION_MODE_AUTO

用于指示虚拟器效果的虚拟化模式必须停止强制处理到 forceVirtualizationMode(int)的特定模式。

常数值:1(0x00000001)

VIRTUALIZATION_MODE_BINAURAL

Added in API level 21
int VIRTUALIZATION_MODE_BINAURAL

通常通过耳机使用的虚拟化模式。 双耳虚拟化描述了虚拟化的音频处理配置,其中左右声道分别到达用户的左耳和右耳,而不馈送相反的耳(如在收听扬声器时的情况)。

因此,此类模式适用于通过立体声有线耳机或耳机播放音频时,以及通过无线A2DP蓝牙链接播放立体声耳机的情况。

请参阅 canVirtualize(int, int)以验证此Virtualizer支持此模式。

常量值:2(0x00000002)

VIRTUALIZATION_MODE_OFF

Added in API level 21
int VIRTUALIZATION_MODE_OFF

指示虚拟化处理的虚拟化模式不活动。 请参阅getVirtualizationMode()作为可能的返回值之一。

常量值:0(0x00000000)

VIRTUALIZATION_MODE_TRANSAURAL

Added in API level 21
int VIRTUALIZATION_MODE_TRANSAURAL

通常用于扬声器的虚拟化模式。 Transaural虚拟化描述了一种不同于双耳的音频处理配置(如VIRTUALIZATION_MODE_BINAURAL中所述,存在串扰,即从左声道播放的音频也到达用户的右耳,反之亦然)。

如果支持此功能,则在通过设备的内置立体声扬声器播放音频(如果具有该功能)时应使用此模式。

请参阅 canVirtualize(int, int)以验证此Virtualizer支持此模式。

常量值:3(0x00000003)

Public constructors

Virtualizer

Added in API level 9
Virtualizer (int priority, 
                int audioSession)

类构造函数。

Parameters
priority int: the priority level requested by the application for controlling the Virtualizer 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 Virtualizer 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

Public methods

canVirtualize

Added in API level 21
boolean canVirtualize (int inputChannelMask, 
                int virtualizationMode)

检查此虚拟器是否支持通道掩码和虚拟化模式的组合。 某些虚拟器实现可能只支持双耳处理(即仅支持耳机输出,请参阅VIRTUALIZATION_MODE_BINAURAL ),有些虚拟器可能支持内置扬声器的transaural处理(即扬声器输出,请参阅VIRTUALIZATION_MODE_TRANSAURAL )。 使用此方法查询虚拟器实施功能。

Parameters
inputChannelMask int: the channel mask of the content to virtualize.
virtualizationMode int: the mode for which virtualization processing is to be performed, one of VIRTUALIZATION_MODE_BINAURAL, VIRTUALIZATION_MODE_TRANSAURAL.
Returns
boolean true if the combination of channel mask and virtualization mode is supported, false otherwise.
An indication that a certain channel mask is not supported doesn't necessarily mean you cannot play content with that channel mask, it more likely implies the content will be downmixed before being virtualized. For instance a virtualizer that only supports a mask such as CHANNEL_OUT_STEREO will still be able to process content with a mask of CHANNEL_OUT_5POINT1, but will downmix the content to stereo first, and then will virtualize, as opposed to virtualizing each channel individually.
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

forceVirtualizationMode

Added in API level 21
boolean forceVirtualizationMode (int virtualizationMode)

强制虚拟器效果使用给定的处理模式。 必须启用该效果才能应用强制模式。

Parameters
virtualizationMode int: one of VIRTUALIZATION_MODE_BINAURAL, VIRTUALIZATION_MODE_TRANSAURAL to force a particular processing mode, or .VIRTUALIZATION_MODE_AUTO to stop forcing a mode.
Returns
boolean true if the processing mode is supported, and it is successfully set, or forcing was successfully disabled, false otherwise.
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

getProperties

Added in API level 9
Virtualizer.Settings getProperties ()

获取虚拟器属性。 当应用程序必须保存当前虚拟器设置的快照时,此方法非常有用。

Returns
Virtualizer.Settings a Virtualizer.Settings object containing all current parameters values
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

getRoundedStrength

Added in API level 9
short getRoundedStrength ()

获取当前效果的强度。

Returns
short the strength of the effect. The valid range for strength is [0, 1000], where 0 per mille designates the mildest effect and 1000 per mille the strongest
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

getSpeakerAngles

Added in API level 21
boolean getSpeakerAngles (int inputChannelMask, 
                int virtualizationMode, 
                int[] angles)

查询通道掩码和虚拟化模式组合的虚拟扬声器角度(方位角和仰角)。 如果支持虚拟化配置(掩码和模式)(请参阅canVirtualize(int, int) ,则返回每个虚拟扬声器的定义以及相对于收听者的方位角和仰角的数组角度。
请注意,在一些虚拟器实施中,角度可能与强度有关。

Parameters
inputChannelMask int: the channel mask of the content to virtualize.
virtualizationMode int: the mode for which virtualization processing is to be performed, one of VIRTUALIZATION_MODE_BINAURAL, VIRTUALIZATION_MODE_TRANSAURAL.
angles int: a non-null array whose length is 3 times the number of channels in the channel mask. If the method indicates the configuration is supported, the array will contain upon return triplets of values: for each channel i among the channels of the mask:
  • the element at index 3*i in the array contains the speaker identification (e.g. CHANNEL_OUT_FRONT_LEFT),
  • the element at index 3*i+1 contains its corresponding azimuth angle expressed in degrees, where 0 is the direction the listener faces, 180 is behind the listener, and -90 is to her/his left,
  • the element at index 3*i+2 contains its corresponding elevation angle where +90 is directly above the listener, 0 is the horizontal plane, and -90 is directly below the listener.
Returns
boolean true if the combination of channel mask and virtualization mode is supported, false otherwise.
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

getStrengthSupported

Added in API level 9
boolean getStrengthSupported ()

指示是否支持设置强度。 如果此方法返回false,则只支持一个强度,并且setStrength()方法总是四舍五入到该值。

Returns
boolean true is strength parameter is supported, false otherwise

getVirtualizationMode

Added in API level 21
int getVirtualizationMode ()

返回正在使用的虚拟化模式(如果有的话)。

Returns
int the virtualization mode being used. If virtualization is not active, the virtualization mode will be VIRTUALIZATION_MODE_OFF. Otherwise the value will be VIRTUALIZATION_MODE_BINAURAL or VIRTUALIZATION_MODE_TRANSAURAL. Virtualization may not be active either because the effect is not enabled or because the current output device is not compatible with this virtualization implementation.
Throws
IllegalStateException
UnsupportedOperationException
IllegalStateException

setParameterListener

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

注册OnParameterChangeListener接口。

Parameters
listener Virtualizer.OnParameterChangeListener: OnParameterChangeListener interface registered

setProperties

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

设置虚拟器属性。 当必须从先前的备份应用虚拟器设置时,此方法非常有用。

Parameters
settings Virtualizer.Settings: a Virtualizer.Settings object containing the properties to apply
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

setStrength

Added in API level 9
void setStrength (short strength)

设置虚拟器效果的强度。 如果实施不支持每千次精度设定强度,则允许将给定强度四舍五入到最接近的支持值。 您可以使用getRoundedStrength()方法查询实际设置的(可能为四舍五入的)值。

Parameters
strength short: strength of the effect. The valid range for strength strength is [0, 1000], where 0 per mille designates the mildest effect and 1000 per mille designates the strongest.
Throws
IllegalStateException
IllegalArgumentException
UnsupportedOperationException
IllegalStateException
IllegalArgumentException

Hooray!