Java Code Examples for javax.sound.sampled.Mixer#getTargetLineInfo()

The following examples show how to use javax.sound.sampled.Mixer#getTargetLineInfo() . 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: 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 2
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 3
Source File: JavaMixer.java    From Spark with Apache License 2.0 6 votes vote down vote up
private Line.Info[] getPortInfo(Mixer mixer) {
    Line.Info[] infos;
    List<Line.Info> portInfoList = new ArrayList<Line.Info>();
    infos = mixer.getSourceLineInfo();
    for (Line.Info info : infos) {
        if (info instanceof Port.Info || info instanceof DataLine.Info) {
            portInfoList.add((Line.Info) info);
        }
    }
    infos = mixer.getTargetLineInfo();
    for (Line.Info info1 : infos) {
        if (info1 instanceof Port.Info || info1 instanceof DataLine.Info) {
            portInfoList.add((Line.Info) info1);
        }
    }
    return portInfoList.toArray(EMPTY_PORT_INFO_ARRAY);
}
 
Example 4
Source File: UnexpectedIAE.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String argv[]) throws Exception {
    boolean success = true;

    Mixer.Info [] infos = AudioSystem.getMixerInfo();

    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        System.out.println("Mixer is: " + mixer);
        Line.Info [] target_line_infos = mixer.getTargetLineInfo();
        for (int j = 0; j < target_line_infos.length; j++) {
            try {
                System.out.println("Trying to get:" + target_line_infos[j]);
                mixer.getLine(target_line_infos[j]);
            } catch (IllegalArgumentException iae) {
                System.out.println("Unexpected IllegalArgumentException raised:");
                iae.printStackTrace();
                success = false;
            } catch (LineUnavailableException lue) {
                System.out.println("Unexpected LineUnavailableException raised:");
                lue.printStackTrace();
                success = false;
            }
        }
    }
    if (success) {
        System.out.println("Test passed");
    } else {
        throw new Exception("Test FAILED");
    }
}
 
Example 5
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 6
Source File: DefaultMixers.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean testMixer(Mixer mixer, Class lineType,
                                 String providerClassName,
                                 String instanceName) {
    boolean allOk = true;

    try {
        String propertyValue = (providerClassName != null) ? providerClassName: "" ;
        propertyValue += "#" + instanceName;
        out("property value: " + propertyValue);
        System.setProperty(lineType.getName(), propertyValue);
        Line line = null;
        Line.Info info = null;
        Line.Info[] infos;
        AudioFormat format = null;
        if (lineType == SourceDataLine.class || lineType == Clip.class) {
            infos = mixer.getSourceLineInfo();
            format = getFirstLinearFormat(infos);
            info = new DataLine.Info(lineType, format);
        } else if (lineType == TargetDataLine.class) {
            infos = mixer.getTargetLineInfo();
            format = getFirstLinearFormat(infos);
            info = new DataLine.Info(lineType, format);
        } else if (lineType == Port.class) {
            /* Actually, a Ports Mixer commonly has source infos
               as well as target infos. We ignore this here, since we
               just need a random one. */
            infos = mixer.getSourceLineInfo();
            for (int i = 0; i < infos.length; i++) {
                if (infos[i] instanceof Port.Info) {
                    info = infos[i];
                    break;
                }
            }
        }
        out("Line.Info: " + info);
        line = AudioSystem.getLine(info);
        out("line: " + line);
        if (! lineType.isInstance(line)) {
            out("type " + lineType + " failed: class should be '" +
                lineType + "' but is '" + line.getClass() + "'!");
            allOk = false;
        }
    } catch (Exception e) {
        out("Exception thrown; Test NOT failed.");
        e.printStackTrace();
    }
    return allOk;
}
 
Example 7
Source File: PhantomMixers.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    int SDLformats = 0;
    int TDLformats = 0;
    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    for(int i=0; i<mixerInfo.length; i++){
        Mixer.Info thisMixerInfo = mixerInfo[i];
        System.out.println("Mixer #"+i+": "
                           + thisMixerInfo.getName()
                           + ": " + thisMixerInfo.getDescription());
        Mixer mixer = AudioSystem.getMixer(thisMixerInfo);
        Line.Info[] srcLineInfo = mixer.getSourceLineInfo();
        Line.Info[] dstLineInfo = mixer.getTargetLineInfo();
        int count = srcLineInfo.length + dstLineInfo.length;
        System.out.print(" -> " + (srcLineInfo.length + dstLineInfo.length) + " line");
        switch (count) {
            case 0: System.out.println("s"); break;
            case 1: System.out.println(""); break;
            default: System.out.println("s:"); break;
        }
        int l;
        for (l = 0; l < srcLineInfo.length; l++) {
            System.out.println("    "+srcLineInfo[l].toString());
            if (srcLineInfo[l].getLineClass() == SourceDataLine.class
                && (srcLineInfo[l] instanceof DataLine.Info)) {
                SDLformats += ((DataLine.Info) srcLineInfo[l]).getFormats().length;
            }
        }
        for (l = 0; l < dstLineInfo.length; l++) {
            System.out.println("    "+dstLineInfo[l].toString());
            if (dstLineInfo[l].getLineClass() == TargetDataLine.class
                && (dstLineInfo[l] instanceof DataLine.Info)) {
                TDLformats += ((DataLine.Info) dstLineInfo[l]).getFormats().length;
            }
        }
    }
    if (mixerInfo.length == 0) {
        System.out.println("[no mixers present]");
    }
    System.out.println(""+SDLformats+" total formats for SourceDataLines");
    System.out.println(""+TDLformats+" total formats for TargetDataLines");
    System.out.println("");
    System.out.println("If there are audio devices correctly installed on your");
    System.out.println("system, you should see at least one Mixer, and in total");
    System.out.println("at least each one SourceDataLine and TargetDataLine, both");
    System.out.println("providing at least one format.");
    System.out.println("");
    System.out.println("Now disable your soundcard and repeat the test.");
    System.out.println("The corresponding mixer(s) should not provide any formats");
    System.out.println("anymore. If you disable all available soundcards");
    System.out.println("on your computer, the number of formats above should be");
    System.out.println("0 for both line types (although mixers are allowed to exist).");
}