KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > sampled > TargetDataLine


1 /*
2  * @(#)TargetDataLine.java 1.20 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.sampled;
9
10 /**
11  * A target data line is a type of <code>{@link DataLine}</code> from which
12  * audio data can be read. The most common example is a data line that gets
13  * its data from an audio capture device. (The device is implemented as a
14  * mixer that writes to the target data line.)
15  * <p>
16  * Note that the naming convention for this interface reflects the relationship
17  * between the line and its mixer. From the perspective of an application,
18  * a target data line may act as a source for audio data.
19  * <p>
20  * The target data line can be obtained from a mixer by invoking the
21  * <code>{@link Mixer#getLine getLine}</code>
22  * method of <code>Mixer</code> with an appropriate
23  * <code>{@link DataLine.Info}</code> object.
24  * <p>
25  * The <code>TargetDataLine</code> interface provides a method for reading the
26  * captured data from the target data line's buffer.Applications
27  * that record audio should read data from the target data line quickly enough
28  * to keep the buffer from overflowing, which could cause discontinuities in
29  * the captured data that are perceived as clicks. Applications can use the
30  * <code>{@link DataLine#available available}</code> method defined in the
31  * <code>DataLine</code> interface to determine the amount of data currently
32  * queued in the data line's buffer. If the buffer does overflow,
33  * the oldest queued data is discarded and replaced by new data.
34  *
35  * @author Kara Kytle
36  * @version 1.20 03/12/19
37  * @see Mixer
38  * @see DataLine
39  * @see SourceDataLine
40  * @since 1.3
41  */

42 public interface TargetDataLine extends DataLine JavaDoc {
43
44
45     /**
46      * Opens the line with the specified format and requested buffer size,
47      * causing the line to acquire any required system resources and become
48      * operational.
49      * <p>
50      * The buffer size is specified in bytes, but must represent an integral
51      * number of sample frames. Invoking this method with a requested buffer
52      * size that does not meet this requirement may result in an
53      * IllegalArgumentException. The actual buffer size for the open line may
54      * differ from the requested buffer size. The value actually set may be
55      * queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
56      * <p>
57      * If this operation succeeds, the line is marked as open, and an
58      * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
59      * line's listeners.
60      * <p>
61      * Invoking this method on a line that is already open is illegal
62      * and may result in an <code>IllegalStateException</code>.
63      * <p>
64      * Some lines, once closed, cannot be reopened. Attempts
65      * to reopen such a line will always result in a
66      * <code>LineUnavailableException</code>.
67      *
68      * @param format the desired audio format
69      * @param bufferSize the desired buffer size, in bytes.
70      * @throws LineUnavailableException if the line cannot be
71      * opened due to resource restrictions
72      * @throws IllegalArgumentException if the buffer size does not represent
73      * an integral number of sample frames,
74      * or if <code>format</code> is not fully specified or invalid
75      * @throws IllegalStateException if the line is already open
76      * @throws SecurityException if the line cannot be
77      * opened due to security restrictions
78      *
79      * @see #open(AudioFormat)
80      * @see Line#open
81      * @see Line#close
82      * @see Line#isOpen
83      * @see LineEvent
84      */

85     public void open(AudioFormat JavaDoc format, int bufferSize) throws LineUnavailableException JavaDoc;
86
87
88     /**
89      * Opens the line with the specified format, causing the line to acquire any
90      * required system resources and become operational.
91      *
92      * <p>
93      * The implementation chooses a buffer size, which is measured in bytes but
94      * which encompasses an integral number of sample frames. The buffer size
95      * that the system has chosen may be queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
96      * <p>
97      * If this operation succeeds, the line is marked as open, and an
98      * <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
99      * line's listeners.
100      * <p>
101      * Invoking this method on a line that is already open is illegal
102      * and may result in an <code>IllegalStateException</code>.
103      * <p>
104      * Some lines, once closed, cannot be reopened. Attempts
105      * to reopen such a line will always result in a
106      * <code>LineUnavailableException</code>.
107      *
108      * @param format the desired audio format
109      * @throws LineUnavailableException if the line cannot be
110      * opened due to resource restrictions
111      * @throws IllegalArgumentException if <code>format</code>
112      * is not fully specified or invalid
113      * @throws IllegalStateException if the line is already open
114      * @throws SecurityException if the line cannot be
115      * opened due to security restrictions
116      *
117      * @see #open(AudioFormat, int)
118      * @see Line#open
119      * @see Line#close
120      * @see Line#isOpen
121      * @see LineEvent
122      */

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

165     public int read(byte[] b, int off, int len);
166
167     /**
168      * Obtains the number of sample frames of audio data that can be read from
169      * the target data line without blocking. Note that the return value
170      * measures sample frames, not bytes.
171      * @return the number of sample frames currently available for reading
172      * @see SourceDataLine#availableWrite
173      */

174     //public int availableRead();
175
}
176
Popular Tags