java类javax.sound.sampled.Line的实例源码

AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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");
}
IsRunningHang.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
private static void test(final AudioFormat format, final byte[] data)
        throws Exception {
    final Line.Info info = new DataLine.Info(Clip.class, format);
    final Clip clip = (Clip) AudioSystem.getLine(info);

    go = new CountDownLatch(1);
    clip.addLineListener(event -> {
        if (event.getType().equals(LineEvent.Type.START)) {
            go.countDown();
        }
    });

    clip.open(format, data, 0, data.length);
    clip.start();
    go.await();
    while (clip.isRunning()) {
        // This loop should not hang
    }
    while (clip.isActive()) {
        // This loop should not hang
    }
    clip.close();
}
DefaultMixers.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
private static AudioFormat getFirstLinearFormat(Line.Info[] infos) {
    for (int i = 0; i < infos.length; i++) {
        if (infos[i] instanceof DataLine.Info) {
            AudioFormat[] formats = ((DataLine.Info) infos[i]).getFormats();
            for (int j = 0; j < formats.length; j++) {
                AudioFormat.Encoding encoding = formats[j].getEncoding();
                int sampleSizeInBits = formats[j].getSampleSizeInBits();
                if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED) &&
                    sampleSizeInBits == 16 ||
                    encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED) &&
                    sampleSizeInBits == 16) {
                    return formats[j];
                }
            }
        }
    }
    return null;
}
AbstractMixer.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AbstractMixer.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
AbstractMixer.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
AbstractMixer.java 文件源码 项目:OpenJSharp 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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");
}
AbstractMixer.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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;
}
BothEndiansAndSigns.java 文件源码 项目:openjdk-jdk10 阅读 17 收藏 0 点赞 0 评论 0
public static void checkLines(Mixer mixer, Line.Info[] infos) {
    for (int i = 0; i<infos.length; i++) {
        try {
            if (infos[i] instanceof DataLine.Info) {
                DataLine.Info info = (DataLine.Info) infos[i];
                System.out.println(" Line "+info+" (max. "+mixer.getMaxLines(info)+" simultaneously): ");
                AudioFormat[] formats = info.getFormats();
                for (int f = 0; f < formats.length; f++) {
                    try {
                        AudioFormat otherEndianOrSign = getOtherEndianOrSign(formats[f]);
                        if (otherEndianOrSign != null) {
                            checkFormat(formats, otherEndianOrSign);
                        }
                    } catch (Exception e1) {
                        out("  Unexpected exception when getting a format: "+e1);
                    }
                }
            }
        } catch (Exception e) {
            out(" Unexpected exception when getting a line: "+e);
        }
    }
}
AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
@Override
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;
}
AbstractMixer.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
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;
    }
AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
@Override
public final Line.Info[] getSourceLineInfo(Line.Info info) {

    int i;
    Vector<Line.Info> 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] = vec.elementAt(i);
    }

    return returnedArray;
}
AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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");
}
StreamPlayer.java 文件源码 项目:java-stream-player 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Returns all available mixers.
 *
 * @return A List of available Mixers
 */
public List<String> getMixers() {
    List<String> mixers = new ArrayList<>();

    // Obtains an array of mixer info objects that represents the set of
    // audio mixers that are currently installed on the system.
    Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

    if (mixerInfos != null)
        Arrays.stream(mixerInfos).forEach(mInfo -> {
            // line info
            Line.Info lineInfo = new Line.Info(SourceDataLine.class);
            Mixer mixer = AudioSystem.getMixer(mInfo);

            // if line supported
            if (mixer.isLineSupported(lineInfo))
                mixers.add(mInfo.getName());

        });

    return mixers;
}
AbstractMixer.java 文件源码 项目:jdk8u-jdk 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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");
}
AbstractMixer.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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");
}
AbstractMixer.java 文件源码 项目:jdk8u-jdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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");
}
AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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");
}
AbstractMixer.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
@Override
public final Line.Info[] getTargetLineInfo(Line.Info info) {

    int i;
    Vector<Line.Info> 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] = vec.elementAt(i);
    }

    return returnedArray;
}
DirectAudioDevice.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
@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;
}
SoftMixingMixer.java 文件源码 项目:openjdk-jdk10 阅读 30 收藏 0 点赞 0 评论 0
@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;
}
Utils.java 文件源码 项目:ripme 阅读 22 收藏 0 点赞 0 评论 0
public static void playSound(String filename) {
    URL resource = ClassLoader.getSystemClassLoader().getResource(filename);
    try {
        final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
        clip.addLineListener(event -> {
            if (event.getType() == LineEvent.Type.STOP) {
                clip.close();
            }
        });
        clip.open(AudioSystem.getAudioInputStream(resource));
        clip.start();
    } catch (Exception e) {
        logger.error("Failed to play sound " + filename, e);
    }
}
Microphone.java 文件源码 项目:BrainControl 阅读 20 收藏 0 点赞 0 评论 0
public static HashMap<String, Line.Info> enumerateMicrophones() {
    HashMap<String, Line.Info> mics = new HashMap<String, Line.Info>();

    Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
    for (Mixer.Info info : mixerInfos) {
        Mixer m = AudioSystem.getMixer(info);
        Line.Info[] lineInfos = m.getTargetLineInfo();
        if (lineInfos.length >= 1 && lineInfos[0].getLineClass().equals(TargetDataLine.class))
            mics.put(info.getName(), lineInfos[0]);
    }
    return mics;
}
VirtualDrummerMicrophoneInput.java 文件源码 项目:jaer 阅读 32 收藏 0 点赞 0 评论 0
void getAudioInfo (){

        Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
        log.info(mixerInfos.length + " mixers");
        for ( int i = 0 ; i < mixerInfos.length ; i++ ){

            Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
            System.out.println("Mixer " + mixer);
            // target data lines
            Line.Info[] lineInfos = mixer.getTargetLineInfo();
            System.out.println("\t" + lineInfos.length + " lineInfos");
            for ( int j = 0 ; j < lineInfos.length ; j++ ){
                if ( lineInfos[j] instanceof DataLine.Info ){
                    AudioFormat[] formats = ( (DataLine.Info)lineInfos[j] ).getFormats();
                    System.out.println("\t\t\t" + formats.length + " formats");
                    for ( int k = 0 ; k < formats.length ; k++ ){
                        System.out.println("\t\tFormat " + formats[k]);
                    }
                }
                Line line = null;
                try{
                    line = mixer.getLine(lineInfos[j]);
                    System.out.println("\tLine " + line);
                } catch ( LineUnavailableException e ){
                    e.printStackTrace();
                }
            }
        }
    }
PortMixer.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
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;
}
AbstractLine.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Constructs a new AbstractLine.
 * @param mixer the mixer with which this line is associated
 * @param controls set of supported controls
 */
protected AbstractLine(Line.Info info, AbstractMixer mixer, Control[] controls) {

    if (controls == null) {
        controls = new Control[0];
    }

    this.info = info;
    this.mixer = mixer;
    this.controls = controls;
}
SoftMixingMixer.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
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);
    }
SoftMixingMixer.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
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;
}
SoftMixingMixer.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
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()]);
}
SoftMixingMixer.java 文件源码 项目:OpenJSharp 阅读 22 收藏 0 点赞 0 评论 0
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;
}


问题


面经


文章

微信
公众号

扫码关注公众号