Package javax.sound.sampled

Examples of javax.sound.sampled.Port


                String strMixerName = mixer.getMixerInfo().getName();
//System.out.println("Mixer: " + strMixerName);
    Port.Info[] infosToCheck = getPortInfo(mixer);
    for (int i = 0; i < infosToCheck.length; i++)
    {
                    Port port = null;
                    try
                    {
                            port = (Port) mixer.getLine(infosToCheck[i]);
                            port.open();
                    }
                    catch (LineUnavailableException e)
                    {
                         //   e.printStackTrace();
                    }
                    if (port != null)
                    {
                        String  strPortName = ((Port.Info) port.getLineInfo()).getName();
//System.out.println("Port: " + strPortName);
                        if (strPortName.toUpperCase().indexOf("MASTER") ==-1 ) continue;
                        Control[]  aControls = port.getControls();
                        for (int t = 0; t < aControls.length; t++)
                        {
                            if (aControls[t] instanceof FloatControl)
                            {
                                FloatControl control = (FloatControl) aControls[t];
View Full Code Here


                for (Mixer.Info info : mixers)
                {
                    Mixer mixer = AudioSystem.getMixer(info);
                    if (mixer.isLineSupported(Port.Info.SPEAKER))
                    {
                        Port port = (Port) mixer.getLine(Port.Info.SPEAKER);
                        boolean openPortNeeded = !port.isOpen();
                        try
                        {
                            if (openPortNeeded)
                            {
                                port.open();
                            }
                            if (port.isControlSupported(FloatControl.Type.VOLUME))
                            {
                                FloatControl volumeControl = (FloatControl) port.getControl(FloatControl.Type.VOLUME);
                                float min = volumeControl.getMinimum();
                                float max = volumeControl.getMaximum();
                                float current = volumeControl.getValue();
                                double percent = 100.0 * (current - min) / (max - min);
//                                System.out.println("Current Volume is " + percent + "%.");
    // setting to 50%
                                float v = (max - min) / 2.0f + min;
                                v = (((max - min)/100)*vol) +min;
                                volumeControl.setValue(v);
                            }

                        } finally
                        {
                            if (openPortNeeded && port.isOpen())
                            {
                                port.close();
                            }
                        }
                    }
                }
            }
View Full Code Here

                String strMixerName = mixer.getMixerInfo().getName();
//System.out.println("Mixer: " + strMixerName);
    Port.Info[] infosToCheck = getPortInfo(mixer);
    for (int i = 0; i < infosToCheck.length; i++)
    {
                    Port port = null;
                    try
                    {
                            port = (Port) mixer.getLine(infosToCheck[i]);
                            port.open();
                    }
                    catch (LineUnavailableException e)
                    {
                         //   e.printStackTrace();
                    }
                    if (port != null)
                    {
                        String  strPortName = ((Port.Info) port.getLineInfo()).getName();
//System.out.println("Port: " + strPortName);
                        if (strPortName.toUpperCase().indexOf("MASTER") ==-1 ) continue;
                        Control[]  aControls = port.getControls();
                        for (int t = 0; t < aControls.length; t++)
                        {
                            if (aControls[t] instanceof FloatControl)
                            {
                                FloatControl control = (FloatControl) aControls[t];
View Full Code Here

  public static void main(String[] args) {
    setDeviceSensitivity(10);
  }

  public static void setDeviceSensitivity(final int sensitivity) {
    final Port lineIn;
    Mixer.Info[] mixerInfoPool=AudioSystem.getMixerInfo();
   
    for (int i = 0; i < mixerInfoPool.length; i++) {
      System.out.println(mixerInfoPool[i]);
    }
   
    final Mixer mixer = AudioSystem.getMixer(mixerInfoPool[6]);
    try {
      if (mixer.isLineSupported(Port.Info.LINE_IN)) {
        lineIn = (Port) mixer.getLine(Port.Info.LINE_IN);
        lineIn.open();
      } else if (mixer.isLineSupported(Port.Info.MICROPHONE)) {
        lineIn = (Port) mixer.getLine(Port.Info.MICROPHONE);
        lineIn.open();
      } else {
        System.out.println("Unable to get Input Port");
        return;
      }
      lineIn.getControls();

      if (lineIn.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
        System.out.println("kewl");
      }

      final CompoundControl cc = (CompoundControl) lineIn.getControls()[0];
      final Control[] controls = cc.getMemberControls();
      for (final Control c : controls) {
        if (c instanceof FloatControl) {
          System.out.println("BEFORE LINE_IN VOL = "
              + ((FloatControl) c).getValue());
View Full Code Here

                                        // AudioFormat
                                        // object

    if (AudioSystem.isLineSupported(Port.Info.MICROPHONE)) {
      try {
        Port port = (Port) AudioSystem.getLine(Port.Info.MICROPHONE);
        port.open();
        System.out.println(port.getLineInfo());
//        line.open(getAudioFormat());
//        line.start();
//        while(true) {
////          System.out.println("Level: " + line.getLevel());
//        }
View Full Code Here

          }
          catch(ClassCastException e1)
          {
            try
            {
              Port sPort = (Port)mixer.getLine(sLineInfos[k]);
              System.out.println("   Port: " + sPort.getLineInfo() + "\t(Name: " + sPort + ")");
            }
            catch (LineUnavailableException e2)
            {
              e2.printStackTrace();
            }
          }
        }
       
      }
     
      Line.Info[] tLineInfos = mixer.getTargetLineInfo();
      System.out.println("  Targets (" + tLineInfos.length + "):");
      for(int k=0; k<tLineInfos.length; k++)
      {
        try
        {
          TargetDataLine tLine = (TargetDataLine)mixer.getLine(tLineInfos[k]);
          System.out.println("   Line: " + tLine.getLineInfo() + "\t(Name: " + tLine + ")");
        }
        catch (LineUnavailableException e)
        {
          e.printStackTrace();
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
         
        }
        catch(ClassCastException e)
        {
          try
          {
            Clip tClip = (Clip)mixer.getLine(tLineInfos[k]);
            System.out.println("   Clip: " + tClip.getLineInfo() + "\t(Name: " + tClip + ")");
          }
          catch (LineUnavailableException e1)
          {
            e1.printStackTrace();
          }
          catch(ClassCastException e1)
          {
            try
            {
              Port tPort = (Port)mixer.getLine(tLineInfos[k]);
              System.out.println("   Port: " + tPort.getLineInfo() + "\t(Name: " + tPort + ")");
            }
            catch (LineUnavailableException e2)
            {
              e2.printStackTrace();
            }
View Full Code Here

import javax.sound.sampled.Port;
import javax.sound.sampled.Mixer.Info;

public class SoundMicroTest4 {
  public static void main(String[] args) throws LineUnavailableException {
    Port lineIn = null;
    FloatControl volCtrl = null;
    Mixer mixer = null;

    Mixer.Info[] mixerInfoPool = AudioSystem.getMixerInfo();
    for (int i = 0; i < mixerInfoPool.length; i++) {
      Info info = mixerInfoPool[i];

      mixer = AudioSystem.getMixer(info);
      final int maxLines = mixer.getMaxLines(Port.Info.MICROPHONE);
      if (maxLines > 0) {
        System.out.println(info);
        lineIn = (Port) mixer.getLine(Port.Info.MICROPHONE);
        lineIn.open();
        Control[] controls = lineIn.getControls();
        for (int j = 0; j < controls.length; j++) {
          Control control = controls[j];
          System.out.println(control);
        }
//        volCtrl = (FloatControl) lineIn
View Full Code Here

  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;
        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);
        }
      }
    }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.Port

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.