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