public class TarsosDSPAudioFormat
extends java.lang.Object
AudioFormat
is the class that specifies a particular arrangement of data in a sound stream.
By examing the information stored in the audio format, you can discover how to interpret the bits in the
binary sound data.
Every data LineWavelet has an audio format associated with its data stream. The audio format of a source (playback) data LineWavelet indicates what kind of data the data LineWavelet expects to receive for output. For a target (capture) data LineWavelet, the audio format specifies the kind of the data that can be read from the LineWavelet. Sound files also have audio formats, of course.
The AudioFormat
class accommodates a number of common sound-file encoding techniques, including
pulse-code modulation (PCM), mu-law encoding, and a-law encoding. These encoding techniques are predefined,
but service providers can create new encoding types.
The encoding that a specific format uses is named by its encoding
field.
In addition to the encoding, the audio format includes other properties that further specify the exact arrangement of the data. These include the number of channels, sample rate, sample size, byte order, frame rate, and frame size. Sounds may have different numbers of audio channels: one for mono, two for stereo. The sample rate measures how many "snapshots" (samples) of the sound pressure are taken per second, per channel. (If the sound is stereo rather than mono, two samples are actually measured at each instant of time: one for the left channel, and another for the right channel; however, the sample rate still measures the number per channel, so the rate is the same regardless of the number of channels. This is the standard use of the term.) The sample size indicates how many bits are used to store each snapshot; 8 and 16 are typical values. For 16-bit samples (or any other sample size larger than a byte), byte order is important; the bytes in each sample are arranged in either the "little-endian" or "big-endian" style. For encodings like PCM, a frame consists of the set of samples for all channels at a given point in time, and so the size of a frame (in bytes) is always equal to the size of a sample (in bytes) times the number of channels. However, with some other sorts of encodings a frame can contain a bundle of compressed data for a whole series of samples, as well as additional, non-sample data. For such encodings, the sample rate and sample size refer to the data after it is decoded into PCM, and so they are completely different from the frame rate and frame size.
An AudioFormat
object can include a set of
properties. A property is a pair of key and value: the key
is of type String
, the associated property
value is an arbitrary object. Properties specify
additional format specifications, like the bit rate for
compressed formats. Properties are mainly used as a means
to transport additional information of the audio format
to and from the service providers. Therefore, properties
are ignored in the AudioFormat method.
The following table lists some common properties which service providers should use, if applicable:
Property key | Value type | Description |
---|---|---|
"bitrate" | Integer |
average bit rate in bits per second |
"vbr" | Boolean |
true , if the file is encoded in variable bit
rate (VBR) |
"quality" | Integer |
encoding/conversion quality, 1..100 |
Vendors of service providers (plugins) are encouraged to seek information about other already established properties in third party plugins, and follow the same conventions.
Modifier and Type | Class and Description |
---|---|
static class |
TarsosDSPAudioFormat.Encoding
The
Encoding class names the specific type of data representation
used for an audio stream. |
Modifier and Type | Field and Description |
---|---|
static int |
NOT_SPECIFIED |
Constructor and Description |
---|
TarsosDSPAudioFormat(float sampleRate,
int sampleSizeInBits,
int channels,
boolean signed,
boolean bigEndian)
Constructs an
AudioFormat with a linear PCM encoding and
the given parameters. |
TarsosDSPAudioFormat(TarsosDSPAudioFormat.Encoding encoding,
float sampleRate,
int sampleSizeInBits,
int channels,
int frameSize,
float frameRate,
boolean bigEndian)
Constructs an
AudioFormat with the given parameters. |
TarsosDSPAudioFormat(TarsosDSPAudioFormat.Encoding encoding,
float sampleRate,
int sampleSizeInBits,
int channels,
int frameSize,
float frameRate,
boolean bigEndian,
java.util.Map<java.lang.String,java.lang.Object> properties)
Constructs an
AudioFormat with the given parameters. |
Modifier and Type | Method and Description |
---|---|
int |
getChannels()
Obtains the number of channels.
|
TarsosDSPAudioFormat.Encoding |
getEncoding()
Obtains the type of encoding for sounds in this format.
|
float |
getFrameRate()
Obtains the frame rate in frames per second.
|
int |
getFrameSize()
Obtains the frame size in bytes.
|
java.lang.Object |
getProperty(java.lang.String key)
Obtain the property value specified by the key.
|
float |
getSampleRate()
Obtains the sample rate.
|
int |
getSampleSizeInBits()
Obtains the size of a sample.
|
boolean |
isBigEndian()
Indicates whether the audio data is stored in big-endian or little-endian
byte order.
|
boolean |
matches(TarsosDSPAudioFormat format)
Indicates whether this format matches the one specified.
|
java.util.Map<java.lang.String,java.lang.Object> |
properties()
Obtain an unmodifiable map of properties.
|
java.lang.String |
toString()
Returns a string that describes the format, such as:
"PCM SIGNED 22050 Hz 16 bit mono big-endian".
|
public static final int NOT_SPECIFIED
public TarsosDSPAudioFormat(TarsosDSPAudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian)
AudioFormat
with the given parameters.
The encoding specifies the convention used to represent the data.
The other parameters are further explained in theencoding
- the audio encoding techniquesampleRate
- the number of samples per secondsampleSizeInBits
- the number of bits in each samplechannels
- the number of channels (1 for mono, 2 for stereo, and so on)frameSize
- the number of bytes in each frameframeRate
- the number of frames per secondbigEndian
- indicates whether the data for a single sample
is stored in big-endian byte order (false
means little-endian)public TarsosDSPAudioFormat(TarsosDSPAudioFormat.Encoding encoding, float sampleRate, int sampleSizeInBits, int channels, int frameSize, float frameRate, boolean bigEndian, java.util.Map<java.lang.String,java.lang.Object> properties)
AudioFormat
with the given parameters.
The encoding specifies the convention used to represent the data.
The other parameters are further explained in theencoding
- the audio encoding techniquesampleRate
- the number of samples per secondsampleSizeInBits
- the number of bits in each samplechannels
- the number of channels (1 for mono, 2 for
stereo, and so on)frameSize
- the number of bytes in each frameframeRate
- the number of frames per secondbigEndian
- indicates whether the data for a single sample
is stored in big-endian byte order
(false
means little-endian)properties
- a Map<String,Object>
object
containing format propertiespublic TarsosDSPAudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
AudioFormat
with a linear PCM encoding and
the given parameters. The frame size is set to the number of bytes
required to contain one sample from each channel, and the frame rate
is set to the sample rate.sampleRate
- the number of samples per secondsampleSizeInBits
- the number of bits in each samplechannels
- the number of channels (1 for mono, 2 for stereo, and so on)signed
- indicates whether the data is signed or unsignedbigEndian
- indicates whether the data for a single sample
is stored in big-endian byte order (false
means little-endian)public TarsosDSPAudioFormat.Encoding getEncoding()
TarsosDSPAudioFormat.Encoding.PCM_SIGNED
,
TarsosDSPAudioFormat.Encoding.PCM_UNSIGNED
,
TarsosDSPAudioFormat.Encoding.ULAW
,
TarsosDSPAudioFormat.Encoding.ALAW
public float getSampleRate()
AudioSystem.NOT_SPECIFIED
means that any sample rate is
acceptable. AudioSystem.NOT_SPECIFIED
is also returned when
the sample rate is not defined for this audio format.AudioSystem.NOT_SPECIFIED
getFrameRate()
public int getSampleSizeInBits()
AudioSystem.NOT_SPECIFIED
means that any sample size is
acceptable. AudioSystem.NOT_SPECIFIED
is also returned when
the sample size is not defined for this audio format.AudioSystem.NOT_SPECIFIED
getFrameSize()
public int getChannels()
AudioSystem.NOT_SPECIFIED
means that any (positive) number of channels is
acceptable.AudioSystem.NOT_SPECIFIED
public int getFrameSize()
AudioSystem.NOT_SPECIFIED
means that any frame size is
acceptable. AudioSystem.NOT_SPECIFIED
is also returned when
the frame size is not defined for this audio format.AudioSystem.NOT_SPECIFIED
getSampleSizeInBits()
public float getFrameRate()
AudioSystem.NOT_SPECIFIED
means that any frame rate is
acceptable. AudioSystem.NOT_SPECIFIED
is also returned when
the frame rate is not defined for this audio format.AudioSystem.NOT_SPECIFIED
getSampleRate()
public boolean isBigEndian()
true
if the data is stored in big-endian byte order,
false
if little-endianpublic java.util.Map<java.lang.String,java.lang.Object> properties()
Map<String,Object>
object containing
all properties. If no properties are recognized, an empty map is
returned.getProperty(String)
public java.lang.Object getProperty(java.lang.String key)
If the specified property is not defined for a
particular file format, this method returns
null
.
key
- the key of the desired propertynull
if the property does not exist.properties()
public boolean matches(TarsosDSPAudioFormat format)
AudioSystem.NOT_SPECIFIED
,
which any sample rate will match. The frame rates must
similarly be equal, unless the specified format has the frame rate
value AudioSystem.NOT_SPECIFIED
. The byte order (big-endian or little-endian)
must match if the sample size is greater than one byte.format
- format to test for matchtrue
if this format matches the one specified,
false
otherwise.public java.lang.String toString()
toString
in class java.lang.Object