Path: blob/master/src/java.desktop/share/classes/javax/sound/sampled/Mixer.java
41159 views
/*1* Copyright (c) 1999, 2020, 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 mixer is an audio device with one or more lines. It need not be designed29* for mixing audio signals. A mixer that actually mixes audio has multiple30* input (source) lines and at least one output (target) line. The former are31* often instances of classes that implement {@link SourceDataLine}, and the32* latter, {@link TargetDataLine}. {@link Port} objects, too, are either source33* lines or target lines. A mixer can accept prerecorded, loopable sound as34* input, by having some of its source lines be instances of objects that35* implement the {@link Clip} interface.36* <p>37* Through methods of the {@code Line} interface, which {@code Mixer} extends, a38* mixer might provide a set of controls that are global to the mixer. For39* example, the mixer can have a master gain control. These global controls are40* distinct from the controls belonging to each of the mixer's individual lines.41* <p>42* Some mixers, especially those with internal digital mixing capabilities, may43* provide additional capabilities by implementing the {@code DataLine}44* interface.45* <p>46* A mixer can support synchronization of its lines. When one line in a47* synchronized group is started or stopped, the other lines in the group48* automatically start or stop simultaneously with the explicitly affected one.49*50* @author Kara Kytle51* @since 1.352*/53public interface Mixer extends Line {5455/**56* Obtains information about this mixer, including the product's name,57* version, vendor, etc.58*59* @return a mixer info object that describes this mixer60* @see Info61*/62Info getMixerInfo();6364/**65* Obtains information about the set of source lines supported by this66* mixer. Some source lines may only be available when this mixer is open.67*68* @return array of {@code Line.Info} objects representing source lines for69* this mixer. If no source lines are supported, an array of length70* 0 is returned.71*/72Line.Info[] getSourceLineInfo();7374/**75* Obtains information about the set of target lines supported by this76* mixer. Some target lines may only be available when this mixer is open.77*78* @return array of {@code Line.Info} objects representing target lines for79* this mixer. If no target lines are supported, an array of length80* 0 is returned.81*/82Line.Info[] getTargetLineInfo();8384/**85* Obtains information about source lines of a particular type supported by86* the mixer. Some source lines may only be available when this mixer is87* open.88*89* @param info a {@code Line.Info} object describing lines about which90* information is queried91* @return an array of {@code Line.Info} objects describing source lines92* matching the type requested. If no matching source lines are93* supported, an array of length 0 is returned.94*/95Line.Info[] getSourceLineInfo(Line.Info info);9697/**98* Obtains information about target lines of a particular type supported by99* the mixer. Some target lines may only be available when this mixer is100* open.101*102* @param info a {@code Line.Info} object describing lines about which103* information is queried104* @return an array of {@code Line.Info} objects describing target lines105* matching the type requested. If no matching target lines are106* supported, an array of length 0 is returned.107*/108Line.Info[] getTargetLineInfo(Line.Info info);109110/**111* Indicates whether the mixer supports a line (or lines) that match the112* specified {@code Line.Info} object. Some lines may only be supported when113* this mixer is open.114*115* @param info describes the line for which support is queried116* @return {@code true} if at least one matching line is supported,117* {@code false} otherwise118*/119boolean isLineSupported(Line.Info info);120121/**122* Obtains a line that is available for use and that matches the description123* in the specified {@code Line.Info} object.124* <p>125* If a {@code DataLine} is requested, and {@code info} is an instance of126* {@code DataLine.Info} specifying at least one fully qualified audio127* format, the last one will be used as the default format of the returned128* {@code DataLine}.129*130* @param info describes the desired line131* @return a line that is available for use and that matches the description132* in the specified {@code Line.Info} object133* @throws LineUnavailableException if a matching line is not available due134* to resource restrictions135* @throws IllegalArgumentException if this mixer does not support any lines136* matching the description137* @throws SecurityException if a matching line is not available due to138* security restrictions139*/140Line getLine(Line.Info info) throws LineUnavailableException;141142//$$fb 2002-04-12: fix for 4667258: behavior of Mixer.getMaxLines(Line.Info) method doesn't match the spec143/**144* Obtains the approximate maximum number of lines of the requested type145* that can be open simultaneously on the mixer.146* <p>147* Certain types of mixers do not have a hard bound and may allow opening148* more lines. Since certain lines are a shared resource, a mixer may not be149* able to open the maximum number of lines if another process has opened150* lines of this mixer.151* <p>152* The requested type is any line that matches the description in the153* provided {@code Line.Info} object. For example, if the info object154* represents a speaker port, and the mixer supports exactly one speaker155* port, this method should return 1. If the info object represents a source156* data line and the mixer supports the use of 32 source data lines157* simultaneously, the return value should be 32. If there is no limit, this158* function returns {@link AudioSystem#NOT_SPECIFIED}.159*160* @param info a {@code Line.Info} that describes the line for which the161* number of supported instances is queried162* @return the maximum number of matching lines supported, or163* {@code AudioSystem.NOT_SPECIFIED}164*/165int getMaxLines(Line.Info info);166167/**168* Obtains the set of all source lines currently open to this mixer.169*170* @return the source lines currently open to the mixer. If no source lines171* are currently open to this mixer, an array of length 0 is172* returned.173* @throws SecurityException if the matching lines are not available due to174* security restrictions175*/176Line[] getSourceLines();177178/**179* Obtains the set of all target lines currently open from this mixer.180*181* @return target lines currently open from the mixer. If no target lines182* are currently open from this mixer, an array of length 0 is183* returned.184* @throws SecurityException if the matching lines are not available due to185* security restrictions186*/187Line[] getTargetLines();188189/**190* Synchronizes two or more lines. Any subsequent command that starts or191* stops audio playback or capture for one of these lines will exert the192* same effect on the other lines in the group, so that they start or stop193* playing or capturing data simultaneously.194*195* @param lines the lines that should be synchronized196* @param maintainSync {@code true} if the synchronization must be197* precisely maintained (i.e., the synchronization must be198* sample-accurate) at all times during operation of the lines, or199* {@code false} if precise synchronization is required only during200* start and stop operations201* @throws IllegalArgumentException if the lines cannot be synchronized.202* This may occur if the lines are of different types or have203* different formats for which this mixer does not support204* synchronization, or if all lines specified do not belong to this205* mixer.206*/207void synchronize(Line[] lines, boolean maintainSync);208209/**210* Releases synchronization for the specified lines. The array must be211* identical to one for which synchronization has already been established;212* otherwise an exception may be thrown. However, {@code null} may be213* specified, in which case all currently synchronized lines that belong to214* this mixer are unsynchronized.215*216* @param lines the synchronized lines for which synchronization should be217* released, or {@code null} for all this mixer's synchronized lines218* @throws IllegalArgumentException if the lines cannot be unsynchronized.219* This may occur if the argument specified does not exactly match a220* set of lines for which synchronization has already been221* established.222*/223void unsynchronize(Line[] lines);224225/**226* Reports whether this mixer supports synchronization of the specified set227* of lines.228*229* @param lines the set of lines for which synchronization support is230* queried231* @param maintainSync {@code true} if the synchronization must be232* precisely maintained (i.e., the synchronization must be233* sample-accurate) at all times during operation of the lines, or234* {@code false} if precise synchronization is required only during235* start and stop operations236* @return {@code true} if the lines can be synchronized, {@code false}237* otherwise238*/239boolean isSynchronizationSupported(Line[] lines, boolean maintainSync);240241/**242* The {@code Mixer.Info} class represents information about an audio mixer,243* including the product's name, version, and vendor, along with a textual244* description. This information may be retrieved through the245* {@link Mixer#getMixerInfo() getMixerInfo} method of the {@code Mixer}246* interface.247*248* @author Kara Kytle249* @since 1.3250*/251class Info {252253/**254* Mixer name.255*/256private final String name;257258/**259* Mixer vendor.260*/261private final String vendor;262263/**264* Mixer description.265*/266private final String description;267268/**269* Mixer version.270*/271private final String version;272273/**274* Constructs a mixer's info object, passing it the given textual275* information.276*277* @param name the name of the mixer278* @param vendor the company who manufactures or creates the hardware279* or software mixer280* @param description descriptive text about the mixer281* @param version version information for the mixer282*/283protected Info(String name, String vendor, String description, String version) {284285this.name = name;286this.vendor = vendor;287this.description = description;288this.version = version;289}290291/**292* Indicates whether the specified object is equal to this info object,293* returning {@code true} if the objects are the same.294*295* @param obj the reference object with which to compare296* @return {@code true} if the specified object is equal to this info297* object; {@code false} otherwise298*/299@Override300public final boolean equals(Object obj) {301return super.equals(obj);302}303304/**305* Returns a hash code value for this info object.306*307* @return a hash code value for this info object308*/309@Override310public final int hashCode() {311return super.hashCode();312}313314/**315* Obtains the name of the mixer.316*317* @return a string that names the mixer318*/319public final String getName() {320return name;321}322323/**324* Obtains the vendor of the mixer.325*326* @return a string that names the mixer's vendor327*/328public final String getVendor() {329return vendor;330}331332/**333* Obtains the description of the mixer.334*335* @return a textual description of the mixer336*/337public final String getDescription() {338return description;339}340341/**342* Obtains the version of the mixer.343*344* @return textual version information for the mixer345*/346public final String getVersion() {347return version;348}349350/**351* Returns a string representation of the info object.352*353* @return a string representation of the info object354*/355@Override356public final String toString() {357return String.format("%s, version %s", name, version);358}359}360}361362363