Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/TargetDataLine.java
38918 views
1
/*
2
* Copyright (c) 1999, 2003, 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
23
* questions.
24
*/
25
26
package javax.sound.sampled;
27
28
/**
29
* A target data line is a type of <code>{@link DataLine}</code> from which
30
* audio data can be read. The most common example is a data line that gets
31
* its data from an audio capture device. (The device is implemented as a
32
* mixer that writes to the target data line.)
33
* <p>
34
* Note that the naming convention for this interface reflects the relationship
35
* between the line and its mixer. From the perspective of an application,
36
* a target data line may act as a source for audio data.
37
* <p>
38
* The target data line can be obtained from a mixer by invoking the
39
* <code>{@link Mixer#getLine getLine}</code>
40
* method of <code>Mixer</code> with an appropriate
41
* <code>{@link DataLine.Info}</code> object.
42
* <p>
43
* The <code>TargetDataLine</code> interface provides a method for reading the
44
* captured data from the target data line's buffer.Applications
45
* that record audio should read data from the target data line quickly enough
46
* to keep the buffer from overflowing, which could cause discontinuities in
47
* the captured data that are perceived as clicks. Applications can use the
48
* <code>{@link DataLine#available available}</code> method defined in the
49
* <code>DataLine</code> interface to determine the amount of data currently
50
* queued in the data line's buffer. If the buffer does overflow,
51
* the oldest queued data is discarded and replaced by new data.
52
*
53
* @author Kara Kytle
54
* @see Mixer
55
* @see DataLine
56
* @see SourceDataLine
57
* @since 1.3
58
*/
59
public interface TargetDataLine extends DataLine {
60
61
62
/**
63
* Opens the line with the specified format and requested buffer size,
64
* causing the line to acquire any required system resources and become
65
* operational.
66
* <p>
67
* The buffer size is specified in bytes, but must represent an integral
68
* number of sample frames. Invoking this method with a requested buffer
69
* size that does not meet this requirement may result in an
70
* IllegalArgumentException. The actual buffer size for the open line may
71
* differ from the requested buffer size. The value actually set may be
72
* queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
73
* <p>
74
* If this operation succeeds, the line is marked as open, and an
75
* <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
76
* line's listeners.
77
* <p>
78
* Invoking this method on a line that is already open is illegal
79
* and may result in an <code>IllegalStateException</code>.
80
* <p>
81
* Some lines, once closed, cannot be reopened. Attempts
82
* to reopen such a line will always result in a
83
* <code>LineUnavailableException</code>.
84
*
85
* @param format the desired audio format
86
* @param bufferSize the desired buffer size, in bytes.
87
* @throws LineUnavailableException if the line cannot be
88
* opened due to resource restrictions
89
* @throws IllegalArgumentException if the buffer size does not represent
90
* an integral number of sample frames,
91
* or if <code>format</code> is not fully specified or invalid
92
* @throws IllegalStateException if the line is already open
93
* @throws SecurityException if the line cannot be
94
* opened due to security restrictions
95
*
96
* @see #open(AudioFormat)
97
* @see Line#open
98
* @see Line#close
99
* @see Line#isOpen
100
* @see LineEvent
101
*/
102
public void open(AudioFormat format, int bufferSize) throws LineUnavailableException;
103
104
105
/**
106
* Opens the line with the specified format, causing the line to acquire any
107
* required system resources and become operational.
108
*
109
* <p>
110
* The implementation chooses a buffer size, which is measured in bytes but
111
* which encompasses an integral number of sample frames. The buffer size
112
* that the system has chosen may be queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>
113
* <p>
114
* If this operation succeeds, the line is marked as open, and an
115
* <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the
116
* line's listeners.
117
* <p>
118
* Invoking this method on a line that is already open is illegal
119
* and may result in an <code>IllegalStateException</code>.
120
* <p>
121
* Some lines, once closed, cannot be reopened. Attempts
122
* to reopen such a line will always result in a
123
* <code>LineUnavailableException</code>.
124
*
125
* @param format the desired audio format
126
* @throws LineUnavailableException if the line cannot be
127
* opened due to resource restrictions
128
* @throws IllegalArgumentException if <code>format</code>
129
* is not fully specified or invalid
130
* @throws IllegalStateException if the line is already open
131
* @throws SecurityException if the line cannot be
132
* opened due to security restrictions
133
*
134
* @see #open(AudioFormat, int)
135
* @see Line#open
136
* @see Line#close
137
* @see Line#isOpen
138
* @see LineEvent
139
*/
140
public void open(AudioFormat format) throws LineUnavailableException;
141
142
143
/**
144
* Reads audio data from the data line's input buffer. The requested
145
* number of bytes is read into the specified array, starting at
146
* the specified offset into the array in bytes. This method blocks until
147
* the requested amount of data has been read. However, if the data line
148
* is closed, stopped, drained, or flushed before the requested amount has
149
* been read, the method no longer blocks, but returns the number of bytes
150
* read thus far.
151
* <p>
152
* The number of bytes that can be read without blocking can be ascertained
153
* using the <code>{@link DataLine#available available}</code> method of the
154
* <code>DataLine</code> interface. (While it is guaranteed that
155
* this number of bytes can be read without blocking, there is no guarantee
156
* that attempts to read additional data will block.)
157
* <p>
158
* The number of bytes to be read must represent an integral number of
159
* sample frames, such that:
160
* <br>
161
* <center><code>[ bytes read ] % [frame size in bytes ] == 0</code></center>
162
* <br>
163
* The return value will always meet this requirement. A request to read a
164
* number of bytes representing a non-integral number of sample frames cannot
165
* be fulfilled and may result in an IllegalArgumentException.
166
*
167
* @param b a byte array that will contain the requested input data when
168
* this method returns
169
* @param off the offset from the beginning of the array, in bytes
170
* @param len the requested number of bytes to read
171
* @return the number of bytes actually read
172
* @throws IllegalArgumentException if the requested number of bytes does
173
* not represent an integral number of sample frames.
174
* or if <code>len</code> is negative.
175
* @throws ArrayIndexOutOfBoundsException if <code>off</code> is negative,
176
* or <code>off+len</code> is greater than the length of the array
177
* <code>b</code>.
178
*
179
* @see SourceDataLine#write
180
* @see DataLine#available
181
*/
182
public int read(byte[] b, int off, int len);
183
184
/**
185
* Obtains the number of sample frames of audio data that can be read from
186
* the target data line without blocking. Note that the return value
187
* measures sample frames, not bytes.
188
* @return the number of sample frames currently available for reading
189
* @see SourceDataLine#availableWrite
190
*/
191
//public int availableRead();
192
}
193
194