jdk/src/share/classes/javax/sound/sampled/AudioFormat.java
author darcy
Thu, 05 Jun 2014 23:17:05 -0700
changeset 25131 49006bd0e69d
parent 25128 2dfdfa369071
permissions -rw-r--r--
8044553: Fix raw and unchecked lint warnings in javax.sound.* Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.sampled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    33
 * {@code AudioFormat} is the class that specifies a particular arrangement of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    34
 * data in a sound stream. By examining the information stored in the audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    35
 * format, you can discover how to interpret the bits in the binary sound data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    37
 * Every data line has an audio format associated with its data stream. The
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    38
 * audio format of a source (playback) data line indicates what kind of data the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    39
 * data line expects to receive for output. For a target (capture) data line,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    40
 * the audio format specifies the kind of the data that can be read from the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    41
 * line.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    42
 * Sound files also have audio formats, of course. The {@link AudioFileFormat}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    43
 * class encapsulates an {@code AudioFormat} in addition to other, file-specific
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    44
 * information. Similarly, an {@link AudioInputStream} has an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    45
 * {@code AudioFormat}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    46
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    47
 * The {@code AudioFormat} class accommodates a number of common sound-file
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    48
 * encoding techniques, including pulse-code modulation (PCM), mu-law encoding,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    49
 * and a-law encoding. These encoding techniques are predefined, but service
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    50
 * providers can create new encoding types. The encoding that a specific format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    51
 * uses is named by its {@code encoding} field.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    53
 * In addition to the encoding, the audio format includes other properties that
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    54
 * further specify the exact arrangement of the data. These include the number
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    55
 * of channels, sample rate, sample size, byte order, frame rate, and frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    56
 * size. Sounds may have different numbers of audio channels: one for mono, two
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    57
 * for stereo. The sample rate measures how many "snapshots" (samples) of the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    58
 * sound pressure are taken per second, per channel. (If the sound is stereo
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    59
 * rather than mono, two samples are actually measured at each instant of time:
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    60
 * one for the left channel, and another for the right channel; however, the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    61
 * sample rate still measures the number per channel, so the rate is the same
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    62
 * regardless of the number of channels. This is the standard use of the term.)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    63
 * The sample size indicates how many bits are used to store each snapshot; 8
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    64
 * and 16 are typical values. For 16-bit samples (or any other sample size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    65
 * larger than a byte), byte order is important; the bytes in each sample are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    66
 * arranged in either the "little-endian" or "big-endian" style. For encodings
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    67
 * like PCM, a frame consists of the set of samples for all channels at a given
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    68
 * point in time, and so the size of a frame (in bytes) is always equal to the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    69
 * size of a sample (in bytes) times the number of channels. However, with some
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    70
 * other sorts of encodings a frame can contain a bundle of compressed data for
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    71
 * a whole series of samples, as well as additional, non-sample data. For such
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    72
 * encodings, the sample rate and sample size refer to the data after it is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    73
 * decoded into PCM, and so they are completely different from the frame rate
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    74
 * and frame size.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    75
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    76
 * An {@code AudioFormat} object can include a set of properties. A property is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    77
 * a pair of key and value: the key is of type {@code String}, the associated
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    78
 * property value is an arbitrary object. Properties specify additional format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    79
 * specifications, like the bit rate for compressed formats. Properties are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    80
 * mainly used as a means to transport additional information of the audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    81
 * format to and from the service providers. Therefore, properties are ignored
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    82
 * in the {@link #matches(AudioFormat)} method. However, methods which rely on
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    83
 * the installed service providers, like
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    84
 * {@link AudioSystem#isConversionSupported (AudioFormat, AudioFormat)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    85
 * isConversionSupported} may consider properties, depending on the respective
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    86
 * service provider implementation.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    87
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    88
 * The following table lists some common properties which service providers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    89
 * should use, if applicable:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <table border=0>
20117
44caeeb854dd 8023042: Inaccuracy in documentation in a sound area
serb
parents: 19207
diff changeset
    92
 *  <caption>Audio Format Properties</caption>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   <th>Property key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *   <th>Value type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   <td>&quot;bitrate&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   <td>{@link java.lang.Integer Integer}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   <td>average bit rate in bits per second</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *   <td>&quot;vbr&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *   <td>{@link java.lang.Boolean Boolean}</td>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   106
 *   <td>{@code true}, if the file is encoded in variable bit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *       rate (VBR)</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *   <td>&quot;quality&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *   <td>{@link java.lang.Integer Integer}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *   <td>encoding/conversion quality, 1..100</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * </table>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   115
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   116
 * Vendors of service providers (plugins) are encouraged to seek information
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   117
 * about other already established properties in third party plugins, and follow
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   118
 * the same conventions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @see DataLine#getFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see AudioInputStream#getFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see AudioFileFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @see javax.sound.sampled.spi.FormatConversionProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
public class AudioFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The audio encoding technique used by this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    protected Encoding encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   136
     * The number of samples played or recorded per second, for sounds that have
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   137
     * this format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected float sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The number of bits in each sample of a sound that has this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected int sampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * The number of audio channels in this format (1 for mono, 2 for stereo).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected int channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * The number of bytes in each frame of a sound that has this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected int frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   157
     * The number of frames played or recorded per second, for sounds that have
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   158
     * this format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected float frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   163
     * Indicates whether the audio data is stored in big-endian or little-endian
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   164
     * order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected boolean bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   168
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   169
     * The set of properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   170
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private HashMap<String, Object> properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   174
     * Constructs an {@code AudioFormat} with the given parameters. The encoding
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   175
     * specifies the convention used to represent the data. The other parameters
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   176
     * are further explained in the {@link AudioFormat class description}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   177
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   178
     * @param  encoding the audio encoding technique
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   179
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   180
     * @param  sampleSizeInBits the number of bits in each sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   181
     * @param  channels the number of channels (1 for mono, 2 for stereo,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   182
     *         and so on)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   183
     * @param  frameSize the number of bytes in each frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   184
     * @param  frameRate the number of frames per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   185
     * @param  bigEndian indicates whether the data for a single sample is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   186
     *         stored in big-endian byte order ({@code false} means
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   187
     *         little-endian)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public AudioFormat(Encoding encoding, float sampleRate, int sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                       int channels, int frameSize, float frameRate, boolean bigEndian) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        this.sampleRate = sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.sampleSizeInBits = sampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        this.channels = channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        this.frameSize = frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        this.frameRate = frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.bigEndian = bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.properties = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   203
     * Constructs an {@code AudioFormat} with the given parameters. The encoding
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   204
     * specifies the convention used to represent the data. The other parameters
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   205
     * are further explained in the {@link AudioFormat class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   207
     * @param  encoding the audio encoding technique
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   208
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   209
     * @param  sampleSizeInBits the number of bits in each sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   210
     * @param  channels the number of channels (1 for mono, 2 for stereo, and so
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   211
     *         on)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   212
     * @param  frameSize the number of bytes in each frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   213
     * @param  frameRate the number of frames per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   214
     * @param  bigEndian indicates whether the data for a single sample is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   215
     *         stored in big-endian byte order ({@code false} means little-endian)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   216
     * @param  properties a {@code Map<String, Object>} object containing format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   217
     *         properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public AudioFormat(Encoding encoding, float sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                       int sampleSizeInBits, int channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                       int frameSize, float frameRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                       boolean bigEndian, Map<String, Object> properties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this(encoding, sampleRate, sampleSizeInBits, channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
             frameSize, frameRate, bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        this.properties = new HashMap<String, Object>(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   230
     * Constructs an {@code AudioFormat} with a linear PCM encoding and the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   231
     * given parameters. The frame size is set to the number of bytes required
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   232
     * to contain one sample from each channel, and the frame rate is set to the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   233
     * sample rate.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   235
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   236
     * @param  sampleSizeInBits the number of bits in each sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   237
     * @param  channels the number of channels (1 for mono, 2 for stereo, and so
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   238
     *         on)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   239
     * @param  signed indicates whether the data is signed or unsigned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   240
     * @param  bigEndian indicates whether the data for a single sample is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   241
     *         stored in big-endian byte order ({@code false} means
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   242
     *         little-endian)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public AudioFormat(float sampleRate, int sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                       int channels, boolean signed, boolean bigEndian) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        this((signed == true ? Encoding.PCM_SIGNED : Encoding.PCM_UNSIGNED),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
             sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
             sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
             (channels == AudioSystem.NOT_SPECIFIED || sampleSizeInBits == AudioSystem.NOT_SPECIFIED)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
             AudioSystem.NOT_SPECIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             ((sampleSizeInBits + 7) / 8) * channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Obtains the type of encoding for sounds in this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @return the encoding type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see Encoding#PCM_SIGNED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see Encoding#PCM_UNSIGNED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see Encoding#ULAW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see Encoding#ALAW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public Encoding getEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   273
     * Obtains the sample rate. For compressed formats, the return value is the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   274
     * sample rate of the uncompressed audio data. When this AudioFormat is used
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   275
     * for queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   276
     * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   277
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample rate
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   278
     * of {@code AudioSystem.NOT_SPECIFIED} means that any sample rate is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   279
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   280
     * sample rate is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   282
     * @return the number of samples per second, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   283
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see #getFrameRate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public float getSampleRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   293
     * Obtains the size of a sample. For compressed formats, the return value is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   294
     * the sample size of the uncompressed audio data. When this AudioFormat is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   295
     * used for queries (e.g. {@link AudioSystem#isConversionSupported(
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   296
     * AudioFormat,AudioFormat) AudioSystem.isConversionSupported}) or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   297
     * capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   298
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   299
     * of {@code AudioSystem.NOT_SPECIFIED} means that any sample size is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   300
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   301
     * sample size is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   303
     * @return the number of bits in each sample, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   304
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #getFrameSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public int getSampleSizeInBits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return sampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   314
     * Obtains the number of channels. When this AudioFormat is used for queries
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   315
     * (e.g. {@link AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   316
     * AudioSystem.isConversionSupported}) or capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   317
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a return
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   318
     * value of {@code AudioSystem.NOT_SPECIFIED} means that any (positive)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   319
     * number of channels is acceptable.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   321
     * @return The number of channels (1 for mono, 2 for stereo, etc.), or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   322
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public int getChannels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   331
     * Obtains the frame size in bytes. When this AudioFormat is used for
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   332
     * queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   333
     * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   334
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   335
     * of {@code AudioSystem.NOT_SPECIFIED} means that any frame size is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   336
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   337
     * frame size is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   339
     * @return the number of bytes per frame, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   340
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #getSampleSizeInBits()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public int getFrameSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   350
     * Obtains the frame rate in frames per second. When this AudioFormat is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   351
     * used for queries (e.g. {@link AudioSystem#isConversionSupported(
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   352
     * AudioFormat,AudioFormat) AudioSystem.isConversionSupported}) or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   353
     * capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   354
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame rate
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   355
     * of {@code AudioSystem.NOT_SPECIFIED} means that any frame rate is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   356
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   357
     * frame rate is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   359
     * @return the number of frames per second, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   360
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see #getSampleRate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public float getFrameRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Indicates whether the audio data is stored in big-endian or little-endian
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   371
     * byte order. If the sample size is not more than one byte, the return
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   372
     * value is irrelevant.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   373
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   374
     * @return {@code true} if the data is stored in big-endian byte order,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   375
     *         {@code false} if little-endian
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public boolean isBigEndian() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   383
     * Obtain an unmodifiable map of properties. The concept of properties is
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   384
     * further explained in the {@link AudioFileFormat class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   386
     * @return a {@code Map<String, Object>} object containing all properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   387
     *         If no properties are recognized, an empty map is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see #getProperty(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   391
    @SuppressWarnings("unchecked") // Cast of result of clone.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public Map<String,Object> properties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        Map<String,Object> ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (properties == null) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   395
            ret = new HashMap<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            ret = (Map<String,Object>) (properties.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   399
        return Collections.unmodifiableMap(ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   403
     * Obtain the property value specified by the key. The concept of properties
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   404
     * is further explained in the {@link AudioFileFormat class description}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   405
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   406
     * If the specified property is not defined for a particular file format,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   407
     * this method returns {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   409
     * @param  key the key of the desired property
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   410
     * @return the value of the property with the specified key, or {@code null}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   411
     *         if the property does not exist
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see #properties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public Object getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return properties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   423
     * Indicates whether this format matches the one specified. To match, two
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   424
     * formats must have the same encoding, and consistent values of the number
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   425
     * of channels, sample rate, sample size, frame rate, and frame size. The
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   426
     * values of the property are consistent if they are equal or the specified
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   427
     * format has the property value {@code AudioSystem.NOT_SPECIFIED}. The byte
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   428
     * order (big-endian or little-endian) must be the same if the sample size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   429
     * is greater than one byte.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   431
     * @param  format format to test for match
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   432
     * @return {@code true} if this format matches the one specified,
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   433
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public boolean matches(AudioFormat format) {
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   436
        if (format.getEncoding().equals(getEncoding())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   437
                && (format.getChannels() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   438
                    || format.getChannels() == getChannels())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   439
                && (format.getSampleRate() == (float)AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   440
                    || format.getSampleRate() == getSampleRate())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   441
                && (format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   442
                    || format.getSampleSizeInBits() == getSampleSizeInBits())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   443
                && (format.getFrameRate() == (float)AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   444
                    || format.getFrameRate() == getFrameRate())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   445
                && (format.getFrameSize() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   446
                    || format.getFrameSize() == getFrameSize())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   447
                && (getSampleSizeInBits() <= 8
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   448
                    || format.isBigEndian() == isBigEndian())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            return true;
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   450
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   455
     * Returns a string that describes the format, such as: "PCM SIGNED 22050 Hz
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   456
     * 16 bit mono big-endian". The contents of the string may vary between
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   457
     * implementations of Java Sound.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @return a string that describes the format parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   461
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        String sEncoding = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (getEncoding() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            sEncoding = getEncoding().toString() + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        String sSampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (getSampleRate() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            sSampleRate = "unknown sample rate, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            sSampleRate = "" + getSampleRate() + " Hz, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        String sSampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (getSampleSizeInBits() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            sSampleSizeInBits = "unknown bits per sample, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            sSampleSizeInBits = "" + getSampleSizeInBits() + " bit, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        String sChannels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (getChannels() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            sChannels = "mono, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (getChannels() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                sChannels = "stereo, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                if (getChannels() == AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    sChannels = " unknown number of channels, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    sChannels = ""+getChannels()+" channels, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        String sFrameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (getFrameSize() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            sFrameSize = "unknown frame size, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            sFrameSize = "" + getFrameSize()+ " bytes/frame, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        String sFrameRate = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if (getFrameRate() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                sFrameRate = "unknown frame rate, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                sFrameRate = getFrameRate() + " frames/second, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        String sEndian = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if ((getEncoding().equals(Encoding.PCM_SIGNED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
             || getEncoding().equals(Encoding.PCM_UNSIGNED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            && ((getSampleSizeInBits() > 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                || (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if (isBigEndian()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                sEndian = "big-endian";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                sEndian = "little-endian";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return sEncoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            + sSampleRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            + sSampleSizeInBits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            + sChannels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            + sFrameSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            + sFrameRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            + sEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   535
     * The {@code Encoding} class names the specific type of data representation
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   536
     * used for an audio stream. The encoding includes aspects of the sound
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   537
     * format other than the number of channels, sample rate, sample size, frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   538
     * rate, frame size, and byte order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * One ubiquitous type of audio encoding is pulse-code modulation (PCM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * which is simply a linear (proportional) representation of the sound
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   542
     * waveform. With PCM, the number stored in each sample is proportional to
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   543
     * the instantaneous amplitude of the sound pressure at that point in time.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   544
     * The numbers may be signed or unsigned integers or floats. Besides PCM,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   545
     * other encodings include mu-law and a-law, which are nonlinear mappings of
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   546
     * the sound amplitude that are often used for recording speech.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * You can use a predefined encoding by referring to one of the static
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   549
     * objects created by this class, such as PCM_SIGNED or PCM_UNSIGNED.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   550
     * Service providers can create new encodings, such as compressed audio
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   551
     * formats, and make these available through the {@link AudioSystem} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   553
     * The {@code Encoding} class is static, so that all {@code AudioFormat}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   554
     * objects that have the same encoding will refer to the same object (rather
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   555
     * than different instances of the same class). This allows matches to be
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   556
     * made by checking that two format's encodings are equal.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   558
     * @author Kara Kytle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see AudioFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see javax.sound.sampled.spi.FormatConversionProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public static class Encoding {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * Specifies signed, linear PCM data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        public static final Encoding PCM_SIGNED = new Encoding("PCM_SIGNED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * Specifies unsigned, linear PCM data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        public static final Encoding PCM_UNSIGNED = new Encoding("PCM_UNSIGNED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        /**
6505
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   576
         * Specifies floating-point PCM data.
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   577
         *
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   578
         * @since 1.7
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   579
         */
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   580
        public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   581
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   582
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         * Specifies u-law encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public static final Encoding ULAW = new Encoding("ULAW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * Specifies a-law encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public static final Encoding ALAW = new Encoding("ALAW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * Encoding name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         * Constructs a new encoding.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   599
         *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   600
         * @param  name the name of the new type of encoding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        public Encoding(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   607
         * Finalizes the equals method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   609
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        public final boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (toString() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                return (obj != null) && (obj.toString() == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (obj instanceof Encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                return toString().equals(obj.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   621
         * Finalizes the hashCode method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   623
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        public final int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            if (toString() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            return toString().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   632
         * Provides the {@code String} representation of the encoding. This
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   633
         * {@code String} is the same name that was passed to the constructor.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   634
         * For the predefined encodings, the name is similar to the encoding's
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   635
         * variable (field) name. For example, {@code PCM_SIGNED.toString()}
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   636
         * returns the name "pcm_signed".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * @return the encoding name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   640
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        public final String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   644
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
}