jdk/src/share/classes/javax/sound/sampled/DataLine.java
author serb
Fri, 16 Aug 2013 20:56:46 +0400
changeset 19368 5d7565f5978c
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor Reviewed-by: art, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, 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
19368
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
    28
import java.util.Arrays;
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <code>DataLine</code> adds media-related functionality to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * superinterface, <code>{@link Line}</code>.  This functionality includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * transport-control methods that start, stop, drain, and flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the audio data that passes through the line.  A data line can also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * report the current position, volume, and audio format of the media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Data lines are used for output of audio by means of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * subinterfaces <code>{@link SourceDataLine}</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>{@link Clip}</code>, which allow an application program to write data.  Similarly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * audio input is handled by the subinterface <code>{@link TargetDataLine}</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * which allows data to be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * A data line has an internal buffer in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the incoming or outgoing audio data is queued.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>{@link #drain()}</code> method blocks until this internal buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * becomes empty, usually because all queued data has been processed.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>{@link #flush()}</code> method discards any available queued data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * from the internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * A data line produces <code>{@link LineEvent.Type#START START}</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>{@link LineEvent.Type#STOP STOP}</code> events whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * it begins or ceases active presentation or capture of data.  These events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * can be generated in response to specific requests, or as a result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * less direct state changes.  For example, if <code>{@link #start()}</code> is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * on an inactive data line, and data is available for capture or playback, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>START</code> event will be generated shortly, when data playback
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * or capture actually begins.  Or, if the flow of data to an active data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * line is constricted so that a gap occurs in the presentation of data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * a <code>STOP</code> event is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Mixers often support synchronized control of multiple data lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Synchronization can be established through the Mixer interface's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>{@link Mixer#synchronize synchronize}</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * See the description of the <code>{@link Mixer Mixer}</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * for a more complete description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public interface DataLine extends Line {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Drains queued data from the line by continuing data I/O until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * data line's internal buffer has been emptied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * This method blocks until the draining is complete.  Because this is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * blocking method, it should be used with care.  If <code>drain()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * is invoked on a stopped line that has data in its queue, the method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * block until the line is running and the data queue becomes empty.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <code>drain()</code> is invoked by one thread, and another continues to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * fill the data queue, the operation will not complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * This method always returns when the data line is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void drain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Flushes queued data from the line.  The flushed data is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * In some cases, not all queued data can be discarded.  For example, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * mixer can flush data from the buffer for a specific input line, but any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * unplayed data already in the output buffer (the result of the mix) will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * still be played.  You can invoke this method after pausing a line (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * normal case) if you want to skip the "stale" data when you restart
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * playback or capture. (It is legal to flush a line that is not stopped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * but doing so on an active line is likely to cause a discontinuity in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * data, resulting in a perceptible click.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #stop()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #drain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Allows a line to engage in data I/O.  If invoked on a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * that is already running, this method does nothing.  Unless the data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * the buffer has been flushed, the line resumes I/O starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * with the first frame that was unprocessed at the time the line was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * stopped. When audio capture or playback starts, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>{@link LineEvent.Type#START START}</code> event is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #stop()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #isRunning()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Stops the line.  A stopped line should cease I/O activity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * If the line is open and running, however, it should retain the resources required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * to resume activity.  A stopped line should retain any audio data in its buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * instead of discarding it, so that upon resumption the I/O can continue where it left off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * if possible.  (This doesn't guarantee that there will never be discontinuities beyond the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * current buffer, of course; if the stopped condition continues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * for too long, input or output samples might be dropped.)  If desired, the retained data can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * discarded by invoking the <code>flush</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * When audio capture or playback stops, a <code>{@link LineEvent.Type#STOP STOP}</code> event is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #isRunning()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Indicates whether the line is running.  The default is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * An open line begins running when the first data is presented in response to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * invocation of the <code>start</code> method, and continues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * until presentation ceases in response to a call to <code>stop</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * because playback completes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return <code>true</code> if the line is running, otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #stop()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public boolean isRunning();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Indicates whether the line is engaging in active I/O (such as playback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * or capture).  When an inactive line becomes active, it sends a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <code>{@link LineEvent.Type#START START}</code> event to its listeners.  Similarly, when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * an active line becomes inactive, it sends a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <code>{@link LineEvent.Type#STOP STOP}</code> event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return <code>true</code> if the line is actively capturing or rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * sound, otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see #isOpen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #addLineListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @see #removeLineListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @see LineEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see LineListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public boolean isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Obtains the current format (encoding, sample rate, number of channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * etc.) of the data line's audio data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <p>If the line is not open and has never been opened, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * the default format. The default format is an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * specific audio format, or, if the <code>DataLine.Info</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * object, which was used to retrieve this <code>DataLine</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * specifies at least one fully qualified audio format, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * last one will be used as the default format. Opening the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * line with a specific audio format (e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * {@link SourceDataLine#open(AudioFormat)}) will override the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * default format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return current audio data format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see AudioFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public AudioFormat getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Obtains the maximum number of bytes of data that will fit in the data line's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * internal buffer.  For a source data line, this is the size of the buffer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * which data can be written.  For a target data line, it is the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * the buffer from which data can be read.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * the units used are bytes, but will always correspond to an integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * number of sample frames of audio data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return the size of the buffer in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public int getBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Obtains the number of bytes of data currently available to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * application for processing in the data line's internal buffer.  For a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * source data line, this is the amount of data that can be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * buffer without blocking.  For a target data line, this is the amount of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * available to be read by the application.  For a clip, this value is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * 0 because the audio data is loaded into the buffer when the clip is opened,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * and persists without modification until the clip is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Note that the units used are bytes, but will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * correspond to an integral number of sample frames of audio data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * An application is guaranteed that a read or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * write operation of up to the number of bytes returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <code>available()</code> will not block; however, there is no guarantee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * that attempts to read or write more data will block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return the amount of data available, in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int available();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Obtains the current position in the audio data, in sample frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * The frame position measures the number of sample
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * frames captured by, or rendered from, the line since it was opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * This return value will wrap around after 2^31 frames. It is recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * to use <code>getLongFramePosition</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @return the number of frames already processed since the line was opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see #getLongFramePosition()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public int getFramePosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Obtains the current position in the audio data, in sample frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * The frame position measures the number of sample
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * frames captured by, or rendered from, the line since it was opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return the number of frames already processed since the line was opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public long getLongFramePosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Obtains the current position in the audio data, in microseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * The microsecond position measures the time corresponding to the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * of sample frames captured by, or rendered from, the line since it was opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * The level of precision is not guaranteed.  For example, an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * might calculate the microsecond position from the current frame position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * and the audio sample frame rate.  The precision in microseconds would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * then be limited to the number of microseconds per sample frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return the number of microseconds of data processed since the line was opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public long getMicrosecondPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Obtains the current volume level for the line.  This level is a measure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * of the signal's current amplitude, and should not be confused with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * current setting of a gain control. The range is from 0.0 (silence) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * 1.0 (maximum possible amplitude for the sound waveform).  The units
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * measure linear amplitude, not decibels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return the current amplitude of the signal in this line, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <code>{@link AudioSystem#NOT_SPECIFIED}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public float getLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Besides the class information inherited from its superclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <code>DataLine.Info</code> provides additional information specific to data lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * This information includes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <li> the audio formats supported by the data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <li> the minimum and maximum sizes of its internal buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Because a <code>Line.Info</code> knows the class of the line its describes, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <code>DataLine.Info</code> object can describe <code>DataLine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * subinterfaces such as <code>{@link SourceDataLine}</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>{@link TargetDataLine}</code>, and <code>{@link Clip}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * You can query a mixer for lines of any of these types, passing an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * instance of <code>DataLine.Info</code> as the argument to a method such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <code>{@link Mixer#getLine Mixer.getLine(Line.Info)}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see Line.Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public static class Info extends Line.Info {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
19368
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   287
        private final AudioFormat[] formats;
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   288
        private final int minBufferSize;
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   289
        private final int maxBufferSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * Constructs a data line's info object from the specified information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * which includes a set of supported audio formats and a range for the buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * This constructor is typically used by mixer implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * when returning information about a supported line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * @param lineClass the class of the data line described by the info object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * @param formats set of formats supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * @param minBufferSize minimum buffer size supported by the data line, in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * @param maxBufferSize maximum buffer size supported by the data line, in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        public Info(Class<?> lineClass, AudioFormat[] formats, int minBufferSize, int maxBufferSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            super(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (formats == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                this.formats = new AudioFormat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } else {
19368
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   309
                this.formats = Arrays.copyOf(formats, formats.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            this.minBufferSize = minBufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            this.maxBufferSize = maxBufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         * Constructs a data line's info object from the specified information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         * which includes a single audio format and a desired buffer size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         * This constructor is typically used by an application to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * describe a desired line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * @param lineClass the class of the data line described by the info object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * @param format desired format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * @param bufferSize desired buffer size in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        public Info(Class<?> lineClass, AudioFormat format, int bufferSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            super(lineClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                this.formats = new AudioFormat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            } else {
19368
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   334
                this.formats = new AudioFormat[]{format};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            this.minBufferSize = bufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            this.maxBufferSize = bufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * Constructs a data line's info object from the specified information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * which includes a single audio format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * This constructor is typically used by an application to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * describe a desired line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * @param lineClass the class of the data line described by the info object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * @param format desired format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        public Info(Class<?> lineClass, AudioFormat format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            this(lineClass, format, AudioSystem.NOT_SPECIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * Obtains a set of audio formats supported by the data line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * Note that <code>isFormatSupported(AudioFormat)</code> might return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * <code>true</code> for certain additional formats that are missing from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * the set returned by <code>getFormats()</code>.  The reverse is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * the case: <code>isFormatSupported(AudioFormat)</code> is guaranteed to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * <code>true</code> for all formats returned by <code>getFormats()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * Some fields in the AudioFormat instances can be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED NOT_SPECIFIED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * if that field does not apply to the format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * or if the format supports a wide range of values for that field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * For example, a multi-channel device supporting up to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * 64 channels, could set the channel field in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         * <code>AudioFormat</code> instances returned by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * method to <code>NOT_SPECIFIED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         * @return a set of supported audio formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * @see #isFormatSupported(AudioFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public AudioFormat[] getFormats() {
19368
5d7565f5978c 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
serb
parents: 5506
diff changeset
   377
            return Arrays.copyOf(formats, formats.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         * Indicates whether this data line supports a particular audio format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         * The default implementation of this method simply returns <code>true</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         * the specified format matches any of the supported formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         * @param format the audio format for which support is queried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         * @return <code>true</code> if the format is supported, otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * @see #getFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         * @see AudioFormat#matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public boolean isFormatSupported(AudioFormat format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            for (int i = 0; i < formats.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                if (format.matches(formats[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         * Obtains the minimum buffer size supported by the data line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         * @return minimum buffer size in bytes, or <code>AudioSystem.NOT_SPECIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        public int getMinBufferSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return minBufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * Obtains the maximum buffer size supported by the data line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         * @return maximum buffer size in bytes, or <code>AudioSystem.NOT_SPECIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        public int getMaxBufferSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return maxBufferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         * Determines whether the specified info object matches this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         * To match, the superclass match requirements must be met.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * addition, this object's minimum buffer size must be at least as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * large as that of the object specified, its maximum buffer size must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         * be at most as large as that of the object specified, and all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
         * formats must match formats supported by the object specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         * @return <code>true</code> if this object matches the one specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         * otherwise <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        public boolean matches(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (! (super.matches(info)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            Info dataLineInfo = (Info)info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // treat anything < 0 as NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // demo code in old Java Sound Demo used a wrong buffer calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            // that would lead to arbitrary negative values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if ((getMaxBufferSize() >= 0) && (dataLineInfo.getMaxBufferSize() >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                if (getMaxBufferSize() > dataLineInfo.getMaxBufferSize()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if ((getMinBufferSize() >= 0) && (dataLineInfo.getMinBufferSize() >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                if (getMinBufferSize() < dataLineInfo.getMinBufferSize()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            AudioFormat[] localFormats = getFormats();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (localFormats != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                for (int i = 0; i < localFormats.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    if (! (localFormats[i] == null) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        if (! (dataLineInfo.isFormatSupported(localFormats[i])) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         * Obtains a textual description of the data line info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         * @return a string description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            StringBuffer buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if ( (formats.length == 1) && (formats[0] != null) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                buf.append(" supporting format " + formats[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            } else if (getFormats().length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                buf.append(" supporting " + getFormats().length + " audio formats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (maxBufferSize != AudioSystem.NOT_SPECIFIED) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                buf.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (minBufferSize > 0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                buf.append(", and buffers of at least " + minBufferSize + " bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            } else if (maxBufferSize != AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                buf.append(", and buffers of up to " + minBufferSize + " bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return new String(super.toString() + buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    } // class Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
} // interface DataLine