javax.sound.sampled.Mixer Java Examples
The following examples show how to use
javax.sound.sampled.Mixer.
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 openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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: SoftMixingMixerProvider.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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
Source File: ClipCloseLoss.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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 #4
Source File: SoftMixingMixerProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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
Source File: DataLine_ArrayIndexOutOfBounds.java From hottub with GNU General Public License v2.0 | 6 votes |
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
Source File: DirectAudioDeviceProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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: ClipCloseLoss.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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"); } } }
Example #8
Source File: AbstractMixer.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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
Source File: ClipSetEndPoint.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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
Source File: DataLine_ArrayIndexOutOfBounds.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: DirectAudioDeviceProvider.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: ClickInPlay.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void play(Mixer mixer) { int res = 0; try { println("Getting clip from mixer..."); source = (Clip) mixer.getLine(info); println("Opening clip..."); source.open(audioFormat, audioData, 0, audioData.length); println("Starting clip..."); source.loop(Clip.LOOP_CONTINUOUSLY); println("Now open your ears:"); println("- if you hear a sine wave playing,"); println(" listen carefully if you can hear clicks."); println(" If no, the bug is fixed."); println("- if you don't hear anything, it's possible"); println(" that this mixer is not connected to an "); println(" amplifier, or that its volume is set to 0"); key(); } catch (IllegalArgumentException iae) { println("IllegalArgumentException: "+iae.getMessage()); println("Sound device cannot handle this audio format."); println("ERROR: Test environment not correctly set up."); if (source!=null) { source.close(); source = null; } return; } catch (LineUnavailableException lue) { println("LineUnavailableException: "+lue.getMessage()); println("This is normal for some mixers."); } catch (Exception e) { println("Unexpected Exception: "+e.toString()); } if (source != null) { println("Stopping..."); source.stop(); println("Closing..."); source.close(); println("Closed."); source = null; } }
Example #13
Source File: SoftMixingMixerProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #14
Source File: ClipFlushCrash.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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
Source File: TGMixer.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
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)); }
Example #16
Source File: AbstractMixer.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #17
Source File: DirectAudioDeviceProvider.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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: DataLine_ArrayIndexOutOfBounds.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #19
Source File: AbstractMixer.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #20
Source File: SoftMixingMixerProvider.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #21
Source File: ClipDrain.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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 #22
Source File: AbstractMixer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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 #23
Source File: DataLine_ArrayIndexOutOfBounds.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #24
Source File: DataLine_ArrayIndexOutOfBounds.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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
Source File: PortMixerProvider.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 #26
Source File: DirectAudioDeviceProvider.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #27
Source File: AudioSystem.java From tuxguitar with GNU Lesser General Public License v2.1 | 5 votes |
/** Return a Mixer with a given name from a given MixerProvider. This method never requires the returned Mixer to do mixing. @param mixerName The name of the Mixer to be returned. @param provider The MixerProvider to check for Mixers. @param info The type of line the returned Mixer is required to support. @return A Mixer matching the requirements, or null if none is found. */ private static Mixer getNamedMixer(String mixerName, MixerProvider provider, Line.Info info) { Mixer.Info[] infos = provider.getMixerInfo(); for (int i = 0; i < infos.length; i++) { if (infos[i].getName().equals(mixerName)) { Mixer mixer = provider.getMixer(infos[i]); if (isAppropriateMixer(mixer, info, false)) { return mixer; } } } return null; }
Example #28
Source File: PortMixerProvider.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 #29
Source File: SoundSystem.java From stendhal with GNU General Public License v2.0 | 5 votes |
public static Mixer tryToFindMixer(AudioFormat audioFormat) { Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo(); Mixer[] mixers = new Mixer[mixerInfos.length]; final DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat); if(mixers.length == 0) { return null; } for(int i=0; i<mixerInfos.length; ++i) { mixers[i] = AudioSystem.getMixer(mixerInfos[i]); } Arrays.sort(mixers, new Comparator<Mixer>() { @Override public int compare(Mixer mixer1, Mixer mixer2) { int numLines1 = mixer1.getMaxLines(dataLineInfo); int numLines2 = mixer2.getMaxLines(dataLineInfo); if(numLines1 == AudioSystem.NOT_SPECIFIED || numLines1 > numLines2) { return -1; } return 1; } }); if(mixers[0].getMaxLines(dataLineInfo) == 0) { return null; } return mixers[0]; }
Example #30
Source File: ClipDrain.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void doAll() throws Exception { Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for (int i=0; i<mixers.length; i++) { Mixer mixer = AudioSystem.getMixer(mixers[i]); System.out.println("--------------"); System.out.println("Testing mixer: "+mixers[i]); doMixerClip(mixer); } if (mixers.length==0) { System.out.println("No mixers available!"); } }