通过 Java SoundSystem 使用 ALSA pcm 输出
我有一个具有多个输出的声卡,并使用 ALSA 将它们映射到 2 个独立的立体声通道。配置工作正常,并允许我使用扬声器测试来在它们上播放音频。
我现在想使用 AudioSystem API 在 Java 程序中使用这 2 个立体声输出。但是,使用 MixerInfo 不会显示立体声 1 和立体声 2。
我不太明白 Java 如何决定使用 AudioSystem API 公开哪些“设备”。我目前正在 Ubuntu 11.10 系统上对此进行测试。
这是使用的 asound.conf:
#/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 ]
}
}
这是我用来显示可用输入和输出的代码:
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.");
}
}
}
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.");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是:不。 Java 无法列出用户定义的 ALSA pcm,因为它仅公开硬件设备和“默认”设备。
从 ALSA 开发人员处获取信息:http://www.spinics。净/linux/fedora/alsa-user/msg10796.html
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