< prev index next >

src/java.desktop/share/classes/javax/sound/sampled/TargetDataLine.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 132      */
 133     void open(AudioFormat format) throws LineUnavailableException;
 134 
 135     /**
 136      * Reads audio data from the data line's input buffer. The requested number
 137      * of bytes is read into the specified array, starting at the specified
 138      * offset into the array in bytes. This method blocks until the requested
 139      * amount of data has been read. However, if the data line is closed,
 140      * stopped, drained, or flushed before the requested amount has been read,
 141      * the method no longer blocks, but returns the number of bytes read thus
 142      * far.
 143      * <p>
 144      * The number of bytes that can be read without blocking can be ascertained
 145      * using the {@link DataLine#available available} method of the
 146      * {@code DataLine} interface. (While it is guaranteed that this number of
 147      * bytes can be read without blocking, there is no guarantee that attempts
 148      * to read additional data will block.)
 149      * <p>
 150      * The number of bytes to be read must represent an integral number of
 151      * sample frames, such that:
 152      * <br>
 153      * <center>{@code [ bytes read ] % [frame size in bytes ] == 0}</center>
 154      * <br>
 155      * The return value will always meet this requirement. A request to read a
 156      * number of bytes representing a non-integral number of sample frames
 157      * cannot be fulfilled and may result in an IllegalArgumentException.
 158      *
 159      * @param  b a byte array that will contain the requested input data when
 160      *         this method returns
 161      * @param  off the offset from the beginning of the array, in bytes
 162      * @param  len the requested number of bytes to read
 163      * @return the number of bytes actually read
 164      * @throws IllegalArgumentException if the requested number of bytes does
 165      *         not represent an integral number of sample frames, or if
 166      *         {@code len} is negative
 167      * @throws ArrayIndexOutOfBoundsException if {@code off} is negative, or
 168      *         {@code off+len} is greater than the length of the array {@code b}
 169      *
 170      * @see SourceDataLine#write
 171      * @see DataLine#available
 172      */
 173     int read(byte[] b, int off, int len);
 174 
   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 132      */
 133     void open(AudioFormat format) throws LineUnavailableException;
 134 
 135     /**
 136      * Reads audio data from the data line's input buffer. The requested number
 137      * of bytes is read into the specified array, starting at the specified
 138      * offset into the array in bytes. This method blocks until the requested
 139      * amount of data has been read. However, if the data line is closed,
 140      * stopped, drained, or flushed before the requested amount has been read,
 141      * the method no longer blocks, but returns the number of bytes read thus
 142      * far.
 143      * <p>
 144      * The number of bytes that can be read without blocking can be ascertained
 145      * using the {@link DataLine#available available} method of the
 146      * {@code DataLine} interface. (While it is guaranteed that this number of
 147      * bytes can be read without blocking, there is no guarantee that attempts
 148      * to read additional data will block.)
 149      * <p>
 150      * The number of bytes to be read must represent an integral number of
 151      * sample frames, such that:
 152      * <p style="text-align:center">
 153      * {@code [ bytes read ] % [frame size in bytes ] == 0}
 154      * <p>
 155      * The return value will always meet this requirement. A request to read a
 156      * number of bytes representing a non-integral number of sample frames
 157      * cannot be fulfilled and may result in an IllegalArgumentException.
 158      *
 159      * @param  b a byte array that will contain the requested input data when
 160      *         this method returns
 161      * @param  off the offset from the beginning of the array, in bytes
 162      * @param  len the requested number of bytes to read
 163      * @return the number of bytes actually read
 164      * @throws IllegalArgumentException if the requested number of bytes does
 165      *         not represent an integral number of sample frames, or if
 166      *         {@code len} is negative
 167      * @throws ArrayIndexOutOfBoundsException if {@code off} is negative, or
 168      *         {@code off+len} is greater than the length of the array {@code b}
 169      *
 170      * @see SourceDataLine#write
 171      * @see DataLine#available
 172      */
 173     int read(byte[] b, int off, int len);
 174 
< prev index next >