小编典典

Java Sound API在您的计算机上找到哪些输出和记录端口?

java

我正在使用Java Sound API,事实证明,如果我想调整录音量,需要对操作系统向Java公开的硬件进行建模。事实证明,呈现的内容多种多样。

因此,我很谦虚地要求任何能够帮助我在他们的计算机上运行以下命令并将结果发回的人,以便我对那里的情况有所了解。

在此先感谢任何可以提供帮助的人:-)

import javax.sound.sampled.*;
public class SoundAudit {
  public static void main(String[] args) { try {
    System.out.println("OS: "+System.getProperty("os.name")+" "+
      System.getProperty("os.version")+"/"+
      System.getProperty("os.arch")+"\nJava: "+
      System.getProperty("java.version")+" ("+
      System.getProperty("java.vendor")+")\n");
      for (Mixer.Info thisMixerInfo : AudioSystem.getMixerInfo()) {
        System.out.println("Mixer: "+thisMixerInfo.getDescription()+
          " ["+thisMixerInfo.getName()+"]");
        Mixer thisMixer = AudioSystem.getMixer(thisMixerInfo);
        for (Line.Info thisLineInfo:thisMixer.getSourceLineInfo()) {
            if (thisLineInfo.getLineClass().getName().equals(
              "javax.sound.sampled.Port")) {
              Line thisLine = thisMixer.getLine(thisLineInfo);
              thisLine.open();
              System.out.println("  Source Port: "
                +thisLineInfo.toString());
              for (Control thisControl : thisLine.getControls()) {
                System.out.println(AnalyzeControl(thisControl));}
              thisLine.close();}}
        for (Line.Info thisLineInfo:thisMixer.getTargetLineInfo()) {
          if (thisLineInfo.getLineClass().getName().equals(
            "javax.sound.sampled.Port")) {
            Line thisLine = thisMixer.getLine(thisLineInfo);
            thisLine.open();
            System.out.println("  Target Port: "
              +thisLineInfo.toString());
            for (Control thisControl : thisLine.getControls()) {
              System.out.println(AnalyzeControl(thisControl));}
            thisLine.close();}}}
  } catch (Exception e) {e.printStackTrace();}}
  public static String AnalyzeControl(Control thisControl) {
    String type = thisControl.getType().toString();
    if (thisControl instanceof BooleanControl) {
      return "    Control: "+type+" (boolean)"; }
    if (thisControl instanceof CompoundControl) {
      System.out.println("    Control: "+type+
        " (compound - values below)");
      String toReturn = "";
      for (Control children:
        ((CompoundControl)thisControl).getMemberControls()) {
        toReturn+="  "+AnalyzeControl(children)+"\n";}
      return toReturn.substring(0, toReturn.length()-1);}
    if (thisControl instanceof EnumControl) {
      return "    Control:"+type+" (enum: "+thisControl.toString()+")";}
    if (thisControl instanceof FloatControl) {
      return "    Control: "+type+" (float: from "+
        ((FloatControl) thisControl).getMinimum()+" to "+
        ((FloatControl) thisControl).getMaximum()+")";}
    return "    Control: unknown type";}
}

该应用程序所做的全部工作就是打印关于OS的一行,关于JVM的一行以及关于发现的与记录硬件有关的硬件的几行内容。例如,在工作中的PC上,我得到以下信息:

操作系统:Windows XP 5.1 / x86 Java:1.6.0_07(Sun Microsystems Inc.)

调音台:直接音频设备:DirectSound播放[主声音驱动程序]
调音台:直接音频设备:DirectSound播放[SoundMAX HD音频]
调音台:直接音频设备:DirectSound Capture [主声音捕获驱动程序]
调音台:直接音频设备:DirectSound捕获[SoundMAX HD音频]
混音器:软件混音器和合成器[Java声音音频引擎]
调音台:端口调音台[Port SoundMAX HD Audio]
  源端口:MICROPHONE源端口
    控制:麦克风(化合物-值如下)
      控制:选择(布尔值)
      控制:麦克风增强(布尔)
      控制:前面板麦克风(布尔)
      控制:音量(浮动:从0.0到1.0)
  源端口:LINE_IN源端口
    控制:行输入(化合物-值如下)
      控制:选择(布尔值)
      控制:音量(浮动:从0.0到1.0)
      控制:平衡(浮动:从-1.0到1.0)

阅读 214

收藏
2020-10-25

共1个答案

小编典典

我从来没有弄过声音API,这是一件好事。谢谢。

戴尔笔记本电脑:

Mixer: Direct Audio Device: DirectSound Playback [Primary Sound Driver]
Mixer: Direct Audio Device: DirectSound Playback [SigmaTel Audio]
Mixer: Direct Audio Device: DirectSound Capture [Primary Sound Capture Driver]
Mixer: Direct Audio Device: DirectSound Capture [SigmaTel Audio]
Mixer: Software mixer and synthesizer [Java Sound Audio Engine]
Mixer: Port Mixer [Port SigmaTel Audio]
  Source Port: Stereo Mix source port
    Control: Stereo Mix (compound - values below)
      Control: Select (boolean)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Balance (float: from -1.0 to 1.0)
  Source Port: LINE_IN source port
    Control: Line In (compound - values below)
      Control: Select (boolean)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Balance (float: from -1.0 to 1.0)
  Source Port: MICROPHONE source port
    Control: Microphone (compound - values below)
      Control: Select (boolean)
      Control: Microphone Boost (boolean)
      Control: Volume (float: from 0.0 to 1.0)
  Source Port: MICROPHONE source port
    Control: Microphone (compound - values below)
      Control: Select (boolean)
      Control: Microphone Boost (boolean)
      Control: Volume (float: from 0.0 to 1.0)
  Target Port: SPEAKER target port
    Control: Volume (float: from 0.0 to 1.0)
    Control: Balance (float: from -1.0 to 1.0)
    Control: Mute (boolean)
    Control: PC Spk Mute (boolean)
    Control: SPDIF Interface (boolean)
    Control: Wave (compound - values below)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Balance (float: from -1.0 to 1.0)
      Control: Mute (boolean)
    Control: SW Synth (compound - values below)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Balance (float: from -1.0 to 1.0)
      Control: Mute (boolean)
    Control: CD Player (compound - values below)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Balance (float: from -1.0 to 1.0)
      Control: Mute (boolean)
    Control: PC Speaker (compound - values below)
      Control: Volume (float: from 0.0 to 1.0)
      Control: Mute (boolean)
2020-10-25