javax.sound.sampled.Line Java Examples

The following examples show how to use javax.sound.sampled.Line. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoftMixingMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Line[] getSourceLines() {

    Line[] localLines;

    synchronized (control_mutex) {

        if (mainmixer == null)
            return new Line[0];
        SoftMixingDataLine[] sourceLines = mainmixer.getOpenLines();

        localLines = new Line[sourceLines.length];

        for (int i = 0; i < localLines.length; i++) {
            localLines[i] = sourceLines[i];
        }
    }

    return localLines;
}
 
Example #2
Source File: AbstractMixer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the first complete Line.Info object it finds that
 * matches the one specified, or null if no matching Line.Info
 * object is found.
 */
final Line.Info getLineInfo(Line.Info info) {
    if (info == null) {
        return null;
    }
    // $$kk: 05.31.99: need to change this so that
    // the format and buffer size get set in the
    // returned info object for data lines??
    for (int i = 0; i < sourceLineInfo.length; i++) {
        if (info.matches(sourceLineInfo[i])) {
            return sourceLineInfo[i];
        }
    }

    for (int i = 0; i < targetLineInfo.length; i++) {
        if (info.matches(targetLineInfo[i])) {
            return targetLineInfo[i];
        }
    }

    return null;
}
 
Example #3
Source File: AbstractMixer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Close all lines and then close this mixer.
 */
public final synchronized void close() {
    if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
    if (isOpen()) {
        // close all source lines
        Line[] localLines = getSourceLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        // close all target lines
        localLines = getTargetLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        implClose();

        // set the open state to false and send events
        setOpen(false);
    }
    manuallyOpened = false;
    if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
 
Example #4
Source File: AbstractMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts the mixer.
 */
final synchronized void start(Line line) {

    if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
        return;
    }

    // we just start the mixer regardless of anything else here.
    if (!started) {
        if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
        implStart();
        started = true;
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
 
Example #5
Source File: DirectAudioDevice.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getMaxLines(Line.Info info) {
    Line.Info fullInfo = getLineInfo(info);

    // if it's not supported at all, return 0.
    if (fullInfo == null) {
        return 0;
    }

    if (fullInfo instanceof DataLine.Info) {
        // DirectAudioDevices should mix !
        return getMaxSimulLines();
    }

    return 0;
}
 
Example #6
Source File: AbstractMixer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes this line from the list of open source lines and
 * open target lines, if it exists in either.
 * If the list is now empty, closes the mixer.
 */
final synchronized void close(Line line) {

    if (Printer.trace) Printer.trace(">> AbstractMixer: close(" + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") nothing done");
        return;
    }

    sourceLines.removeElement(line);
    targetLines.removeElement(line);

    if (Printer.debug) Printer.debug("AbstractMixer: close(line): sourceLines.size() now: " + sourceLines.size());
    if (Printer.debug) Printer.debug("AbstractMixer: close(line): targetLines.size() now: " + targetLines.size());


    if (sourceLines.isEmpty() && targetLines.isEmpty() && !manuallyOpened) {
        if (Printer.trace) Printer.trace("AbstractMixer: close(" + line + "): need to close the mixer");
        close();
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") succeeded");
}
 
Example #7
Source File: AbstractMixer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the first complete Line.Info object it finds that
 * matches the one specified, or null if no matching Line.Info
 * object is found.
 */
final Line.Info getLineInfo(Line.Info info) {
    if (info == null) {
        return null;
    }
    // $$kk: 05.31.99: need to change this so that
    // the format and buffer size get set in the
    // returned info object for data lines??
    for (int i = 0; i < sourceLineInfo.length; i++) {
        if (info.matches(sourceLineInfo[i])) {
            return sourceLineInfo[i];
        }
    }

    for (int i = 0; i < targetLineInfo.length; i++) {
        if (info.matches(targetLineInfo[i])) {
            return targetLineInfo[i];
        }
    }

    return null;
}
 
Example #8
Source File: AbstractMixer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts the mixer.
 */
final synchronized void start(Line line) {

    if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
        return;
    }

    // we just start the mixer regardless of anything else here.
    if (!started) {
        if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
        implStart();
        started = true;
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
 
Example #9
Source File: AbstractMixer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new AbstractMixer.
 * @param mixer the mixer with which this line is associated
 * @param controls set of supported controls
 */
protected AbstractMixer(Mixer.Info mixerInfo,
                        Control[] controls,
                        Line.Info[] sourceLineInfo,
                        Line.Info[] targetLineInfo) {

    // Line.Info, AbstractMixer, Control[]
    super(new Line.Info(Mixer.class), null, controls);

    // setup the line part
    this.mixer = this;
    if (controls == null) {
        controls = new Control[0];
    }

    // setup the mixer part
    this.mixerInfo = mixerInfo;
    this.sourceLineInfo = sourceLineInfo;
    this.targetLineInfo = targetLineInfo;
}
 
Example #10
Source File: AbstractMixer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public final Line.Info[] getTargetLineInfo(Line.Info info) {

        int i;
        Vector vec = new Vector();

        for (i = 0; i < targetLineInfo.length; i++) {

            if (info.matches(targetLineInfo[i])) {
                vec.addElement(targetLineInfo[i]);
            }
        }

        Line.Info[] returnedArray = new Line.Info[vec.size()];
        for (i = 0; i < returnedArray.length; i++) {
            returnedArray[i] = (Line.Info)vec.elementAt(i);
        }

        return returnedArray;
    }
 
Example #11
Source File: AbstractMixer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes this line from the list of open source lines and
 * open target lines, if it exists in either.
 * If the list is now empty, closes the mixer.
 */
final synchronized void close(Line line) {

    if (Printer.trace) Printer.trace(">> AbstractMixer: close(" + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") nothing done");
        return;
    }

    sourceLines.removeElement(line);
    targetLines.removeElement(line);

    if (Printer.debug) Printer.debug("AbstractMixer: close(line): sourceLines.size() now: " + sourceLines.size());
    if (Printer.debug) Printer.debug("AbstractMixer: close(line): targetLines.size() now: " + targetLines.size());


    if (sourceLines.isEmpty() && targetLines.isEmpty() && !manuallyOpened) {
        if (Printer.trace) Printer.trace("AbstractMixer: close(" + line + "): need to close the mixer");
        close();
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") succeeded");
}
 
Example #12
Source File: AbstractMixer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Close all lines and then close this mixer.
 */
public final synchronized void close() {
    if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
    if (isOpen()) {
        // close all source lines
        Line[] localLines = getSourceLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        // close all target lines
        localLines = getTargetLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        implClose();

        // set the open state to false and send events
        setOpen(false);
    }
    manuallyOpened = false;
    if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
 
Example #13
Source File: AbstractMixer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts the mixer.
 */
final synchronized void start(Line line) {

    if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
        return;
    }

    // we just start the mixer regardless of anything else here.
    if (!started) {
        if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
        implStart();
        started = true;
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
 
Example #14
Source File: JavaSoundAudioDevice.java    From jsyn with Apache License 2.0 6 votes vote down vote up
/**
 * Build device info and determine default devices.
 */
private void sniffAvailableMixers() {
    Mixer.Info[] mixers = AudioSystem.getMixerInfo();
    for (int i = 0; i < mixers.length; i++) {
        DeviceInfo deviceInfo = new DeviceInfo();

        deviceInfo.name = mixers[i].getName();
        Mixer mixer = AudioSystem.getMixer(mixers[i]);

        Line.Info[] lines = mixer.getTargetLineInfo();
        deviceInfo.maxInputs = scanMaxChannels(lines);
        // Remember first device that supports input.
        if ((defaultInputDeviceID < 0) && (deviceInfo.maxInputs > 0)) {
            defaultInputDeviceID = i;
        }

        lines = mixer.getSourceLineInfo();
        deviceInfo.maxOutputs = scanMaxChannels(lines);
        // Remember first device that supports output.
        if ((defaultOutputDeviceID < 0) && (deviceInfo.maxOutputs > 0)) {
            defaultOutputDeviceID = i;
        }

        deviceRecords.add(deviceInfo);
    }
}
 
Example #15
Source File: AbstractMixer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public final Line.Info[] getSourceLineInfo(Line.Info info) {

        int i;
        Vector vec = new Vector();

        for (i = 0; i < sourceLineInfo.length; i++) {

            if (info.matches(sourceLineInfo[i])) {
                vec.addElement(sourceLineInfo[i]);
            }
        }

        Line.Info[] returnedArray = new Line.Info[vec.size()];
        for (i = 0; i < returnedArray.length; i++) {
            returnedArray[i] = (Line.Info)vec.elementAt(i);
        }

        return returnedArray;
    }
 
Example #16
Source File: AbstractMixer.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the first complete Line.Info object it finds that
 * matches the one specified, or null if no matching Line.Info
 * object is found.
 */
final Line.Info getLineInfo(Line.Info info) {
    if (info == null) {
        return null;
    }
    // $$kk: 05.31.99: need to change this so that
    // the format and buffer size get set in the
    // returned info object for data lines??
    for (int i = 0; i < sourceLineInfo.length; i++) {
        if (info.matches(sourceLineInfo[i])) {
            return sourceLineInfo[i];
        }
    }

    for (int i = 0; i < targetLineInfo.length; i++) {
        if (info.matches(targetLineInfo[i])) {
            return targetLineInfo[i];
        }
    }
    return null;
}
 
Example #17
Source File: AbstractMixer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public final boolean isLineSupported(Line.Info info) {

        int i;

        for (i = 0; i < sourceLineInfo.length; i++) {

            if (info.matches(sourceLineInfo[i])) {
                return true;
            }
        }

        for (i = 0; i < targetLineInfo.length; i++) {

            if (info.matches(targetLineInfo[i])) {
                return true;
            }
        }

        return false;
    }
 
Example #18
Source File: AbstractMixer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public final Line.Info[] getTargetLineInfo(Line.Info info) {

        int i;
        Vector vec = new Vector();

        for (i = 0; i < targetLineInfo.length; i++) {

            if (info.matches(targetLineInfo[i])) {
                vec.addElement(targetLineInfo[i]);
            }
        }

        Line.Info[] returnedArray = new Line.Info[vec.size()];
        for (i = 0; i < returnedArray.length; i++) {
            returnedArray[i] = (Line.Info)vec.elementAt(i);
        }

        return returnedArray;
    }
 
Example #19
Source File: AbstractMixer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a new AbstractMixer.
 * @param mixer the mixer with which this line is associated
 * @param controls set of supported controls
 */
protected AbstractMixer(Mixer.Info mixerInfo,
                        Control[] controls,
                        Line.Info[] sourceLineInfo,
                        Line.Info[] targetLineInfo) {

    // Line.Info, AbstractMixer, Control[]
    super(new Line.Info(Mixer.class), null, controls);

    // setup the line part
    this.mixer = this;
    if (controls == null) {
        controls = new Control[0];
    }

    // setup the mixer part
    this.mixerInfo = mixerInfo;
    this.sourceLineInfo = sourceLineInfo;
    this.targetLineInfo = targetLineInfo;
}
 
Example #20
Source File: AbstractMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Close all lines and then close this mixer.
 */
@Override
public final synchronized void close() {
    if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
    if (isOpen()) {
        // close all source lines
        Line[] localLines = getSourceLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        // close all target lines
        localLines = getTargetLines();
        for (int i = 0; i<localLines.length; i++) {
            localLines[i].close();
        }

        implClose();

        // set the open state to false and send events
        setOpen(false);
    }
    manuallyOpened = false;
    if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
 
Example #21
Source File: AbstractMixer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * The default implementation of this method just determines whether
 * this line is a source or target line, calls open(no-arg) on the
 * mixer, and adds the line to the appropriate vector.
 * The mixer may be opened at a format different than the line's
 * format if it is a DataLine.
 */
final synchronized void open(Line line) throws LineUnavailableException {
    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        return;
    }

    // source line?
    if (isSourceLine(line.getLineInfo())) {
        if (! sourceLines.contains(line) ) {
            // call the no-arg open method for the mixer; it should open at its
            // default format if it is not open yet
            open(false);

            // we opened successfully! add the line to the list
            sourceLines.addElement(line);
        }
    } else {
        // target line?
        if(isTargetLine(line.getLineInfo())) {
            if (! targetLines.contains(line) ) {
                // call the no-arg open method for the mixer; it should open at its
                // default format if it is not open yet
                open(false);

                // we opened successfully!  add the line to the list
                targetLines.addElement(line);
            }
        } else {
            if (Printer.err) Printer.err("Unknown line received for AbstractMixer.open(Line): " + line);
        }
    }
}
 
Example #22
Source File: AbstractMixer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The default implementation of this method just determines whether
 * this line is a source or target line, calls open(no-arg) on the
 * mixer, and adds the line to the appropriate vector.
 * The mixer may be opened at a format different than the line's
 * format if it is a DataLine.
 */
final synchronized void open(Line line) throws LineUnavailableException {

    if (Printer.trace) Printer.trace(">> AbstractMixer: open(line = " + line + ")");

    // $$kk: 06.11.99: ignore ourselves for now
    if (this.equals(line)) {
        if (Printer.trace) Printer.trace("<< AbstractMixer: open(" + line + ") nothing done");
        return;
    }

    // source line?
    if (isSourceLine(line.getLineInfo())) {
        if (! sourceLines.contains(line) ) {
            // call the no-arg open method for the mixer; it should open at its
            // default format if it is not open yet
            open(false);

            // we opened successfully! add the line to the list
            sourceLines.addElement(line);
        }
    } else {
        // target line?
        if(isTargetLine(line.getLineInfo())) {
            if (! targetLines.contains(line) ) {
                // call the no-arg open method for the mixer; it should open at its
                // default format if it is not open yet
                open(false);

                // we opened successfully!  add the line to the list
                targetLines.addElement(line);
            }
        } else {
            if (Printer.err) Printer.err("Unknown line received for AbstractMixer.open(Line): " + line);
        }
    }

    if (Printer.trace) Printer.trace("<< AbstractMixer: open(" + line + ") completed");
}
 
Example #23
Source File: PortMixer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Line getLine(Line.Info info) throws LineUnavailableException {
    Line.Info fullInfo = getLineInfo(info);

    if ((fullInfo != null) && (fullInfo instanceof Port.Info)) {
        for (int i = 0; i < portInfos.length; i++) {
            if (fullInfo.equals(portInfos[i])) {
                return getPort(i);
            }
        }
    }
    throw new IllegalArgumentException("Line unsupported: " + info);
}
 
Example #24
Source File: BogusMixers.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        out("4667064: Java Sound provides bogus SourceDataLine and TargetDataLine");

        Mixer.Info[]    aInfos = AudioSystem.getMixerInfo();
        out("  available Mixers:");
        for (int i = 0; i < aInfos.length; i++) {
            if (aInfos[i].getName().startsWith("Java Sound Audio Engine")) {
                Mixer mixer = AudioSystem.getMixer(aInfos[i]);
                Line.Info[] tlInfos = mixer.getTargetLineInfo();
                for (int ii = 0; ii<tlInfos.length; ii++) {
                    if (tlInfos[ii].getLineClass() == DataLine.class) {
                        throw new Exception("Bogus TargetDataLine with DataLine info present!");
                    }
                }
            }
            if (aInfos[i].getName().startsWith("WinOS,waveOut,multi threaded")) {
                throw new Exception("Bogus mixer 'WinOS,waveOut,multi threaded' present!");
            }
            out(aInfos[i].getName());
        }
        if (aInfos.length == 0)
        {
            out("[No mixers available] - not a failure of this test case.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    out("Test passed");
}
 
Example #25
Source File: TGMixer.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Line getLine(final Line.Info info) throws LineUnavailableException {
	if(!this.isLineSupported(info)) {
		throw new IllegalArgumentException("Line unsupported: " + info);
	}
	if((info.getLineClass() == SourceDataLine.class)) {
		return this.findOrCreateLine(TGSourceDataLine.class, new Callable<Line>() {
			public Line call() {
				return new TGSourceDataLine((DataLine.Info) info);
			}
		});
	}
	
	throw new IllegalArgumentException("Line unsupported: " + info);
}
 
Example #26
Source File: SoftMixingMixer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: AbstractMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether this is a source line for this mixer.
 * Right now this just checks whether it's supported, but should
 * check whether it actually belongs to this mixer....
 */
final boolean isSourceLine(Line.Info info) {

    for (int i = 0; i < sourceLineInfo.length; i++) {
        if (info.matches(sourceLineInfo[i])) {
            return true;
        }
    }

    return false;
}
 
Example #28
Source File: TGMixer.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Line.Info[] getSourceLineInfo(Line.Info info) {
	List<Line.Info> infos = new ArrayList<Line.Info>();
	for(Line.Info sourceLineInfo : this.sourceLineInfo) {
		if( info.matches(sourceLineInfo) ) {
			infos.add(sourceLineInfo);
		}
	}
       return infos.toArray(new Line.Info[infos.size()]);
}
 
Example #29
Source File: AbstractMixer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether this is a target line for this mixer.
 * Right now this just checks whether it's supported, but should
 * check whether it actually belongs to this mixer....
 */
final boolean isTargetLine(Line.Info info) {

    for (int i = 0; i < targetLineInfo.length; i++) {
        if (info.matches(targetLineInfo[i])) {
            return true;
        }
    }

    return false;
}
 
Example #30
Source File: SoftMixingMixer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}