Path: blob/master/src/java.desktop/share/classes/javax/sound/sampled/TargetDataLine.java
41159 views
/*1* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled;2627/**28* A target data line is a type of {@link DataLine} from which audio data can be29* read. The most common example is a data line that gets its data from an audio30* capture device. (The device is implemented as a mixer that writes to the31* target data line.)32* <p>33* Note that the naming convention for this interface reflects the relationship34* between the line and its mixer. From the perspective of an application, a35* target data line may act as a source for audio data.36* <p>37* The target data line can be obtained from a mixer by invoking the38* {@link Mixer#getLine getLine} method of {@code Mixer} with an appropriate39* {@link DataLine.Info} object.40* <p>41* The {@code TargetDataLine} interface provides a method for reading the42* captured data from the target data line's buffer. Applications that record43* audio should read data from the target data line quickly enough to keep the44* buffer from overflowing, which could cause discontinuities in the captured45* data that are perceived as clicks. Applications can use the46* {@link DataLine#available available} method defined in the {@code DataLine}47* interface to determine the amount of data currently queued in the data line's48* buffer. If the buffer does overflow, the oldest queued data is discarded and49* replaced by new data.50*51* @author Kara Kytle52* @see Mixer53* @see DataLine54* @see SourceDataLine55* @since 1.356*/57public interface TargetDataLine extends DataLine {5859/**60* Opens the line with the specified format and requested buffer size,61* causing the line to acquire any required system resources and become62* operational.63* <p>64* The buffer size is specified in bytes, but must represent an integral65* number of sample frames. Invoking this method with a requested buffer66* size that does not meet this requirement may result in an67* {@code IllegalArgumentException}. The actual buffer size for the open68* line may differ from the requested buffer size. The value actually set69* may be queried by subsequently calling {@link DataLine#getBufferSize}70* <p>71* If this operation succeeds, the line is marked as open, and an72* {@link LineEvent.Type#OPEN OPEN} event is dispatched to the line's73* listeners.74* <p>75* Invoking this method on a line that is already open is illegal and may76* result in an {@code IllegalStateException}.77* <p>78* Some lines, once closed, cannot be reopened. Attempts to reopen such a79* line will always result in a {@code LineUnavailableException}.80*81* @param format the desired audio format82* @param bufferSize the desired buffer size, in bytes83* @throws LineUnavailableException if the line cannot be opened due to84* resource restrictions85* @throws IllegalArgumentException if the buffer size does not represent an86* integral number of sample frames, or if {@code format} is not87* fully specified or invalid88* @throws IllegalStateException if the line is already open89* @throws SecurityException if the line cannot be opened due to security90* restrictions91* @see #open(AudioFormat)92* @see Line#open93* @see Line#close94* @see Line#isOpen95* @see LineEvent96*/97void open(AudioFormat format, int bufferSize) throws LineUnavailableException;9899/**100* Opens the line with the specified format, causing the line to acquire any101* required system resources and become operational.102* <p>103* The implementation chooses a buffer size, which is measured in bytes but104* which encompasses an integral number of sample frames. The buffer size105* that the system has chosen may be queried by subsequently calling106* {@link DataLine#getBufferSize}107* <p>108* If this operation succeeds, the line is marked as open, and an109* {@link LineEvent.Type#OPEN OPEN} event is dispatched to the line's110* listeners.111* <p>112* Invoking this method on a line that is already open is illegal and may113* result in an {@code IllegalStateException}.114* <p>115* Some lines, once closed, cannot be reopened. Attempts to reopen such a116* line will always result in a {@code LineUnavailableException}.117*118* @param format the desired audio format119* @throws LineUnavailableException if the line cannot be opened due to120* resource restrictions121* @throws IllegalArgumentException if {@code format} is not fully specified122* or invalid123* @throws IllegalStateException if the line is already open124* @throws SecurityException if the line cannot be opened due to security125* restrictions126* @see #open(AudioFormat, int)127* @see Line#open128* @see Line#close129* @see Line#isOpen130* @see LineEvent131*/132void open(AudioFormat format) throws LineUnavailableException;133134/**135* Reads audio data from the data line's input buffer. The requested number136* of bytes is read into the specified array, starting at the specified137* offset into the array in bytes. This method blocks until the requested138* amount of data has been read. However, if the data line is closed,139* stopped, drained, or flushed before the requested amount has been read,140* the method no longer blocks, but returns the number of bytes read thus141* far.142* <p>143* The number of bytes that can be read without blocking can be ascertained144* using the {@link DataLine#available available} method of the145* {@code DataLine} interface. (While it is guaranteed that this number of146* bytes can be read without blocking, there is no guarantee that attempts147* to read additional data will block.)148* <p>149* The number of bytes to be read must represent an integral number of150* sample frames, such that:151* <p style="text-align:center">152* {@code [ bytes read ] % [frame size in bytes ] == 0}153* <p>154* The return value will always meet this requirement. A request to read a155* number of bytes representing a non-integral number of sample frames156* cannot be fulfilled and may result in an IllegalArgumentException.157*158* @param b a byte array that will contain the requested input data when159* this method returns160* @param off the offset from the beginning of the array, in bytes161* @param len the requested number of bytes to read162* @return the number of bytes actually read163* @throws IllegalArgumentException if the requested number of bytes does164* not represent an integral number of sample frames, or if165* {@code len} is negative166* @throws ArrayIndexOutOfBoundsException if {@code off} is negative, or167* {@code off+len} is greater than the length of the array {@code b}168*169* @see SourceDataLine#write170* @see DataLine#available171*/172int read(byte[] b, int off, int len);173174/**175* Obtains the number of sample frames of audio data that can be read from176* the target data line without blocking. Note that the return value177* measures sample frames, not bytes.178*179* @return the number of sample frames currently available for reading180* @see SourceDataLine#availableWrite181*/182//public int availableRead();183}184185186