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