类javax.sound.sampled.Line源码实例Demo

下面列出了怎么用javax.sound.sampled.Line的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Bytecoder   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码2 项目: jdk8u60   文件: AbstractMixer.java
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;
    }
 
源代码3 项目: jdk8u_jdk   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码4 项目: dragonwell8_jdk   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码5 项目: openjdk-8   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码6 项目: dragonwell8_jdk   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码7 项目: hottub   文件: AbstractMixer.java
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;
    }
 
源代码8 项目: openjdk-jdk8u   文件: AbstractMixer.java
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;
    }
 
源代码9 项目: openjdk-jdk9   文件: SoftMixingMixer.java
@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;
}
 
源代码10 项目: openjdk-jdk9   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: AbstractMixer.java
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;
    }
 
源代码12 项目: jsyn   文件: JavaSoundAudioDevice.java
/**
 * 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);
    }
}
 
源代码13 项目: jdk8u-jdk   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码14 项目: openjdk-jdk9   文件: DirectAudioDevice.java
@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;
}
 
源代码15 项目: openjdk-jdk9   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码17 项目: jdk8u60   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码18 项目: TencentKona-8   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码19 项目: TencentKona-8   文件: AbstractMixer.java
/**
 * 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");
}
 
源代码20 项目: openjdk-jdk8u   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码21 项目: jdk8u60   文件: SoftMixingMixer.java
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;
            }
        }
    }
    return false;
}
 
源代码22 项目: dragonwell8_jdk   文件: PortMixer.java
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 Port.Info) {
        //return AudioSystem.NOT_SPECIFIED; // if several instances of PortMixerPort
        return 1;
    }
    return 0;
}
 
源代码23 项目: jdk8u-jdk   文件: PortMixer.java
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);
}
 
源代码24 项目: openjdk-jdk9   文件: ClipOpenException.java
public static void test(Line line) {
    for (int format = 0; format < formats.length; format++) {
        try {
            println("  Opening the line with format "+(format+1));
            if (line instanceof Clip) {
                ((Clip) line).open(formats[format], audioData, 0, audioData.length);
            } else
            if (line instanceof SourceDataLine) {
                ((SourceDataLine) line).open(formats[format]);
            } else
            if (line instanceof TargetDataLine) {
                ((TargetDataLine) line).open(formats[format]);
            } else {
                println("    Unknown type of line: "+line.getClass());
                return;
            }
            println("    No exception! not OK.");
            failed = true;
        } catch (IllegalArgumentException iae) {
            println("    IllegalArgumentException: "+iae.getMessage());
            println("    OK");
        } catch (LineUnavailableException lue) {
            println("    LineUnavailableException: "+lue.getMessage());
            println("    Probably incorrect, but may happen if the test system is correctly set up.");
        } catch (Exception e) {
            println("    Unexpected Exception: "+e.toString());
            println("    NOT OK!");
            failed = true;
        }
        println("    Closing line.");
        line.close();
    }
}
 
源代码25 项目: jdk8u-jdk   文件: SoftMixingMixer.java
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;
}
 
源代码26 项目: jsyn   文件: JavaSoundAudioDevice.java
private int scanMaxChannels(Line.Info[] lines) {
    int maxChannels = 0;
    for (Line.Info line : lines) {
        if (line instanceof DataLine.Info) {
            int numChannels = scanMaxChannels(((DataLine.Info) line));
            if (numChannels > maxChannels) {
                maxChannels = numChannels;
            }
        }
    }
    return maxChannels;
}
 
源代码27 项目: openjdk-jdk9   文件: SoftMixingMixer.java
@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()]);
}
 
源代码28 项目: jdk8u-jdk   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码29 项目: openjdk-jdk9   文件: AbstractMixer.java
/**
 * 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;
}
 
源代码30 项目: jdk8u_jdk   文件: SoftMixingMixer.java
public Line getLine(Line.Info info) throws LineUnavailableException {

        if (!isLineSupported(info))
            throw new IllegalArgumentException("Line unsupported: " + info);

        if ((info.getLineClass() == SourceDataLine.class)) {
            return new SoftMixingSourceDataLine(this, (DataLine.Info) info);
        }
        if ((info.getLineClass() == Clip.class)) {
            return new SoftMixingClip(this, (DataLine.Info) info);
        }

        throw new IllegalArgumentException("Line unsupported: " + info);
    }