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 23 * questions. 24 */ 25 26 package javax.sound.sampled; 27 28 /** 29 * A mixer is an audio device with one or more lines. It need not be designed 30 * for mixing audio signals. A mixer that actually mixes audio has multiple 31 * input (source) lines and at least one output (target) line. The former are 32 * often instances of classes that implement {@link SourceDataLine}, and the 33 * latter, {@link TargetDataLine}. {@link Port} objects, too, are either source 34 * lines or target lines. A mixer can accept prerecorded, loopable sound as 35 * input, by having some of its source lines be instances of objects that 36 * implement the {@link Clip} interface. 37 * <p> 38 * Through methods of the {@code Line} interface, which {@code Mixer} extends, a 39 * mixer might provide a set of controls that are global to the mixer. For 40 * example, the mixer can have a master gain control. These global controls are 41 * distinct from the controls belonging to each of the mixer's individual lines. 42 * <p> 43 * Some mixers, especially those with internal digital mixing capabilities, may 44 * provide additional capabilities by implementing the {@code DataLine} 45 * interface. 46 * <p> 47 * A mixer can support synchronization of its lines. When one line in a 48 * synchronized group is started or stopped, the other lines in the group 49 * automatically start or stop simultaneously with the explicitly affected one. 50 * 51 * @author Kara Kytle 52 * @since 1.3 53 */ 54 public interface Mixer extends Line { 55 56 /** 57 * Obtains information about this mixer, including the product's name, 58 * version, vendor, etc. 59 * 60 * @return a mixer info object that describes this mixer 61 * @see Info 62 */ 63 Info getMixerInfo(); 64 65 /** 66 * Obtains information about the set of source lines supported by this 67 * mixer. Some source lines may only be available when this mixer is open. 68 * 69 * @return array of {@code Line.Info} objects representing source lines for 70 * this mixer. If no source lines are supported, an array of length 71 * 0 is returned. 72 */ 73 Line.Info[] getSourceLineInfo(); 74 75 /** 76 * Obtains information about the set of target lines supported by this 77 * mixer. Some target lines may only be available when this mixer is open. 78 * 79 * @return array of {@code Line.Info} objects representing target lines for 80 * this mixer. If no target lines are supported, an array of length 81 * 0 is returned. 82 */ 83 Line.Info[] getTargetLineInfo(); 84 85 /** 86 * Obtains information about source lines of a particular type supported by 87 * the mixer. Some source lines may only be available when this mixer is 88 * open. 89 * 90 * @param info a {@code Line.Info} object describing lines about which 91 * information is queried 92 * @return an array of {@code Line.Info} objects describing source lines 93 * matching the type requested. If no matching source lines are 94 * supported, an array of length 0 is returned. 95 */ 96 Line.Info[] getSourceLineInfo(Line.Info info); 97 98 /** 99 * Obtains information about target lines of a particular type supported by 100 * the mixer. Some target lines may only be available when this mixer is 101 * open. 102 * 103 * @param info a {@code Line.Info} object describing lines about which 104 * information is queried 105 * @return an array of {@code Line.Info} objects describing target lines 106 * matching the type requested. If no matching target lines are 107 * supported, an array of length 0 is returned. 108 */ 109 Line.Info[] getTargetLineInfo(Line.Info info); 110 111 /** 112 * Indicates whether the mixer supports a line (or lines) that match the 113 * specified {@code Line.Info} object. Some lines may only be supported when 114 * this mixer is open. 115 * 116 * @param info describes the line for which support is queried 117 * @return {@code true} if at least one matching line is supported, 118 * {@code false} otherwise 119 */ 120 boolean isLineSupported(Line.Info info); 121 122 /** 123 * Obtains a line that is available for use and that matches the description 124 * in the specified {@code Line.Info} object. 125 * <p> 126 * If a {@code DataLine} is requested, and {@code info} is an instance of 127 * {@code DataLine.Info} specifying at least one fully qualified audio 128 * format, the last one will be used as the default format of the returned 129 * {@code DataLine}. 130 * 131 * @param info describes the desired line 132 * @return a line that is available for use and that matches the description 133 * in the specified {@code Line.Info} object 134 * @throws LineUnavailableException if a matching line is not available due 135 * to resource restrictions 136 * @throws IllegalArgumentException if this mixer does not support any lines 137 * matching the description 138 * @throws SecurityException if a matching line is not available due to 139 * security restrictions 140 */ 141 Line getLine(Line.Info info) throws LineUnavailableException; 142 143 //$$fb 2002-04-12: fix for 4667258: behavior of Mixer.getMaxLines(Line.Info) method doesn't match the spec 144 /** 145 * Obtains the approximate maximum number of lines of the requested type 146 * that can be open simultaneously on the mixer. 147 * <p> 148 * Certain types of mixers do not have a hard bound and may allow opening 149 * more lines. Since certain lines are a shared resource, a mixer may not be 150 * able to open the maximum number of lines if another process has opened 151 * lines of this mixer. 152 * <p> 153 * The requested type is any line that matches the description in the 154 * provided {@code Line.Info} object. For example, if the info object 155 * represents a speaker port, and the mixer supports exactly one speaker 156 * port, this method should return 1. If the info object represents a source 157 * data line and the mixer supports the use of 32 source data lines 158 * simultaneously, the return value should be 32. If there is no limit, this 159 * function returns {@link AudioSystem#NOT_SPECIFIED}. 160 * 161 * @param info a {@code Line.Info} that describes the line for which the 162 * number of supported instances is queried 163 * @return the maximum number of matching lines supported, or 164 * {@code AudioSystem.NOT_SPECIFIED} 165 */ 166 int getMaxLines(Line.Info info); 167 168 /** 169 * Obtains the set of all source lines currently open to this mixer. 170 * 171 * @return the source lines currently open to the mixer. If no source lines 172 * are currently open to this mixer, an array of length 0 is 173 * returned. 174 * @throws SecurityException if the matching lines are not available due to 175 * security restrictions 176 */ 177 Line[] getSourceLines(); 178 179 /** 180 * Obtains the set of all target lines currently open from this mixer. 181 * 182 * @return target lines currently open from the mixer. If no target lines 183 * are currently open from this mixer, an array of length 0 is 184 * returned. 185 * @throws SecurityException if the matching lines are not available due to 186 * security restrictions 187 */ 188 Line[] getTargetLines(); 189 190 /** 191 * Synchronizes two or more lines. Any subsequent command that starts or 192 * stops audio playback or capture for one of these lines will exert the 193 * same effect on the other lines in the group, so that they start or stop 194 * playing or capturing data simultaneously. 195 * 196 * @param lines the lines that should be synchronized 197 * @param maintainSync {@code true} if the synchronization must be 198 * precisely maintained (i.e., the synchronization must be 199 * sample-accurate) at all times during operation of the lines, or 200 * {@code false} if precise synchronization is required only during 201 * start and stop operations 202 * @throws IllegalArgumentException if the lines cannot be synchronized. 203 * This may occur if the lines are of different types or have 204 * different formats for which this mixer does not support 205 * synchronization, or if all lines specified do not belong to this 206 * mixer. 207 */ 208 void synchronize(Line[] lines, boolean maintainSync); 209 210 /** 211 * Releases synchronization for the specified lines. The array must be 212 * identical to one for which synchronization has already been established; 213 * otherwise an exception may be thrown. However, {@code null} may be 214 * specified, in which case all currently synchronized lines that belong to 215 * this mixer are unsynchronized. 216 * 217 * @param lines the synchronized lines for which synchronization should be 218 * released, or {@code null} for all this mixer's synchronized lines 219 * @throws IllegalArgumentException if the lines cannot be unsynchronized. 220 * This may occur if the argument specified does not exactly match a 221 * set of lines for which synchronization has already been 222 * established. 223 */ 224 void unsynchronize(Line[] lines); 225 226 /** 227 * Reports whether this mixer supports synchronization of the specified set 228 * of lines. 229 * 230 * @param lines the set of lines for which synchronization support is 231 * queried 232 * @param maintainSync {@code true} if the synchronization must be 233 * precisely maintained (i.e., the synchronization must be 234 * sample-accurate) at all times during operation of the lines, or 235 * {@code false} if precise synchronization is required only during 236 * start and stop operations 237 * @return {@code true} if the lines can be synchronized, {@code false} 238 * otherwise 239 */ 240 boolean isSynchronizationSupported(Line[] lines, boolean maintainSync); 241 242 /** 243 * The {@code Mixer.Info} class represents information about an audio mixer, 244 * including the product's name, version, and vendor, along with a textual 245 * description. This information may be retrieved through the 246 * {@link Mixer#getMixerInfo() getMixerInfo} method of the {@code Mixer} 247 * interface. 248 * 249 * @author Kara Kytle 250 * @since 1.3 251 */ 252 class Info { 253 254 /** 255 * Mixer name. 256 */ 257 private final String name; 258 259 /** 260 * Mixer vendor. 261 */ 262 private final String vendor; 263 264 /** 265 * Mixer description. 266 */ 267 private final String description; 268 269 /** 270 * Mixer version. 271 */ 272 private final String version; 273 274 /** 275 * Constructs a mixer's info object, passing it the given textual 276 * information. 277 * 278 * @param name the name of the mixer 279 * @param vendor the company who manufactures or creates the hardware 280 * or software mixer 281 * @param description descriptive text about the mixer 282 * @param version version information for the mixer 283 */ 284 protected Info(String name, String vendor, String description, String version) { 285 286 this.name = name; 287 this.vendor = vendor; 288 this.description = description; 289 this.version = version; 290 } 291 292 /** 293 * Indicates whether the specified object is equal to this info object, 294 * returning {@code true} if the objects are identical. 295 * 296 * @param obj the reference object with which to compare 297 * @return {@code true} if this info object is the same as the 298 * {@code obj} argument; {@code false} otherwise 299 */ 300 @Override 301 public final boolean equals(Object obj) { 302 return super.equals(obj); 303 } 304 305 /** 306 * Returns a hash code value for this info object. 307 * 308 * @return a hash code value for this info object 309 */ 310 @Override 311 public final int hashCode() { 312 return super.hashCode(); 313 } 314 315 /** 316 * Obtains the name of the mixer. 317 * 318 * @return a string that names the mixer 319 */ 320 public final String getName() { 321 return name; 322 } 323 324 /** 325 * Obtains the vendor of the mixer. 326 * 327 * @return a string that names the mixer's vendor 328 */ 329 public final String getVendor() { 330 return vendor; 331 } 332 333 /** 334 * Obtains the description of the mixer. 335 * 336 * @return a textual description of the mixer 337 */ 338 public final String getDescription() { 339 return description; 340 } 341 342 /** 343 * Obtains the version of the mixer. 344 * 345 * @return textual version information for the mixer 346 */ 347 public final String getVersion() { 348 return version; 349 } 350 351 /** 352 * Provides a string representation of the mixer info. 353 * 354 * @return a string describing the info object 355 */ 356 @Override 357 public final String toString() { 358 return (name + ", version " + version); 359 } 360 } 361 }