public static class AudioFormat.Builder
extends Object
| java.lang.Object | |
| android.media.AudioFormat.Builder | |
AudioFormat对象的生成器类。 使用这个类来配置和创建一个AudioFormat实例。 通过设置音频编码,通道掩码或采样率等格式特性,您可以指出在使用此音频格式的任何地方,哪些设备的默认行为不同。 有关可用于配置AudioFormat实例的不同参数的完整说明,请参见AudioFormat 。
AudioFormat例如用于AudioTrack(AudioAttributes, AudioFormat, int, int, int) 。 在此构造函数中, Builder (例如setSampleRate(int) )上设置的每个格式特征都将更改AudioTrack使用的默认值。 在这种情况下为音频播放与AudioTrack ,在设置采样率Builder会覆盖,否则默认选择平台的输出采样率。
Public constructors |
|
|---|---|
AudioFormat.Builder() 构造一个没有设置格式特性的新的Builder。 |
|
AudioFormat.Builder(AudioFormat af) 从给定的 |
|
公共方法(Public methods) |
|
|---|---|
AudioFormat |
build() 组合所有已设置的格式特征并返回一个新的 |
AudioFormat.Builder |
setChannelIndexMask(int channelIndexMask) 设置频道索引掩码。 |
AudioFormat.Builder |
setChannelMask(int channelMask) 设置通道位置遮罩。 |
AudioFormat.Builder |
setEncoding(int encoding) 设置数据编码格式。 |
AudioFormat.Builder |
setSampleRate(int sampleRate) 设置采样率。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
AudioFormat.Builder (AudioFormat af)
从给定的 AudioFormat构造一个新的Builder。
| 参数(Parameters) | |
|---|---|
af |
AudioFormat: the AudioFormat object whose data will be reused in the new Builder. |
AudioFormat build ()
结合了所有已设置并返回一个新的格式特征 AudioFormat对象。
| 返回(Returns) | |
|---|---|
AudioFormat |
a new AudioFormat object |
AudioFormat.Builder setChannelIndexMask (int channelIndexMask)
设置频道索引掩码。 通道索引掩码指定帧中的音频采样与编号的端点通道的关联。 信道索引掩码中的第i位对应于第i个端点信道。 例如,具有四个通道的端点被表示为索引掩码位0至3.这个位置掩码解释的这个setChannelMask(int) 。
AudioTrack和AudioRecord支持通道索引掩码。 如果指定了通道索引掩码,则使用该掩码,否则使用由setChannelMask指定的通道位置掩码。 对于AudioTrack和AudioRecord ,如果指定了通道索引掩码,则不需要通道位置掩码。
| 参数(Parameters) | |
|---|---|
channelIndexMask |
int: describes the configuration of the audio channels. 对于输出, 对于输入, |
| 返回(Returns) | |
|---|---|
AudioFormat.Builder |
the same Builder instance. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the channel index mask is invalid or if both channel index mask and channel position mask are specified but do not have the same channel count. |
AudioFormat.Builder setChannelMask (int channelMask)
设置通道位置遮罩。 通道位置掩码指定具有命名端点通道的帧中的音频采样之间的关联。 帧中的采样对应于通道位置掩码中指定的设置位,按升序顺序排列。 请参阅setChannelIndexMask(int)根据端点编号通道指定通道。 这Parameters channelMask int: describes the configuration of the audio channels.
For output, the channelMask can be an OR-ed combination of channel position masks, e.g. CHANNEL_OUT_FRONT_LEFT , CHANNEL_OUT_FRONT_RIGHT , CHANNEL_OUT_FRONT_CENTER , CHANNEL_OUT_LOW_FREQUENCY CHANNEL_OUT_BACK_LEFT , CHANNEL_OUT_BACK_RIGHT , CHANNEL_OUT_BACK_CENTER , CHANNEL_OUT_SIDE_LEFT , CHANNEL_OUT_SIDE_RIGHT 。
对于有效的AudioTrack频道位置掩码,以下条件适用:
(1)最多可以使用八个通道位置;
(2)应该匹配右/左对。
对于输入或AudioRecord ,掩码应为CHANNEL_IN_MONO或CHANNEL_IN_STEREO 。 CHANNEL_IN_MONO保证可以在所有设备上工作。
| 返回(Returns) | |
|---|---|
AudioFormat.Builder |
the same Builder instance. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the channel mask is invalid or if both channel index mask and channel position mask are specified but do not have the same channel count. |
AudioFormat.Builder setEncoding (int encoding)
设置数据编码格式。
| 参数(Parameters) | |
|---|---|
encoding |
int: one of ENCODING_DEFAULT, ENCODING_PCM_8BIT, ENCODING_PCM_16BIT, ENCODING_PCM_FLOAT, ENCODING_AC3, ENCODING_E_AC3. ENCODING_DTS, ENCODING_DTS_HD. |
| 返回(Returns) | |
|---|---|
AudioFormat.Builder |
the same Builder instance. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
|
AudioFormat.Builder setSampleRate (int sampleRate)
设置采样率。
| 参数(Parameters) | |
|---|---|
sampleRate |
int: the sample rate expressed in Hz |
| 返回(Returns) | |
|---|---|
AudioFormat.Builder |
the same Builder instance. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
|