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

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

源代码1 项目: jdk8u-jdk   文件: SoftMixingMixerProvider.java
public Mixer getMixer(Info info) {
    if (!(info == null || info == SoftMixingMixer.info)) {
        throw new IllegalArgumentException("Mixer " + info.toString()
                + " not supported by this provider.");
    }
    synchronized (mutex) {
        if (lockthread != null)
            if (Thread.currentThread() == lockthread)
                throw new IllegalArgumentException("Mixer "
                        + info.toString()
                        + " not supported by this provider.");
        if (globalmixer == null)
            globalmixer = new SoftMixingMixer();
        return globalmixer;
    }

}
 
源代码2 项目: hottub   文件: DataLine_ArrayIndexOutOfBounds.java
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码3 项目: openjdk-jdk9   文件: ClipCloseLoss.java
public static void main(String[] args) throws Exception    {
    if (isSoundcardInstalled()) {
        bais.mark(0);
        run(null);
        Mixer.Info[] infos = AudioSystem.getMixerInfo();
        for (int i = 0; i<infos.length; i++) {
            try {
                Mixer m = AudioSystem.getMixer(infos[i]);
                run(m);
            } catch (Exception e) {
            }
        }
        out("Waiting 1 second to dispose of all threads");
        Thread.sleep(1000);
        if (getClipThreadCount() > 0) {
            out("Unused clip threads exist! Causes test failure");
            failed = true;
        }
        if (failed) throw new Exception("Test FAILED!");
        if (success > 0) {
            out("Test passed.");
        } else {
            System.err.println("Test could not execute: please install an audio device");
        }
    }
}
 
源代码4 项目: openjdk-jdk9   文件: ClipCloseLoss.java
/**
* Returns true if at least one soundcard is correctly installed
* on the system.
*/
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
源代码5 项目: openjdk-jdk9   文件: ClipSetEndPoint.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: " + e);
    }
    if (!result) {
        System.err.println(
                "Soundcard does not exist or sound drivers not installed!");
        System.err.println(
                "This test requires sound drivers for execution.");
    }
    return result;
}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码7 项目: jdk8u-jdk   文件: SoftMixingMixerProvider.java
public Mixer getMixer(Info info) {
    if (!(info == null || info == SoftMixingMixer.info)) {
        throw new IllegalArgumentException("Mixer " + info.toString()
                + " not supported by this provider.");
    }
    synchronized (mutex) {
        if (lockthread != null)
            if (Thread.currentThread() == lockthread)
                throw new IllegalArgumentException("Mixer "
                        + info.toString()
                        + " not supported by this provider.");
        if (globalmixer == null)
            globalmixer = new SoftMixingMixer();
        return globalmixer;
    }

}
 
源代码8 项目: openjdk-jdk9   文件: AbstractMixer.java
/**
 * Constructs a new AbstractMixer.
 * @param mixerInfo 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;
}
 
源代码9 项目: openjdk-jdk9   文件: ClipDrain.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
源代码10 项目: openjdk-8-source   文件: SoftMixingMixerProvider.java
public Mixer getMixer(Info info) {
    if (!(info == null || info == SoftMixingMixer.info)) {
        throw new IllegalArgumentException("Mixer " + info.toString()
                + " not supported by this provider.");
    }
    synchronized (mutex) {
        if (lockthread != null)
            if (Thread.currentThread() == lockthread)
                throw new IllegalArgumentException("Mixer "
                        + info.toString()
                        + " not supported by this provider.");
        if (globalmixer == null)
            globalmixer = new SoftMixingMixer();
        return globalmixer;
    }

}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码12 项目: jdk8u-dev-jdk   文件: DirectAudioDeviceProvider.java
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.");
}
 
源代码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 项目: tuxguitar   文件: TGMixer.java
public TGMixer() {
	super(new Line.Info(Mixer.class));
	
	this.lines = new HashMap<Class<?>, Line>();
	this.sourceLineInfo = new ArrayList<DataLine.Info>();
	this.targetLineInfo = new ArrayList<DataLine.Info>();
	
	List<AudioFormat> formats = new ArrayList<AudioFormat>();
	for (int channels = 1; channels <= 2; channels++) {
		formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false)); 
		formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false));
			for (int bits = 16; bits < 32; bits += 8) {
				formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
				formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
				formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
				formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
			}
			formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, false));
			formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, true));
			formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, false));
			formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, true));
		}
		
		this.sourceLineInfo.add(new DataLine.Info(SourceDataLine.class, formats.toArray(new AudioFormat[formats.size()]), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED));
}
 
源代码15 项目: openjdk-jdk8u   文件: DirectAudioDeviceProvider.java
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.");
}
 
源代码16 项目: 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;
}
 
源代码17 项目: jdk8u_jdk   文件: DataLine_ArrayIndexOutOfBounds.java
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码18 项目: openjdk-jdk9   文件: ClipFlushCrash.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
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.");
}
 
源代码21 项目: Bytecoder   文件: AbstractMixer.java
/**
 * Constructs a new AbstractMixer.
 * @param mixerInfo 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;
}
 
源代码22 项目: openjdk-8   文件: SoftMixingMixerProvider.java
public Mixer getMixer(Info info) {
    if (!(info == null || info == SoftMixingMixer.info)) {
        throw new IllegalArgumentException("Mixer " + info.toString()
                + " not supported by this provider.");
    }
    synchronized (mutex) {
        if (lockthread != null)
            if (Thread.currentThread() == lockthread)
                throw new IllegalArgumentException("Mixer "
                        + info.toString()
                        + " not supported by this provider.");
        if (globalmixer == null)
            globalmixer = new SoftMixingMixer();
        return globalmixer;
    }

}
 
源代码23 项目: jdk8u-jdk   文件: DirectAudioDeviceProvider.java
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.");
}
 
源代码24 项目: openjdk-jdk9   文件: DirectAudioDeviceProvider.java
private static Mixer getDevice(DirectAudioDeviceInfo info) {
    int index = info.getIndex();
    if (devices[index] == null) {
        devices[index] = new DirectAudioDevice(info);
    }
    return devices[index];
}
 
源代码25 项目: jdk8u-dev-jdk   文件: PortMixerProvider.java
public Mixer.Info[] getMixerInfo() {
    synchronized (PortMixerProvider.class) {
        Mixer.Info[] localArray = new Mixer.Info[infos.length];
        System.arraycopy(infos, 0, localArray, 0, infos.length);
        return localArray;
    }
}
 
源代码26 项目: FoxTelem   文件: SinkAudio.java
public void setDevice(int position) throws LineUnavailableException, IllegalArgumentException {
	if (position == 0 || position == -1) {
		initializeOutput();
	} else {
		Mixer appMixer = mixerList[position];

		Info sdlLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
		
		sourceDataLine = (SourceDataLine) appMixer.getLine(sdlLineInfo);
		sourceDataLine.open(audioFormat);
		sourceDataLine.start();
	}
		

}
 
源代码27 项目: openjdk-jdk9   文件: NoSimpleInputDevice.java
public static void main(String[] args) throws Exception {
    out("4936397: Verify that there'll be either SimpleInputDevice OR DirectAudioDevice");
    boolean foundSimpleInputDevice = false;
    boolean foundDirectAudioDevice = false;

    Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
    for (int i = 0; i < aInfos.length; i++) {
        try {
            Mixer mixer = AudioSystem.getMixer(aInfos[i]);
            String mixerClass = mixer.getClass().toString();
            if (mixerClass.indexOf("SimpleInputDevice") >= 0) {
                out("Found SimpleInputDevice: "+aInfos[i]);
                foundSimpleInputDevice = true;
            }
            if (mixerClass.indexOf("DirectAudioDevice") >= 0) {
                out("Found DirectAudioDevice: "+aInfos[i]);
                foundDirectAudioDevice = true;
            }
        } catch (Exception e) {
            out("Unexpected exception: "+e);
        }
    }
    if (aInfos.length == 0) {
        out("[No mixers available] - cannot exercise this test.");
    } else {
        if (foundSimpleInputDevice && foundDirectAudioDevice) {
            out("Found both types of capture devices!");
            throw new Exception("Test FAILED!");
        }
        out("Did not find both types of capture devices. Test passed");
    }
}
 
源代码28 项目: TencentKona-8   文件: DirectAudioDeviceProvider.java
public Mixer.Info[] getMixerInfo() {
    synchronized (DirectAudioDeviceProvider.class) {
        Mixer.Info[] localArray = new Mixer.Info[infos.length];
        System.arraycopy(infos, 0, localArray, 0, infos.length);
        return localArray;
    }
}
 
源代码29 项目: TencentKona-8   文件: DirectAudioDeviceProvider.java
private static Mixer getDevice(DirectAudioDeviceInfo info) {
    int index = info.getIndex();
    if (devices[index] == null) {
        devices[index] = new DirectAudioDevice(info);
    }
    return devices[index];
}
 
源代码30 项目: TencentKona-8   文件: PortMixerProvider.java
private static Mixer getDevice(PortMixerInfo info) {
    int index = info.getIndex();
    if (devices[index] == null) {
        devices[index] = new PortMixer(info);
    }
    return devices[index];
}