How does one choose which microphone/line-in to capture from
I'm working on a program that will record audio from one or more sources. I've got it so that I can list all the TargetDataLine objects for all of the Mixers on the system at runtime. My confusion comes when I try to determine which TargetDataLine is mapped to which Port? If I have two microphone ports, or a microphone and a "line-in" jack on the sound card, is there a way to know which one the mixer is reading from? Similarly, if there is more than one speaker output, is it possible to choose which set of speakers to output to?
Right now my code for output looks like:
//
audioFormat =new AudioFormat(sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
DataLine.Info info =new DataLine.Info(SourceDataLine.class,
audioFormat);
try{
SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(info);
sdl.open(audioFormat);
sdl.start();
}catch (LineUnavailableException e){
e.printStackTrace();
}
//
and my code for input looks like:
//
audioFormat =new AudioFormat(sampleRate,
sampleSize,
channels,
sign,
endian);
try{
DataLine.Info dataLineInfo =new DataLine.Info(
TargetDataLine.class,
audioFormat);
Mixer mixer = AudioSystem.getMixer(mixerInfo);
targetDataLine = (TargetDataLine)(mixer.getLine(dataLineInfo));
}catch (Exception e){
e.printStackTrace();
}
//
Both seem to work fine, but my confusion about how to select specific inputs or outputs persists.
-Will
[2214 byte] By [
wheina] at [2007-11-27 8:32:32]

# 1
Draw the traces on-screen, and ask the user
to choose.
Here is a Java application that draws traces
of the sound lines..
http://www.physci.org/sound/audiotrace.html
It defaults to showing the first, but go to..
View | Options | Display all lines
..to see traces of all available sound lines
Here is an early, but functional, version of that code
http://www.physci.org/test/oscilloscope/AudioTrace.java
# 2
Thanks Andrew, but that doesn't really get me any farther. I am looking for a way to know *which* Line the program is listening to, and more specifically what type of line (microphone, line-in, etc.) it is. It is not enough sufficient to have the user try one or more lines through trial and error to see which is the one to listen to. In my setup there are multiple microphones, all of which may be capturing sound, but I'd like to be able to determine which "channel" of the sound card is responsible for the left microphone, center microphone, right microphone, etc. even if it is just a label that I can put on radio buttons and then let the user decide which to use. My hurdle is getting the labels automatically using the program, and then pick off their names/descriptions similar to the way the Mixer class has a getName() and a getDescription() method.
Currently I have a program that enumerates through all of the Mixers and lists their attributes. I want to extend this to include microphone and line-in jacks.
//
System.out.println("Supported audio mixers:");
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (int i=0; i<mixerInfos.length; i++) {
System.out.println("MIXER: " + mixerInfos[i].toString());
System.out.println("\t-" + mixerInfos[i].getDescription());
System.out.println("\t-" + mixerInfos[i].getName());
System.out.println("\t-" + mixerInfos[i].getVendor());
System.out.println("\t-" + mixerInfos[i].getVersion());
Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
Line.Info[] sourceLineInfos = mixer.getSourceLineInfo();
System.out.println(" Available source line infos:");
for (int j=0; j><sourceLineInfos.length; j++) {
System.out.println("\t\t-" + sourceLineInfos[j].toString());
try {
Line mixerLine = mixer.getLine(sourceLineInfos[j]);
Control[] controls = mixerLine.getControls();
for (int k=0; k><controls.length; k++) {
System.out.println("\t\t\t-" + controls[k].toString());
}
} catch (LineUnavailableException lue) {
System.err.println("Source line unavailable!");
lue.printStackTrace();
}
}
Line.Info[] targetLineInfos = mixer.getTargetLineInfo();
System.out.println(" Available target line infos:");
for (int j=0; j><targetLineInfos.length; j++) {
System.out.println("-" + targetLineInfos[j].toString());
try {
Line mixerLine = mixer.getLine(targetLineInfos[j]);
Control[] controls = mixer.getLine(targetLineInfos[j]).getControls();
for (int k=0; k><controls.length; k++) {
System.out.println("-" + controls[k].toString());
}
} catch (LineUnavailableException lue) {
System.err.println("Target line unavailable!");
lue.printStackTrace();
}
}
//
>
wheina at 2007-7-12 20:28:24 >
