I have a sound card with multiple outputs and use ALSA to map them to 2 separate stereo channels. The configuration works fine and allows me, for example with speaker-test to play audio on them.
I now want to use those 2 stereo outputs in a Java program, using the AudioSystem API. However, the stereo1 and stereo2 dont' show up using MixerInfo.
I do not really understand how Java decides which "devices" to expose using the AudioSystem API. I'm currently testing this on an Ubuntu 11.10 system.
This is the asound.conf used:
#/etc/asound.conf
pcm_slave.fourchannels {
pcm "hw:0,0"
channels 4
}
pcm.stereo1 {
type plug
slave.pcm {
type dshare
ipc_key 87882222
slave fourchannels
bindings [ 0 1 ]
}
}
pcm.stereo2 {
type plug
slave.pcm {
type dshare
ipc_key 87882222
slave fourchannels
bindings [ 2 3 ]
}
}
This is the code I'm using to show the available inputs and outputs:
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixers) {
System.out.println("Found Mixer: " + mixerInfo);
Mixer m = AudioSystem.getMixer(mixerInfo);
Line.Info[] sourceLines = m.getSourceLineInfo();
for (Line.Info li : sourceLines) {
System.out.println(" Found source line: " + li);
try {
m.open();
} catch (LineUnavailableException e) {
System.out.println(" Line unavailable.");
}
}
Line.Info[] targetLines = m.getTargetLineInfo();
for (Line.Info li : targetLines) {
System.out.println(" Found source line: " + li);
try {
m.open();
} catch (LineUnavailableException e) {
System.out.println(" Line unavailable.");
}
}
}
The answer is: no. Java is not able to list the user-defined ALSA pcms, as it exposes only the hardware devices and the "default" device.
Got the info from an ALSA dev here: http://www.spinics.net/linux/fedora/alsa-user/msg10796.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With