Java Code Examples for javax.sound.sampled.Mixer

The following are top voted examples for showing how to use javax.sound.sampled.Mixer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: java-stream-player   File: StreamPlayer.java   View source code 6 votes vote down vote up
/**
 * Returns the mixer with this name.
 *
 * @param name
 *            the name
 * @return The Mixer with that name
 */
private Mixer getMixer(String name) {
	Mixer mixer = null;
	
	// 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 (name != null && mixerInfos != null)
		for (int i = 0; i < mixerInfos.length; i++)
			if (mixerInfos[i].getName().equals(name)) {
				mixer = AudioSystem.getMixer(mixerInfos[i]);
				break;
			}
	return mixer;
}
 
Example 2
Project: OpenJSharp   File: SoftMixingMixerProvider.java   View source code 6 votes vote down vote up
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;
    }

}
 
Example 3
Project: jdk8u-jdk   File: DirectAudioDeviceProvider.java   View source code 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 4
Project: jdk8u-jdk   File: SoftMixingMixerProvider.java   View source code 6 votes vote down vote up
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;
    }

}
 
Example 5
Project: jdk8u-jdk   File: DataLine_ArrayIndexOutOfBounds.java   View source code 6 votes vote down vote up
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");
    }
}
 
Example 6
Project: openjdk-jdk10   File: DirectAudioDeviceProvider.java   View source code 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 7
Project: openjdk-jdk10   File: SoftMixingMixerProvider.java   View source code 6 votes vote down vote up
@Override
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;
    }
}
 
Example 8
Project: openjdk-jdk10   File: AbstractMixer.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Project: openjdk-jdk10   File: ExtraCharInSoundbank.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 10
Project: openjdk-jdk10   File: FloatControlBug.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 11
Project: openjdk-jdk10   File: ClipSetEndPoint.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 12
Project: openjdk-jdk10   File: ClipFlushCrash.java   View source code 6 votes vote down vote up
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) {
            }
        }
        if (success > 0) {
            out("No crash -> Test passed");
        } else {
            System.err.println("Test could not execute: please install an audio device");
        }
    }
}
 
Example 13
Project: openjdk-jdk10   File: ClipCloseLoss.java   View source code 6 votes vote down vote up
/**
* 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;
}
 
Example 14
Project: openjdk-jdk10   File: ClipDuration.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Project: openjdk-jdk10   File: ClipLinuxCrash2.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 16
Project: openjdk-jdk10   File: SDLLinuxCrash.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 17
Project: openjdk-jdk10   File: DefaultMixers.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    boolean allOk = true;
    Mixer.Info[] infos;

    out("Testing Mixers retrieved via AudioSystem");
    infos = AudioSystem.getMixerInfo();
    allOk &= testMixers(infos, null);

    out("Testing MixerProviders");
    List providers = JDK13Services.getProviders(MixerProvider.class);
    for (int i = 0; i < providers.size(); i++) {
        MixerProvider provider = (MixerProvider) providers.get(i);
        infos = provider.getMixerInfo();
        allOk &= testMixers(infos, provider.getClass().getName());
    }

    if (! allOk) {
        throw new Exception("Test failed");
    } else {
        out("Test passed");
    }
}
 
Example 18
Project: openjdk-jdk10   File: DefaultMixers.java   View source code 6 votes vote down vote up
private static boolean testMixers(Mixer.Info[] infos,
                                  String providerClassName) {
    boolean allOk = true;

    for (int i = 0; i < infos.length; i++) {
        Mixer mixer = null;
        try {
            mixer = AudioSystem.getMixer(infos[i]);
        } catch (NullPointerException e) {
            out("Exception thrown; Test NOT failed.");
            e.printStackTrace();
        }
        for (int j = 0; j < lineClasses.length; j++) {
            if (mixer.isLineSupported(new Line.Info(lineClasses[j]))) {
                allOk &= testMixer(mixer, lineClasses[j],
                                   providerClassName);
            }
        }
    }
    return allOk;
}
 
Example 19
Project: openjdk-jdk10   File: LineDefFormat.java   View source code 6 votes vote down vote up
private static void doMixerClip(Mixer mixer, AudioFormat format) {
    if (mixer==null) return;
    try {
        System.out.println("Clip from mixer "+mixer+":");
        System.out.println("   "+mixer.getMixerInfo());
            DataLine.Info info = new DataLine.Info(
                                      Clip.class,
                                      format);

        if (mixer.isLineSupported(info)) {
            Clip clip = (Clip) mixer.getLine(info);
            doLine1(clip, format);
        } else {
            System.out.println("  - Line not supported");
        }
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
    }
}
 
Example 20
Project: openjdk-jdk10   File: LineDefFormat.java   View source code 6 votes vote down vote up
private static void doMixerSDL(Mixer mixer, AudioFormat format) {
    if (mixer==null) return;
    try {
        System.out.println("SDL from mixer "+mixer+":");
            DataLine.Info info = new DataLine.Info(
                                      SourceDataLine.class,
                                      format);

        if (mixer.isLineSupported(info)) {
            SourceDataLine sdl = (SourceDataLine) mixer.getLine(info);
            doLine1(sdl, format);
            doLine2(sdl, format);
        } else {
            System.out.println("  - Line not supported");
        }
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
    }
}
 
Example 21
Project: openjdk-jdk10   File: LineDefFormat.java   View source code 6 votes vote down vote up
private static void doMixerTDL(Mixer mixer, AudioFormat format) {
    if (mixer==null) return;
    try {
        System.out.println("TDL from mixer "+mixer+":");
            DataLine.Info info = new DataLine.Info(
                                      TargetDataLine.class,
                                      format);
        if (mixer.isLineSupported(info)) {
            TargetDataLine tdl = (TargetDataLine) mixer.getLine(info);
            doLine1(tdl, format);
            doLine2(tdl, format);
        } else {
            System.out.println("  - Line not supported");
        }
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
    }
}
 
Example 22
Project: rcom   File: Replay.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws IOException, LineUnavailableException {
	File folder=new File("/home/rizsi/tmp/video");
	byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
	byte[] data2=UtilFile.loadFile(new File(folder, "local.sw"));
	System.out.println("remote.sw max: "+measureMax(data));
	System.out.println("local.sw max: "+measureMax(data2));
	byte[] data3=sum(data, data2);
	UtilFile.saveAsFile(new File(folder, "rawmic.sw"), data3);
	AudioFormat format=ManualTestEchoCancel.getFormat();
	final Mixer mixer = AudioSystem.getMixer(null);
	Play p=new Play(mixer, format, ManualTestEchoCancel.frameSamples)
	{
		@Override
		protected void switchBuffer() {
			if(getSample()==data)
			{
				setSample(data2);
			}else if(getSample()==data2)
			{
				setSample(data3);
			}
		}
	};
	p.start();
	p.setSample(data);
}
 
Example 23
Project: openjdk-jdk10   File: DataLineInfoNegBufferSize.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 24
Project: openjdk-jdk10   File: DataLine_ArrayIndexOutOfBounds.java   View source code 6 votes vote down vote up
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");
    }
}
 
Example 25
Project: openjdk-jdk10   File: BufferSizeCheck.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 26
Project: java-stream-player   File: StreamPlayer.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 27
Project: openjdk-jdk10   File: BothEndiansAndSigns.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    out("4936397: Verify that there'll for a given endianness, there's also the little endian version");
    out("         and the same for signed'ness for 8-bit formats");

    Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
    for (int i = 0; i < aInfos.length; i++) {
        try {
            Mixer mixer = AudioSystem.getMixer(aInfos[i]);
            out("Mixer "+aInfos[i]);
            checkLines(mixer, mixer.getSourceLineInfo());
            checkLines(mixer, mixer.getTargetLineInfo());
        } catch (Exception e) {
            out("Unexpected exception when getting a mixer: "+e);
        }
    }
    if (testedFormats == 0) {
        out("[No appropriate lines available] - cannot exercise this test.");
    } else {
        if (failed) {
            throw new Exception("Test FAILED!");
        }
        out("Test passed");
    }
}
 
Example 28
Project: openjdk-jdk10   File: BothEndiansAndSigns.java   View source code 6 votes vote down vote up
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);
        }
    }
}
 
Example 29
Project: romanov   File: Minim.java   View source code 5 votes vote down vote up
/**
 * When using the JavaSound implementation of Minim, this sets the JavaSound Mixer 
 * that will be used for obtaining input sources such as AudioInputs.
 * THIS METHOD WILL BE REPLACED IN A FUTURE VERSION.
 * 
 * @param mixer
 *            The Mixer we should try to acquire inputs from.
 */
@Deprecated
public void setInputMixer(Mixer mixer)
{
	if ( mimp instanceof JSMinim )
	{
		( (JSMinim)mimp ).setInputMixer( mixer );
	}
}
 
Example 30
Project: BrainControl   File: Microphone.java   View source code 5 votes vote down vote up
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;
}
 
Example 31
Project: BrainControl   File: Microphone.java   View source code 5 votes vote down vote up
/**
 * Gets the Mixer to use. Depends upon selectedMixerIndex being defined.
 *
 * @see #newProperties
 */
private Mixer getSelectedMixer() {
	if (selectedMixerIndex.equals("default")) {
		return null;
	} else {
		Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
		if (selectedMixerIndex.equals("last")) {
			return AudioSystem.getMixer(mixerInfo[mixerInfo.length - 1]);
		} else {
			int index = Integer.parseInt(selectedMixerIndex);
			return AudioSystem.getMixer(mixerInfo[index]);
		}
	}
}
 
Example 32
Project: rcom   File: Replay2.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws IOException, LineUnavailableException {
	try(Scanner br=new Scanner(System.in))
	{
		String s=br.nextLine();
		byte[] data=UtilFile.loadFile(new File("/tmp/"+s+".sw"));
		System.out.println("Playing: "+s);
		AudioFormat format=ManualTestEchoCancel.getFormat();
		final Mixer mixer = AudioSystem.getMixer(null);
		Play p=new Play(mixer, format, ManualTestEchoCancel.frameSamples)
		{
		};
		p.start();
		p.setSample(data);
	}
}
 
Example 33
Project: freecol   File: SoundController.java   View source code 5 votes vote down vote up
/**
 * Get the label text for the sound player mixer.
 *
 * Needed by the audio mixer option UI.
 *
 * @return The text.
 */
public String getSoundMixerLabelText() {
    Mixer mixer;
    String text = (soundPlayer == null)
        ? Messages.message("nothing")
        : ((mixer = soundPlayer.getMixer()) == null)
            ? Messages.message("none")
            : mixer.getMixerInfo().getName();
    return Messages.message("current") + ":  " + text;
}
 
Example 34
Project: OpenJSharp   File: DirectAudioDeviceProvider.java   View source code 5 votes vote down vote up
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;
    }
}
 
Example 35
Project: OpenJSharp   File: DirectAudioDeviceProvider.java   View source code 5 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 36
Project: OpenJSharp   File: PortMixerProvider.java   View source code 5 votes vote down vote up
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;
    }
}
 
Example 37
Project: OpenJSharp   File: PortMixerProvider.java   View source code 5 votes vote down vote up
public Mixer getMixer(Mixer.Info info) {
    synchronized (PortMixerProvider.class) {
        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 38
Project: rcom   File: ResampleExample.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {
		AbstractRcomArgs a=new AbstractRcomArgs();
		UtilCli.parse(a, args, true);
		File folder=new File("/home/rizsi/tmp/video");
		byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
		AudioFormat format=ManualTestEchoCancel.getFormat();
		final Mixer mixer = AudioSystem.getMixer(null);
		DataLine.Info info2= new DataLine.Info(SourceDataLine.class, format);
		SourceDataLine s=(SourceDataLine) mixer.getLine(info2);
		s.open(format, framesamples*2);
		s.start();
		try(LoopInputStream lis=new LoopInputStream(data))
		{
			try(SpeexResampler resampler=new SpeexResampler(a, framesamples, new ResampledReceiver(s)))
			{
				final byte[] buffer=new byte[framesamples*2];;
				while(true)
				{
					UtilStream.readFully(buffer, lis, buffer.length);
					feed(resampler, buffer);
				}
			}
//			byte[] buffer=new byte[framesamples*2];
//			while(true)
//			{
//				UtilStream.readFully(buffer, resampled, buffer.length);
//			}
		}
	}
 
Example 39
Project: openjdk-jdk10   File: BogusMixers.java   View source code 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 40
Project: rcom   File: Record.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	AudioFormat format=ManualTestEchoCancel.getFormat();
	final Mixer mixer = AudioSystem.getMixer(null);
	Mic m=new Mic(mixer, format, ManualTestEchoCancel.frameSamples);
	m.start();
	try(Scanner br=new Scanner(System.in))
	{
		System.out.println("Press ENTER to start recording");
		br.nextLine();
		try(FileOutputStream fos=new FileOutputStream("/tmp/out.sw"))
		{
			m.setRecord(fos);
			System.out.println("Press ENTER to stop recording");
			br.nextLine();
			m.setRecord(null);
		}
	}
	System.exit(0);
}