javax.sound.sampled

Class AudioFormat

public class AudioFormat extends Object

This class describes an audio format, including its encoding, the number of channels, its frame rate, etc.

Since: 1.3

Nested Class Summary
static classAudioFormat.Encoding
This describes a given audio format encoding.
Field Summary
protected booleanbigEndian
True if the audio data is stored big-endian.
protected intchannels
The number of channels of data in this format.
protected AudioFormat.Encodingencoding
The encoding of this format.
protected floatframeRate
The frame rate of this format.
protected intframeSize
The number of bytes per frame in this format.
protected floatsampleRate
The number of samples per second.
protected intsampleSizeInBits
The number of bits in each sample.
Constructor Summary
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
Create a new audio format, given various attributes of it.
AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, Map<String,Object> properties)
Create a new audio format, given various attributes of it.
AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
Create a new PCM-based audio format, given various attributes of it.
Method Summary
intgetChannels()
Return the number of channels in this format.
AudioFormat.EncodinggetEncoding()
Return the encoding of this format.
floatgetFrameRate()
Return the frame rate of this format.
intgetFrameSize()
Return the frame size of this format.
ObjectgetProperty(String key)
Given a key, return a property associated with this format; or null if this property is not set.
floatgetSampleRate()
Return the sample rate of this format.
intgetSampleSizeInBits()
Return the sample size of this format, in bits.
booleanisBigEndian()
Return true if this format is big endian, false otherwise.
booleanmatches(AudioFormat fmt)
Return true if this audio format matches another.
Map<String,Object>properties()
Return a read-only Map holding the properties associated with this format.
StringtoString()
Return a description of this format.

Field Detail

bigEndian

protected boolean bigEndian
True if the audio data is stored big-endian.

channels

protected int channels
The number of channels of data in this format.

encoding

protected AudioFormat.Encoding encoding
The encoding of this format.

frameRate

protected float frameRate
The frame rate of this format. This is the number of frames per second.

frameSize

protected int frameSize
The number of bytes per frame in this format.

sampleRate

protected float sampleRate
The number of samples per second.

sampleSizeInBits

protected int sampleSizeInBits
The number of bits in each sample.

Constructor Detail

AudioFormat

public AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
Create a new audio format, given various attributes of it. The properties map for this format will be empty.

Parameters: encoding the encoding for this format sampleRate the sample rate sampleSizeInBits the sample size, in bits channels the number of channels frameSize the frame size, in bytes frameRate the frame rate, in frames per second bigEndian true if the data is stored big-endian

AudioFormat

public AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, Map<String,Object> properties)
Create a new audio format, given various attributes of it. The properties map is copied by this constructor, so changes to the argument Map will not affect the new object.

Parameters: encoding the encoding for this format sampleRate the sample rate sampleSizeInBits the sample size, in bits channels the number of channels frameSize the frame size, in bytes frameRate the frame rate, in frames per second bigEndian true if the data is stored big-endian properties a map describing properties of this format

AudioFormat

public AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
Create a new PCM-based audio format, given various attributes of it. The encoding will either be Encoding#PCM_SIGNED or Encoding#PCM_UNSIGNED. The frame size for this format will be derived from the sample size in bits and the number of channels, unless one of those is AudioSystem#NOT_SPECIFIED. The frame rate will be the same as the sample rate, and the properties map will be empty.

Parameters: sampleRate the sample rate sampleSizeInBits the sample size, in bits channels the number of channels signed true if this is a signed encoding bigEndian true if the data is stored big-endian

Method Detail

getChannels

public int getChannels()
Return the number of channels in this format.

getEncoding

public AudioFormat.Encoding getEncoding()
Return the encoding of this format.

getFrameRate

public float getFrameRate()
Return the frame rate of this format.

getFrameSize

public int getFrameSize()
Return the frame size of this format.

getProperty

public Object getProperty(String key)
Given a key, return a property associated with this format; or null if this property is not set.

Parameters: key the name of the property

Returns: the value of the property, or null if the property is not set

getSampleRate

public float getSampleRate()
Return the sample rate of this format.

getSampleSizeInBits

public int getSampleSizeInBits()
Return the sample size of this format, in bits.

isBigEndian

public boolean isBigEndian()
Return true if this format is big endian, false otherwise. This only matters for formats whose sample size is greater than one byte.

matches

public boolean matches(AudioFormat fmt)
Return true if this audio format matches another.

Parameters: fmt the format to match against

Returns: true if they match, false otherwise

properties

public Map<String,Object> properties()
Return a read-only Map holding the properties associated with this format.

toString

public String toString()
Return a description of this format.