src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java
author serb
Fri, 22 Jun 2018 19:19:43 -0700
changeset 50832 e069b9e49ca7
parent 47498 aa0344e6f39b
permissions -rw-r--r--
8205456: Unification of iterations over arrays Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50832
e069b9e49ca7 8205456: Unification of iterations over arrays
serb
parents: 47498
diff changeset
     2
 * Copyright (c) 1999, 2018, 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;
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
    31
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    34
 * {@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
    35
 * 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
    36
 * format, you can discover how to interpret the bits in the binary sound data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    38
 * 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
    39
 * 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
    40
 * 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
    41
 * 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
    42
 * line.
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
    43
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    44
 * 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
    45
 * 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
    46
 * information. Similarly, an {@link AudioInputStream} has an
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    47
 * {@code AudioFormat}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    48
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    49
 * 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
    50
 * encoding techniques, including pulse-code modulation (PCM), mu-law encoding,
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    51
 * 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
    52
 * 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
    53
 * uses is named by its {@code encoding} field.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    55
 * 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
    56
 * 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
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * 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
    61
 * 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
    62
 * 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
    63
 * 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
    64
 * 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
    65
 * 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
    66
 * 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
    67
 * 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
    68
 * 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
    69
 * 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
    70
 * 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
    71
 * 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
    72
 * 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
    73
 * 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
    74
 * 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
    75
 * 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
    76
 * and frame size.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    77
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    78
 * 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
    79
 * 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
    80
 * property value is an arbitrary object. Properties specify additional format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    81
 * specifications, like the bit rate for compressed formats. Properties are
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    82
 * 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
    83
 * 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
    84
 * 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
    85
 * the installed service providers, like
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    86
 * {@link AudioSystem#isConversionSupported (AudioFormat, AudioFormat)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    87
 * isConversionSupported} may consider properties, depending on the respective
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    88
 * service provider implementation.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    89
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    90
 * The following table lists some common properties which service providers
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
    91
 * should use, if applicable:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
    93
 * <table class="striped">
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
    94
 * <caption>Audio Format Properties</caption>
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
    95
 * <thead>
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
    96
 *   <tr>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
    97
 *     <th scope="col">Property key
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
    98
 *     <th scope="col">Value type
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
    99
 *     <th scope="col">Description
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
   100
 * </thead>
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
   101
 * <tbody>
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   102
 *   <tr>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
   103
 *     <th scope="row">"bitrate"
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   104
 *     <td>{@link java.lang.Integer Integer}
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   105
 *     <td>average bit rate in bits per second
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   106
 *   <tr>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
   107
 *     <th scope="row">"vbr"
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   108
 *     <td>{@link java.lang.Boolean Boolean}
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   109
 *     <td>{@code true}, if the file is encoded in variable bit rate (VBR)
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   110
 *   <tr>
47498
aa0344e6f39b 8184219: Fix accessibility of tables in the java.desktop module
serb
parents: 47216
diff changeset
   111
 *     <th scope="row">"quality"
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   112
 *     <td>{@link java.lang.Integer Integer}
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   113
 *     <td>encoding/conversion quality, 1..100
45648
87c997b74bb8 8180326: Update the tables in java.desktop to be HTML-5 friendly
serb
parents: 42186
diff changeset
   114
 * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * </table>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   116
 * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   117
 * Vendors of service providers (plugins) are encouraged to seek information
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   118
 * 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
   119
 * the same conventions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see DataLine#getFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see AudioInputStream#getFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @see AudioFileFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @see javax.sound.sampled.spi.FormatConversionProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
public class AudioFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The audio encoding technique used by this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected Encoding encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   137
     * 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
   138
     * this format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected float sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * The number of bits in each sample of a sound that has this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected int sampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * The number of audio channels in this format (1 for mono, 2 for stereo).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected int channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The number of bytes in each frame of a sound that has this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected int frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   158
     * 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
   159
     * this format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected float frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   164
     * 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
   165
     * order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected boolean bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   169
    /**
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   170
     * The set of properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   171
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private HashMap<String, Object> properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   175
     * Constructs an {@code AudioFormat} with the given parameters. The encoding
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   176
     * 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
   177
     * are further explained in the {@link AudioFormat class description}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   178
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   179
     * @param  encoding the audio encoding technique
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   180
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   181
     * @param  sampleSizeInBits the number of bits in each sample
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   182
     * @param  channels the number of channels (1 for mono, 2 for stereo, and so
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   183
     *         on)
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   184
     * @param  frameSize the number of bytes in each frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   185
     * @param  frameRate the number of frames per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   186
     * @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
   187
     *         stored in big-endian byte order ({@code false} means
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   188
     *         little-endian)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public AudioFormat(Encoding encoding, float sampleRate, int sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                       int channels, int frameSize, float frameRate, boolean bigEndian) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.sampleRate = sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        this.sampleSizeInBits = sampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        this.channels = channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        this.frameSize = frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.frameRate = frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.bigEndian = bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this.properties = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   204
     * Constructs an {@code AudioFormat} with the given parameters. The encoding
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   205
     * 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
   206
     * are further explained in the {@link AudioFormat class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   208
     * @param  encoding the audio encoding technique
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   209
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   210
     * @param  sampleSizeInBits the number of bits in each sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   211
     * @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
   212
     *         on)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   213
     * @param  frameSize the number of bytes in each frame
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   214
     * @param  frameRate the number of frames per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   215
     * @param  bigEndian indicates whether the data for a single sample is
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   216
     *         stored in big-endian byte order ({@code false} means
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   217
     *         little-endian)
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   218
     * @param  properties a {@code Map<String, Object>} object containing format
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   219
     *         properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public AudioFormat(Encoding encoding, float sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                       int sampleSizeInBits, int channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                       int frameSize, float frameRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                       boolean bigEndian, Map<String, Object> properties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        this(encoding, sampleRate, sampleSizeInBits, channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
             frameSize, frameRate, bigEndian);
40444
afabcfc2f3ef 8163949: Cleanup of classes which are related to JavaSound
serb
parents: 38972
diff changeset
   228
        this.properties = new HashMap<>(properties);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   232
     * 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
   233
     * 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
   234
     * 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
   235
     * sample rate.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   237
     * @param  sampleRate the number of samples per second
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   238
     * @param  sampleSizeInBits the number of bits in each sample
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   239
     * @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
   240
     *         on)
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   241
     * @param  signed indicates whether the data is signed or unsigned
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   242
     * @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
   243
     *         stored in big-endian byte order ({@code false} means
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   244
     *         little-endian)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public AudioFormat(float sampleRate, int sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                       int channels, boolean signed, boolean bigEndian) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        this((signed == true ? Encoding.PCM_SIGNED : Encoding.PCM_UNSIGNED),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
             sampleSizeInBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
             channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             (channels == AudioSystem.NOT_SPECIFIED || sampleSizeInBits == AudioSystem.NOT_SPECIFIED)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             AudioSystem.NOT_SPECIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             ((sampleSizeInBits + 7) / 8) * channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             sampleRate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             bigEndian);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Obtains the type of encoding for sounds in this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return the encoding type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see Encoding#PCM_SIGNED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see Encoding#PCM_UNSIGNED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see Encoding#ULAW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see Encoding#ALAW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public Encoding getEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   274
     * Obtains the sample rate. For compressed formats, the return value is the
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   275
     * sample rate of the uncompressed audio data. When this {@code AudioFormat}
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   276
     * is used for queries (e.g.
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   277
     * {@link AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   278
     * AudioSystem.isConversionSupported}) or capabilities (e.g.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   279
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample rate
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   280
     * 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
   281
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   282
     * sample rate is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   284
     * @return the number of samples per second, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   285
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see #getFrameRate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public float getSampleRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return sampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   294
     * Obtains the size of a sample. For compressed formats, the return value is
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   295
     * the sample size of the uncompressed audio data. When this
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   296
     * {@code AudioFormat} is used for queries (e.g.
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   297
     * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   298
     * AudioSystem.isConversionSupported}) or capabilities (e.g.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   299
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   300
     * 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
   301
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   302
     * sample size is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   304
     * @return the number of bits in each sample, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   305
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getFrameSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public int getSampleSizeInBits() {
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
    /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   314
     * Obtains the number of channels. When this {@code AudioFormat} is used for
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   315
     * queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   316
     * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
25128
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
        return channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   330
     * Obtains the frame size in bytes. When this {@code AudioFormat} is used
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   331
     * for queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   332
     * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   333
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame size
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   334
     * 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
   335
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   336
     * frame size is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   338
     * @return the number of bytes per frame, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   339
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #getSampleSizeInBits()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public int getFrameSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   348
     * Obtains the frame rate in frames per second. When this
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   349
     * {@code AudioFormat} is used for queries (e.g.
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   350
     * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   351
     * AudioSystem.isConversionSupported}) or capabilities (e.g.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   352
     * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame rate
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   353
     * 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
   354
     * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   355
     * frame rate is not defined for this audio format.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   357
     * @return the number of frames per second, or
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   358
     *         {@code AudioSystem.NOT_SPECIFIED}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see #getSampleRate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see AudioSystem#NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public float getFrameRate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return frameRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * 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
   368
     * 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
   369
     * value is irrelevant.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   370
     *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   371
     * @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
   372
     *         {@code false} if little-endian
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public boolean isBigEndian() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return bigEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   379
     * 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
   380
     * further explained in the {@link AudioFileFormat class description}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   382
     * @return a {@code Map<String, Object>} object containing all properties.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   383
     *         If no properties are recognized, an empty map is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @see #getProperty(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   387
    @SuppressWarnings("unchecked") // Cast of result of clone.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public Map<String,Object> properties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        Map<String,Object> ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (properties == null) {
25131
49006bd0e69d 8044553: Fix raw and unchecked lint warnings in javax.sound.*
darcy
parents: 25128
diff changeset
   391
            ret = new HashMap<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            ret = (Map<String,Object>) (properties.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   395
        return Collections.unmodifiableMap(ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   399
     * 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
   400
     * is further explained in the {@link AudioFileFormat class description}.
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   401
     * <p>
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   402
     * 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
   403
     * this method returns {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   405
     * @param  key the key of the desired property
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   406
     * @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
   407
     *         if the property does not exist
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @see #properties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public Object getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return properties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   419
     * 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
   420
     * 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
   421
     * 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
   422
     * 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
   423
     * 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
   424
     * 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
   425
     * is greater than one byte.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   427
     * @param  format format to test for match
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   428
     * @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
   429
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public boolean matches(AudioFormat format) {
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   432
        if (format.getEncoding().equals(getEncoding())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   433
                && (format.getChannels() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   434
                    || format.getChannels() == getChannels())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   435
                && (format.getSampleRate() == (float)AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   436
                    || format.getSampleRate() == getSampleRate())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   437
                && (format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   438
                    || format.getSampleSizeInBits() == getSampleSizeInBits())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   439
                && (format.getFrameRate() == (float)AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   440
                    || format.getFrameRate() == getFrameRate())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   441
                && (format.getFrameSize() == AudioSystem.NOT_SPECIFIED
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   442
                    || format.getFrameSize() == getFrameSize())
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   443
                && (getSampleSizeInBits() <= 8
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   444
                    || format.isBigEndian() == isBigEndian())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            return true;
6506
36a2d4253a54 4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields
amenkov
parents: 5506
diff changeset
   446
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   451
     * 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
   452
     * 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
   453
     * implementations of Java Sound.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @return a string that describes the format parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   457
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        String sEncoding = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (getEncoding() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            sEncoding = getEncoding().toString() + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        String sSampleRate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (getSampleRate() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            sSampleRate = "unknown sample rate, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            sSampleRate = "" + getSampleRate() + " Hz, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String sSampleSizeInBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (getSampleSizeInBits() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            sSampleSizeInBits = "unknown bits per sample, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            sSampleSizeInBits = "" + getSampleSizeInBits() + " bit, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        String sChannels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (getChannels() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            sChannels = "mono, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (getChannels() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                sChannels = "stereo, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                if (getChannels() == AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    sChannels = " unknown number of channels, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    sChannels = ""+getChannels()+" channels, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        String sFrameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (getFrameSize() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            sFrameSize = "unknown frame size, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            sFrameSize = "" + getFrameSize()+ " bytes/frame, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        String sFrameRate = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            if (getFrameRate() == (float) AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                sFrameRate = "unknown frame rate, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                sFrameRate = getFrameRate() + " frames/second, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        String sEndian = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if ((getEncoding().equals(Encoding.PCM_SIGNED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
             || getEncoding().equals(Encoding.PCM_UNSIGNED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            && ((getSampleSizeInBits() > 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                || (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (isBigEndian()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                sEndian = "big-endian";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                sEndian = "little-endian";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return sEncoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            + sSampleRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            + sSampleSizeInBits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            + sChannels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            + sFrameSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            + sFrameRate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            + sEndian;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   531
     * 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
   532
     * 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
   533
     * 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
   534
     * rate, frame size, and byte order.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * One ubiquitous type of audio encoding is pulse-code modulation (PCM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * 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
   538
     * 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
   539
     * 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
   540
     * 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
   541
     * 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
   542
     * the sound amplitude that are often used for recording speech.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * You can use a predefined encoding by referring to one of the static
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   545
     * objects created by this class, such as {@code PCM_SIGNED} or
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   546
     * {@code PCM_UNSIGNED}. Service providers can create new encodings, such as
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   547
     * compressed audio formats, and make these available through the
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   548
     * {@link AudioSystem} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <p>
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   550
     * 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
   551
     * 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
   552
     * 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
   553
     * made by checking that two format's encodings are equal.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   555
     * @author Kara Kytle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see AudioFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see javax.sound.sampled.spi.FormatConversionProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public static class Encoding {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         * Specifies signed, linear PCM data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        public static final Encoding PCM_SIGNED = new Encoding("PCM_SIGNED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         * Specifies unsigned, linear PCM data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        public static final Encoding PCM_UNSIGNED = new Encoding("PCM_UNSIGNED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        /**
6505
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   573
         * Specifies floating-point PCM data.
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   574
         *
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   575
         * @since 1.7
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   576
         */
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   577
        public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   578
b1faae5e44a3 6944033: RFE: add PCM_FLOAT support
amenkov
parents: 5506
diff changeset
   579
        /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * Specifies u-law encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        public static final Encoding ULAW = new Encoding("ULAW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * Specifies a-law encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        public static final Encoding ALAW = new Encoding("ALAW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * Encoding name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         */
40444
afabcfc2f3ef 8163949: Cleanup of classes which are related to JavaSound
serb
parents: 38972
diff changeset
   592
        private final String name;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
         * Constructs a new encoding.
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   596
         *
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   597
         * @param  name the name of the new type of encoding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         */
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   599
        public Encoding(final String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   604
         * Indicates whether the specified object is equal to this encoding,
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   605
         * returning {@code true} if the objects are equal.
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   606
         *
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   607
         * @param  obj the reference object with which to compare
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   608
         * @return {@code true} if the specified object is equal to this
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   609
         *         encoding; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   611
        @Override
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   612
        public final boolean equals(final Object obj) {
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   613
            if (this == obj) {
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   614
                return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   616
            if (!(obj instanceof Encoding)) {
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   617
                return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   619
            return Objects.equals(name, ((Encoding) obj).name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        /**
47195
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   623
         * Returns a hash code value for this encoding.
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   624
         *
b309b58eb190 8181566: JavaSound javadoc clarification
serb
parents: 45648
diff changeset
   625
         * @return a hash code value for this encoding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   627
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        public final int hashCode() {
42186
7092af944dca 8168998: Incorrect implementation of equals in Encoding and Type in JavaSound
serb
parents: 40444
diff changeset
   629
            return name != null ? name.hashCode() : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        /**
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   633
         * Provides the {@code String} representation of the encoding. This
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   634
         * {@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
   635
         * 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
   636
         * variable (field) name. For example, {@code PCM_SIGNED.toString()}
38972
5b37aa89e909 8156583: Typo in the spec of javax.sound.sampled.AudioFormat.Encoding.toString()
serb
parents: 25859
diff changeset
   637
         * returns the name "PCM_SIGNED".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         * @return the encoding name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         */
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   641
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        public final String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
25128
2dfdfa369071 8043979: Javadoc cleanup of javax.sound.sampled package
serb
parents: 22584
diff changeset
   645
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
}