List of usage examples for javax.sound.sampled AudioSystem getMixerInfo
public static Mixer.Info[] getMixerInfo()
From source file:com.gameminers.mav.audio.AudioManager.java
public void init() { Mixer.Info info = AudioSystem.getMixerInfo()[0]; mixer = AudioSystem.getMixer(info); // TODO loadClip("notif1"); loadClip("notif2"); loadClip("notif3"); loadClip("recog1"); loadClip("fail1"); loadClip("fail2"); loadClip("listen1"); sink = new AudioPlayback(Constants.FORMAT_CODE_CD, mixer, Constants.BUFFER_SIZE_MILLIS[Constants.BUFFER_SIZE_INDEX_DEFAULT]); source = new AudioCapture(Constants.FORMAT_CODE_SPHINX, mixer, Constants.BUFFER_SIZE_MILLIS[Constants.BUFFER_SIZE_INDEX_DEFAULT]); try {//from ww w.j ava 2s. co m sink.open(); } catch (Exception e) { e.printStackTrace(); } try { source.open(); } catch (Exception e) { e.printStackTrace(); } try { sink.start(); } catch (Exception e) { e.printStackTrace(); } try { source.start(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.offbynull.voip.audio.gateways.io.AudioRunnable.java
private Object loadDevices() { Map<Integer, LineEntry> newOutputDevices = new HashMap<>(); Map<Integer, LineEntry> newInputDevices = new HashMap<>(); List<OutputDevice> respOutputDevices = new LinkedList<>(); List<InputDevice> respInputDevices = new LinkedList<>(); Mixer.Info[] mixerInfos;//from ww w .j av a2s . c om try { mixerInfos = AudioSystem.getMixerInfo(); } catch (Exception e) { LOG.error("Unable to get mixers", e); return new ErrorResponse("Unable to get mixers: " + e); } for (Mixer.Info info : mixerInfos) { Mixer mixer; try { mixer = AudioSystem.getMixer(info); } catch (Exception e) { LOG.error("Unable to get mixer", e); continue; } Line.Info[] lineInfos; Map<Integer, LineEntry> newEntries; // out devices try { lineInfos = mixer.getSourceLineInfo(new Line.Info(SourceDataLine.class)); newEntries = generateLineEntriesFromJavaSound(mixer, lineInfos); newOutputDevices.putAll(newEntries); newEntries.entrySet().forEach(x -> { Mixer.Info mi = x.getValue().getMixer().getMixerInfo(); String name = "OUT:" + mi.getName() + "/" + mi.getVersion() + "/" + mi.getVendor() + "/" + mi.getDescription(); OutputDevice outputDevice = new OutputDevice(x.getKey(), name); respOutputDevices.add(outputDevice); }); } catch (LineUnavailableException lue) { LOG.error("Unable to get line from mixer", lue); } // in devices try { lineInfos = mixer.getTargetLineInfo(new Line.Info(TargetDataLine.class)); newEntries = generateLineEntriesFromJavaSound(mixer, lineInfos); newInputDevices.putAll(newEntries); newEntries.entrySet().forEach(x -> { Mixer.Info mi = x.getValue().getMixer().getMixerInfo(); String name = "IN:" + mi.getName() + "/" + mi.getVersion() + "/" + mi.getVendor() + "/" + mi.getDescription(); InputDevice inputDevice = new InputDevice(x.getKey(), name); respInputDevices.add(inputDevice); }); } catch (LineUnavailableException lue) { LOG.error("Unable to get line from mixer", lue); } } inputDevices = newInputDevices; outputDevices = newOutputDevices; return new LoadDevicesResponse(respOutputDevices, respInputDevices); }
From source file:com.lfv.lanzius.application.Controller.java
public synchronized void init(int id) { clear();/*w w w . j a va2s . co m*/ state = CLIENT_STATE_DISCONNECTED; reconnectPrintCount = 5; // Load terminal properties try { properties = new TerminalProperties(id); } catch (Exception ex) { log.error("Invalid or no terminal properties file (data/properties/terminalproperties.xml). Exiting!", ex); System.exit(0); } // Overwrite if specified externally on the command line if (id > 0) properties.setTerminalId(id); log.info("Starting terminal " + properties.getTerminalId()); // Setup codec values AudioDecoder.setJitterBufferSize(properties.getJitterBufferSize()); AudioDecoder.setOutputBufferSize(properties.getOutputBufferSize()); AudioEncoder.setInputBufferSize(properties.getInputBufferSize()); // Initialize the timing system Time.init(); // Setup a socket address to the server try { serverSocketAddr = new SocketAddress(properties.getServerAddress(), properties.getServerUdpPort()); } catch (UnknownHostException ex) { log.error("Invalid server address. Exiting!", ex); System.exit(0); } // Create a bundle bundle = new ClientBundle(); // Create the network manager try { networkManager = new ClientNetworkManager(properties.getTerminalId(), bundle, serverSocketAddr, new SocketAddress(properties.getLocalBindAddress(), properties.getLocalBindPort()), new SocketAddress(properties.getMulticastAddress(), properties.getMulticastPort()), properties.getMulticastTTL(), properties); packetReceiver = networkManager.getReceiver(); } catch (IOException ex) { log.error( "The network manager could not be created, possibly due to an invalid multicast socket setting. Exiting!", ex); System.exit(0); } // Create push to talk interfaces if (properties.getEventDeviceName().length() > 0) { eventSwitch = new EventSwitchController(this, properties.getEventDeviceName()); } if (properties.getFootSwitchInterface().length() > 0) { try { footSwitch = new FootSwitchController(this, properties.getFootSwitchInterface(), properties.getFootSwitchPollTimeMillis(), properties.isFootSwitchInverted()); } catch (UnsatisfiedLinkError err) { log.error("UnsatisfiedLinkError: " + err.getMessage()); log.warn("Missing ftsw library (ftsw.dll or libftsw.so)"); if (!properties.getFootSwitchInterface().equalsIgnoreCase("ftdi")) log.warn("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)"); log.warn("The footswitch has been disabled!"); footSwitch = null; } catch (NoClassDefFoundError err) { log.warn("Missing ftsw library (ftsw.dll or libftsw.so)"); if (!properties.getFootSwitchInterface().equalsIgnoreCase("ftdi")) log.warn("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)"); log.warn("The footswitch has been disabled!"); footSwitch = null; } } // Get the selected audio devices Mixer.Info[] mixerinfo = AudioSystem.getMixerInfo(); if ((properties.getSoundOutputDevice() >= mixerinfo.length) || (properties.getSoundInputDevice() >= mixerinfo.length)) { log.error("Invalid sound device. Exiting!"); //System.exit(0); } outputMixer = AudioSystem.getMixer(mixerinfo[properties.getSoundOutputDevice()]); inputMixer = AudioSystem.getMixer(mixerinfo[properties.getSoundInputDevice()]); if (log.isDebugEnabled()) { log.debug("Using output device " + properties.getSoundOutputDevice() + " (" + mixerinfo[properties.getSoundOutputDevice()] + ")"); log.debug("Using input device " + properties.getSoundInputDevice() + " (" + mixerinfo[properties.getSoundInputDevice()] + ")"); } // Creating sound clips clipRingTone = new SoundClip(outputMixer, "data/resources/sounds/phone_ringtone_mono.wav", "data/resources/sounds/phone_ringtone_stereo.wav", 1100, properties.getSignalVolumeAdjustment()); volumeClipList.add(clipRingTone); clipRingBack = new SoundClip(outputMixer, "data/resources/sounds/phone_ringback_mono.wav", "data/resources/sounds/phone_ringback_stereo.wav", 2100, properties.getSignalVolumeAdjustment()); volumeClipList.add(clipRingBack); clipRingBusy = new SoundClip(outputMixer, "data/resources/sounds/phone_busy_mono.wav", "data/resources/sounds/phone_busy_stereo.wav", 400, properties.getSignalVolumeAdjustment()); volumeClipList.add(clipRingBusy); clipWarning = new SoundClip(outputMixer, "data/resources/sounds/radio_error_mono.wav", "data/resources/sounds/radio_error_stereo.wav", 1000, properties.getSignalVolumeAdjustment()); volumeClipList.add(clipWarning); clipNotify = new SoundClip(outputMixer, "data/resources/sounds/ding_mono.wav", "data/resources/sounds/ding_stereo.wav", 1000, properties.getSignalVolumeAdjustment()); volumeClipList.add(clipNotify); // Create peripheral link peripheralLink = null; int peripheralLinkPort = properties.getPeripheralLinkPort(); if (peripheralLinkPort > 0) { try { peripheralLink = new PeripheralLink(properties.getTerminalId(), peripheralLinkPort); peripheralLink.startModule(); } catch (IOException ex) { log.warn("Unable to create peripheral link, disabling!"); peripheralLink = null; } } // Add shutdown hook if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); hookThread = new Thread(new Runnable() { public void run() { stop(true, true); shutdown(true); sleep(25); dbgListThreads(); log.info("Bye!"); } }, "Thook"); Runtime.getRuntime().addShutdownHook(hookThread); if (Config.CLIENT_SERVERLESS) { state = CLIENT_STATE_CONNECTED; sessionStart(); } else { // Setup handler for incoming requests and timeouts networkManager.setNetworkHandler(this); // Try to connect to server log.info("Connecting to server on " + properties.getServerAddress() + "..."); networkManager.serverConnect(); } if (autoTesterEnabled) { autoTester = new AutoTester(this); } }
From source file:BasicPlayer.java
public List getMixers() { ArrayList mixers = new ArrayList(); Mixer.Info[] mInfos = AudioSystem.getMixerInfo(); if (mInfos != null) { for (int i = 0; i < mInfos.length; i++) { Line.Info lineInfo = new Line.Info(SourceDataLine.class); Mixer mixer = AudioSystem.getMixer(mInfos[i]); if (mixer.isLineSupported(lineInfo)) { mixers.add(mInfos[i].getName()); }//from www. j av a 2s . c o m } } return mixers; }
From source file:BasicPlayer.java
public Mixer getMixer(String name) { Mixer mixer = null;//from w w w .j av a 2 s .c o m if (name != null) { Mixer.Info[] mInfos = AudioSystem.getMixerInfo(); if (mInfos != null) { for (int i = 0; i < mInfos.length; i++) { if (mInfos[i].getName().equals(name)) { mixer = AudioSystem.getMixer(mInfos[i]); break; } } } } return mixer; }
From source file:GUI.AllForDealFrame.java
private void btnSonOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSonOnActionPerformed // TODO add your handling code here: Mixer.Info[] mixInfo = AudioSystem.getMixerInfo(); mixer = AudioSystem.getMixer(mixInfo[0]); DataLine.Info dataLine = new DataLine.Info(Clip.class, null); try {/*from w w w . j av a 2s.c o m*/ clip = (Clip) mixer.getLine(dataLine); } catch (LineUnavailableException ex) { ex.printStackTrace(); } try { URL soundURL = this.getClass().getResource("/images/The_Eagles-Hotel_California_acoustic_live_www.wav"); AudioInputStream audioImput = AudioSystem.getAudioInputStream(soundURL); clip.open(audioImput); } catch (LineUnavailableException ex) { ex.printStackTrace(); } catch (UnsupportedAudioFileException exp) { exp.printStackTrace(); } catch (IOException io) { io.printStackTrace(); } clip.start(); }
From source file:org.eclipse.smarthome.io.javasound.internal.JavaSoundAudioSink.java
private void runVolumeCommand(Closure closure) { Mixer.Info[] infos = AudioSystem.getMixerInfo(); for (Mixer.Info info : infos) { Mixer mixer = AudioSystem.getMixer(info); if (mixer.isLineSupported(Port.Info.SPEAKER)) { Port port;// w w w. j a va 2 s. c o m try { port = (Port) mixer.getLine(Port.Info.SPEAKER); port.open(); if (port.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl volume = (FloatControl) port.getControl(FloatControl.Type.VOLUME); closure.execute(volume); } port.close(); } catch (LineUnavailableException e) { logger.error("Cannot access master volume control", e); } } } }
From source file:org.openhab.io.javasound.internal.JavaSoundAudioSink.java
private void runVolumeCommand(Closure closure) { Mixer.Info[] infos = AudioSystem.getMixerInfo(); for (Mixer.Info info : infos) { Mixer mixer = AudioSystem.getMixer(info); if (mixer.isLineSupported(Port.Info.SPEAKER)) { Port port;//from w w w . java 2 s .c o m try { port = (Port) mixer.getLine(Port.Info.SPEAKER); port.open(); if (port.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl volume = (FloatControl) port.getControl(FloatControl.Type.VOLUME); closure.execute(volume); } port.close(); } catch (LineUnavailableException e) { LOGGER.error("Cannot access master volume control", e); } } } }
From source file:org.openhab.io.multimedia.actions.Audio.java
private static void runVolumeCommand(Closure closure) { Mixer.Info[] infos = AudioSystem.getMixerInfo(); for (Mixer.Info info : infos) { Mixer mixer = AudioSystem.getMixer(info); if (mixer.isLineSupported(Port.Info.SPEAKER)) { Port port;// w ww . j a v a 2s . c o m try { port = (Port) mixer.getLine(Port.Info.SPEAKER); port.open(); if (port.isControlSupported(FloatControl.Type.VOLUME)) { FloatControl volume = (FloatControl) port.getControl(FloatControl.Type.VOLUME); closure.execute(volume); } port.close(); } catch (LineUnavailableException e) { logger.error("Cannot access master volume control", e); } } } }
From source file:org.snitko.app.record.SoundRecorder.java
public AudioInputStream record(long durationInSeconds) throws LineUnavailableException { Mixer.Info[] mixers = AudioSystem.getMixerInfo(); for (Mixer.Info mixer : mixers) { System.out.printf("mixer name/desc/vendor/version: %s, %s, %s, %s\n", mixer.getName(), mixer.getDescription(), mixer.getVendor(), mixer.getVersion()); }/*from ww w .java 2s .co m*/ AudioFileFormat.Type[] types = AudioSystem.getAudioFileTypes(); for (AudioFileFormat.Type type : types) { System.out.println("audio types are: " + type.toString()); } AudioFormat audioFormat = getAudioFormat(); // the targetDataLine from which audio data is captured TargetDataLine targetDataLine = AudioSystem.getTargetDataLine(audioFormat); System.out.println("targetDataLine: " + targetDataLine + "\n\tlineInfo" + targetDataLine.getLineInfo() + "\n\tformat: " + targetDataLine.getFormat()); // checks if system supports the data targetDataLine if (!AudioSystem.isLineSupported(targetDataLine.getLineInfo())) { System.out.println("Line not supported"); System.exit(0); } targetDataLine.addLineListener(new TimedLineListener(targetDataLine, durationInSeconds)); targetDataLine.open(audioFormat); targetDataLine.start(); // start capturing System.out.println("Start capturing..."); AudioInputStream audioInputStream = new AudioInputStream(targetDataLine); System.out.println("Start recording..."); return audioInputStream; }