0N/A/*
2362N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sound.sampled;
0N/A
0N/Aimport java.util.Collections;
0N/Aimport java.util.HashMap;
0N/Aimport java.util.Map;
0N/A
0N/A/**
0N/A * <code>AudioFormat</code> is the class that specifies a particular arrangement of data in a sound stream.
0N/A * By examing the information stored in the audio format, you can discover how to interpret the bits in the
0N/A * binary sound data.
0N/A * <p>
0N/A * Every data line has an audio format associated with its data stream. The audio format of a source (playback) data line indicates
0N/A * what kind of data the data line expects to receive for output. For a target (capture) data line, the audio format specifies the kind
0N/A * of the data that can be read from the line.
0N/A * Sound files also have audio formats, of course. The <code>{@link AudioFileFormat}</code>
0N/A * class encapsulates an <code>AudioFormat</code> in addition to other,
0N/A * file-specific information. Similarly, an <code>{@link AudioInputStream}</code> has an
0N/A * <code>AudioFormat</code>.
0N/A * <p>
0N/A * The <code>AudioFormat</code> class accommodates a number of common sound-file encoding techniques, including
0N/A * pulse-code modulation (PCM), mu-law encoding, and a-law encoding. These encoding techniques are predefined,
0N/A * but service providers can create new encoding types.
0N/A * The encoding that a specific format uses is named by its <code>encoding</code> field.
0N/A *<p>
0N/A * In addition to the encoding, the audio format includes other properties that further specify the exact
0N/A * arrangement of the data.
0N/A * These include the number of channels, sample rate, sample size, byte order, frame rate, and frame size.
0N/A * Sounds may have different numbers of audio channels: one for mono, two for stereo.
0N/A * The sample rate measures how many "snapshots" (samples) of the sound pressure are taken per second, per channel.
0N/A * (If the sound is stereo rather than mono, two samples are actually measured at each instant of time: one for the left channel,
0N/A * and another for the right channel; however, the sample rate still measures the number per channel, so the rate is the same
0N/A * regardless of the number of channels. This is the standard use of the term.)
0N/A * The sample size indicates how many bits are used to store each snapshot; 8 and 16 are typical values.
0N/A * For 16-bit samples (or any other sample size larger than a byte),
0N/A * byte order is important; the bytes in each sample are arranged in
0N/A * either the "little-endian" or "big-endian" style.
0N/A * For encodings like PCM, a frame consists of the set of samples for all channels at a given
0N/A * point in time, and so the size of a frame (in bytes) is always equal to the size of a sample (in bytes) times
0N/A * the number of channels. However, with some other sorts of encodings a frame can contain
0N/A * a bundle of compressed data for a whole series of samples, as well as additional, non-sample
0N/A * data. For such encodings, the sample rate and sample size refer to the data after it is decoded into PCM,
0N/A * and so they are completely different from the frame rate and frame size.
0N/A *
0N/A * <p>An <code>AudioFormat</code> object can include a set of
0N/A * properties. A property is a pair of key and value: the key
0N/A * is of type <code>String</code>, the associated property
0N/A * value is an arbitrary object. Properties specify
0N/A * additional format specifications, like the bit rate for
0N/A * compressed formats. Properties are mainly used as a means
0N/A * to transport additional information of the audio format
0N/A * to and from the service providers. Therefore, properties
0N/A * are ignored in the {@link #matches(AudioFormat)} method.
0N/A * However, methods which rely on the installed service
0N/A * providers, like {@link AudioSystem#isConversionSupported
0N/A * (AudioFormat, AudioFormat) isConversionSupported} may consider
0N/A * properties, depending on the respective service provider
0N/A * implementation.
0N/A *
0N/A * <p>The following table lists some common properties which
0N/A * service providers should use, if applicable:
0N/A *
0N/A * <table border=0>
0N/A * <tr>
0N/A * <th>Property key</th>
0N/A * <th>Value type</th>
0N/A * <th>Description</th>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>&quot;bitrate&quot;</td>
0N/A * <td>{@link java.lang.Integer Integer}</td>
0N/A * <td>average bit rate in bits per second</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>&quot;vbr&quot;</td>
0N/A * <td>{@link java.lang.Boolean Boolean}</td>
0N/A * <td><code>true</code>, if the file is encoded in variable bit
0N/A * rate (VBR)</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>&quot;quality&quot;</td>
0N/A * <td>{@link java.lang.Integer Integer}</td>
0N/A * <td>encoding/conversion quality, 1..100</td>
0N/A * </tr>
0N/A * </table>
0N/A *
0N/A * <p>Vendors of service providers (plugins) are encouraged
0N/A * to seek information about other already established
0N/A * properties in third party plugins, and follow the same
0N/A * conventions.
0N/A *
0N/A * @author Kara Kytle
1495N/A * @author Florian Bomers
1495N/A * @see DataLine#getFormat
1495N/A * @see AudioInputStream#getFormat
1495N/A * @see AudioFileFormat
1503N/A * @see javax.sound.sampled.spi.FormatConversionProvider
1495N/A * @since 1.3
0N/A */
1495N/Apublic class AudioFormat {
2259N/A
2259N/A // INSTANCE VARIABLES
2259N/A
0N/A
0N/A /**
4273N/A * The audio encoding technique used by this format.
4273N/A */
4273N/A protected Encoding encoding;
0N/A
0N/A /**
4273N/A * The number of samples played or recorded per second, for sounds that have this format.
0N/A */
1495N/A protected float sampleRate;
0N/A
0N/A /**
1495N/A * The number of bits in each sample of a sound that has this format.
0N/A */
0N/A protected int sampleSizeInBits;
0N/A
0N/A /**
0N/A * The number of audio channels in this format (1 for mono, 2 for stereo).
0N/A */
0N/A protected int channels;
0N/A
0N/A /**
0N/A * The number of bytes in each frame of a sound that has this format.
0N/A */
0N/A protected int frameSize;
0N/A
0N/A /**
0N/A * The number of frames played or recorded per second, for sounds that have this format.
0N/A */
0N/A protected float frameRate;
0N/A
0N/A /**
0N/A * Indicates whether the audio data is stored in big-endian or little-endian order.
0N/A */
0N/A protected boolean bigEndian;
0N/A
0N/A
0N/A /** The set of properties */
0N/A private HashMap<String, Object> properties;
0N/A
0N/A
0N/A /**
0N/A * Constructs an <code>AudioFormat</code> with the given parameters.
0N/A * The encoding specifies the convention used to represent the data.
0N/A * The other parameters are further explained in the {@link AudioFormat
0N/A * class description}.
0N/A * @param encoding the audio encoding technique
0N/A * @param sampleRate the number of samples per second
0N/A * @param sampleSizeInBits the number of bits in each sample
0N/A * @param channels the number of channels (1 for mono, 2 for stereo, and so on)
0N/A * @param frameSize the number of bytes in each frame
0N/A * @param frameRate the number of frames per second
0N/A * @param bigEndian indicates whether the data for a single sample
0N/A * is stored in big-endian byte order (<code>false</code>
0N/A * means little-endian)
0N/A */
0N/A public AudioFormat(Encoding encoding, float sampleRate, int sampleSizeInBits,
0N/A int channels, int frameSize, float frameRate, boolean bigEndian) {
0N/A
0N/A this.encoding = encoding;
0N/A this.sampleRate = sampleRate;
0N/A this.sampleSizeInBits = sampleSizeInBits;
0N/A this.channels = channels;
0N/A this.frameSize = frameSize;
0N/A this.frameRate = frameRate;
0N/A this.bigEndian = bigEndian;
0N/A this.properties = null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructs an <code>AudioFormat</code> with the given parameters.
0N/A * The encoding specifies the convention used to represent the data.
0N/A * The other parameters are further explained in the {@link AudioFormat
0N/A * class description}.
0N/A * @param encoding the audio encoding technique
0N/A * @param sampleRate the number of samples per second
0N/A * @param sampleSizeInBits the number of bits in each sample
0N/A * @param channels the number of channels (1 for mono, 2 for
0N/A * stereo, and so on)
0N/A * @param frameSize the number of bytes in each frame
0N/A * @param frameRate the number of frames per second
0N/A * @param bigEndian indicates whether the data for a single sample
0N/A * is stored in big-endian byte order
0N/A * (<code>false</code> means little-endian)
0N/A * @param properties a <code>Map&lt;String,Object&gt;</code> object
0N/A * containing format properties
0N/A *
0N/A * @since 1.5
0N/A */
0N/A public AudioFormat(Encoding encoding, float sampleRate,
0N/A int sampleSizeInBits, int channels,
0N/A int frameSize, float frameRate,
0N/A boolean bigEndian, Map<String, Object> properties) {
0N/A this(encoding, sampleRate, sampleSizeInBits, channels,
0N/A frameSize, frameRate, bigEndian);
0N/A this.properties = new HashMap<String, Object>(properties);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructs an <code>AudioFormat</code> with a linear PCM encoding and
0N/A * the given parameters. The frame size is set to the number of bytes
0N/A * required to contain one sample from each channel, and the frame rate
0N/A * is set to the sample rate.
0N/A *
0N/A * @param sampleRate the number of samples per second
0N/A * @param sampleSizeInBits the number of bits in each sample
0N/A * @param channels the number of channels (1 for mono, 2 for stereo, and so on)
0N/A * @param signed indicates whether the data is signed or unsigned
0N/A * @param bigEndian indicates whether the data for a single sample
0N/A * is stored in big-endian byte order (<code>false</code>
0N/A * means little-endian)
0N/A */
0N/A public AudioFormat(float sampleRate, int sampleSizeInBits,
0N/A int channels, boolean signed, boolean bigEndian) {
0N/A
0N/A this((signed == true ? Encoding.PCM_SIGNED : Encoding.PCM_UNSIGNED),
0N/A sampleRate,
0N/A sampleSizeInBits,
0N/A channels,
0N/A (channels == AudioSystem.NOT_SPECIFIED || sampleSizeInBits == AudioSystem.NOT_SPECIFIED)?
0N/A AudioSystem.NOT_SPECIFIED:
0N/A ((sampleSizeInBits + 7) / 8) * channels,
0N/A sampleRate,
0N/A bigEndian);
0N/A }
0N/A
0N/A /**
0N/A * Obtains the type of encoding for sounds in this format.
0N/A *
0N/A * @return the encoding type
0N/A * @see Encoding#PCM_SIGNED
0N/A * @see Encoding#PCM_UNSIGNED
0N/A * @see Encoding#ULAW
0N/A * @see Encoding#ALAW
0N/A */
252N/A public Encoding getEncoding() {
252N/A
0N/A return encoding;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the sample rate.
0N/A * For compressed formats, the return value is the sample rate of the uncompressed
0N/A * audio data.
0N/A * When this AudioFormat is used for queries (e.g. {@link
0N/A * AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
0N/A * AudioSystem.isConversionSupported}) or capabilities (e.g. {@link
0N/A * DataLine.Info#getFormats() DataLine.Info.getFormats}), a sample rate of
0N/A * <code>AudioSystem.NOT_SPECIFIED</code> means that any sample rate is
0N/A * acceptable. <code>AudioSystem.NOT_SPECIFIED</code> is also returned when
0N/A * the sample rate is not defined for this audio format.
0N/A * @return the number of samples per second,
0N/A * or <code>AudioSystem.NOT_SPECIFIED</code>
0N/A *
0N/A * @see #getFrameRate()
0N/A * @see AudioSystem#NOT_SPECIFIED
0N/A */
0N/A public float getSampleRate() {
0N/A
0N/A return sampleRate;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the size of a sample.
0N/A * For compressed formats, the return value is the sample size of the
0N/A * uncompressed audio data.
0N/A * When this AudioFormat is used for queries (e.g. {@link
0N/A * AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
0N/A * AudioSystem.isConversionSupported}) or capabilities (e.g. {@link
0N/A * DataLine.Info#getFormats() DataLine.Info.getFormats}), a sample size of
0N/A * <code>AudioSystem.NOT_SPECIFIED</code> means that any sample size is
0N/A * acceptable. <code>AudioSystem.NOT_SPECIFIED</code> is also returned when
0N/A * the sample size is not defined for this audio format.
0N/A * @return the number of bits in each sample,
0N/A * or <code>AudioSystem.NOT_SPECIFIED</code>
0N/A *
0N/A * @see #getFrameSize()
0N/A * @see AudioSystem#NOT_SPECIFIED
0N/A */
0N/A public int getSampleSizeInBits() {
0N/A
0N/A return sampleSizeInBits;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the number of channels.
0N/A * When this AudioFormat is used for queries (e.g. {@link
0N/A * AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
0N/A * AudioSystem.isConversionSupported}) or capabilities (e.g. {@link
0N/A * DataLine.Info#getFormats() DataLine.Info.getFormats}), a return value of
0N/A * <code>AudioSystem.NOT_SPECIFIED</code> means that any (positive) number of channels is
0N/A * acceptable.
0N/A * @return The number of channels (1 for mono, 2 for stereo, etc.),
0N/A * or <code>AudioSystem.NOT_SPECIFIED</code>
0N/A *
0N/A * @see AudioSystem#NOT_SPECIFIED
0N/A */
0N/A public int getChannels() {
0N/A
0N/A return channels;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the frame size in bytes.
0N/A * When this AudioFormat is used for queries (e.g. {@link
0N/A * AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
0N/A * AudioSystem.isConversionSupported}) or capabilities (e.g. {@link
0N/A * DataLine.Info#getFormats() DataLine.Info.getFormats}), a frame size of
0N/A * <code>AudioSystem.NOT_SPECIFIED</code> means that any frame size is
0N/A * acceptable. <code>AudioSystem.NOT_SPECIFIED</code> is also returned when
0N/A * the frame size is not defined for this audio format.
0N/A * @return the number of bytes per frame,
0N/A * or <code>AudioSystem.NOT_SPECIFIED</code>
0N/A *
0N/A * @see #getSampleSizeInBits()
0N/A * @see AudioSystem#NOT_SPECIFIED
0N/A */
0N/A public int getFrameSize() {
0N/A
0N/A return frameSize;
0N/A }
0N/A
0N/A /**
0N/A * Obtains the frame rate in frames per second.
0N/A * When this AudioFormat is used for queries (e.g. {@link
0N/A * AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
0N/A * AudioSystem.isConversionSupported}) or capabilities (e.g. {@link
0N/A * DataLine.Info#getFormats() DataLine.Info.getFormats}), a frame rate of
0N/A * <code>AudioSystem.NOT_SPECIFIED</code> means that any frame rate is
0N/A * acceptable. <code>AudioSystem.NOT_SPECIFIED</code> is also returned when
0N/A * the frame rate is not defined for this audio format.
0N/A * @return the number of frames per second,
0N/A * or <code>AudioSystem.NOT_SPECIFIED</code>
0N/A *
0N/A * @see #getSampleRate()
0N/A * @see AudioSystem#NOT_SPECIFIED
0N/A */
0N/A public float getFrameRate() {
0N/A
0N/A return frameRate;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the audio data is stored in big-endian or little-endian
0N/A * byte order. If the sample size is not more than one byte, the return value is
0N/A * irrelevant.
0N/A * @return <code>true</code> if the data is stored in big-endian byte order,
0N/A * <code>false</code> if little-endian
0N/A */
0N/A public boolean isBigEndian() {
0N/A
0N/A return bigEndian;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtain an unmodifiable map of properties.
0N/A * The concept of properties is further explained in
0N/A * the {@link AudioFileFormat class description}.
0N/A *
0N/A * @return a <code>Map&lt;String,Object&gt;</code> object containing
0N/A * all properties. If no properties are recognized, an empty map is
0N/A * returned.
0N/A *
0N/A * @see #getProperty(String)
0N/A * @since 1.5
0N/A */
0N/A public Map<String,Object> properties() {
0N/A Map<String,Object> ret;
0N/A if (properties == null) {
0N/A ret = new HashMap<String,Object>(0);
0N/A } else {
0N/A ret = (Map<String,Object>) (properties.clone());
0N/A }
0N/A return (Map<String,Object>) Collections.unmodifiableMap(ret);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtain the property value specified by the key.
0N/A * The concept of properties is further explained in
0N/A * the {@link AudioFileFormat class description}.
0N/A *
0N/A * <p>If the specified property is not defined for a
0N/A * particular file format, this method returns
0N/A * <code>null</code>.
0N/A *
0N/A * @param key the key of the desired property
0N/A * @return the value of the property with the specified key,
0N/A * or <code>null</code> if the property does not exist.
0N/A *
0N/A * @see #properties()
0N/A * @since 1.5
0N/A */
0N/A public Object getProperty(String key) {
0N/A if (properties == null) {
0N/A return null;
0N/A }
0N/A return properties.get(key);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicates whether this format matches the one specified.
0N/A * To match, two formats must have the same encoding,
0N/A * and consistent values of the number of channels, sample rate, sample size,
0N/A * frame rate, and frame size.
0N/A * The values of the property are consistent if they are equal
0N/A * or the specified format has the property value
0N/A * {@code AudioSystem.NOT_SPECIFIED}.
0N/A * The byte order (big-endian or little-endian) must be the same
0N/A * if the sample size is greater than one byte.
0N/A *
0N/A * @param format format to test for match
0N/A * @return {@code true} if this format matches the one specified,
0N/A * {@code false} otherwise.
0N/A */
0N/A public boolean matches(AudioFormat format) {
0N/A if (format.getEncoding().equals(getEncoding())
0N/A && (format.getChannels() == AudioSystem.NOT_SPECIFIED
0N/A || format.getChannels() == getChannels())
0N/A && (format.getSampleRate() == (float)AudioSystem.NOT_SPECIFIED
0N/A || format.getSampleRate() == getSampleRate())
0N/A && (format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED
0N/A || format.getSampleSizeInBits() == getSampleSizeInBits())
0N/A && (format.getFrameRate() == (float)AudioSystem.NOT_SPECIFIED
0N/A || format.getFrameRate() == getFrameRate())
0N/A && (format.getFrameSize() == AudioSystem.NOT_SPECIFIED
0N/A || format.getFrameSize() == getFrameSize())
0N/A && (getSampleSizeInBits() <= 8
0N/A || format.isBigEndian() == isBigEndian())) {
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string that describes the format, such as:
0N/A * "PCM SIGNED 22050 Hz 16 bit mono big-endian". The contents of the string
0N/A * may vary between implementations of Java Sound.
0N/A *
0N/A * @return a string that describes the format parameters
0N/A */
0N/A public String toString() {
0N/A String sEncoding = "";
0N/A if (getEncoding() != null) {
0N/A sEncoding = getEncoding().toString() + " ";
0N/A }
0N/A
0N/A String sSampleRate;
0N/A if (getSampleRate() == (float) AudioSystem.NOT_SPECIFIED) {
0N/A sSampleRate = "unknown sample rate, ";
0N/A } else {
0N/A sSampleRate = "" + getSampleRate() + " Hz, ";
0N/A }
0N/A
0N/A String sSampleSizeInBits;
0N/A if (getSampleSizeInBits() == (float) AudioSystem.NOT_SPECIFIED) {
0N/A sSampleSizeInBits = "unknown bits per sample, ";
0N/A } else {
0N/A sSampleSizeInBits = "" + getSampleSizeInBits() + " bit, ";
0N/A }
0N/A
0N/A String sChannels;
0N/A if (getChannels() == 1) {
0N/A sChannels = "mono, ";
0N/A } else
0N/A if (getChannels() == 2) {
0N/A sChannels = "stereo, ";
0N/A } else {
0N/A if (getChannels() == AudioSystem.NOT_SPECIFIED) {
0N/A sChannels = " unknown number of channels, ";
0N/A } else {
0N/A sChannels = ""+getChannels()+" channels, ";
0N/A }
0N/A }
0N/A
0N/A String sFrameSize;
0N/A if (getFrameSize() == (float) AudioSystem.NOT_SPECIFIED) {
0N/A sFrameSize = "unknown frame size, ";
0N/A } else {
0N/A sFrameSize = "" + getFrameSize()+ " bytes/frame, ";
0N/A }
0N/A
0N/A String sFrameRate = "";
0N/A if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) {
0N/A if (getFrameRate() == (float) AudioSystem.NOT_SPECIFIED) {
0N/A sFrameRate = "unknown frame rate, ";
0N/A } else {
0N/A sFrameRate = getFrameRate() + " frames/second, ";
0N/A }
0N/A }
0N/A
0N/A String sEndian = "";
0N/A if ((getEncoding().equals(Encoding.PCM_SIGNED)
0N/A || getEncoding().equals(Encoding.PCM_UNSIGNED))
0N/A && ((getSampleSizeInBits() > 8)
0N/A || (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) {
0N/A if (isBigEndian()) {
0N/A sEndian = "big-endian";
0N/A } else {
0N/A sEndian = "little-endian";
0N/A }
0N/A }
0N/A
0N/A return sEncoding
0N/A + sSampleRate
0N/A + sSampleSizeInBits
0N/A + sChannels
0N/A + sFrameSize
0N/A + sFrameRate
0N/A + sEndian;
0N/A
0N/A }
0N/A
0N/A /**
0N/A * The <code>Encoding</code> class names the specific type of data representation
0N/A * used for an audio stream. The encoding includes aspects of the
0N/A * sound format other than the number of channels, sample rate, sample size,
0N/A * frame rate, frame size, and byte order.
0N/A * <p>
0N/A * One ubiquitous type of audio encoding is pulse-code modulation (PCM),
0N/A * which is simply a linear (proportional) representation of the sound
0N/A * waveform. With PCM, the number stored in each sample is proportional
0N/A * to the instantaneous amplitude of the sound pressure at that point in
0N/A * time. The numbers may be signed or unsigned integers or floats.
0N/A * Besides PCM, other encodings include mu-law and a-law, which are nonlinear
0N/A * mappings of the sound amplitude that are often used for recording speech.
0N/A * <p>
0N/A * You can use a predefined encoding by referring to one of the static
0N/A * objects created by this class, such as PCM_SIGNED or
0N/A * PCM_UNSIGNED. Service providers can create new encodings, such as
0N/A * compressed audio formats, and make
2259N/A * these available through the <code>{@link AudioSystem}</code> class.
2259N/A * <p>
2259N/A * The <code>Encoding</code> class is static, so that all
0N/A * <code>AudioFormat</code> objects that have the same encoding will refer
0N/A * to the same object (rather than different instances of the same class).
0N/A * This allows matches to be made by checking that two format's encodings
0N/A * are equal.
2259N/A *
0N/A * @see AudioFormat
2259N/A * @see javax.sound.sampled.spi.FormatConversionProvider
0N/A *
0N/A * @author Kara Kytle
0N/A * @since 1.3
0N/A */
0N/A public static class Encoding {
0N/A
0N/A
2259N/A // ENCODING DEFINES
0N/A
2259N/A /**
0N/A * Specifies signed, linear PCM data.
0N/A */
0N/A public static final Encoding PCM_SIGNED = new Encoding("PCM_SIGNED");
0N/A
0N/A /**
0N/A * Specifies unsigned, linear PCM data.
0N/A */
0N/A public static final Encoding PCM_UNSIGNED = new Encoding("PCM_UNSIGNED");
0N/A
0N/A /**
0N/A * Specifies floating-point PCM data.
0N/A *
0N/A * @since 1.7
0N/A */
0N/A public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
0N/A
0N/A /**
0N/A * Specifies u-law encoded data.
0N/A */
0N/A public static final Encoding ULAW = new Encoding("ULAW");
0N/A
0N/A /**
0N/A * Specifies a-law encoded data.
0N/A */
0N/A public static final Encoding ALAW = new Encoding("ALAW");
0N/A
0N/A
0N/A // INSTANCE VARIABLES
0N/A
0N/A /**
0N/A * Encoding name.
0N/A */
0N/A private String name;
0N/A
0N/A
0N/A // CONSTRUCTOR
2259N/A
2259N/A /**
2259N/A * Constructs a new encoding.
2259N/A * @param name the name of the new type of encoding
2259N/A */
2259N/A public Encoding(String name) {
2259N/A this.name = name;
0N/A }
0N/A
0N/A
2259N/A // METHODS
2259N/A
2259N/A /**
2259N/A * Finalizes the equals method
2259N/A */
2259N/A public final boolean equals(Object obj) {
2259N/A if (toString() == null) {
2259N/A return (obj != null) && (obj.toString() == null);
2259N/A }
0N/A if (obj instanceof Encoding) {
0N/A return toString().equals(obj.toString());
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Finalizes the hashCode method
0N/A */
0N/A public final int hashCode() {
0N/A if (toString() == null) {
0N/A return 0;
0N/A }
0N/A return toString().hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Provides the <code>String</code> representation of the encoding. This <code>String</code> is
0N/A * the same name that was passed to the constructor. For the predefined encodings, the name
0N/A * is similar to the encoding's variable (field) name. For example, <code>PCM_SIGNED.toString()</code> returns
0N/A * the name "pcm_signed".
0N/A *
0N/A * @return the encoding name
0N/A */
0N/A public final String toString() {
0N/A return name;
0N/A }
0N/A
0N/A } // class Encoding
0N/A}
0N/A