< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/SoftMixingMixer.java
Print this page
*** 20,52 ****
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.media.sound;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Control;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
- import javax.sound.sampled.AudioFormat.Encoding;
- import javax.sound.sampled.Control.Type;
/**
! * Software audio mixer
*
* @author Karl Helgason
*/
public final class SoftMixingMixer implements Mixer {
--- 20,53 ----
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package com.sun.media.sound;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.sound.sampled.AudioFormat;
+ import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Control;
+ import javax.sound.sampled.Control.Type;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
/**
! * Software audio mixer.
*
* @author Karl Helgason
*/
public final class SoftMixingMixer implements Mixer {
*** 86,104 ****
private final long latency = 100000; // 100 msec
private final boolean jitter_correction = false;
! private final List<LineListener> listeners = new ArrayList<LineListener>();
private final javax.sound.sampled.Line.Info[] sourceLineInfo;
public SoftMixingMixer() {
sourceLineInfo = new javax.sound.sampled.Line.Info[2];
! ArrayList<AudioFormat> formats = new ArrayList<AudioFormat>();
for (int channels = 1; channels <= 2; channels++) {
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
--- 87,105 ----
private final long latency = 100000; // 100 msec
private final boolean jitter_correction = false;
! private final List<LineListener> listeners = new ArrayList<>();
private final javax.sound.sampled.Line.Info[] sourceLineInfo;
public SoftMixingMixer() {
sourceLineInfo = new javax.sound.sampled.Line.Info[2];
! ArrayList<AudioFormat> formats = new ArrayList<>();
for (int channels = 1; channels <= 2; channels++) {
formats.add(new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED, 8, channels, channels,
AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(Encoding.PCM_UNSIGNED,
*** 138,147 ****
--- 139,149 ----
AudioSystem.NOT_SPECIFIED);
sourceLineInfo[1] = new DataLine.Info(Clip.class, formats_array,
AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED);
}
+ @Override
public Line getLine(Line.Info info) throws LineUnavailableException {
if (!isLineSupported(info))
throw new IllegalArgumentException("Line unsupported: " + info);
*** 153,194 ****
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
public int getMaxLines(Line.Info info) {
if (info.getLineClass() == SourceDataLine.class)
return AudioSystem.NOT_SPECIFIED;
if (info.getLineClass() == Clip.class)
return AudioSystem.NOT_SPECIFIED;
return 0;
}
public javax.sound.sampled.Mixer.Info getMixerInfo() {
return info;
}
public javax.sound.sampled.Line.Info[] getSourceLineInfo() {
Line.Info[] localArray = new Line.Info[sourceLineInfo.length];
System.arraycopy(sourceLineInfo, 0, localArray, 0,
sourceLineInfo.length);
return localArray;
}
public javax.sound.sampled.Line.Info[] getSourceLineInfo(
javax.sound.sampled.Line.Info info) {
int i;
! ArrayList<javax.sound.sampled.Line.Info> infos = new ArrayList<javax.sound.sampled.Line.Info>();
for (i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
infos.add(sourceLineInfo[i]);
}
}
return infos.toArray(new Line.Info[infos.size()]);
}
public Line[] getSourceLines() {
Line[] localLines;
synchronized (control_mutex) {
--- 155,201 ----
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
+ @Override
public int getMaxLines(Line.Info info) {
if (info.getLineClass() == SourceDataLine.class)
return AudioSystem.NOT_SPECIFIED;
if (info.getLineClass() == Clip.class)
return AudioSystem.NOT_SPECIFIED;
return 0;
}
+ @Override
public javax.sound.sampled.Mixer.Info getMixerInfo() {
return info;
}
+ @Override
public javax.sound.sampled.Line.Info[] getSourceLineInfo() {
Line.Info[] localArray = new Line.Info[sourceLineInfo.length];
System.arraycopy(sourceLineInfo, 0, localArray, 0,
sourceLineInfo.length);
return localArray;
}
+ @Override
public javax.sound.sampled.Line.Info[] getSourceLineInfo(
javax.sound.sampled.Line.Info info) {
int i;
! ArrayList<javax.sound.sampled.Line.Info> infos = new ArrayList<>();
for (i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
infos.add(sourceLineInfo[i]);
}
}
return infos.toArray(new Line.Info[infos.size()]);
}
+ @Override
public Line[] getSourceLines() {
Line[] localLines;
synchronized (control_mutex) {
*** 205,227 ****
--- 212,238 ----
}
return localLines;
}
+ @Override
public javax.sound.sampled.Line.Info[] getTargetLineInfo() {
return new javax.sound.sampled.Line.Info[0];
}
+ @Override
public javax.sound.sampled.Line.Info[] getTargetLineInfo(
javax.sound.sampled.Line.Info info) {
return new javax.sound.sampled.Line.Info[0];
}
+ @Override
public Line[] getTargetLines() {
return new Line[0];
}
+ @Override
public boolean isLineSupported(javax.sound.sampled.Line.Info info) {
if (info != null) {
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return true;
*** 229,252 ****
--- 240,267 ----
}
}
return false;
}
+ @Override
public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) {
return false;
}
+ @Override
public void synchronize(Line[] lines, boolean maintainSync) {
throw new IllegalArgumentException(
"Synchronization not supported by this mixer.");
}
+ @Override
public void unsynchronize(Line[] lines) {
throw new IllegalArgumentException(
"Synchronization not supported by this mixer.");
}
+ @Override
public void addLineListener(LineListener listener) {
synchronized (control_mutex) {
listeners.add(listener);
}
}
*** 259,268 ****
--- 274,284 ----
for (LineListener listener : listener_array) {
listener.update(event);
}
}
+ @Override
public void close() {
if (!isOpen())
return;
sendEvent(new LineEvent(this, LineEvent.Type.CLOSE,
*** 306,338 ****
--- 322,360 ----
}
}
+ @Override
public Control getControl(Type control) {
throw new IllegalArgumentException("Unsupported control type : "
+ control);
}
+ @Override
public Control[] getControls() {
return new Control[0];
}
+ @Override
public javax.sound.sampled.Line.Info getLineInfo() {
return new Line.Info(Mixer.class);
}
+ @Override
public boolean isControlSupported(Type control) {
return false;
}
+ @Override
public boolean isOpen() {
synchronized (control_mutex) {
return open;
}
}
+ @Override
public void open() throws LineUnavailableException {
if (isOpen()) {
implicitOpen = false;
return;
}
*** 496,505 ****
--- 518,528 ----
}
}
+ @Override
public void removeLineListener(LineListener listener) {
synchronized (control_mutex) {
listeners.remove(listener);
}
}
*** 523,529 ****
SoftMixingMainMixer getMainMixer() {
if (!isOpen())
return null;
return mainmixer;
}
-
}
--- 546,551 ----
< prev index next >