286N/A/*
286N/A * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
286N/A * This code is free software; you can redistribute it and/or modify it
286N/A * under the terms of the GNU General Public License version 2 only, as
286N/A * published by the Free Software Foundation. Oracle designates this
286N/A * particular file as subject to the "Classpath" exception as provided
286N/A * by Oracle in the LICENSE file that accompanied this code.
286N/A *
286N/A * This code is distributed in the hope that it will be useful, but WITHOUT
286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/A * version 2 for more details (a copy is included in the LICENSE file that
286N/A * accompanied this code).
286N/A *
286N/A * You should have received a copy of the GNU General Public License version
286N/A * 2 along with this work; if not, write to the Free Software Foundation,
286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A *
286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/A * or visit www.oracle.com if you need additional information or have any
286N/A * questions.
286N/A */
286N/A
286N/Apackage javax.sound.sampled;
286N/A
286N/A/**
286N/A * A target data line is a type of <code>{@link DataLine}</code> from which
286N/A * audio data can be read. The most common example is a data line that gets
286N/A * its data from an audio capture device. (The device is implemented as a
286N/A * mixer that writes to the target data line.)
286N/A * <p>
286N/A * Note that the naming convention for this interface reflects the relationship
286N/A * between the line and its mixer. From the perspective of an application,
286N/A * a target data line may act as a source for audio data.
286N/A * <p>
286N/A * The target data line can be obtained from a mixer by invoking the
286N/A * <code>{@link Mixer#getLine getLine}</code>
286N/A * method of <code>Mixer</code> with an appropriate
286N/A * <code>{@link DataLine.Info}</code> object.
286N/A * <p>
286N/A * The <code>TargetDataLine</code> interface provides a method for reading the
286N/A * captured data from the target data line's buffer.Applications
286N/A * that record audio should read data from the target data line quickly enough
286N/A * to keep the buffer from overflowing, which could cause discontinuities in
286N/A * the captured data that are perceived as clicks. Applications can use the
286N/A * <code>{@link DataLine#available available}</code> method defined in the
286N/A * <code>DataLine</code> interface to determine the amount of data currently
286N/A * queued in the data line's buffer. If the buffer does overflow,
286N/A * the oldest queued data is discarded and replaced by new data.
286N/A *
286N/A * @author Kara Kytle
286N/A * @see Mixer
286N/A * @see DataLine
286N/A * @see SourceDataLine
286N/A * @since 1.3
286N/A */
286N/Apublic interface TargetDataLine extends DataLine {
286N/A
286N/A
286N/A /**
286N/A * Opens the line with the specified format and requested buffer size,
286N/A * causing the line to acquire any required system resources and become
286N/A * operational.
286N/A * <p>
286N/A * The buffer size is specified in bytes, but must represent an integral
286N/A * number of sample frames. Invoking this method with a requested buffer
286N/A * size that does not meet this requirement may result in an
286N/A * IllegalArgumentException. The actual buffer size for the open line may
286N/A * differ from the requested buffer size. The value actually set may be
286N/A * queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
286N/A * <p>
286N/A * If this operation succeeds, the line is marked as open, and an
286N/A * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
286N/A * line's listeners.
286N/A * <p>
286N/A * Invoking this method on a line that is already open is illegal
286N/A * and may result in an <code>IllegalStateException</code>.
286N/A * <p>
286N/A * Some lines, once closed, cannot be reopened. Attempts
286N/A * to reopen such a line will always result in a
286N/A * <code>LineUnavailableException</code>.
286N/A *
286N/A * @param format the desired audio format
286N/A * @param bufferSize the desired buffer size, in bytes.
286N/A * @throws LineUnavailableException if the line cannot be
286N/A * opened due to resource restrictions
286N/A * @throws IllegalArgumentException if the buffer size does not represent
286N/A * an integral number of sample frames,
286N/A * or if <code>format</code> is not fully specified or invalid
286N/A * @throws IllegalStateException if the line is already open
286N/A * @throws SecurityException if the line cannot be
286N/A * opened due to security restrictions
286N/A *
286N/A * @see #open(AudioFormat)
286N/A * @see Line#open
286N/A * @see Line#close
286N/A * @see Line#isOpen
286N/A * @see LineEvent
286N/A */
286N/A public void open(AudioFormat format, int bufferSize) throws LineUnavailableException;
286N/A
286N/A
286N/A /**
286N/A * Opens the line with the specified format, causing the line to acquire any
286N/A * required system resources and become operational.
286N/A *
286N/A * <p>
286N/A * The implementation chooses a buffer size, which is measured in bytes but
286N/A * which encompasses an integral number of sample frames. The buffer size
286N/A * that the system has chosen may be queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
286N/A * <p>
286N/A * If this operation succeeds, the line is marked as open, and an
286N/A * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
286N/A * line's listeners.
286N/A * <p>
286N/A * Invoking this method on a line that is already open is illegal
286N/A * and may result in an <code>IllegalStateException</code>.
286N/A * <p>
286N/A * Some lines, once closed, cannot be reopened. Attempts
286N/A * to reopen such a line will always result in a
286N/A * <code>LineUnavailableException</code>.
286N/A *
286N/A * @param format the desired audio format
286N/A * @throws LineUnavailableException if the line cannot be
286N/A * opened due to resource restrictions
286N/A * @throws IllegalArgumentException if <code>format</code>
286N/A * is not fully specified or invalid
293N/A * @throws IllegalStateException if the line is already open
286N/A * @throws SecurityException if the line cannot be
286N/A * opened due to security restrictions
286N/A *
286N/A * @see #open(AudioFormat, int)
286N/A * @see Line#open
286N/A * @see Line#close
286N/A * @see Line#isOpen
286N/A * @see LineEvent
286N/A */
286N/A public void open(AudioFormat format) throws LineUnavailableException;
286N/A
293N/A
293N/A /**
293N/A * Reads audio data from the data line's input buffer. The requested
293N/A * number of bytes is read into the specified array, starting at
293N/A * the specified offset into the array in bytes. This method blocks until
293N/A * the requested amount of data has been read. However, if the data line
293N/A * is closed, stopped, drained, or flushed before the requested amount has
293N/A * been read, the method no longer blocks, but returns the number of bytes
293N/A * read thus far.
293N/A * <p>
293N/A * The number of bytes that can be read without blocking can be ascertained
293N/A * using the <code>{@link DataLine#available available}</code> method of the
293N/A * <code>DataLine</code> interface. (While it is guaranteed that
293N/A * this number of bytes can be read without blocking, there is no guarantee
286N/A * that attempts to read additional data will block.)
286N/A * <p>
286N/A * The number of bytes to be read must represent an integral number of
286N/A * sample frames, such that:
286N/A * <br>
286N/A * <center><code>[ bytes read ] % [frame size in bytes ] == 0</code></center>
286N/A * <br>
286N/A * The return value will always meet this requirement. A request to read a
286N/A * number of bytes representing a non-integral number of sample frames cannot
286N/A * be fulfilled and may result in an IllegalArgumentException.
286N/A *
286N/A * @param b a byte array that will contain the requested input data when
286N/A * this method returns
286N/A * @param off the offset from the beginning of the array, in bytes
286N/A * @param len the requested number of bytes to read
286N/A * @return the number of bytes actually read
286N/A * @throws IllegalArgumentException if the requested number of bytes does
286N/A * not represent an integral number of sample frames.
286N/A * or if <code>len</code> is negative.
286N/A * @throws ArrayIndexOutOfBoundsException if <code>off</code> is negative,
286N/A * or <code>off+len</code> is greater than the length of the array
286N/A * <code>b</code>.
286N/A *
286N/A * @see SourceDataLine#write
286N/A * @see DataLine#available
286N/A */
286N/A public int read(byte[] b, int off, int len);
286N/A
286N/A /**
286N/A * Obtains the number of sample frames of audio data that can be read from
286N/A * the target data line without blocking. Note that the return value
286N/A * measures sample frames, not bytes.
286N/A * @return the number of sample frames currently available for reading
286N/A * @see SourceDataLine#availableWrite
286N/A */
286N/A //public int availableRead();
286N/A}
286N/A