Package audio

Source Code of audio.SoundMicroTest3

package audio;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.CompoundControl;
import javax.sound.sampled.Control;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Port;

public class SoundMicroTest3 {
  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());
          ((FloatControl) c).setValue((float) sensitivity / 100);
          System.out.println("AFTER LINE_IN VOL = "
              + ((FloatControl) c).getValue());
        }
      }
    } catch (final Exception e) {
      System.out.println(e);
    }
  }
}
TOP

Related Classes of audio.SoundMicroTest3

TOP
Copyright © 2018 www.massapi.com. 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.