AudioFormat.Builder
public
static
class
AudioFormat.Builder
extends Object
java.lang.Object | |
↳ | android.media.AudioFormat.Builder |
Builder class for AudioFormat
objects.
Use this class to configure and create an AudioFormat instance. By setting format
characteristics such as audio encoding, channel mask or sample rate, you indicate which
of those are to vary from the default behavior on this device wherever this audio format
is used. See AudioFormat
for a complete description of the different parameters that
can be used to configure an AudioFormat
instance.
AudioFormat
is for instance used in
AudioTrack.AudioTrack(AudioAttributes, AudioFormat, int, int, int)
. In this
constructor, every format characteristic set on the Builder
(e.g. with
setSampleRate(int)
) will alter the default values used by an
AudioTrack
. In this case for audio playback with AudioTrack
, the
sample rate set in the Builder
would override the platform output sample rate
which would otherwise be selected by default.
Summary
Public constructors | |
---|---|
Builder()
Constructs a new Builder with none of the format characteristics set. |
|
Builder(AudioFormat af)
Constructs a new Builder from a given |
Public methods | |
---|---|
AudioFormat
|
build()
Combines all of the format characteristics that have been set and return a new
|
AudioFormat.Builder
|
setChannelIndexMask(int channelIndexMask)
Sets the channel index mask. |
AudioFormat.Builder
|
setChannelMask(int channelMask)
Sets the channel position mask. |
AudioFormat.Builder
|
setEncoding(int encoding)
Sets the data encoding format. |
AudioFormat.Builder
|
setSampleRate(int sampleRate)
Sets the sample rate. |
Inherited methods | |
---|---|
Public constructors
Builder
public Builder ()
Constructs a new Builder with none of the format characteristics set.
Builder
public Builder (AudioFormat af)
Constructs a new Builder from a given AudioFormat
.
Parameters | |
---|---|
af |
AudioFormat : the AudioFormat object whose data will be reused in the new Builder. |
Public methods
build
public AudioFormat build ()
Combines all of the format characteristics that have been set and return a new
AudioFormat
object.
Returns | |
---|---|
AudioFormat |
a new AudioFormat object |
setChannelIndexMask
public AudioFormat.Builder setChannelIndexMask (int channelIndexMask)
Sets the channel index mask. A channel index mask specifies the association of audio samples in the frame with numbered endpoint channels. The i-th bit in the channel index mask corresponds to the i-th endpoint channel. For example, an endpoint with four channels is represented as index mask bits 0 through 3. This setChannelMask(int) for a positional mask interpretation.
Both AudioTrack
and AudioRecord
support
a channel index mask.
If a channel index mask is specified it is used,
otherwise the channel position mask specified
by setChannelMask
is used.
For AudioTrack
and AudioRecord
,
a channel position mask is not required if a channel index mask is specified.
Parameters | |
---|---|
channelIndexMask |
int : describes the configuration of the audio channels.
For output, the For input, the |
Returns | |
---|---|
AudioFormat.Builder |
the same Builder instance.
This value cannot be null . |
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. |
setChannelMask
public AudioFormat.Builder setChannelMask (int channelMask)
Sets the channel position mask.
The channel position mask specifies the association between audio samples in a frame
with named endpoint channels. The samples in the frame correspond to the
named set bits in the channel position mask, in ascending bit order.
See setChannelIndexMask(int)
to specify channels
based on endpoint numbered channels. This description of
channel position masks covers the concept in more details.
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.
For output or For input or |
Returns | |
---|---|
AudioFormat.Builder |
the same Builder instance.
This value cannot be null . |
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. |
setEncoding
public AudioFormat.Builder setEncoding (int encoding)
Sets the data encoding format.
Returns | |
---|---|
AudioFormat.Builder |
the same Builder instance. |
Throws | |
---|---|
|
java.lang.IllegalArgumentException |
IllegalArgumentException |
setSampleRate
public AudioFormat.Builder setSampleRate (int sampleRate)
Sets the sample rate.
Parameters | |
---|---|
sampleRate |
int : the sample rate expressed in Hz |
Returns | |
---|---|
AudioFormat.Builder |
the same Builder instance. |
Throws | |
---|---|
|
java.lang.IllegalArgumentException |
IllegalArgumentException |