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

The following examples show how to use javax.sound.sampled.Mixer#getSourceLineInfo() . 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: DirectAudioDeviceProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
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: 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 4
Source File: DirectAudioDeviceProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 5
Source File: DirectAudioDeviceProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 6
Source File: DirectAudioDeviceProvider.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 7
Source File: DirectAudioDeviceProvider.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 8
Source File: DirectAudioDeviceProvider.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 9
Source File: DirectAudioDeviceProvider.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 10
Source File: DirectAudioDeviceProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 11
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 12
Source File: DirectAudioDeviceProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException(
            String.format("Mixer %s not supported by this provider", info));
}
 
Example 13
Source File: DirectAudioDeviceProvider.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException(
            String.format("Mixer %s not supported by this provider", info));
}
 
Example 14
Source File: DirectAudioDeviceProvider.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 15
Source File: DirectAudioDeviceProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 16
Source File: DirectAudioDeviceProvider.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 17
Source File: DirectAudioDeviceProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (DirectAudioDeviceProvider.class) {
        // if the default device is asked, we provide the mixer
        // with SourceDataLine's
        if (info == null) {
            for (int i = 0; i < infos.length; i++) {
                Mixer mixer = getDevice(infos[i]);
                if (mixer.getSourceLineInfo().length > 0) {
                    return mixer;
                }
            }
        }
        // otherwise get the first mixer that matches
        // the requested info object
        for (int i = 0; i < infos.length; i++) {
            if (infos[i].equals(info)) {
                return getDevice(infos[i]);
            }
        }
    }
    throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
 
Example 18
Source File: FrameSizeTest.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 {
    boolean res=true;
    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    for (int i = 0; i < mixerInfo.length; i++) {
        Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
        System.out.println(mixer);
        Line.Info[] lineinfo = mixer.getSourceLineInfo();
        for (int j = 0; j < lineinfo.length; j++) {
            System.out.println("  " + lineinfo[j]);
            try {
                AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();
                for (int k = 0; k < formats.length; k++) {
                    if ( (formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
                          || formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))
                         && (formats[k].getFrameSize() != AudioSystem.NOT_SPECIFIED)
                         && ((formats[k].getSampleSizeInBits() == 16) || (formats[k].getSampleSizeInBits() == 8))
                         && ((((formats[k].getSampleSizeInBits() + 7) / 8) * formats[k].getChannels()) != formats[k].getFrameSize())) {
                        System.out.println(" # " + formats[k] + ", getFrameSize() wrongly returns"+ formats[k].getFrameSize());
                        res=false;
                    }
                }
            } catch (ClassCastException e) {
            }
        }
    }

    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
}
 
Example 19
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 20
Source File: JavaInfo.java    From haxademic with MIT License 4 votes vote down vote up
public static void printAudioInfo() {
		P.out("----------------- printAudioInfo -------------------");
		Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
		for(int i = 0; i < mixerInfo.length; i++) {
			P.out("########## mixerInfo["+i+"]", mixerInfo[i].getName());

//			Mixer mixer = AudioSystem.getMixer(null); // default mixer
			Mixer mixer = AudioSystem.getMixer(mixerInfo[i]); // default mixer
			try {
				mixer.open();
			} catch (LineUnavailableException e) {
				e.printStackTrace();
			}
	
			P.out("Supported SourceDataLines of default mixer (%s):\n\n", mixer.getMixerInfo().getName());
			for(Line.Info info : mixer.getSourceLineInfo()) {
			    if(SourceDataLine.class.isAssignableFrom(info.getLineClass())) {
			        SourceDataLine.Info info2 = (SourceDataLine.Info) info;
			        P.out(info2);
			        System.out.printf("  max buffer size: \t%d\n", info2.getMaxBufferSize());
			        System.out.printf("  min buffer size: \t%d\n", info2.getMinBufferSize());
			        AudioFormat[] formats = info2.getFormats();
			        P.out("  Supported Audio formats: ");
			        for(AudioFormat format : formats) {
			        	P.out("    "+format);
			          System.out.printf("      encoding:           %s\n", format.getEncoding());
			          System.out.printf("      channels:           %d\n", format.getChannels());
			          System.out.printf(format.getFrameRate()==-1?"":"      frame rate [1/s]:   %s\n", format.getFrameRate());
			          System.out.printf("      frame size [bytes]: %d\n", format.getFrameSize());
			          System.out.printf(format.getSampleRate()==-1?"":"      sample rate [1/s]:  %s\n", format.getSampleRate());
			          System.out.printf("      sample size [bit]:  %d\n", format.getSampleSizeInBits());
			          System.out.printf("      big endian:         %b\n", format.isBigEndian());
			          
			          Map<String,Object> prop = format.properties();
			          if(!prop.isEmpty()) {
			        	  P.out("      Properties: ");
			              for(Map.Entry<String, Object> entry : prop.entrySet()) {
			                  System.out.printf("      %s: \t%s\n", entry.getKey(), entry.getValue());
			              }
			          }
			        }
			        P.out();
			    } else {
			    	P.out(info.toString());
			    }
			    P.out();
			}
			mixer.close();
		}
	}