What output and recording ports does the Java Sound API find on your computer?
Posted
by Dave Carpeneto
on Stack Overflow
See other posts from Stack Overflow
or by Dave Carpeneto
Published on 2009-02-18T18:26:17Z
Indexed on
2010/04/09
0:23 UTC
Read the original article
Hit count: 727
Hi all - I'm working with the Java Sound API, and it turns out if I want to adjust recording volumes I need to model the hardware that the OS exposes to Java. Turns out there's a lot of variety in what's presented.
Because of this I'm humbly asking that anyone able to help me run the following on their computer and post back the results so that I can get an idea of what's out there.
A thanks in advance to anyone that can assist :-)
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";}
}
All the application does is print out a line about the OS, a line about the JVM, and a few lines about the hardware found that may pertain to recording hardware. For example on my PC at work I get the following:
OS: Windows XP 5.1/x86
Java: 1.6.0_07 (Sun Microsystems Inc.)
Mixer: Direct Audio Device: DirectSound Playback [Primary Sound Driver]
Mixer: Direct Audio Device: DirectSound Playback [SoundMAX HD Audio]
Mixer: Direct Audio Device: DirectSound Capture [Primary Sound Capture Driver]
Mixer: Direct Audio Device: DirectSound Capture [SoundMAX HD Audio]
Mixer: Software mixer and synthesizer [Java Sound Audio Engine]
Mixer: Port Mixer [Port SoundMAX HD Audio]
Source Port: MICROPHONE source port
Control: Microphone (compound - values below)
Control: Select (boolean)
Control: Microphone Boost (boolean)
Control: Front panel microphone (boolean)
Control: Volume (float: from 0.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)
© Stack Overflow or respective owner