1. /*
  2. * @(#)Mixer.java 1.31 04/07/14
  3. *
  4. * Copyright 2004 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.31, 04/07/14
  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 source lines of a particular type supported
  65. * by the mixer.
  66. * Some source lines may only be available when this mixer is open.
  67. * @param info a <code>Line.Info</code> object describing lines about which information
  68. * is queried
  69. * @return an array of <code>Line.Info</code> objects describing source lines matching
  70. * the type requested. If no matching source lines are supported, an array of length 0
  71. * is returned.
  72. */
  73. public Line.Info[] getSourceLineInfo(Line.Info info);
  74. /**
  75. * Obtains information about target lines of a particular type supported
  76. * by the mixer.
  77. * Some target lines may only be available when this mixer is open.
  78. * @param info a <code>Line.Info</code> object describing lines about which information
  79. * is queried
  80. * @return an array of <code>Line.Info</code> objects describing target lines matching
  81. * the type requested. If no matching target lines are supported, an array of length 0
  82. * is returned.
  83. */
  84. public Line.Info[] getTargetLineInfo(Line.Info info);
  85. /**
  86. * Indicates whether the mixer supports a line (or lines) that match
  87. * the specified <code>Line.Info</code> object.
  88. * Some lines may only be supported when this mixer is open.
  89. * @param info describes the line for which support is queried
  90. * @return <code>true</code> if at least one matching line is
  91. * supported, <code>false</code> otherwise
  92. */
  93. public boolean isLineSupported(Line.Info info);
  94. /**
  95. * Obtains a line that is available for use and that matches the description
  96. * in the specified <code>Line.Info</code> object.
  97. *
  98. * <p>If a <code>DataLine</code> is requested, and <code>info</code>
  99. * is an instance of <code>DataLine.Info</code> specifying at
  100. * least one fully qualified audio format, the last one
  101. * will be used as the default format of the returned
  102. * <code>DataLine</code>.
  103. *
  104. * @param info describes the desired line
  105. * @throws LineUnavailableException if a matching line
  106. * is not available due to resource restrictions
  107. * @throws IllegalArgumentException if this mixer does
  108. * not support any lines matching the description
  109. * @throws SecurityException if a matching line
  110. * is not available due to security restrictions
  111. */
  112. public Line getLine(Line.Info info) throws LineUnavailableException;
  113. //$$fb 2002-04-12: fix for 4667258: behavior of Mixer.getMaxLines(Line.Info) method doesn't match the spec
  114. /**
  115. * Obtains the approximate maximum number of lines of the requested type that can be open
  116. * simultaneously on the mixer.
  117. *
  118. * Certain types of mixers do not have a hard bound and may allow opening more lines.
  119. * Since certain lines are a shared resource, a mixer may not be able to open the maximum
  120. * number of lines if another process has opened lines of this mixer.
  121. *
  122. * The requested type is any line that matches the description in
  123. * the provided <code>Line.Info</code> object. For example, if the info
  124. * object represents a speaker
  125. * port, and the mixer supports exactly one speaker port, this method
  126. * should return 1. If the info object represents a source data line
  127. * and the mixer supports the use of 32 source data lines simultaneously,
  128. * the return value should be 32.
  129. * If there is no limit, this function returns <code>AudioSystem.NOT_SPECIFIED</code>.
  130. * @param info a <code>Line.Info</code> that describes the line for which
  131. * the number of supported instances is queried
  132. * @return the maximum number of matching lines supported, or <code>AudioSystem.NOT_SPECIFIED</code>
  133. */
  134. public int getMaxLines(Line.Info info);
  135. /**
  136. * Obtains the set of all source lines currently open to this mixer.
  137. *
  138. * @return the source lines currently open to the mixer.
  139. * If no source lines are currently open to this mixer, an
  140. * array of length 0 is returned.
  141. * @throws SecurityException if the matching lines
  142. * are not available due to security restrictions
  143. */
  144. public Line[] getSourceLines();
  145. /**
  146. * Obtains the set of all target lines currently open from this mixer.
  147. *
  148. * @return target lines currently open from the mixer.
  149. * If no target lines are currently open from this mixer, an
  150. * array of length 0 is returned.
  151. * @throws SecurityException if the matching lines
  152. * are not available due to security restrictions
  153. */
  154. public Line[] getTargetLines();
  155. /**
  156. * Synchronizes two or more lines. Any subsequent command that starts or stops
  157. * audio playback or capture for one of these lines will exert the
  158. * same effect on the other lines in the group, so that they start or stop playing or
  159. * capturing data simultaneously.
  160. *
  161. * @param lines the lines that should be synchronized
  162. * @param maintainSync <code>true</code> if the synchronization
  163. * must be precisely maintained (i.e., the synchronization must be sample-accurate)
  164. * at all times during operation of the lines , or <code>false</code>
  165. * if precise synchronization is required only during start and stop operations
  166. *
  167. * @throws IllegalArgumentException if the lines cannot be synchronized.
  168. * This may occur if the lines are of different types or have different
  169. * formats for which this mixer does not support synchronization, or if
  170. * all lines specified do not belong to this mixer.
  171. */
  172. public void synchronize(Line[] lines, boolean maintainSync);
  173. /**
  174. * Releases synchronization for the specified lines. The array must
  175. * be identical to one for which synchronization has already been
  176. * established; otherwise an exception may be thrown. However, <code>null</code>
  177. * may be specified, in which case all currently synchronized lines that belong
  178. * to this mixer are unsynchronized.
  179. * @param lines the synchronized lines for which synchronization should be
  180. * released, or <code>null</code> for all this mixer's synchronized lines
  181. *
  182. * @throws IllegalArgumentException if the lines cannot be unsynchronized.
  183. * This may occur if the argument specified does not exactly match a set
  184. * of lines for which synchronization has already been established.
  185. */
  186. public void unsynchronize(Line[] lines);
  187. /**
  188. * Reports whether this mixer supports synchronization of the specified set of lines.
  189. *
  190. * @param lines the set of lines for which synchronization support is queried
  191. * @param maintainSync <code>true</code> if the synchronization
  192. * must be precisely maintained (i.e., the synchronization must be sample-accurate)
  193. * at all times during operation of the lines , or <code>false</code>
  194. * if precise synchronization is required only during start and stop operations
  195. *
  196. * @return <code>true</code> if the lines can be synchronized, <code>false</code>
  197. * otherwise
  198. */
  199. public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync);
  200. /**
  201. * The <code>Mixer.Info</code> class represents information about an audio mixer,
  202. * including the product's name, version, and vendor, along with a textual
  203. * description. This information may be retrieved through the
  204. * {@link Mixer#getMixerInfo() getMixerInfo}
  205. * method of the <code>Mixer</code> interface.
  206. *
  207. * @author Kara Kytle
  208. * @version 1.31, 04/07/14
  209. * @since 1.3
  210. */
  211. public static class Info {
  212. /**
  213. * Mixer name.
  214. */
  215. private /*final*/ String name;
  216. /**
  217. * Mixer vendor.
  218. */
  219. private /*final*/ String vendor;
  220. /**
  221. * Mixer description.
  222. */
  223. private /*final*/ String description;
  224. /**
  225. * Mixer version.
  226. */
  227. private /*final*/ String version;
  228. /**
  229. * Constructs a mixer's info object, passing it the given
  230. * textual information.
  231. * @param name the name of the mixer
  232. * @param vendor the company who manufactures or creates the hardware
  233. * or software mixer
  234. * @param description descriptive text about the mixer
  235. * @param version version information for the mixer
  236. */
  237. protected Info(String name, String vendor, String description, String version) {
  238. this.name = name;
  239. this.vendor = vendor;
  240. this.description = description;
  241. this.version = version;
  242. }
  243. /**
  244. * Indicates whether two info objects are equal, returning <code>true</code> if
  245. * they are identical.
  246. * @param obj the reference object with which to compare this info
  247. * object
  248. * @return <code>true</code> if this info object is the same as the
  249. * <code>obj</code> argument; <code>false</code> otherwise
  250. */
  251. public final boolean equals(Object obj) {
  252. return super.equals(obj);
  253. }
  254. /**
  255. * Finalizes the hashcode method.
  256. *
  257. * @return the hashcode for this object
  258. */
  259. public final int hashCode() {
  260. return super.hashCode();
  261. }
  262. /**
  263. * Obtains the name of the mixer.
  264. * @return a string that names the mixer
  265. */
  266. public final String getName() {
  267. return name;
  268. }
  269. /**
  270. * Obtains the vendor of the mixer.
  271. * @return a string that names the mixer's vendor
  272. */
  273. public final String getVendor() {
  274. return vendor;
  275. }
  276. /**
  277. * Obtains the description of the mixer.
  278. * @return a textual description of the mixer
  279. */
  280. public final String getDescription() {
  281. return description;
  282. }
  283. /**
  284. * Obtains the version of the mixer.
  285. * @return textual version information for the mixer
  286. */
  287. public final String getVersion() {
  288. return version;
  289. }
  290. /**
  291. * Provides a string representation of the mixer info.
  292. * @return a string describing the info object
  293. */
  294. public final String toString() {
  295. return (name + ", version " + version);
  296. }
  297. } // class Info
  298. }